Add support for CAB archives to rbutil

Change-Id: Ia8b4953343caf8bc2b3c5a6cfd53c921c6d082b1
Reviewed-on: http://gerrit.rockbox.org/418
Reviewed-by: Dominik Riebeling <Dominik.Riebeling@gmail.com>
This commit is contained in:
Amaury Pouly 2013-03-11 18:57:11 +01:00 committed by Dominik Riebeling
parent 289acf3333
commit 6375c47f03
8 changed files with 350 additions and 14 deletions

View file

@ -22,6 +22,7 @@
#include "bootloaderinstallbase.h"
#include "utils.h"
#include "ziputil.h"
#include "mspackutil.h"
#if defined(Q_OS_MACX)
#include <sys/param.h>
@ -215,11 +216,34 @@ void BootloaderInstallBase::setBlFile(QStringList sl)
bool BootloaderInstallBase::setOfFile(QString of, QStringList blfile)
{
bool found = false;
ZipUtil z(this);
// check if the file set is in zip format
if(z.open(of)) {
ArchiveUtil *util = 0;
// try ZIP first
ZipUtil *zu = new ZipUtil(this);
if(zu->open(of))
{
emit logItem(tr("Zip file format detected"), LOGINFO);
QStringList contents = z.files();
util = zu;
}
else
delete zu;
// if ZIP failed, try CAB
if(util == 0)
{
MsPackUtil *msu = new MsPackUtil(this);
if(msu->open(of))
{
emit logItem(tr("CAB file format detected"), LOGINFO);
util = msu;
}
else
delete msu;
}
// check if the file set is in zip format
if(util) {
QStringList contents = util->files();
qDebug() << "[BootloaderInstallBase] archive contains:" << contents;
for(int i = 0; i < blfile.size(); ++i) {
// strip any path, we don't know the structure in the zip
@ -237,7 +261,7 @@ bool BootloaderInstallBase::setOfFile(QString of, QStringList blfile)
m_tempof.open();
m_offile = m_tempof.fileName();
m_tempof.close();
if(!z.extractArchive(m_offile, contents.at(j))) {
if(!util->extractArchive(m_offile, contents.at(j))) {
emit logItem(tr("Error extracting firmware from archive"), LOGERROR);
found = false;
break;
@ -249,12 +273,13 @@ bool BootloaderInstallBase::setOfFile(QString of, QStringList blfile)
if(!found) {
emit logItem(tr("Could not find firmware in archive"), LOGERROR);
}
delete util;
}
else {
m_offile = of;
found = true;
}
return found;
}