@ -26,15 +26,15 @@
* the Free Software Foundation ; either version 2 of the License , or *
* the Free Software Foundation ; either version 2 of the License , or *
* ( at your option ) any later version . *
* ( at your option ) any later version . *
* *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
// QT includes
// QT includes
# include <tqtextstream.h>
# include <tqtextstream.h>
// KDE includes
// KDE includes
# include <kprocess.h>
# include <kprocess.h>
# include <tdetempfile.h>
# include <tdetempfile.h>
# include <tdelocale.h>
# include <tdelocale.h>
# include <tdemessagebox.h>
# include <tdemessagebox.h>
# include <tdeio/passdlg.h>
# include <tdeio/passdlg.h>
# include <tqfile.h>
# include <tqfile.h>
# include <kstandarddirs.h>
# include <kstandarddirs.h>
# include <ktar.h>
# include <ktar.h>
@ -46,7 +46,7 @@
# include "../krservices.h"
# include "../krservices.h"
# include "../Dialogs/krpleasewait.h"
# include "../Dialogs/krpleasewait.h"
static TQStringList arcProtocols = TQStringList : : split ( " ; " , " tar;bzip;bzip2;gzip;krarc;zip " ) ;
static TQStringList arcProtocols = TQStringList : : split ( " ; " , " tar;bzip;bzip2;gzip;krarc;zip ;xz " ) ;
TDEWallet : : Wallet * KRarcHandler : : wallet = 0 ;
TDEWallet : : Wallet * KRarcHandler : : wallet = 0 ;
@ -69,6 +69,7 @@ TQStringList KRarcHandler::supportedPackers() {
if ( KrServices : : cmdExist ( " dpkg " ) ) packers . append ( " dpkg " ) ;
if ( KrServices : : cmdExist ( " dpkg " ) ) packers . append ( " dpkg " ) ;
if ( KrServices : : cmdExist ( " 7z " ) | | KrServices : : cmdExist ( " 7za " ) ) packers . append ( " 7z " ) ;
if ( KrServices : : cmdExist ( " 7z " ) | | KrServices : : cmdExist ( " 7za " ) ) packers . append ( " 7z " ) ;
if ( KrServices : : cmdExist ( " rpm " ) & & KrServices : : cmdExist ( " rpm2cpio " ) ) packers . append ( " rpm " ) ;
if ( KrServices : : cmdExist ( " rpm " ) & & KrServices : : cmdExist ( " rpm2cpio " ) ) packers . append ( " rpm " ) ;
if ( KrServices : : cmdExist ( " xz " ) ) packers . append ( " xz " ) ;
// kdDebug() << "Supported Packers:" << endl;
// kdDebug() << "Supported Packers:" << endl;
//TQStringList::Iterator it;
//TQStringList::Iterator it;
//for( it = packers.begin(); it != packers.end(); ++it )
//for( it = packers.begin(); it != packers.end(); ++it )
@ -90,6 +91,8 @@ bool KRarcHandler::arcSupported( TQString type ) {
return true ;
return true ;
else if ( type = = " -tgz " & & lst . contains ( " tar " ) )
else if ( type = = " -tgz " & & lst . contains ( " tar " ) )
return true ;
return true ;
else if ( type = = " -txz " & & lst . contains ( " tar " ) )
return true ;
else if ( type = = " tarz " & & lst . contains ( " tar " ) )
else if ( type = = " tarz " & & lst . contains ( " tar " ) )
return true ;
return true ;
else if ( type = = " gzip " & & lst . contains ( " gzip " ) )
else if ( type = = " gzip " & & lst . contains ( " gzip " ) )
@ -110,7 +113,9 @@ bool KRarcHandler::arcSupported( TQString type ) {
return true ;
return true ;
else if ( type = = " -deb " & & ( lst . contains ( " dpkg " ) & & lst . contains ( " tar " ) ) )
else if ( type = = " -deb " & & ( lst . contains ( " dpkg " ) & & lst . contains ( " tar " ) ) )
return true ;
return true ;
else if ( type = = " -7z " & & lst . contains ( " 7z " ) )
else if ( type = = " -7z " & & lst . contains ( " 7z " ) )
return true ;
else if ( type = = " -xz " & & lst . contains ( " xz " ) )
return true ;
return true ;
// not supported : (
// not supported : (
return false ;
return false ;
@ -123,19 +128,21 @@ bool KRarcHandler::arcHandled( TQString type ) {
krConfig - > setGroup ( " Archives " ) ;
krConfig - > setGroup ( " Archives " ) ;
if ( ( type = = " -tgz " & & krConfig - > readBoolEntry ( " Do GZip " , _DoGZip ) ) | |
if ( ( type = = " -tgz " & & krConfig - > readBoolEntry ( " Do GZip " , _DoGZip ) ) | |
( type = = " tarz " & & krConfig - > readBoolEntry ( " Do GZip " , _DoGZip ) ) | |
( type = = " tarz " & & krConfig - > readBoolEntry ( " Do GZip " , _DoGZip ) ) | |
( type = = " -tar " & & krConfig - > readBoolEntry ( " Do Tar " , _DoTar ) ) | |
( type = = " -tar " & & krConfig - > readBoolEntry ( " Do Tar " , _DoTar ) ) | |
( type = = " -tbz " & & krConfig - > readBoolEntry ( " Do BZip2 " , _DoBZip2 ) ) | |
( type = = " -tbz " & & krConfig - > readBoolEntry ( " Do BZip2 " , _DoBZip2 ) ) | |
( type = = " -txz " & & krConfig - > readBoolEntry ( " Do Xz " , _DoXz ) ) | |
( type = = " gzip " & & krConfig - > readBoolEntry ( " Do GZip " , _DoGZip ) ) | |
( type = = " gzip " & & krConfig - > readBoolEntry ( " Do GZip " , _DoGZip ) ) | |
( type = = " zip2 " & & krConfig - > readBoolEntry ( " Do BZip2 " , _DoBZip2 ) ) | |
( type = = " zip2 " & & krConfig - > readBoolEntry ( " Do BZip2 " , _DoBZip2 ) ) | |
( type = = " -zip " & & krConfig - > readBoolEntry ( " Do UnZip " , _DoUnZip ) ) | |
( type = = " -zip " & & krConfig - > readBoolEntry ( " Do UnZip " , _DoUnZip ) ) | |
( type = = " -lha " & & krConfig - > readBoolEntry ( " Do Lha " , _DoUnZip ) ) | |
( type = = " -lha " & & krConfig - > readBoolEntry ( " Do Lha " , _DoUnZip ) ) | |
( type = = " -rar " & & krConfig - > readBoolEntry ( " Do UnRar " , _DoUnRar ) ) | |
( type = = " -rar " & & krConfig - > readBoolEntry ( " Do UnRar " , _DoUnRar ) ) | |
( type = = " -arj " & & krConfig - > readBoolEntry ( " Do UnArj " , _DoUnarj ) ) | |
( type = = " -arj " & & krConfig - > readBoolEntry ( " Do UnArj " , _DoUnarj ) ) | |
( type = = " -ace " & & krConfig - > readBoolEntry ( " Do UnAce " , _DoUnAce ) ) | |
( type = = " -ace " & & krConfig - > readBoolEntry ( " Do UnAce " , _DoUnAce ) ) | |
( type = = " cpio " & & krConfig - > readBoolEntry ( " Do RPM " , _DoRPM ) ) | |
( type = = " cpio " & & krConfig - > readBoolEntry ( " Do RPM " , _DoRPM ) ) | |
( type = = " -rpm " & & krConfig - > readBoolEntry ( " Do RPM " , _DoRPM ) ) | |
( type = = " -rpm " & & krConfig - > readBoolEntry ( " Do RPM " , _DoRPM ) ) | |
( type = = " -deb " & & krConfig - > readBoolEntry ( " Do DEB " , _DoDEB ) ) | |
( type = = " -deb " & & krConfig - > readBoolEntry ( " Do DEB " , _DoDEB ) ) | |
( type = = " -7z " & & krConfig - > readBoolEntry ( " Do 7z " , _Do7z ) ) )
( type = = " -7z " & & krConfig - > readBoolEntry ( " Do 7z " , _Do7z ) ) | |
( type = = " -xz " & & krConfig - > readBoolEntry ( " Do Xz " , _DoXz ) ) )
return true ;
return true ;
else
else
return false ;
return false ;
@ -148,8 +155,8 @@ long KRarcHandler::arcFileCount( TQString archive, TQString type, TQString passw
// first check if supported
// first check if supported
if ( ! arcSupported ( type ) ) return 0 ;
if ( ! arcSupported ( type ) ) return 0 ;
// bzip an gzip archive contains only one file
// bzip , gzip and xz archives contain only one file
if ( type = = " zip2 " | | type = = " gzip " ) return 1L ;
if ( type = = " zip2 " | | type = = " gzip " | | type = = " -xz " ) return 1L ;
// set the right lister to do the job
// set the right lister to do the job
TQString lister ;
TQString lister ;
@ -159,6 +166,7 @@ long KRarcHandler::arcFileCount( TQString archive, TQString type, TQString passw
else if ( type = = " -tgz " ) lister = KrServices : : fullPathName ( " tar " ) + " -tvzf " ;
else if ( type = = " -tgz " ) lister = KrServices : : fullPathName ( " tar " ) + " -tvzf " ;
else if ( type = = " tarz " ) lister = KrServices : : fullPathName ( " tar " ) + " -tvzf " ;
else if ( type = = " tarz " ) lister = KrServices : : fullPathName ( " tar " ) + " -tvzf " ;
else if ( type = = " -tbz " ) lister = KrServices : : fullPathName ( " tar " ) + " -tjvf " ;
else if ( type = = " -tbz " ) lister = KrServices : : fullPathName ( " tar " ) + " -tjvf " ;
else if ( type = = " -txz " ) lister = KrServices : : fullPathName ( " tar " ) + " -tJvf " ;
else if ( type = = " -lha " ) lister = KrServices : : fullPathName ( " lha " ) + " l " ;
else if ( type = = " -lha " ) lister = KrServices : : fullPathName ( " lha " ) + " l " ;
else if ( type = = " -rar " ) lister = KrServices : : fullPathName ( KrServices : : cmdExist ( " rar " ) ? " rar " : " unrar " ) + " l -v " ;
else if ( type = = " -rar " ) lister = KrServices : : fullPathName ( KrServices : : cmdExist ( " rar " ) ? " rar " : " unrar " ) + " l -v " ;
else if ( type = = " -ace " ) lister = KrServices : : fullPathName ( " unace " ) + " l " ;
else if ( type = = " -ace " ) lister = KrServices : : fullPathName ( " unace " ) + " l " ;
@ -171,8 +179,9 @@ long KRarcHandler::arcFileCount( TQString archive, TQString type, TQString passw
else if ( type = = " -rpm " ) lister = KrServices : : fullPathName ( " rpm " ) + " --dump -lpq " ;
else if ( type = = " -rpm " ) lister = KrServices : : fullPathName ( " rpm " ) + " --dump -lpq " ;
else if ( type = = " -deb " ) lister = KrServices : : fullPathName ( " dpkg " ) + " -c " ;
else if ( type = = " -deb " ) lister = KrServices : : fullPathName ( " dpkg " ) + " -c " ;
else if ( type = = " -7z " ) lister = KrServices : : fullPathName ( " 7z " ) + " -y l " ;
else if ( type = = " -7z " ) lister = KrServices : : fullPathName ( " 7z " ) + " -y l " ;
else if ( type = = " -xz " ) lister = KrServices : : fullPathName ( " xz " ) + " -l " ;
else return 0L ;
else return 0L ;
if ( ! password . isNull ( ) ) {
if ( ! password . isNull ( ) ) {
if ( type = = " -arj " )
if ( type = = " -arj " )
lister + = " -g' " + password + " ' " ;
lister + = " -g' " + password + " ' " ;
@ -198,11 +207,11 @@ long KRarcHandler::arcFileCount( TQString archive, TQString type, TQString passw
list . kill ( ) ;
list . kill ( ) ;
}
}
; // busy wait - need to find something better...
; // busy wait - need to find something better...
krApp - > stopWait ( ) ;
krApp - > stopWait ( ) ;
if ( ! list . normalExit ( ) | | ! checkStatus ( type , list . exitStatus ( ) ) ) {
if ( ! list . normalExit ( ) | | ! checkStatus ( type , list . exitStatus ( ) ) ) {
KMessageBox : : detailedError ( krApp , i18n ( " Failed to list the content of the archive (%1)! " ) . arg ( archive ) ,
KMessageBox : : detailedError ( krApp , i18n ( " Failed to list the content of the archive (%1)! " ) . arg ( archive ) ,
list . getErrorMsg ( ) , i18n ( " Error " ) ) ;
list . getErrorMsg ( ) , i18n ( " Error " ) ) ;
return 0 ;
return 0 ;
}
}
@ -241,6 +250,7 @@ bool KRarcHandler::unpack( TQString archive, TQString type, TQString password, T
else if ( type = = " -tgz " ) packer = KrServices : : fullPathName ( " tar " ) + " -xvzf " ;
else if ( type = = " -tgz " ) packer = KrServices : : fullPathName ( " tar " ) + " -xvzf " ;
else if ( type = = " tarz " ) packer = KrServices : : fullPathName ( " tar " ) + " -xvzf " ;
else if ( type = = " tarz " ) packer = KrServices : : fullPathName ( " tar " ) + " -xvzf " ;
else if ( type = = " -tbz " ) packer = KrServices : : fullPathName ( " tar " ) + " -xjvf " ;
else if ( type = = " -tbz " ) packer = KrServices : : fullPathName ( " tar " ) + " -xjvf " ;
else if ( type = = " -txz " ) packer = KrServices : : fullPathName ( " tar " ) + " -xJvf " ;
else if ( type = = " gzip " ) packer = KrServices : : fullPathName ( " gzip " ) + " -cd " ;
else if ( type = = " gzip " ) packer = KrServices : : fullPathName ( " gzip " ) + " -cd " ;
else if ( type = = " zip2 " ) packer = KrServices : : fullPathName ( " bzip2 " ) + " -cdk " ;
else if ( type = = " zip2 " ) packer = KrServices : : fullPathName ( " bzip2 " ) + " -cdk " ;
else if ( type = = " -lha " ) packer = KrServices : : fullPathName ( " lha " ) + " xf " ;
else if ( type = = " -lha " ) packer = KrServices : : fullPathName ( " lha " ) + " xf " ;
@ -250,6 +260,7 @@ bool KRarcHandler::unpack( TQString archive, TQString type, TQString password, T
KrServices : : fullPathName ( " arj " ) + " -y -v x " :
KrServices : : fullPathName ( " arj " ) + " -y -v x " :
KrServices : : fullPathName ( " unarj " ) + " x " ;
KrServices : : fullPathName ( " unarj " ) + " x " ;
else if ( type = = " -7z " ) packer = KrServices : : fullPathName ( " 7z " ) + " -y x " ;
else if ( type = = " -7z " ) packer = KrServices : : fullPathName ( " 7z " ) + " -y x " ;
else if ( type = = " -xz " ) packer = KrServices : : fullPathName ( " xz " ) + " -cdk " ;
else if ( type = = " -rpm " ) {
else if ( type = = " -rpm " ) {
TQString tempDir = locateLocal ( " tmp " , TQString ( ) ) ;
TQString tempDir = locateLocal ( " tmp " , TQString ( ) ) ;
@ -259,11 +270,11 @@ bool KRarcHandler::unpack( TQString archive, TQString type, TQString password, T
cpio < < KrServices : : fullPathName ( " rpm2cpio " ) < < " " + KrServices : : quote ( archive ) < < " > " < < cpioName ;
cpio < < KrServices : : fullPathName ( " rpm2cpio " ) < < " " + KrServices : : quote ( archive ) < < " > " < < cpioName ;
cpio . start ( TDEProcess : : Block , TDEProcess : : AllOutput ) ;
cpio . start ( TDEProcess : : Block , TDEProcess : : AllOutput ) ;
if ( ! cpio . normalExit ( ) | | ! checkStatus ( " cpio " , cpio . exitStatus ( ) ) ) {
if ( ! cpio . normalExit ( ) | | ! checkStatus ( " cpio " , cpio . exitStatus ( ) ) ) {
KMessageBox : : detailedError ( krApp , i18n ( " Failed to convert rpm (%1) to cpio! " ) . arg ( archive ) ,
KMessageBox : : detailedError ( krApp , i18n ( " Failed to convert rpm (%1) to cpio! " ) . arg ( archive ) ,
cpio . getErrorMsg ( ) , i18n ( " Error " ) ) ;
cpio . getErrorMsg ( ) , i18n ( " Error " ) ) ;
return 0 ;
return 0 ;
}
}
archive = cpioName ;
archive = cpioName ;
packer = KrServices : : fullPathName ( " cpio " ) + " --force-local --no-absolute-filenames -iuvdF " ;
packer = KrServices : : fullPathName ( " cpio " ) + " --force-local --no-absolute-filenames -iuvdF " ;
}
}
@ -276,18 +287,18 @@ bool KRarcHandler::unpack( TQString archive, TQString type, TQString password, T
dpkg < < KrServices : : fullPathName ( " dpkg " ) < < " --fsys-tarfile " + KrServices : : quote ( archive ) < < " > " < < cpioName ;
dpkg < < KrServices : : fullPathName ( " dpkg " ) < < " --fsys-tarfile " + KrServices : : quote ( archive ) < < " > " < < cpioName ;
dpkg . start ( TDEProcess : : Block , TDEProcess : : AllOutput ) ;
dpkg . start ( TDEProcess : : Block , TDEProcess : : AllOutput ) ;
if ( ! dpkg . normalExit ( ) | | ! checkStatus ( " -deb " , dpkg . exitStatus ( ) ) ) {
if ( ! dpkg . normalExit ( ) | | ! checkStatus ( " -deb " , dpkg . exitStatus ( ) ) ) {
KMessageBox : : detailedError ( krApp , i18n ( " Failed to convert deb (%1) to tar! " ) . arg ( archive ) ,
KMessageBox : : detailedError ( krApp , i18n ( " Failed to convert deb (%1) to tar! " ) . arg ( archive ) ,
dpkg . getErrorMsg ( ) , i18n ( " Error " ) ) ;
dpkg . getErrorMsg ( ) , i18n ( " Error " ) ) ;
return 0 ;
return 0 ;
}
}
archive = cpioName ;
archive = cpioName ;
packer = KrServices : : fullPathName ( " tar " ) + " xvf " ;
packer = KrServices : : fullPathName ( " tar " ) + " xvf " ;
}
}
else return false ;
else return false ;
if ( ! password . isNull ( ) ) {
if ( ! password . isNull ( ) ) {
if ( type = = " -zip " )
if ( type = = " -zip " )
packer + = " -P ' " + password + " ' " ;
packer + = " -P ' " + password + " ' " ;
if ( type = = " -arj " )
if ( type = = " -arj " )
packer + = " -g' " + password + " ' " ;
packer + = " -g' " + password + " ' " ;
@ -305,7 +316,7 @@ bool KRarcHandler::unpack( TQString archive, TQString type, TQString password, T
}
}
if ( type = = " -ace " & & TQFile ( " /dev/ptmx " ) . exists ( ) ) // Don't remove, unace crashes if missing!!!
if ( type = = " -ace " & & TQFile ( " /dev/ptmx " ) . exists ( ) ) // Don't remove, unace crashes if missing!!!
proc < < " < " < < " /dev/ptmx " ;
proc < < " < " < < " /dev/ptmx " ;
TQString save = getcwd ( 0 , 0 ) ;
TQString save = getcwd ( 0 , 0 ) ;
chdir ( dest . local8Bit ( ) ) ;
chdir ( dest . local8Bit ( ) ) ;
@ -333,11 +344,11 @@ bool KRarcHandler::unpack( TQString archive, TQString type, TQString password, T
if ( ! cpioName . isEmpty ( ) )
if ( ! cpioName . isEmpty ( ) )
TQFile ( cpioName ) . remove ( ) ; /* remove the cpio file */
TQFile ( cpioName ) . remove ( ) ; /* remove the cpio file */
// check the return value
// check the return value
if ( ! proc . normalExit ( ) | | ! checkStatus ( type , proc . exitStatus ( ) ) ) {
if ( ! proc . normalExit ( ) | | ! checkStatus ( type , proc . exitStatus ( ) ) ) {
KMessageBox : : detailedError ( krApp , i18n ( " Failed to unpack %1! " ) . arg ( archive ) ,
KMessageBox : : detailedError ( krApp , i18n ( " Failed to unpack %1! " ) . arg ( archive ) ,
krApp - > wasWaitingCancelled ( ) ? i18n ( " User cancelled. " ) :
krApp - > wasWaitingCancelled ( ) ? i18n ( " User cancelled. " ) :
proc . getErrorMsg ( ) , i18n ( " Error " ) ) ;
proc . getErrorMsg ( ) , i18n ( " Error " ) ) ;
return false ;
return false ;
}
}
@ -354,6 +365,7 @@ bool KRarcHandler::test( TQString archive, TQString type, TQString password, lon
else if ( type = = " -tgz " ) packer = KrServices : : fullPathName ( " tar " ) + " -tvzf " ;
else if ( type = = " -tgz " ) packer = KrServices : : fullPathName ( " tar " ) + " -tvzf " ;
else if ( type = = " tarz " ) packer = KrServices : : fullPathName ( " tar " ) + " -tvzf " ;
else if ( type = = " tarz " ) packer = KrServices : : fullPathName ( " tar " ) + " -tvzf " ;
else if ( type = = " -tbz " ) packer = KrServices : : fullPathName ( " tar " ) + " -tjvf " ;
else if ( type = = " -tbz " ) packer = KrServices : : fullPathName ( " tar " ) + " -tjvf " ;
else if ( type = = " -txz " ) packer = KrServices : : fullPathName ( " tar " ) + " -tJvf " ;
else if ( type = = " gzip " ) packer = KrServices : : fullPathName ( " gzip " ) + " -tv " ;
else if ( type = = " gzip " ) packer = KrServices : : fullPathName ( " gzip " ) + " -tv " ;
else if ( type = = " zip2 " ) packer = KrServices : : fullPathName ( " bzip2 " ) + " -tv " ;
else if ( type = = " zip2 " ) packer = KrServices : : fullPathName ( " bzip2 " ) + " -tv " ;
else if ( type = = " -rar " ) packer = KrServices : : fullPathName ( KrServices : : cmdExist ( " rar " ) ? " rar " : " unrar " ) + " t " ;
else if ( type = = " -rar " ) packer = KrServices : : fullPathName ( KrServices : : cmdExist ( " rar " ) ? " rar " : " unrar " ) + " t " ;
@ -362,10 +374,11 @@ bool KRarcHandler::test( TQString archive, TQString type, TQString password, lon
else if ( type = = " -arj " ) packer = KrServices : : fullPathName ( KrServices : : cmdExist ( " arj " ) ? " arj " : " unarj " ) + " t " ;
else if ( type = = " -arj " ) packer = KrServices : : fullPathName ( KrServices : : cmdExist ( " arj " ) ? " arj " : " unarj " ) + " t " ;
else if ( type = = " cpio " ) packer = KrServices : : fullPathName ( " cpio " ) + " --only-verify-crc -tvF " ;
else if ( type = = " cpio " ) packer = KrServices : : fullPathName ( " cpio " ) + " --only-verify-crc -tvF " ;
else if ( type = = " -7z " ) packer = KrServices : : fullPathName ( " 7z " ) + " -y t " ;
else if ( type = = " -7z " ) packer = KrServices : : fullPathName ( " 7z " ) + " -y t " ;
else if ( type = = " -xz " ) packer = KrServices : : fullPathName ( " xz " ) + " -tv " ;
else return false ;
else return false ;
if ( ! password . isNull ( ) ) {
if ( ! password . isNull ( ) ) {
if ( type = = " -zip " )
if ( type = = " -zip " )
packer + = " -P ' " + password + " ' " ;
packer + = " -P ' " + password + " ' " ;
if ( type = = " -arj " )
if ( type = = " -arj " )
packer + = " -g' " + password + " ' " ;
packer + = " -g' " + password + " ' " ;
@ -379,7 +392,7 @@ bool KRarcHandler::test( TQString archive, TQString type, TQString password, lon
if ( type = = " -ace " & & TQFile ( " /dev/ptmx " ) . exists ( ) ) // Don't remove, unace crashes if missing!!!
if ( type = = " -ace " & & TQFile ( " /dev/ptmx " ) . exists ( ) ) // Don't remove, unace crashes if missing!!!
proc < < " < " < < " /dev/ptmx " ;
proc < < " < " < < " /dev/ptmx " ;
// tell the user to wait
// tell the user to wait
krApp - > startWaiting ( i18n ( " Testing Archive " ) , count , true ) ;
krApp - > startWaiting ( i18n ( " Testing Archive " ) , count , true ) ;
if ( count ! = 0 ) connect ( & proc , TQT_SIGNAL ( receivedStdout ( TDEProcess * , char * , int ) ) ,
if ( count ! = 0 ) connect ( & proc , TQT_SIGNAL ( receivedStdout ( TDEProcess * , char * , int ) ) ,
@ -407,23 +420,25 @@ bool KRarcHandler::pack( TQStringList fileNames, TQString type, TQString dest, l
// set the right packer to do the job
// set the right packer to do the job
TQString packer ;
TQString packer ;
if ( type = = " zip " ) { packer = KrServices : : fullPathName ( " zip " ) + " -ry " ; type = " -zip " ; }
if ( type = = " zip " ) { packer = KrServices : : fullPathName ( " zip " ) + " -ry " ; type = " -zip " ; }
else if ( type = = " tar " ) { packer = KrServices : : fullPathName ( " tar " ) + " -cvf " ; type = " -tar " ; }
else if ( type = = " tar " ) { packer = KrServices : : fullPathName ( " tar " ) + " -cvf " ; type = " -tar " ; }
else if ( type = = " tar.gz " ) { packer = KrServices : : fullPathName ( " tar " ) + " -cvzf " ; type = " -tgz " ; }
else if ( type = = " tar.gz " ) { packer = KrServices : : fullPathName ( " tar " ) + " -cvzf " ; type = " -tgz " ; }
else if ( type = = " tar.bz2 " ) { packer = KrServices : : fullPathName ( " tar " ) + " -cvjf " ; type = " -tbz " ; }
else if ( type = = " tar.bz2 " ) { packer = KrServices : : fullPathName ( " tar " ) + " -cvjf " ; type = " -tbz " ; }
else if ( type = = " rar " ) { packer = KrServices : : fullPathName ( " rar " ) + " -r a " ; type = " -rar " ; }
else if ( type = = " tar.xz " ) { packer = KrServices : : fullPathName ( " tar " ) + " -cvJf " ; type = " -txz " ; }
else if ( type = = " lha " ) { packer = KrServices : : fullPathName ( " lha " ) + " a " ; type = " -lha " ; }
else if ( type = = " rar " ) { packer = KrServices : : fullPathName ( " rar " ) + " -r a " ; type = " -rar " ; }
else if ( type = = " arj " ) { packer = KrServices : : fullPathName ( " arj " ) + " -r -y a " ; type = " -arj " ; }
else if ( type = = " lha " ) { packer = KrServices : : fullPathName ( " lha " ) + " a " ; type = " -lha " ; }
else if ( type = = " 7z " ) { packer = KrServices : : fullPathName ( " 7z " ) + " -y a " ; type = " -7z " ; }
else if ( type = = " arj " ) { packer = KrServices : : fullPathName ( " arj " ) + " -r -y a " ; type = " -arj " ; }
else if ( type = = " 7z " ) { packer = KrServices : : fullPathName ( " 7z " ) + " -y a " ; type = " -7z " ; }
else if ( type = = " xz " ) { packer = KrServices : : fullPathName ( " xz " ) + " -z " ; type = " -xz " ; }
else return false ;
else return false ;
TQString password = TQString ( ) ;
TQString password = TQString ( ) ;
if ( extraProps . count ( " Password " ) > 0 ) {
if ( extraProps . count ( " Password " ) > 0 ) {
password = extraProps [ " Password " ] ;
password = extraProps [ " Password " ] ;
if ( ! password . isNull ( ) ) {
if ( ! password . isNull ( ) ) {
if ( type = = " -zip " )
if ( type = = " -zip " )
packer + = " -P ' " + password + " ' " ;
packer + = " -P ' " + password + " ' " ;
else if ( type = = " -arj " )
else if ( type = = " -arj " )
packer + = " -g' " + password + " ' " ;
packer + = " -g' " + password + " ' " ;
@ -473,11 +488,15 @@ bool KRarcHandler::pack( TQStringList fileNames, TQString type, TQString dest, l
static const int sevenZipLevels [ ] = { 0 , 1 , 2 , 4 , 5 , 6 , 7 , 8 , 9 } ;
static const int sevenZipLevels [ ] = { 0 , 1 , 2 , 4 , 5 , 6 , 7 , 8 , 9 } ;
packer + = TQString ( " -mx%1 " ) . arg ( sevenZipLevels [ level ] ) ;
packer + = TQString ( " -mx%1 " ) . arg ( sevenZipLevels [ level ] ) ;
}
}
else if ( type = = " -xz " ) {
static const int xzLevels [ ] = { 0 , 1 , 2 , 4 , 5 , 6 , 7 , 8 , 9 } ;
packer + = TQString ( " -%1 " ) . arg ( xzLevels [ level ] ) ;
}
}
}
if ( extraProps . count ( " CommandLineSwitches " ) > 0 )
if ( extraProps . count ( " CommandLineSwitches " ) > 0 )
packer + = TQString ( " %1 " ) . arg ( extraProps [ " CommandLineSwitches " ] ) ;
packer + = TQString ( " %1 " ) . arg ( extraProps [ " CommandLineSwitches " ] ) ;
// prepare to pack
// prepare to pack
KrShellProcess proc ;
KrShellProcess proc ;
proc < < packer < < KrServices : : quote ( dest ) ;
proc < < packer < < KrServices : : quote ( dest ) ;
@ -505,8 +524,8 @@ bool KRarcHandler::pack( TQStringList fileNames, TQString type, TQString dest, l
// check the return value
// check the return value
if ( ! proc . normalExit ( ) | | ! checkStatus ( type , proc . exitStatus ( ) ) ) {
if ( ! proc . normalExit ( ) | | ! checkStatus ( type , proc . exitStatus ( ) ) ) {
KMessageBox : : detailedError ( krApp , i18n ( " Failed to pack %1! " ) . arg ( dest ) ,
KMessageBox : : detailedError ( krApp , i18n ( " Failed to pack %1! " ) . arg ( dest ) ,
krApp - > wasWaitingCancelled ( ) ? i18n ( " User cancelled. " ) : proc . getErrorMsg ( ) ,
krApp - > wasWaitingCancelled ( ) ? i18n ( " User cancelled. " ) : proc . getErrorMsg ( ) ,
i18n ( " Error " ) ) ;
i18n ( " Error " ) ) ;
return false ;
return false ;
}
}
@ -522,9 +541,9 @@ bool KRarcHandler::pack( TQStringList fileNames, TQString type, TQString dest, l
TQString KRarcHandler : : getPassword ( TQString path ) {
TQString KRarcHandler : : getPassword ( TQString path ) {
TQString password ;
TQString password ;
TQString key = " krarc- " + path ;
TQString key = " krarc- " + path ;
if ( ! TDEWallet : : Wallet : : keyDoesNotExist ( TDEWallet : : Wallet : : NetworkWallet ( ) , TDEWallet : : Wallet : : PasswordFolder ( ) , key ) ) {
if ( ! TDEWallet : : Wallet : : keyDoesNotExist ( TDEWallet : : Wallet : : NetworkWallet ( ) , TDEWallet : : Wallet : : PasswordFolder ( ) , key ) ) {
if ( ! TDEWallet : : Wallet : : isOpen ( TDEWallet : : Wallet : : NetworkWallet ( ) ) & & wallet ! = 0 ) {
if ( ! TDEWallet : : Wallet : : isOpen ( TDEWallet : : Wallet : : NetworkWallet ( ) ) & & wallet ! = 0 ) {
delete wallet ;
delete wallet ;
@ -542,7 +561,7 @@ TQString KRarcHandler::getPassword( TQString path ) {
}
}
}
}
}
}
bool keep = true ;
bool keep = true ;
TQString user = " archive " ;
TQString user = " archive " ;
TDEIO : : PasswordDialog passDlg ( i18n ( " This archive is encrypted, please supply the password: " ) ,
TDEIO : : PasswordDialog passDlg ( i18n ( " This archive is encrypted, please supply the password: " ) ,
@ -572,7 +591,7 @@ TQString KRarcHandler::getPassword( TQString path ) {
}
}
return password ;
return password ;
}
}
return " " ;
return " " ;
}
}
@ -580,7 +599,7 @@ bool KRarcHandler::isArchive(const KURL& url) {
TQString protocol = url . protocol ( ) ;
TQString protocol = url . protocol ( ) ;
if ( arcProtocols . find ( protocol ) ! = arcProtocols . end ( ) )
if ( arcProtocols . find ( protocol ) ! = arcProtocols . end ( ) )
return true ;
return true ;
else return false ;
else return false ;
}
}
TQString KRarcHandler : : getType ( bool & encrypted , TQString fileName , TQString mime , bool checkEncrypted ) {
TQString KRarcHandler : : getType ( bool & encrypted , TQString fileName , TQString mime , bool checkEncrypted ) {
@ -589,10 +608,16 @@ TQString KRarcHandler::getType( bool &encrypted, TQString fileName, TQString mim
result = mime ;
result = mime ;
else
else
result = " - " + result ;
result = " - " + result ;
if ( result . endsWith ( " -7z " ) )
if ( result . endsWith ( " -7z " ) )
{
result = " -7z " ;
result = " -7z " ;
}
if ( result . endsWith ( " -xz " ) )
{
result = " -xz " ;
}
return result . right ( 4 ) ;
return result . right ( 4 ) ;
}
}
@ -602,9 +627,9 @@ bool KRarcHandler::checkStatus( TQString type, int exitCode ) {
return exitCode = = 0 | | exitCode = = 1 ;
return exitCode = = 0 | | exitCode = = 1 ;
else if ( type = = " -ace " | | type = = " zip2 " | | type = = " -lha " | | type = = " -rpm " | | type = = " cpio " | |
else if ( type = = " -ace " | | type = = " zip2 " | | type = = " -lha " | | type = = " -rpm " | | type = = " cpio " | |
type = = " -tar " | | type = = " tarz " | | type = = " -tbz " | | type = = " -tgz " | | type = = " -arj " | |
type = = " -tar " | | type = = " tarz " | | type = = " -tbz " | | type = = " -tgz " | | type = = " -arj " | |
type = = " -deb " )
type = = " -deb " | | type = = " -txz " | | type = = " -xz " )
return exitCode = = 0 ;
return exitCode = = 0 ;
else if ( type = = " gzip " )
else if ( type = = " gzip " | | type = = " -xz " )
return exitCode = = 0 | | exitCode = = 2 ;
return exitCode = = 0 | | exitCode = = 2 ;
else
else
return exitCode = = 0 ;
return exitCode = = 0 ;
@ -623,27 +648,28 @@ TQString KRarcHandler::detectArchive( bool &encrypted, TQString fileName, bool c
{ " rpm " , 0 , " \xed \xab \xee \xdb " } ,
{ " rpm " , 0 , " \xed \xab \xee \xdb " } ,
{ " ace " , 7 , " **ACE** " } ,
{ " ace " , 7 , " **ACE** " } ,
{ " bzip2 " , 0 , " \x42 \x5a \x68 \x39 \x31 " } ,
{ " bzip2 " , 0 , " \x42 \x5a \x68 \x39 \x31 " } ,
{ " gzip " , 0 , " \x1f \x8b " } ,
{ " gzip " , 0 , " \x1f \x8b " } ,
{ " deb " , 0 , " !<arch> \n debian-binary " } ,
{ " deb " , 0 , " !<arch> \n debian-binary " } ,
{ " 7z " , 0 , " 7z \xbc \xaf \x27 \x1c " } } ;
{ " 7z " , 0 , " 7z \xbc \xaf \x27 \x1c " } ,
{ " xz " , 0 , " \xfd7 zXZ \x00 " } } ;
static int autoDetectElems = sizeof ( autoDetectParams ) / sizeof ( AutoDetectParams ) ;
static int autoDetectElems = sizeof ( autoDetectParams ) / sizeof ( AutoDetectParams ) ;
encrypted = false ;
encrypted = false ;
TQFile arcFile ( fileName ) ;
TQFile arcFile ( fileName ) ;
if ( arcFile . open ( IO_ReadOnly ) ) {
if ( arcFile . open ( IO_ReadOnly ) ) {
char buffer [ 1024 ] ;
char buffer [ 1024 ] ;
long sizeMax = arcFile . readBlock ( buffer , sizeof ( buffer ) ) ;
long sizeMax = arcFile . readBlock ( buffer , sizeof ( buffer ) ) ;
arcFile . close ( ) ;
arcFile . close ( ) ;
for ( int i = 0 ; i < autoDetectElems ; i + + ) {
for ( int i = 0 ; i < autoDetectElems ; i + + ) {
TQString detectionString = autoDetectParams [ i ] . detectionString ;
TQString detectionString = autoDetectParams [ i ] . detectionString ;
int location = autoDetectParams [ i ] . location ;
int location = autoDetectParams [ i ] . location ;
int endPtr = detectionString . length ( ) + location ;
int endPtr = detectionString . length ( ) + location ;
if ( endPtr > sizeMax )
if ( endPtr > sizeMax )
continue ;
continue ;
unsigned int j = 0 ;
unsigned int j = 0 ;
for ( ; j ! = detectionString . length ( ) ; j + + ) {
for ( ; j ! = detectionString . length ( ) ; j + + ) {
if ( detectionString [ j ] = = ' ? ' )
if ( detectionString [ j ] = = ' ? ' )
@ -651,7 +677,7 @@ TQString KRarcHandler::detectArchive( bool &encrypted, TQString fileName, bool c
if ( buffer [ location + j ] ! = detectionString [ j ] )
if ( buffer [ location + j ] ! = detectionString [ j ] )
break ;
break ;
}
}
if ( j = = detectionString . length ( ) ) {
if ( j = = detectionString . length ( ) ) {
TQString type = autoDetectParams [ i ] . type ;
TQString type = autoDetectParams [ i ] . type ;
if ( type = = " bzip2 " | | type = = " gzip " ) {
if ( type = = " bzip2 " | | type = = " gzip " ) {
@ -686,7 +712,7 @@ TQString KRarcHandler::detectArchive( bool &encrypted, TQString fileName, bool c
long headerSize = ( ( unsigned char * ) buffer ) [ offset + 5 ] + 256 * ( ( unsigned char * ) buffer ) [ offset + 6 ] ;
long headerSize = ( ( unsigned char * ) buffer ) [ offset + 5 ] + 256 * ( ( unsigned char * ) buffer ) [ offset + 6 ] ;
bool isDir = ( buffer [ offset + 7 ] = = ' \0 ' ) & & ( buffer [ offset + 8 ] = = ' \0 ' ) & &
bool isDir = ( buffer [ offset + 7 ] = = ' \0 ' ) & & ( buffer [ offset + 8 ] = = ' \0 ' ) & &
( buffer [ offset + 9 ] = = ' \0 ' ) & & ( buffer [ offset + 10 ] = = ' \0 ' ) ;
( buffer [ offset + 9 ] = = ' \0 ' ) & & ( buffer [ offset + 10 ] = = ' \0 ' ) ;
if ( buffer [ offset + 2 ] ! = ( char ) 0x74 )
if ( buffer [ offset + 2 ] ! = ( char ) 0x74 )
break ;
break ;
if ( ! isDir ) {
if ( ! isDir ) {
@ -706,7 +732,7 @@ TQString KRarcHandler::detectArchive( bool &encrypted, TQString fileName, bool c
long headerSize = ( ( unsigned char * ) buffer ) [ offset + 2 ] + 256 * ( ( unsigned char * ) buffer ) [ offset + 3 ] + 4 ;
long headerSize = ( ( unsigned char * ) buffer ) [ offset + 2 ] + 256 * ( ( unsigned char * ) buffer ) [ offset + 3 ] + 4 ;
bool isDir = ( buffer [ offset + 11 ] = = ' \0 ' ) & & ( buffer [ offset + 12 ] = = ' \0 ' ) & &
bool isDir = ( buffer [ offset + 11 ] = = ' \0 ' ) & & ( buffer [ offset + 12 ] = = ' \0 ' ) & &
( buffer [ offset + 13 ] = = ' \0 ' ) & & ( buffer [ offset + 14 ] = = ' \0 ' ) ;
( buffer [ offset + 13 ] = = ' \0 ' ) & & ( buffer [ offset + 14 ] = = ' \0 ' ) ;
if ( buffer [ offset + 4 ] ! = ( char ) 0x01 )
if ( buffer [ offset + 4 ] ! = ( char ) 0x01 )
break ;
break ;
if ( ! isDir ) {
if ( ! isDir ) {
@ -729,7 +755,7 @@ TQString KRarcHandler::detectArchive( bool &encrypted, TQString fileName, bool c
return type ;
return type ;
}
}
}
}
if ( sizeMax > = 512 ) {
if ( sizeMax > = 512 ) {
/* checking if it's a tar file */
/* checking if it's a tar file */
unsigned checksum = 32 * 8 ;
unsigned checksum = 32 * 8 ;
@ -749,6 +775,16 @@ TQString KRarcHandler::detectArchive( bool &encrypted, TQString fileName, bool c
}
}
}
}
}
}
if ( fileName . endsWith ( " .tar.xz " ) )
{
return " txz " ;
}
else if ( fileName . endsWith ( " .xz " ) )
{
return " xz " ;
}
return TQString ( ) ;
return TQString ( ) ;
}
}