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, Archive::CopyFlags flags )
00062 {
00063
00064 const bool preservePaths = flags & Archive::PreservePaths;
00065
00066 foreach( const QVariant& file, files )
00067 {
00068 int rc;
00069
00070 kDebug( 1601 ) << "Trying to extract " << file.toByteArray() ;
00071 rc = bk_extract( &m_volInfo, file.toByteArray(), QFile::encodeName( destinationDirectory ), true, 0 );
00072 if ( rc <= 0 )
00073 {
00074 error( QString( "Could not extract '%1'" ).arg( file.toString() ) );
00075 return false;
00076 }
00077 }
00078 return true;
00079 }
00080
00081 bool BKInterface::browse( BkFileBase* base, const QString& prefix )
00082 {
00083 QString name( base->name );
00084 QString fullpath = prefix.isEmpty()? name : prefix + '/' + name;
00085 if ( !name.isEmpty() )
00086 {
00087 ArchiveEntry e;
00088 e[ FileName ] = fullpath;
00089 e[ InternalID ] = '/'+fullpath;
00090
00091 if ( IS_SYMLINK( base->posixFileMode ) )
00092 {
00093 e[ Link ] = QByteArray( BK_SYMLINK_PTR( base )->target );
00094 }
00095 if ( IS_REG_FILE( base->posixFileMode ) )
00096 {
00097 e[ Size ] = ( qulonglong ) BK_FILE_PTR( base )->size;
00098 }
00099 if ( IS_DIR( base->posixFileMode ) )
00100 {
00101 e[ IsDirectory ] = true;
00102 }
00103
00104 entry( e );
00105 }
00106
00107 if ( IS_DIR( base->posixFileMode ) )
00108 {
00109 BkFileBase *child = BK_DIR_PTR( base )->children;
00110 while ( child )
00111 {
00112 if ( !browse( child, fullpath ) )
00113 {
00114 return false;
00115 }
00116 child = child->next;
00117 }
00118 }
00119
00120 return true;
00121 }
00122
00123 bool BKInterface::addFiles( const QString& path, const QStringList & files )
00124 {
00125 Q_UNUSED(files );
00126 return false;
00127 }
00128
00129 bool BKInterface::deleteFiles( const QList<QVariant> & files )
00130 {
00131 Q_UNUSED(files );
00132 return false;
00133 }
00134
00135 KERFUFFLE_PLUGIN_FACTORY( BKInterface )
00136