Commit 47bc8b2a authored by Henrique Pinto's avatar Henrique Pinto
Browse files

* We can now use libarchive to list an archive's contents. We can extract top-level files too...

svn path=/branches/work/libarchive-based-ark/ark/; revision=672751
parent 54da752a
......@@ -29,22 +29,23 @@ install(TARGETS ark DESTINATION ${BIN_INSTALL_DIR} )
set(arkpart_PART_SRCS ${libark_common_SRCS}
ark_part.cpp
arkfactory.cpp
zip.cpp
tar.cpp
filelistview.cpp
archive.cpp
lha.cpp
compressedfile.cpp
zoo.cpp
rar.cpp
ar.cpp
arkutils.cpp
archiveformatdlg.cpp
arkwidget.cpp
arkviewer.cpp
sevenzip.cpp
extractiondialog.cpp
ace.cpp )
extractiondialog.cpp
arch.cpp
tar.cpp
libarchivehandler.cpp
#zip.cpp
#lha.cpp
#compressedfile.cpp
#zoo.cpp
#rar.cpp
#ar.cpp
#sevenzip.cpp
)
kde4_automoc(${arkpart_PART_SRCS})
......@@ -53,7 +54,7 @@ kde4_add_ui_files(arkpart_PART_SRCS general.ui )
kde4_add_plugin(arkpart WITH_PREFIX ${arkpart_PART_SRCS})
target_link_libraries(arkpart ${KDE4_KFILE_LIBS})
target_link_libraries(arkpart ${KDE4_KFILE_LIBS} ${KDE4_THREADWEAVER_LIBRARIES} ${LIBARCHIVE_LIBRARY})
install(TARGETS arkpart DESTINATION ${PLUGIN_INSTALL_DIR})
......
#! /bin/sh
$XGETTEXT *.cpp archive.h -o $podir/ark.pot
$XGETTEXT *.cpp arch.h -o $podir/ark.pot
/*
ark -- archiver for the KDE project
Copyright (C) 2005 Henrique Pinto <henrique.pinto@kdemail.net>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "ace.h"
#include "arkwidget.h"
#include "settings.h"
#include <QDir>
#include <KGlobal>
#include <KLocale>
#include <KDebug>
#include <KUrl>
#include <KMessageBox>
#include <K3Process>
#include <KStandardDirs>
AceArch::AceArch( ArkWidget *gui, const QString &filename )
: Arch( gui, filename )
{
//m_archiver_program = m_unarchiver_program = "/usr/local/bin/unace";
m_archiver_program = m_unarchiver_program = "/home/henrique/ArkTest/teste.sh";
verifyUtilityIsAvailable( m_archiver_program );
m_headerString = "Date Time Packed Size RatioFile";
m_repairYear = 5; m_fixMonth = 6; m_fixDay = 7; m_fixTime = 8;
m_dateCol = 3;
m_numCols = 5;
m_archCols.append( ArchColumns( 7, QRegExp( "[0-3][0-9]" ), 2 ) ); // Day
m_archCols.append( ArchColumns( 6, QRegExp( "[01][0-9]" ), 2 ) ); // Month
m_archCols.append( ArchColumns( 5, QRegExp( "[0-9][0-9]" ), 4 ) ); // Year
m_archCols.append( ArchColumns( 8, QRegExp( "[0-9:]+" ), 8 ) ); // Time
m_archCols.append( ArchColumns( 2, QRegExp( "[0-9]+" ) ) ); // Compressed Size
m_archCols.append( ArchColumns( 1, QRegExp( "[0-9]+" ) ) ); // Size
m_archCols.append( ArchColumns( 9, QRegExp( "[0-9][0-9]%" ) ) ); // Ratio
m_archCols.append( ArchColumns( 0, QRegExp( "[^\\n]+" ), 4096 ) ); // Name
}
AceArch::~AceArch()
{
}
void AceArch::setHeaders()
{
ColumnList list;
list.append( FILENAME_COLUMN );
list.append( SIZE_COLUMN );
list.append( PACKED_COLUMN );
list.append( TIMESTAMP_COLUMN );
emit headers( list );
}
void AceArch::open()
{
kDebug(1601) << "+AceArch::open()" << endl;
setHeaders();
m_buffer = "";
m_header_removed = false;
m_finished = false;
K3Process *kp = m_currentProcess = new K3Process;
*kp << m_archiver_program << "v" << m_filename;
//kp->setUseShell( true );
kDebug() << "AceArch::open(): kp->args(): " << kp->args() << endl;
connect( kp, SIGNAL( receivedStdout(K3Process*, char*, int) ),
SLOT( slotReceivedTOC(K3Process*, char*, int) ) );
connect( kp, SIGNAL( receivedStderr(K3Process*, char*, int) ),
SLOT( slotReceivedOutput(K3Process*, char*, int) ) );
connect( kp, SIGNAL( processExited(K3Process*) ),
SLOT( slotOpenExited(K3Process*) ) );
connect( kp, SIGNAL( receivedStdout(K3Process*, char*, int) ),
this, SLOT( catchMeIfYouCan(K3Process*, char*, int) ) );
if ( !kp->start( K3Process::NotifyOnExit, K3Process::AllOutput ) )
{
KMessageBox::error( 0, i18n( "Could not start a subprocess." ) );
emit sigOpen( this, false, QString(), 0 );
}
}
void AceArch::create()
{
emit sigCreate( this, true, m_filename,
Arch::Extract | Arch::View );
}
void AceArch::addFile( const QStringList & urls )
{
Q_UNUSED( urls );
}
void AceArch::addDir( const QString & dirName )
{
Q_UNUSED( dirName );
}
void AceArch::remove( QStringList *list )
{
Q_UNUSED( list );
}
void AceArch::unarchFileInternal( )
{
if ( m_destDir.isEmpty() || m_destDir.isNull() )
{
kError( 1601 ) << "There was no extract directory given." << endl;
return;
}
K3Process *kp = m_currentProcess = new K3Process;
kp->clearArguments();
// extract (and maybe overwrite)
*kp << m_unarchiver_program << "x" << "-y";
if ( ArkSettings::extractOverwrite() )
{
*kp << "-o";
}
*kp << m_filename;
*kp << m_destDir ;
// if the file list is empty, no filenames go on the command line,
// and we then extract everything in the archive.
if ( m_fileList )
{
QStringList::Iterator it;
for ( it = m_fileList->begin(); it != m_fileList->end(); ++it )
{
*kp << (*it);
}
}
connect( kp, SIGNAL( receivedStdout(K3Process*, char*, int) ),
SLOT( slotReceivedOutput(K3Process*, char*, int) ) );
connect( kp, SIGNAL( receivedStderr(K3Process*, char*, int) ),
SLOT( slotReceivedOutput(K3Process*, char*, int) ) );
connect( kp, SIGNAL( processExited(K3Process*) ),
SLOT( slotExtractExited(K3Process*) ) );
if ( !kp->start( K3Process::NotifyOnExit, K3Process::AllOutput ) )
{
KMessageBox::error( 0, i18n( "Could not start a subprocess." ) );
emit sigExtract( false );
}
}
void AceArch::catchMeIfYouCan( K3Process*, char *buffer, int buflen )
{
QString myBuf = QString::fromLatin1( buffer, buflen );
kDebug(1601) << " Wololo!: " << myBuf << endl;
}
#include "ace.moc"
// kate: space-indent off; mixedindent off; indent-mode cstyle;
/*
ark -- archiver for the KDE project
Copyright (C) 2005 Henrique Pinto <henrique.pinto@kdemail.net>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef ARK_ACE_H
#define ARK_ACE_H
#include "archive.h"
class K3Process; // TODO: Remove me!
class AceArch : public Arch
{
Q_OBJECT
public:
AceArch( ArkWidget *, const QString & );
virtual ~AceArch();
virtual void open();
virtual void create();
virtual void addFile( const QStringList & );
virtual void addDir( const QString & );
virtual void remove( QStringList * );
virtual void unarchFileInternal( );
private slots:
void catchMeIfYouCan( K3Process*, char*, int );
private:
void setHeaders();
};
#endif // ARK_ACE_H
/*
ark -- archiver for the KDE project
Copyright (C) 1997-1999 Rob Palmbos <palm9744@kettering.edu>
Copyright (C) 2000 Corel Corporation (author: Emily Ezust, emilye@corel.com)
Copyright (C) 2001 Corel Corporation (author: Michael Jarrett, michaelj@corel.com)
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
// ark includes
#include "ar.h"
#include "arkwidget.h"
#include "settings.h"
// C includes
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
// QT includes
#include <QDir>
// KDE includes
#include <KDebug>
#include <KLocale>
#include <KMessageBox>
#include <K3Process>
ArArch::ArArch( ArkWidget *_gui, const QString & _fileName )
: Arch(_gui, _fileName )
{
m_archiver_program = "ar";
m_unarchiver_program = QString();
verifyUtilityIsAvailable(m_archiver_program, m_unarchiver_program);
// Do not set headerString - there is none for Ar
m_numCols = 5;
m_dateCol = 4; m_fixYear = 8; m_repairMonth = 5; m_fixDay = 6; m_fixTime = 7;
m_archCols.append(ArchColumns(1, QRegExp("[a-zA-Z-]+"), 12)); // Perms
m_archCols.append(ArchColumns(2, QRegExp("[^\\s]+"), 128)); //User/grp
m_archCols.append(ArchColumns(3, QRegExp("[0-9]+"))); // Size
m_archCols.append(ArchColumns(5, QRegExp("[a-zA-Z]+"), 4)); // Month
m_archCols.append(ArchColumns(6, QRegExp("[0-9]+"), 2)); // Day
m_archCols.append(ArchColumns(7, QRegExp("[0-9:]+"), 6)); // Time
m_archCols.append(ArchColumns(8, QRegExp("[0-9]+"), 5)); // Year
m_archCols.append(ArchColumns(0, QRegExp("[^\\s][^\\n]+"), 4096));// File
kDebug(1601) << "ArArch constructor" << endl;
}
void ArArch::setHeaders()
{
ColumnList list;
list.append( FILENAME_COLUMN );
list.append( PERMISSION_COLUMN );
list.append( OWNER_GROUP_COLUMN );
list.append( SIZE_COLUMN );
list.append( TIMESTAMP_COLUMN );
emit headers( list );
}
void ArArch::open()
{
kDebug(1601) << "+ArArch::open" << endl;
setHeaders();
m_buffer = "";
K3Process *kp = m_currentProcess = new K3Process;
*kp << m_archiver_program << "vt" << m_filename;
connect( kp, SIGNAL(receivedStdout(K3Process*, char*, int)),
this, SLOT(slotReceivedTOC(K3Process*, char*, int)));
connect( kp, SIGNAL(receivedStderr(K3Process*, char*, int)),
this, SLOT(slotReceivedOutput(K3Process*, char*, int)));
connect( kp, SIGNAL(processExited(K3Process*)), this,
SLOT(slotOpenExited(K3Process*)));
if (kp->start(K3Process::NotifyOnExit, K3Process::AllOutput) == false)
{
KMessageBox::error( 0, i18n("Could not start a subprocess.") );
emit sigOpen(this, false, QString(), 0 );
}
kDebug(1601) << "-ArArch::open" << endl;
}
void ArArch::create()
{
K3Process *kp = m_currentProcess = new K3Process;
kp->clearArguments();
*kp << m_archiver_program << "c" << m_filename;
connect( kp, SIGNAL(receivedStdout(K3Process*, char*, int)),
this, SLOT(slotReceivedOutput(K3Process*, char*, int)));
connect( kp, SIGNAL(receivedStderr(K3Process*, char*, int)),
this, SLOT(slotReceivedOutput(K3Process*, char*, int)));
if (kp->start(K3Process::Block) == false)
{
KMessageBox::error( 0, i18n("Could not start a subprocess.") );
emit sigCreate(this, false, m_filename,
Arch::Extract | Arch::Delete | Arch::Add
| Arch::View);
}
else
emit sigCreate(this, true, m_filename,
Arch::Extract | Arch::Delete | Arch::Add
| Arch::View);
}
void ArArch::addFile( const QStringList &urls )
{
kDebug(1601) << "+ArArch::addFile" << endl;
K3Process *kp = m_currentProcess = new K3Process;
kp->clearArguments();
*kp << m_archiver_program;
if (ArkSettings::replaceOnlyWithNewer())
*kp << "ru";
else
*kp << "r";
*kp << m_filename;
QStringList::ConstIterator iter;
KUrl url( urls.first() );
QDir::setCurrent( url.directory() );
for (iter = urls.begin(); iter != urls.end(); ++iter )
{
KUrl fileURL( *iter );
*kp << fileURL.fileName();
}
connect( kp, SIGNAL(receivedStdout(K3Process*, char*, int)),
this, SLOT(slotReceivedOutput(K3Process*, char*, int)));
connect( kp, SIGNAL(receivedStderr(K3Process*, char*, int)),
this, SLOT(slotReceivedOutput(K3Process*, char*, int)));
connect( kp, SIGNAL(processExited(K3Process*)), this,
SLOT(slotAddExited(K3Process*)));
if (kp->start(K3Process::NotifyOnExit, K3Process::AllOutput) == false)
{
KMessageBox::error( 0, i18n("Could not start a subprocess.") );
emit sigAdd(false);
}
kDebug(1601) << "-ArArch::addFile" << endl;
}
void ArArch::unarchFileInternal()
{
// if m_fileList is empty, we extract all.
// if m_destDir is empty, abort with error.
kDebug(1601) << "+ArArch::unarchFile" << endl;
QString dest;
if (m_destDir.isEmpty() || m_destDir.isNull())
{
kError(1601) << "There was no extract directory given." << endl;
return;
}
else dest = m_destDir;
// ar has no option to specify the destination directory
// so I have to change to it.
bool ret = QDir::setCurrent(dest);
// I already checked the validity of the dir before coming here
Q_ASSERT(ret);
K3Process *kp = m_currentProcess = new K3Process;
kp->clearArguments();
*kp << m_archiver_program;
*kp << "vx";
*kp << m_filename;
// if the list is empty, no filenames go on the command line,
// and we then extract everything in the archive.
if (m_fileList)
{
for ( QStringList::Iterator it = m_fileList->begin();
it != m_fileList->end(); ++it )
{
*kp << (*it);
}
}
connect( kp, SIGNAL(receivedStdout(K3Process*, char*, int)),
this, SLOT(slotReceivedOutput(K3Process*, char*, int)));
connect( kp, SIGNAL(receivedStderr(K3Process*, char*, int)),
this, SLOT(slotReceivedOutput(K3Process*, char*, int)));
connect( kp, SIGNAL(processExited(K3Process*)), this,
SLOT(slotExtractExited(K3Process*)));
if (kp->start(K3Process::NotifyOnExit, K3Process::AllOutput) == false)
{
KMessageBox::error( 0, i18n("Could not start a subprocess.") );
emit sigExtract(false);
}
}
void ArArch::remove(QStringList *list)
{
kDebug(1601) << "+ArArch::remove" << endl;
if (!list)
return;
K3Process *kp = m_currentProcess = new K3Process;
kp->clearArguments();
*kp << m_archiver_program << "d" << m_filename;
for ( QStringList::Iterator it = list->begin();
it != list->end(); ++it )
{
QString str = *it;
*kp << str;
}
connect( kp, SIGNAL(receivedStdout(K3Process*, char*, int)),
this, SLOT(slotReceivedOutput(K3Process*, char*, int)));
connect( kp, SIGNAL(receivedStderr(K3Process*, char*, int)),
this, SLOT(slotReceivedOutput(K3Process*, char*, int)));
connect( kp, SIGNAL(processExited(K3Process*)), this,
SLOT(slotDeleteExited(K3Process*)));
if (kp->start(K3Process::NotifyOnExit, K3Process::AllOutput) == false)
{
KMessageBox::error( 0, i18n("Could not start a subprocess.") );
emit sigDelete(false);
}
kDebug(1601) << "-ArArch::remove" << endl;
}
#include "ar.moc"
/*
ark -- archiver for the KDE project
Copyright (C) 2001: Corel Corporation (author: Michael Jarrett <michaelj@corel.com>)
Copyright (C) 1999-2000: Corel Corporation (author: Emily Ezust <emilye@corel.com>)
Copyright (C) 1997-1999: Rob Palmbos <palm9744@kettering.edu>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef ARARCH_H
#define ARARCH_H
#include "archive.h"
#include <QStringList>
#include <QByteArray>
class QString;
class QByteArray;
class QStringList;
class Arch;
class ArkWidget;
class ArArch : public Arch
{
Q_OBJECT
public:
ArArch( ArkWidget *_gui,
const QString & _fileName );
virtual ~ArArch() {}
virtual void open();
virtual void create();
virtual void addFile( const QStringList & );
virtual void addDir(const QString &) {} // never gets called
virtual void remove(QStringList *);
virtual void unarchFileInternal();
private:
void setHeaders();
};
#endif /* ARARCH_H */
......@@ -25,7 +25,7 @@
*/
// ark includes
#include "archive.h"
#include "arch.h"
#include "arkwidget.h"
#include "arkutils.h"
#include "filelistview.h"
......@@ -50,14 +50,15 @@
// the archive types
#include "tar.h"
#include "zip.h"
#include "lha.h"
#include "compressedfile.h"
#include "zoo.h"
#include "rar.h"
#include "ar.h"
#include "sevenzip.h"
#include "ace.h"
#include "libarchivehandler.h"
//#include "zip.h"