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)
.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
+}
void populatePlatformSelectBox();
void populateMediaTypeSelectBox();
void launch(const Executable*, const MediaImageContainer*);
+ void cleanTmp();
};
#endif // EMULAUNCHER_H
#include "unziphelper.h"
#include "../dataobjects/mediaimagecontainer.h"
#include "../dataobjects/executable.h"
+#include "../exceptions/emufrontexception.h"
EmuHelper::EmuHelper(QObject *parent) :
ProcessHelper(parent)
//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
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)));
+}
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
// 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"
// 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();
}
-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();
}
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;