Zip archives are now extracted with unzip utility instead of OSDaB-Zip.
authorMikko Keinänen <mikko.keinanen@gmail.com>
Sat, 16 Oct 2010 21:40:25 +0000 (00:40 +0300)
committerMikko Keinänen <mikko.keinanen@gmail.com>
Sat, 16 Oct 2010 21:40:25 +0000 (00:40 +0300)
src/emulauncher.cpp
src/emulauncher.h
src/utils/emuhelper.cpp
src/utils/emuhelper.h
src/utils/unziphelper.cpp
src/utils/unziphelper.h

index 15417c3..f334e60 100644 (file)
@@ -181,6 +181,7 @@ void EmuLauncher::launchEmu()
 
 void EmuLauncher::processError(QProcess::ProcessError e)
 {
+    cleanTmp();
     QString stdErr = emuHelper->readAllStandardError();
     QMessageBox::warning(this, tr("Emulator"),
         tr("Launching emulator failed with: %1.\n").arg(e)
@@ -188,11 +189,18 @@ void EmuLauncher::processError(QProcess::ProcessError e)
         .append(stdErr)), QMessageBox::Ok );
 }
 
+/* Slot for EmuHelper process finished, clears the temporary folder files */
 void EmuLauncher::processFinished(int a)
 {
+    cleanTmp();
     QString stdErr = emuHelper->readAllStandardError();
     QString stdMsg = emuHelper->readAllStandardOutput();
     QString msg = tr("Emulator has finished with: %1.\n").arg(a).append(stdMsg);
     if (a) msg.append("; ").append(proc->errorString()).append(";\n").append(stdErr);
     QMessageBox::information(this, tr("Emulator finished"), msg, QMessageBox::Ok);
 }
+
+void EmuLauncher::cleanTmp()
+{
+    // TODO
+}
index 703247e..c879a8b 100644 (file)
@@ -71,6 +71,7 @@ private:
     void populatePlatformSelectBox();
     void populateMediaTypeSelectBox();
     void launch(const Executable*, const MediaImageContainer*);
+    void cleanTmp();
 };
 
 #endif // EMULAUNCHER_H
index a17f1e3..9e6c331 100644 (file)
@@ -23,6 +23,7 @@
 #include "unziphelper.h"
 #include "../dataobjects/mediaimagecontainer.h"
 #include "../dataobjects/executable.h"
+#include "../exceptions/emufrontexception.h"
 
 EmuHelper::EmuHelper(QObject *parent) :
     ProcessHelper(parent)
@@ -45,7 +46,11 @@ void EmuHelper::launch(const Executable * ex, const MediaImageContainer * mic)
     //int err = unz.extractAll("/tmp/"); // TODO: this must be set dynamically
     //qDebug() << "extractAll to " << fp << " : " << err;
 
-    unzipHelper->extractAll(fp, "/tmp/");
+    int ret = unzipHelper->extractAll(fp, "/tmp/");
+
+    if (ret) {
+        throw EmuFrontException(tr("Unzip failed with %1.").arg(ret));
+    }
 
     // TODO: launch the 1st media image in the media image list of ex
     // or if emulator command options has a place for more than one
@@ -69,3 +74,17 @@ void EmuHelper::launch(const Executable * ex, const MediaImageContainer * mic)
     start(cmdWithParams, QIODevice::ReadOnly);
 }
 
+void EmuHelper::processError(QProcess::ProcessError)
+{
+
+}
+
+void EmuHelper::processFinished(int)
+{
+}
+
+void EmuHelper::connectSignals()
+{
+    connect(unzipHelper, SIGNAL(error(QProcess::ProcessError)), this, SLOT(processError(QProcess::ProcessError)));
+    connect(unzipHelper, SIGNAL(finished(int)), this, SLOT(processFinished(int)));
+}
index 4f9b6f3..c11e40d 100644 (file)
@@ -28,11 +28,16 @@ class UnzipHelper;
 
 class EmuHelper : public ProcessHelper
 {
+    Q_OBJECT
 public:
     explicit EmuHelper(QObject *parent = 0);
     void launch(const Executable * ex, const MediaImageContainer * mic);
+private slots:
+    void processError(QProcess::ProcessError);
+    void processFinished(int);
 private:
     UnzipHelper *unzipHelper;
+    void connectSignals();
 };
 
 #endif // EMUHELPER_H
index 7d387cf..e58ed03 100644 (file)
@@ -17,7 +17,7 @@
 // You should have received a copy of the GNU General Public License
 // along with EmuFront.  If not, see <http://www.gnu.org/licenses/>.
 
-#include <QFile>
+#include <QFileInfo>
 #include <QDebug>
 #include "unziphelper.h"
 #include "../dataobjects/mediaimage.h"
@@ -57,7 +57,7 @@ QList<MediaImage*> UnzipHelper::listContents(const QString filePath, const FileP
     // TODO: slot(s) for (start and) error signal(s)
     bool procOk = waitForFinished();
     if (!procOk) {
-        throw new EmuFrontException(tr("Listing information from file %1 failed with unzip.").arg(filePath));
+        throw EmuFrontException(tr("Listing information from file %1 failed with unzip.").arg(filePath));
     }
     QString err = readAllStandardError();
     QString msg = readAllStandardOutput();
@@ -139,8 +139,35 @@ QList<MediaImage*> UnzipHelper::listContents(const QString filePath, const FileP
 
 }
 
-bool UnzipHelper::extractAll(QString filePath, QString targetPath)
+/*
+    Returns the exit code of the unzip process.
+    Throws EmuFrontException if filePath is not readable
+    or targetPath is not writable.
+*/
+int UnzipHelper::extractAll(QString filePath, QString targetPath)
 {
+    QFileInfo fp(filePath);
+    if (!fp.isReadable()) {
+        throw EmuFrontException(tr("Cannot read file %1.").arg(filePath));
+    }
+    QFileInfo tp(targetPath);
+    if (!tp.isWritable()) {
+        throw EmuFrontException(tr("Cannot write to %1.").arg(targetPath));
+    }
+
     // unzip filepath -d targetpath
-    return false;
+    QString command;
+    command.append(UNZIP_COMMAND);
+    command.append("\"");
+    command.append(filePath);
+    command.append("\"");
+    command.append(" -d ");
+    command.append(targetPath);
+    qDebug() << "Starting unzip command: " << command;
+    start(command);
+    bool procOk = waitForFinished(); // TODO: set timeout, now using default 30000ms
+    if (!procOk) {
+        throw EmuFrontException(tr("Failed unzipping file '%1' to '%2'.").arg(filePath).arg(targetPath));
+    }
+    return exitCode();
 }
index 50fc563..6f92d5f 100644 (file)
@@ -30,7 +30,7 @@ class UnzipHelper : public ProcessHelper
 public:
     UnzipHelper(QObject *parent = 0);
     QList<MediaImage*> listContents(const QString filePath, const FilePathObject *fp);
-    bool extractAll(QString filePath, QString targetPath);
+    int extractAll(QString filePath, QString targetPath);
 private:
     static const QString UNZIP_COMMAND;
     static const QString UNZIP_LIST_ARGS;