ark
bkplugin.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "bkplugin.h"
00022 #include "kerfuffle/archivefactory.h"
00023
00024 #include <QFile>
00025 #include <KDebug>
00026
00027 BKInterface::BKInterface( const QString & filename, QObject *parent )
00028 : ReadWriteArchiveInterface( filename, parent )
00029 {
00030 }
00031
00032 BKInterface::~BKInterface()
00033 {
00034 bk_destroy_vol_info( &m_volInfo );
00035 }
00036
00037 bool BKInterface::list()
00038 {
00039 int rc;
00040
00041 rc = bk_init_vol_info( &m_volInfo, true );
00042 if ( rc <= 0 ) return false;
00043
00044 rc = bk_open_image( &m_volInfo, filename().toAscii().constData() );
00045 if ( rc <= 0 ) return false;
00046
00047 rc = bk_read_vol_info( &m_volInfo );
00048 if ( rc <= 0 ) return false;
00049
00050 if(m_volInfo.filenameTypes & FNTYPE_ROCKRIDGE)
00051 rc = bk_read_dir_tree( &m_volInfo, FNTYPE_ROCKRIDGE, true, 0 );
00052 else if(m_volInfo.filenameTypes & FNTYPE_JOLIET)
00053 rc = bk_read_dir_tree( &m_volInfo, FNTYPE_JOLIET, false, 0 );
00054 else
00055 rc = bk_read_dir_tree( &m_volInfo, FNTYPE_9660, false, 0 );
00056 if(rc <= 0) return false;
00057
00058 return browse( BK_BASE_PTR( &( m_volInfo.dirTree ) ) );
00059 }
00060
00061 bool BKInterface::copyFiles( const QList<QVariant> & files, const QString & destinationDirectory, bool preservePaths )
00062 {
00063 foreach( const QVariant& file, files )
00064 {
00065 int rc;
00066
00067 kDebug( 1601 ) << "Trying to extract " << file.toByteArray() ;
00068 rc = bk_extract( &m_volInfo, file.toByteArray(), QFile::encodeName( destinationDirectory ), true, 0 );
00069 if ( rc <= 0 )
00070 {
00071 error( QString( "Couldn't extract '%1'" ).arg( file.toString() ) );
00072 return false;
00073 }
00074 }
00075 return true;
00076 }
00077
00078 bool BKInterface::browse( BkFileBase* base, const QString& prefix )
00079 {
00080 QString name( base->name );
00081 QString fullpath = prefix.isEmpty()? name : prefix + '/' + name;
00082 if ( !name.isEmpty() )
00083 {
00084 ArchiveEntry e;
00085 e[ FileName ] = fullpath;
00086 e[ OriginalFileName ] = '/'+fullpath;
00087
00088 if ( IS_SYMLINK( base->posixFileMode ) )
00089 {
00090 e[ Link ] = QByteArray( BK_SYMLINK_PTR( base )->target );
00091 }
00092 if ( IS_REG_FILE( base->posixFileMode ) )
00093 {
00094 e[ Size ] = ( qulonglong ) BK_FILE_PTR( base )->size;
00095 }
00096 if ( IS_DIR( base->posixFileMode ) )
00097 {
00098 e[ IsDirectory ] = true;
00099 }
00100
00101 entry( e );
00102 }
00103
00104 if ( IS_DIR( base->posixFileMode ) )
00105 {
00106 BkFileBase *child = BK_DIR_PTR( base )->children;
00107 while ( child )
00108 {
00109 if ( !browse( child, fullpath ) )
00110 {
00111 return false;
00112 }
00113 child = child->next;
00114 }
00115 }
00116
00117 return true;
00118 }
00119
00120 bool BKInterface::addFiles( const QStringList & files )
00121 {
00122 return false;
00123 }
00124
00125 bool BKInterface::deleteFiles( const QList<QVariant> & files )
00126 {
00127 return false;
00128 }
00129
00130 KERFUFFLE_PLUGIN_FACTORY( BKInterface )
00131