|
Lines 25-35
Link Here
|
| 25 |
|
25 |
|
| 26 |
// Std includes |
26 |
// Std includes |
| 27 |
#include <sys/errno.h> |
27 |
#include <sys/errno.h> |
|
|
28 |
#include <assert.h> |
| 28 |
#include <unistd.h> |
29 |
#include <unistd.h> |
| 29 |
#include <iostream> |
30 |
#include <iostream> |
| 30 |
#include <string> |
31 |
#include <string> |
| 31 |
|
32 |
|
| 32 |
// QT includes |
33 |
// QT includes |
|
|
34 |
#include <tqstring.h> |
| 35 |
#include <tqregexp.h> |
| 33 |
#include <tqfile.h> |
36 |
#include <tqfile.h> |
| 34 |
#include <tqdir.h> |
37 |
#include <tqdir.h> |
| 35 |
#include <tqtextcodec.h> |
38 |
#include <tqtextcodec.h> |
|
Lines 39-44
Link Here
|
| 39 |
#include <tdeglobal.h> |
42 |
#include <tdeglobal.h> |
| 40 |
#include <tdelocale.h> |
43 |
#include <tdelocale.h> |
| 41 |
#include <tdemessagebox.h> |
44 |
#include <tdemessagebox.h> |
|
|
45 |
#include <kmimetype.h> |
| 42 |
#include <kpassdlg.h> |
46 |
#include <kpassdlg.h> |
| 43 |
#include <kprocess.h> |
47 |
#include <kprocess.h> |
| 44 |
#include <kstandarddirs.h> |
48 |
#include <kstandarddirs.h> |
|
Lines 83-176
RarArch::RarArch( ArkWidget *_gui, const TQString & _fileName )
Link Here
|
| 83 |
verifyUncompressUtilityIsAvailable( m_unarchiver_program ); |
87 |
verifyUncompressUtilityIsAvailable( m_unarchiver_program ); |
| 84 |
setReadOnly( true ); |
88 |
setReadOnly( true ); |
| 85 |
} |
89 |
} |
| 86 |
|
|
|
| 87 |
m_headerString = ""; |
| 88 |
} |
90 |
} |
| 89 |
|
91 |
|
| 90 |
bool RarArch::processLine( const TQCString &line ) |
92 |
bool RarArch::processLine( const TQCString &line ) |
| 91 |
{ |
93 |
{ |
| 92 |
TQString unicode_line; |
94 |
TQString uline = TQTextCodec::codecForLocale()->toUnicode(line); |
| 93 |
|
95 |
|
| 94 |
TQTextCodec *codec = TQTextCodec::codecForLocale(); |
96 |
// Look for rar/unrar version first |
| 95 |
unicode_line = codec->toUnicode( line ); |
97 |
if (!m_version) |
| 96 |
|
|
|
| 97 |
// Look for rar/unrar version first |
| 98 |
if (!m_version) |
| 99 |
{ |
| 100 |
if (line.left(3) == "RAR") |
| 101 |
{ |
| 102 |
bool ok_flag = false; |
| 103 |
short version = line.mid(4, 1).toShort(&ok_flag); |
| 104 |
if (ok_flag) |
| 105 |
{ |
| 106 |
m_version = version; |
| 107 |
if (m_version < VERSION_5) |
| 108 |
{ |
| 109 |
m_headerString = "-------------------------------------------------------------------------------"; |
| 110 |
m_isFirstLine = true; |
| 111 |
} |
| 112 |
else |
| 113 |
{ |
| 114 |
m_headerString = "----------- --------- -------- ----- ---------- ----- -------- ----"; |
| 115 |
} |
| 116 |
setHeaders(); |
| 117 |
return true; |
| 118 |
} |
| 119 |
} |
| 120 |
return false; |
| 121 |
} |
| 122 |
|
| 123 |
if (m_version < VERSION_5 && m_isFirstLine) |
| 124 |
{ |
98 |
{ |
| 125 |
m_entryFilename = TQString::fromLocal8Bit( line ); |
99 |
TQRegExp versionRegExp (TQString::fromLatin1 ("RAR\\s(\\d+)\\.(\\S+)\\s.*")); |
| 126 |
m_entryFilename.remove( 0, 1 ); |
100 |
|
| 127 |
m_isFirstLine = false; |
101 |
if (versionRegExp.exactMatch (uline)) |
| 128 |
return true; |
102 |
{ |
|
|
103 |
m_version = versionRegExp.capturedTexts()[1].toShort (); |
| 104 |
|
| 105 |
if (m_version < VERSION_5) { |
| 106 |
m_headerString = "-------------------------------------------------------------------------------"; |
| 107 |
m_isFirstLine = true; |
| 108 |
} else { |
| 109 |
m_headerString = "----------- --------- -------- ----- ---------- ----- -------- ----"; |
| 110 |
} |
| 111 |
setHeaders(); //< Note: header order for version 5 is different, but keep the old one for consistency |
| 112 |
return true; |
| 113 |
} |
| 114 |
return false; |
| 129 |
} |
115 |
} |
| 130 |
|
116 |
|
| 131 |
TQStringList list; |
117 |
TQStringList entry; |
| 132 |
TQStringList l2 = TQStringList::split( ' ', line ); |
118 |
TQStringList parsedData = TQStringList::split(QChar(' '), uline); |
| 133 |
|
119 |
|
| 134 |
if (m_version < VERSION_5) |
120 |
if (m_version < VERSION_5) { |
|
|
121 |
if (m_isFirstLine) |
| 122 |
{ |
| 123 |
m_entryFilename = uline.remove( 0, 1 ); |
| 124 |
m_isFirstLine = false; |
| 125 |
return true; |
| 126 |
} |
| 127 |
|
| 128 |
if (parsedData.size() < 9) { |
| 129 |
kdError ( 1601 ) << "Failed to parse rar<5 output string: \"" << uline << "\"" << endl; |
| 130 |
} |
| 131 |
|
| 132 |
entry << m_entryFilename; // filename |
| 133 |
entry << parsedData[ 0 ]; // size |
| 134 |
entry << parsedData[ 1 ]; // packed |
| 135 |
entry << parsedData[ 2 ]; // ratio |
| 136 |
|
| 137 |
TQStringList date = TQStringList::split( '-', parsedData[ 3 ] ); |
| 138 |
entry << ArkUtils::fixYear( date[ 2 ].latin1() ) + '-' + date[ 1 ] + '-' + date [ 0 ] + ' ' + parsedData[4]; // date |
| 139 |
entry << parsedData[ 5 ]; // attributes |
| 140 |
entry << parsedData[ 6 ]; // crc |
| 141 |
entry << parsedData[ 7 ]; // method |
| 142 |
entry << parsedData[ 8 ]; // Version |
| 143 |
|
| 144 |
m_isFirstLine = true; |
| 145 |
} |
| 146 |
else |
| 135 |
{ |
147 |
{ |
| 136 |
list << m_entryFilename; // filename |
148 |
// Note: don't use parsedData for names due to they may contain trailing spaces |
| 137 |
list << l2[ 0 ]; // size |
149 |
TQRegExp nameRegExp (TQString::fromLatin1 ("\\s*(\\S+\\s+){6}\\S+ (.*)")); |
| 138 |
list << l2[ 1 ]; // packed |
150 |
|
| 139 |
list << l2[ 2 ]; // ratio |
151 |
if (parsedData.size() >= 8 && nameRegExp.exactMatch (uline)) { |
| 140 |
|
152 |
m_entryFilename = nameRegExp.capturedTexts()[2]; |
| 141 |
TQStringList date = TQStringList::split( '-', l2[ 3 ] ); |
153 |
|
| 142 |
list << ArkUtils::fixYear( date[ 2 ].latin1() ) + '-' + date[ 1 ] + '-' + date [ 0 ] + ' ' + l2[4]; // date |
154 |
entry << m_entryFilename; // filename |
| 143 |
list << l2[ 5 ]; // attributes |
155 |
entry << parsedData[ 1 ]; // size |
| 144 |
list << l2[ 6 ]; // crc |
156 |
entry << parsedData[ 2 ]; // packed |
| 145 |
list << l2[ 7 ]; // method |
157 |
entry << parsedData[ 3 ]; // ratio |
| 146 |
list << l2[ 8 ]; // Version |
158 |
|
| 147 |
|
159 |
entry << parsedData[ 4 ] + " " + parsedData[ 5 ]; // date and time |
| 148 |
m_isFirstLine = true; |
160 |
entry << parsedData[ 0 ]; // attributes |
| 149 |
} |
161 |
entry << parsedData[ 6 ]; // crc |
| 150 |
else |
162 |
} else { |
| 151 |
{ |
163 |
kdError ( 1601 ) << "Failed to parse rar-5+ output string: \"" << uline << "\"" << endl; |
| 152 |
m_entryFilename = line.mid(line.find(l2[7])); |
164 |
return false; |
| 153 |
list << m_entryFilename; // filename |
165 |
} |
| 154 |
list << l2[ 1 ]; // size |
166 |
} |
| 155 |
list << l2[ 2 ]; // packed |
167 |
|
| 156 |
list << l2[ 3 ]; // ratio |
168 |
// send to GUI |
| 157 |
|
169 |
// Use addOrUpdateItem() rather than addItem() due to recent RAR version |
| 158 |
TQStringList date = TQStringList::split('-', l2[4]); |
170 |
// place directories in archive after their content. |
| 159 |
list << l2[ 4 ] + " " + l2[ 5 ]; // date and time |
171 |
FileLVI *item = m_gui->fileList()->addOrUpdateItem( entry ); |
| 160 |
list << l2[ 0 ]; // attributes |
172 |
|
| 161 |
list << l2[ 6 ]; // crc |
173 |
// But archives packaged with older versions of ark may have directories |
| 162 |
} |
174 |
// entries first, so make sure they will get apropriate icon |
| 163 |
// send to GUI |
175 |
if (entry[5].find('d', 0, /*cs=*/ false) != -1) { |
| 164 |
if ( l2[6] == "00000000" ) |
176 |
// check attr's for d (case insansitive to handle windows archives) |
| 165 |
{ |
177 |
assert (item); |
| 166 |
// folders have CRC equal to 00000000 |
178 |
item->setPixmap( 0, KMimeType::mimeType( "inode/directory" )->pixmap( TDEIcon::Small ) ); |
| 167 |
// RAR utilities show the folders at the end of the listing so the folders |
179 |
} |
| 168 |
// have been already added to the listview at this point without specifying |
180 |
|
| 169 |
// all the columns but the name. Update the item with the missing info |
|
|
| 170 |
m_gui->fileList()->updateItem( list ); |
| 171 |
} |
| 172 |
else |
| 173 |
m_gui->fileList()->addItem( list ); |
| 174 |
return true; |
181 |
return true; |
| 175 |
} |
182 |
} |
| 176 |
|
183 |
|
|
Lines 216-224
void RarArch::setHeaders()
Link Here
|
| 216 |
list.append( CRC_COLUMN ); |
223 |
list.append( CRC_COLUMN ); |
| 217 |
if (m_version < VERSION_5) |
224 |
if (m_version < VERSION_5) |
| 218 |
{ |
225 |
{ |
| 219 |
list.append( METHOD_COLUMN ); |
226 |
list.append( METHOD_COLUMN ); |
| 220 |
list.append( VERSION_COLUMN ); |
227 |
list.append( VERSION_COLUMN ); |
| 221 |
} |
228 |
} |
| 222 |
emit headers( list ); |
229 |
emit headers( list ); |
| 223 |
} |
230 |
} |
| 224 |
|
231 |
|
| 225 |
- |
|
|