used as is).
Setup *s = 0;
if (!rec) return s;
int id = rec->value(Setup_Id).toInt();
- QString extensions = rec->value(Setup_FileTypeExtensions).toString();
- QStringList list = extensions.split(FILE_TYPE_EXTENSION_SEPARATOR);
+ QString extensions = rec->value(Setup_FileTypeExtensions).toString().trimmed();
+ QStringList list;
+ if (!extensions.isEmpty())
+ list = extensions.split(FILE_TYPE_EXTENSION_SEPARATOR);
int plfId = rec->value(Setup_PlatformId).toInt();
int mtId = rec->value(Setup_MediaTypeId).toInt();
Platform *plf = dynamic_cast<Platform*>(dbPlatform->getDataObject(plfId));
query.bindValue(":platformid", fpo->getPlatform()->getId());
if (fpo->getMediaType())
query.bindValue(":mediatypeid", fpo->getMediaType()->getId());
- query.bindValue(":filetypeextensions", fpo->getSupportedFileTypeExtensions().join(FILE_TYPE_EXTENSION_SEPARATOR));
+ query.bindValue(":filetypeextensions", supportedExtensionsToDb(fpo->getSupportedFileTypeExtensions()));
query.bindValue(":id", fpo->getId());
ret = query.exec();
if (!ret) qDebug() << query.lastError().text() << query.executedQuery();
return ret;
}
+QString DbSetup::supportedExtensionsToDb(QStringList list)
+{
+ return list.isEmpty() ? "" : list.join(FILE_TYPE_EXTENSION_SEPARATOR);
+}
+
int DbSetup::insertDataObjectToModel(const EmuFrontObject *ob)
{
qDebug() << "Inserting setup to database...";
"VALUES (NULL, :platformid, :mediatypeid, :fileextensions)");
int plfId = fpo->getPlatform() ? fpo->getPlatform()->getId() : -1;
int mtId = fpo->getMediaType() ? fpo->getMediaType()->getId() : -1;
- QString exts = fpo->getSupportedFileTypeExtensions().join(FILE_TYPE_EXTENSION_SEPARATOR);
- qDebug() << "Going to insert setup with platform " << plfId << ", media type " << mtId << " and extensions " << exts;
query.bindValue(":platformid", plfId);
query.bindValue(":mediatypeid", mtId);
- query.bindValue(":filetypeextensions", exts);
+ query.bindValue(":filetypeextensions", supportedExtensionsToDb(fpo->getSupportedFileTypeExtensions()));
int id = -1;
if (query.exec())
id = query.lastInsertId().toInt();
virtual QString getCountRefsSelect(int) const;
DbPlatform *dbPlatform;
DbMediaType *dbMediaType;
+ QString supportedExtensionsToDb(QStringList list);
};
#endif // DBSETUP_H
void EmuLauncher::launchEmu()
{
+ // if selected emulator has no extensions configured, it's assumed to be a M.A.M.E. or similar and
+ // map of media images will be no be used
QMap<QString, EmuFrontObject*> mediaImages;
QList<MediaImageContainer*> mediaImageContainers;
Executable *exe = 0;
throw EmuFrontException(tr("Failed creating Emulator object!"));
}
+
+ qDebug() << "File types; " << exe->getSetup()->getSupportedFileTypeExtensions().count();
+
+ bool mame = exe->getSetup()->getSupportedFileTypeExtensions().isEmpty();
+
+
+
+ if (mame && listMIndex.count() > 1) {
+ throw new EmuFrontException(tr("No supported file types configured for this emulator configuration. "
+ "Assuming emulator support container files as is. "
+ "Only one container can be selected without configuring supported file types."
+ ));
+ }
+
+
+ // Now we have one or more media image containers and an emulator selected,
+ // let's fetch the media image container data.
+
foreach(QModelIndex mind, listMIndex) {
if (!mind.isValid()) continue;
EmuFrontObject *obImg = dbMic->getDataObjectFromModel(&mind);
mediaImages.unite(contained);
}
+ if (mame) {
+ emuHelper->launch(exe, mediaImageContainers);
+ return;
+ }
+
+ // mediaImageContainers list contains all the selected media image containers and
+ // mediaImages list contains all the media images inside all the selected containers
+
+
+ QList<EmuFrontObject*> selectedImages;
if (mediaImages.count() < 1) {
throw EmuFrontException("No media images available!");
}
list << rx.cap(1);
pos += rx.matchedLength();
}
-
bool ok;
- QList<EmuFrontObject*> selectedImages;
+
if (list.count() > mediaImages.count()) {
throw EmuFrontException(tr("Select %1 media images for this emulator configuration").arg(list.count()));
}
else if (mediaImages.count() > 1) {
// show select boot image dialog
EmuFrontObject *efo = EmuFrontInputDialog::getItem(
- this, tr("Select boot image"), tr("Select"), mediaImages.values(), 0, false, &ok);
+ this, tr("Select boot image"), tr("Select"), mediaImages.values(), 0, false, &ok);
if (!ok) {
throw EmuFrontException(tr("Boot image selection was canceled, aborting."));
}
if (selectedImages.count() < 1)
throw EmuFrontException(tr("No media images selected"));
+
emuHelper->launch(exe, mediaImageContainers, selectedImages, list.count(), tmpDirPath);
micTable->clearSelection();
} catch (EmuFrontException efe) {
unzipHelper = new UnzipHelper(this);
}
+
+// TODO: These two launch functions may be merged to one and/or split into some common helper functions.
+void EmuHelper::launch(const Executable * ex, QList<MediaImageContainer *> micList)
+{
+ if (micList.count() < 1) {
+ throw EmuFrontException(tr("No media image containers available!"));
+ }
+
+ MediaImageContainer *mic = micList.first();
+ QString fp = " \"";
+ fp.append(mic->getFilePath()->getName());
+ if (!fp.endsWith('/'))
+ fp.append("/");
+ fp.append(mic->getName());
+ fp.append("\"");
+
+ QString opts = ex->getOptions();
+ opts.replace(QString("$1"), fp);
+
+ QString cmdWithParams;
+ cmdWithParams.append(ex->getExecutable());
+ cmdWithParams.append(" ").append(opts);
+
+ qDebug() << "Command with params " << cmdWithParams;
+ start(cmdWithParams, QIODevice::ReadOnly);
+
+ // for the moment, we'll wait for the process to be finished until we continue
+ waitForFinished(-1);
+
+ delete ex;
+ qDeleteAll(micList);
+}
+
void EmuHelper::launch(const Executable * ex, QList<MediaImageContainer *> micList,
QList<EmuFrontObject *> miList, int mediaCount, QString tmp)
{
// clean the temp dir
foreach(EmuFrontObject *ob, miList) {
QString fp = " \"";
- fp.append(tmp);
+ fp.append(tmp);
fp.append(ob->getName());
fp.append("\"");
if (!QFile::remove(fp))
public:
explicit EmuHelper(QObject *parent = 0);
void launch(const Executable * ex, QList<MediaImageContainer *> micList, QList<EmuFrontObject*> miList, int mediaCount = 1, QString tmp = ".");
+ void launch(const Executable * ex, QList<MediaImageContainer *> micList);
private slots:
void processError(QProcess::ProcessError);
void processFinished(int);
{
QStringList l;
for(int i = 0; i < stringList->count(); ++i)
- l << stringList->item(i)->text();
+ if (!stringList->item(i)->text().trimmed().isEmpty())
+ l << stringList->item(i)->text();
return l;
}
{
stringList->clear();
foreach(QString s, list)
- stringList->addItem(s);
+ if (!s.trimmed().isEmpty()) stringList->addItem(s);
}