|
Line 0
Link Here
|
|
|
1 |
/* |
| 2 |
|
| 3 |
ark -- archiver for the KDE project |
| 4 |
|
| 5 |
Copyright (C) |
| 6 |
|
| 7 |
1997-1999: Rob Palmbos palm9744@kettering.edu |
| 8 |
1999: Francois-Xavier Duranceau duranceau@kde.org |
| 9 |
1999-2000: Corel Corporation (author: Emily Ezust, emilye@corel.com) |
| 10 |
2001: Corel Corporation (author: Michael Jarrett, michaelj@corel.com) |
| 11 |
2007: ALT Linux (author: Sergey V Turchin, zerg@altlinux.org) |
| 12 |
|
| 13 |
This program is free software; you can redistribute it and/or |
| 14 |
modify it under the terms of the GNU General Public License |
| 15 |
as published by the Free Software Foundation; either version 2 |
| 16 |
of the License, or (at your option) any later version. |
| 17 |
|
| 18 |
This program is distributed in the hope that it will be useful, |
| 19 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 |
GNU General Public License for more details. |
| 22 |
|
| 23 |
You should have received a copy of the GNU General Public License |
| 24 |
along with this program; if not, write to the Free Software |
| 25 |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 26 |
|
| 27 |
*/ |
| 28 |
|
| 29 |
|
| 30 |
// Qt includes |
| 31 |
#include <qdir.h> |
| 32 |
#include <qtextcodec.h> |
| 33 |
|
| 34 |
// KDE includes |
| 35 |
#include <kdebug.h> |
| 36 |
#include <klocale.h> |
| 37 |
#include <kmessagebox.h> |
| 38 |
#include <kprocess.h> |
| 39 |
#include <kpassdlg.h> |
| 40 |
|
| 41 |
// ark includes |
| 42 |
#include "arj.h" |
| 43 |
#include "arkwidget.h" |
| 44 |
#include "settings.h" |
| 45 |
|
| 46 |
|
| 47 |
ArjArch::ArjArch( ArkWidget *_gui, const QString & _fileName ) |
| 48 |
: Arch( _gui, _fileName ) |
| 49 |
{ |
| 50 |
m_archiver_program = "arj"; |
| 51 |
m_unarchiver_program = "arj"; |
| 52 |
verifyCompressUtilityIsAvailable( m_archiver_program ); |
| 53 |
verifyUncompressUtilityIsAvailable( m_unarchiver_program ); |
| 54 |
|
| 55 |
m_headerString = "-----------"; |
| 56 |
m_numCols = 6; |
| 57 |
} |
| 58 |
|
| 59 |
void ArjArch::setHeaders() |
| 60 |
{ |
| 61 |
ColumnList list; |
| 62 |
list.append( FILENAME_COLUMN ); |
| 63 |
list.append( SIZE_COLUMN ); |
| 64 |
list.append( PACKED_COLUMN ); |
| 65 |
list.append( RATIO_COLUMN ); |
| 66 |
list.append( TIMESTAMP_COLUMN ); |
| 67 |
list.append( PERMISSION_COLUMN ); |
| 68 |
|
| 69 |
emit headers( list ); |
| 70 |
} |
| 71 |
|
| 72 |
void ArjArch::create() |
| 73 |
{ |
| 74 |
emit sigCreate( this, true, m_filename, |
| 75 |
Arch::Extract | Arch::Delete | Arch::Add | Arch::View ); |
| 76 |
} |
| 77 |
|
| 78 |
void ArjArch::createPassword() |
| 79 |
{ |
| 80 |
if( m_password.isEmpty() && ArkSettings::askCreatePassword() ) |
| 81 |
KPasswordDialog::getNewPassword( m_password, i18n("Warning!\nUsing KGpg for encryption is more secure.\nCancel this dialog or enter password for %1 archiver:").arg(m_archiver_program) ); |
| 82 |
} |
| 83 |
|
| 84 |
|
| 85 |
void ArjArch::addDir( const QString & _dirName ) |
| 86 |
{ |
| 87 |
if ( !_dirName.isEmpty() ) |
| 88 |
{ |
| 89 |
QStringList list; |
| 90 |
list.append( _dirName ); |
| 91 |
addFile( list ); |
| 92 |
} |
| 93 |
} |
| 94 |
|
| 95 |
void ArjArch::addFile( const QStringList & urls ) |
| 96 |
{ |
| 97 |
KProcess *kp = m_currentProcess = new KProcess; |
| 98 |
|
| 99 |
kp->clearArguments(); |
| 100 |
*kp << m_archiver_program; |
| 101 |
*kp << "a"; |
| 102 |
|
| 103 |
if ( ArkSettings::replaceOnlyWithNewer() ) |
| 104 |
*kp << "-u"; |
| 105 |
|
| 106 |
if ( ArkSettings::rarRecurseSubdirs() ) |
| 107 |
*kp << "-r"; |
| 108 |
|
| 109 |
if ( !m_password.isEmpty() ) |
| 110 |
*kp << "-g"+m_password; |
| 111 |
|
| 112 |
*kp << m_filename; |
| 113 |
|
| 114 |
KURL dir( urls.first() ); |
| 115 |
QDir::setCurrent( dir.directory() ); |
| 116 |
|
| 117 |
QStringList::ConstIterator iter; |
| 118 |
for ( iter = urls.begin(); iter != urls.end(); ++iter ) |
| 119 |
{ |
| 120 |
KURL url( *iter ); |
| 121 |
*kp << url.fileName(); |
| 122 |
} |
| 123 |
|
| 124 |
connect( kp, SIGNAL( receivedStdout(KProcess*, char*, int) ), |
| 125 |
SLOT( slotReceivedOutput(KProcess*, char*, int) ) ); |
| 126 |
connect( kp, SIGNAL( receivedStderr(KProcess*, char*, int) ), |
| 127 |
SLOT( slotReceivedOutput(KProcess*, char*, int) ) ); |
| 128 |
connect( kp, SIGNAL( processExited(KProcess*) ), |
| 129 |
SLOT( slotAddExited(KProcess*) ) ); |
| 130 |
|
| 131 |
if ( !kp->start( KProcess::NotifyOnExit, KProcess::AllOutput ) ) |
| 132 |
{ |
| 133 |
KMessageBox::error( 0, i18n( "Could not start a subprocess." ) ); |
| 134 |
emit sigAdd( false ); |
| 135 |
} |
| 136 |
} |
| 137 |
|
| 138 |
bool ArjArch::processLine( const QCString &line ) |
| 139 |
{ |
| 140 |
QString unicode_line; |
| 141 |
|
| 142 |
QTextCodec *codec = QTextCodec::codecForLocale(); |
| 143 |
QTextCodec *codec_alt = QTextCodec::codecForName("CP1251"); |
| 144 |
unicode_line = codec->toUnicode( line ); |
| 145 |
|
| 146 |
QStringList list; |
| 147 |
|
| 148 |
QStringList l2 = QStringList::split( ' ', line ); |
| 149 |
if( l2.size() >= 2 && l2[0].endsWith(")") && l2[0].length() == 4 ) |
| 150 |
{ |
| 151 |
file_entry = line.mid(4); |
| 152 |
} |
| 153 |
else if( l2.size() > 3 ) |
| 154 |
{ |
| 155 |
if( l2[1] == "UNIX" ) |
| 156 |
list << codec->toUnicode(file_entry).stripWhiteSpace(); // filename |
| 157 |
else |
| 158 |
list << codec_alt->toUnicode(file_entry).stripWhiteSpace(); // filename |
| 159 |
|
| 160 |
list << l2[ 2 ]; // size |
| 161 |
list << l2[ 3 ]; // packed |
| 162 |
double ratio = l2[4].toDouble(); |
| 163 |
if( ratio == 0 ) |
| 164 |
ratio = 1; |
| 165 |
list << QString("%1").arg(100-100/ratio); // ratio |
| 166 |
|
| 167 |
QStringList date = QStringList::split( '-', l2[ 5 ] ); |
| 168 |
list << ArkUtils::fixYear( date[ 0 ].latin1() ) + '-' + date[ 1 ] + '-' + date [ 2 ] + ' ' + l2[6]; // date |
| 169 |
list << l2[ 7 ]; // attributes |
| 170 |
|
| 171 |
m_gui->fileList()->addItem( list ); // send to GUI |
| 172 |
|
| 173 |
file_entry = ""; |
| 174 |
} |
| 175 |
|
| 176 |
return true; |
| 177 |
} |
| 178 |
|
| 179 |
|
| 180 |
void ArjArch::open() |
| 181 |
{ |
| 182 |
setHeaders(); |
| 183 |
|
| 184 |
m_buffer = ""; |
| 185 |
m_header_removed = false; |
| 186 |
m_finished = false; |
| 187 |
|
| 188 |
KProcess *kp = m_currentProcess = new KProcess; |
| 189 |
|
| 190 |
*kp << m_unarchiver_program << "v" << m_filename; |
| 191 |
|
| 192 |
connect( kp, SIGNAL( receivedStdout(KProcess*, char*, int) ), |
| 193 |
SLOT( slotReceivedTOC(KProcess*, char*, int) ) ); |
| 194 |
connect( kp, SIGNAL( receivedStderr(KProcess*, char*, int) ), |
| 195 |
SLOT( slotReceivedOutput(KProcess*, char*, int) ) ); |
| 196 |
connect( kp, SIGNAL( processExited(KProcess*) ), |
| 197 |
SLOT( slotOpenExited(KProcess*) ) ); |
| 198 |
|
| 199 |
if ( !kp->start( KProcess::NotifyOnExit, KProcess::AllOutput ) ) |
| 200 |
{ |
| 201 |
KMessageBox::error( 0, i18n( "Could not start a subprocess." ) ); |
| 202 |
emit sigOpen( this, false, QString::null, 0 ); |
| 203 |
} |
| 204 |
} |
| 205 |
|
| 206 |
void ArjArch::unarchFileInternal() |
| 207 |
{ |
| 208 |
// if fileList is empty, all files are extracted. |
| 209 |
// if destDir is empty, abort with error. |
| 210 |
if ( m_destDir.isEmpty() || m_destDir.isNull() ) |
| 211 |
{ |
| 212 |
kdError( 1601 ) << "There was no extract directory given." << endl; |
| 213 |
return; |
| 214 |
} |
| 215 |
|
| 216 |
KProcess *kp = m_currentProcess = new KProcess; |
| 217 |
kp->clearArguments(); |
| 218 |
|
| 219 |
*kp << m_unarchiver_program; |
| 220 |
*kp << "x"; |
| 221 |
|
| 222 |
if ( !m_password.isEmpty() ) |
| 223 |
*kp << "-g" + m_password; |
| 224 |
|
| 225 |
if ( ArkSettings::extractOverwrite() ) |
| 226 |
*kp << "-jyo"; |
| 227 |
|
| 228 |
*kp << "-jycv"; |
| 229 |
|
| 230 |
*kp << "-w" + m_destDir; |
| 231 |
*kp << "-ht" + m_destDir; |
| 232 |
|
| 233 |
QTextCodec *codec = QTextCodec::codecForLocale(); |
| 234 |
*kp << codec->fromUnicode(m_filename); |
| 235 |
|
| 236 |
// if the list is empty, no filenames go on the command line, |
| 237 |
// and we then extract everything in the archive. |
| 238 |
if ( m_fileList ) |
| 239 |
{ |
| 240 |
QStringList::Iterator it; |
| 241 |
|
| 242 |
for ( it = m_fileList->begin(); it != m_fileList->end(); ++it ) |
| 243 |
{ |
| 244 |
*kp << codec->fromUnicode(*it); |
| 245 |
} |
| 246 |
} |
| 247 |
|
| 248 |
connect( kp, SIGNAL( receivedStdout(KProcess*, char*, int) ), |
| 249 |
SLOT( slotReceivedOutput(KProcess*, char*, int) ) ); |
| 250 |
connect( kp, SIGNAL( receivedStderr(KProcess*, char*, int) ), |
| 251 |
SLOT( slotReceivedOutput(KProcess*, char*, int) ) ); |
| 252 |
connect( kp, SIGNAL( processExited(KProcess*) ), |
| 253 |
SLOT( slotExtractExited(KProcess*) ) ); |
| 254 |
|
| 255 |
if ( !kp->start( KProcess::NotifyOnExit, KProcess::AllOutput ) ) |
| 256 |
{ |
| 257 |
KMessageBox::error( 0, i18n( "Could not start a subprocess." ) ); |
| 258 |
emit sigExtract( false ); |
| 259 |
} |
| 260 |
} |
| 261 |
|
| 262 |
bool ArjArch::passwordRequired() |
| 263 |
{ |
| 264 |
return m_lastShellOutput.findRev("File is password encrypted") != -1; |
| 265 |
} |
| 266 |
|
| 267 |
void ArjArch::remove( QStringList *list ) |
| 268 |
{ |
| 269 |
if ( !list ) |
| 270 |
return; |
| 271 |
|
| 272 |
KProcess *kp = m_currentProcess = new KProcess; |
| 273 |
kp->clearArguments(); |
| 274 |
|
| 275 |
*kp << m_archiver_program << "d" << m_filename; |
| 276 |
|
| 277 |
QStringList::Iterator it; |
| 278 |
for ( it = list->begin(); it != list->end(); ++it ) |
| 279 |
{ |
| 280 |
QString str = *it; |
| 281 |
*kp << str; |
| 282 |
} |
| 283 |
|
| 284 |
connect( kp, SIGNAL( receivedStdout(KProcess*, char*, int) ), |
| 285 |
SLOT( slotReceivedOutput(KProcess*, char*, int) ) ); |
| 286 |
connect( kp, SIGNAL( receivedStderr(KProcess*, char*, int) ), |
| 287 |
SLOT( slotReceivedOutput(KProcess*, char*, int) ) ); |
| 288 |
connect( kp, SIGNAL( processExited(KProcess*) ), |
| 289 |
SLOT( slotDeleteExited(KProcess*) ) ); |
| 290 |
|
| 291 |
if ( !kp->start( KProcess::NotifyOnExit, KProcess::AllOutput ) ) |
| 292 |
{ |
| 293 |
KMessageBox::error( 0, i18n( "Could not start a subprocess." ) ); |
| 294 |
emit sigDelete( false ); |
| 295 |
} |
| 296 |
} |
| 297 |
|
| 298 |
void ArjArch::test() |
| 299 |
{ |
| 300 |
clearShellOutput(); |
| 301 |
|
| 302 |
KProcess *kp = m_currentProcess = new KProcess; |
| 303 |
kp->clearArguments(); |
| 304 |
|
| 305 |
*kp << m_unarchiver_program << "t"; |
| 306 |
|
| 307 |
if ( !m_password.isEmpty() ) |
| 308 |
*kp << "-g" + m_password; |
| 309 |
|
| 310 |
*kp << m_filename; |
| 311 |
|
| 312 |
connect( kp, SIGNAL( receivedStdout(KProcess*, char*, int) ), |
| 313 |
SLOT( slotReceivedOutput(KProcess*, char*, int) ) ); |
| 314 |
connect( kp, SIGNAL( receivedStderr(KProcess*, char*, int) ), |
| 315 |
SLOT( slotReceivedOutput(KProcess*, char*, int) ) ); |
| 316 |
connect( kp, SIGNAL( processExited(KProcess*) ), |
| 317 |
SLOT( slotTestExited(KProcess*) ) ); |
| 318 |
|
| 319 |
if ( !kp->start( KProcess::NotifyOnExit, KProcess::AllOutput ) ) |
| 320 |
{ |
| 321 |
KMessageBox::error( 0, i18n( "Could not start a subprocess." ) ); |
| 322 |
emit sigTest( false ); |
| 323 |
} |
| 324 |
} |
| 325 |
|
| 326 |
#include "arj.moc" |