From 74f40aa76a59135eefdb30a61638799f66490bf1 Mon Sep 17 00:00:00 2001 From: Slávek Banko Date: Sun, 17 Jun 2012 19:09:27 +0200 Subject: [Ark] Repairs and extensions Added support for Arj Added support for check archives Added support for password processing Fix show broken filenames into real UTF-8 This closes Bug 1030 (cherry picked from commit 1c84948d57c174bcd9732a5a0a51d42d3626d000) --- ark/sevenzip.cpp | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 2 deletions(-) (limited to 'ark/sevenzip.cpp') diff --git a/ark/sevenzip.cpp b/ark/sevenzip.cpp index 216fb8d..c1dc7a7 100644 --- a/ark/sevenzip.cpp +++ b/ark/sevenzip.cpp @@ -25,6 +25,7 @@ */ #include +#include #include #include @@ -120,6 +121,12 @@ void SevenZipArch::create() Arch::Extract | Arch::Delete | Arch::Add | Arch::View ); } +void SevenZipArch::createPassword() +{ + if( m_password.isEmpty() && ArkSettings::askCreatePassword() ) + 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) ); +} + void SevenZipArch::addFile( const TQStringList & urls ) { KProcess *kp = m_currentProcess = new KProcess; @@ -127,6 +134,9 @@ void SevenZipArch::addFile( const TQStringList & urls ) kp->clearArguments(); *kp << m_archiver_program << "a" ; + if ( !m_password.isEmpty() ) + *kp << "-p" + m_password; + KURL url( urls.first() ); TQDir::setCurrent( url.directory() ); @@ -163,6 +173,11 @@ void SevenZipArch::addDir( const TQString & dirName ) } } +bool SevenZipArch::passwordRequired() +{ + return m_lastShellOutput.find("Enter password") >= 0; +} + void SevenZipArch::remove( TQStringList *list ) { if ( !list ) @@ -212,6 +227,12 @@ void SevenZipArch::unarchFileInternal( ) //*kp << "-ao"; } + // FIXME overwrite existing files created with wrong password + *kp << "-y"; + + if ( !m_password.isEmpty() ) + *kp << "-p" + m_password; + *kp << m_filename; // if the file list is empty, no filenames go on the command line, @@ -243,12 +264,15 @@ void SevenZipArch::unarchFileInternal( ) bool SevenZipArch::processLine( const TQCString& _line ) { - TQCString line( _line ); + TQString line; TQString columns[ 11 ]; unsigned int pos = 0; int strpos, len; - columns[ 0 ] = line.right( line.length() - m_nameColumnPos +1); + TQTextCodec *codec = TQTextCodec::codecForLocale(); + line = codec->toUnicode( _line ); + + columns[ 0 ] = line.right( line.length() - m_nameColumnPos); line.truncate( m_nameColumnPos ); // Go through our columns, try to pick out data, return silently on failure @@ -275,6 +299,8 @@ bool SevenZipArch::processLine( const TQCString& _line ) columns[ curCol->colRef ] = line.mid( strpos, len ); } + // Separated directories pass + if(columns[4].length() && columns[4][0] == 'D') return true; if ( m_dateCol >= 0 ) { @@ -364,4 +390,32 @@ void SevenZipArch::slotReceivedTOC( KProcess*, char* data, int length ) data[ length ] = endchar; } +void SevenZipArch::test() +{ + clearShellOutput(); + + KProcess *kp = m_currentProcess = new KProcess; + kp->clearArguments(); + + *kp << m_unarchiver_program << "t"; + + if ( !m_password.isEmpty() ) + *kp << "-p" + m_password; + + *kp << m_filename; + + connect( kp, SIGNAL( receivedStdout(KProcess*, char*, int) ), + SLOT( slotReceivedOutput(KProcess*, char*, int) ) ); + connect( kp, SIGNAL( receivedStderr(KProcess*, char*, int) ), + SLOT( slotReceivedOutput(KProcess*, char*, int) ) ); + connect( kp, SIGNAL( processExited(KProcess*) ), + SLOT( slotTestExited(KProcess*) ) ); + + if ( !kp->start( KProcess::NotifyOnExit, KProcess::AllOutput ) ) + { + KMessageBox::error( 0, i18n( "Could not start a subprocess." ) ); + emit sigTest( false ); + } +} + #include "sevenzip.moc" -- cgit v1.2.3