2 // Copyright 2010 Mikko Keinänen
4 // This file is part of EmuFront.
7 // EmuFront is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License version 2 as published by
9 // the Free Software Foundation and appearing in the file gpl.txt included in the
10 // packaging of this file.
12 // EmuFront is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with EmuFront. If not, see <http://www.gnu.org/licenses/>.
22 #include <QMessageBox>
23 #include "emuhelper.h"
24 #include "unziphelper.h"
25 #include "../dataobjects/mediaimagecontainer.h"
26 #include "../dataobjects/executable.h"
27 #include "../exceptions/emufrontexception.h"
29 EmuHelper::EmuHelper(QObject *parent) :
32 unzipHelper = new UnzipHelper(this);
35 void EmuHelper::launch(const Executable * ex, QList<MediaImageContainer *> micList,
36 QList<EmuFrontObject *> miList, int mediaCount)
38 if (miList.count() < 1) {
39 throw EmuFrontException(tr("No media images available!"));
41 if (micList.count() < 1) {
42 throw EmuFrontException(tr("No media image containers available!"));
45 QString tmp = "/tmp/"; // TODO: do this configurable!
47 // extract the media image container to tmp folder
48 // (TODO: tmp folder configuration)
49 foreach(MediaImageContainer *mic, micList) {
51 fp.append(mic->getFilePath()->getName());
52 if (!fp.endsWith('/')) fp.append("/");
53 fp.append(mic->getName());
54 int ret = unzipHelper->extractAll(fp, tmp);
56 qDebug() << "Failed unzipping " << fp << ".";
60 // fill in the media image slots in the command line options ($1, $2, ...)
61 QString opts = ex->getOptions();
62 for(int i = 0; i < mediaCount && i < miList.size(); i++) {
63 QString tmpfp = " \"/tmp/";
64 tmpfp.append (miList.at(i)->getName());
66 opts.replace(QString("$%1").arg(i+1), tmpfp);
69 QString cmdWithParams;
70 cmdWithParams.append(ex->getExecutable());
71 cmdWithParams.append(" ").append(opts);
73 qDebug() << "Command with params " << cmdWithParams;
74 start(cmdWithParams, QIODevice::ReadOnly);
76 // for the moment, we'll wait for the process to be finished until we continue
80 foreach(EmuFrontObject *ob, miList) {
82 fp.append(ob->getName());
85 qDebug() << "Removing " << fp << " failed.";
89 //qDeleteAll(miList); these objects are already deleted along with micList
93 void EmuHelper::processError(QProcess::ProcessError)
98 void EmuHelper::processFinished(int)
102 void EmuHelper::connectSignals()
104 connect(unzipHelper, SIGNAL(error(QProcess::ProcessError)), this, SLOT(processError(QProcess::ProcessError)));
105 connect(unzipHelper, SIGNAL(finished(int)), this, SLOT(processFinished(int)));