GameHandler* GameHandler::GetHandler(RomInfo *rominfo) { if (!rominfo) return NULL; for (int x = 0; x < handlers->size(); x++) { GameHandler *handler = handlers->at(x); if (handler) { if (rominfo->System() == handler->SystemName()) return handler; } } return NULL; }
GameHandler* GameHandler::GetHandlerByName(QString systemname) { if (systemname.isEmpty() || systemname.isNull()) return NULL; for (int x = 0; x < handlers->size(); x++) { GameHandler *handler = handlers->at(x); if (handler) { if (handler->SystemName() == systemname) return handler; } } return NULL; }
void GameHandler::Launchgame(RomInfo *romdata, QString systemname) { GameHandler *handler; if (!systemname.isEmpty() && !systemname.isNull()) { handler = GetHandlerByName(systemname); } else if (!(handler = GetHandler(romdata))) { // Couldn't get handler so abort. return; } QString exec = handler->SystemCmdLine(); if (exec.isEmpty()) return; if (handler->GameType() != "PC") { QString arg = "\"" + romdata->Rompath() + "/" + romdata->Romname() + "\""; // If they specified a %s in the commandline place the romname // in that location, otherwise tack it on to the end of // the command. if (exec.contains("%s") || handler->SpanDisks()) { exec = exec.replace(QRegExp("%s"),arg); if (handler->SpanDisks()) { QRegExp rxp = QRegExp( "%d[0-4]", Qt::CaseSensitive, QRegExp::RegExp); if (exec.contains(rxp)) { if (romdata->DiskCount() > 1) { // Chop off the extension, . and last character of the name which we are assuming is the disk # QString basename = romdata->Romname().left(romdata->Romname().length() - (romdata->getExtension().length() + 2)); QString extension = romdata->getExtension(); QString rom; QString diskid[] = { "%d0", "%d1", "%d2", "%d3", "%d4", "%d5", "%d6" }; for (int disk = 1; disk <= romdata->DiskCount(); disk++) { rom = QString("\"%1/%2%3.%4\"") .arg(romdata->Rompath()) .arg(basename) .arg(disk) .arg(extension); exec = exec.replace(QRegExp(diskid[disk]),rom); } } else { // If there is only one disk make sure we replace %d1 just like %s exec = exec.replace(QRegExp("%d1"),arg); } } } } else { exec = exec + " \"" + romdata->Rompath() + "/" + romdata->Romname() + "\""; } } QString savedir = QDir::current().path(); QDir d; if (!handler->SystemWorkingPath().isEmpty()) { if (!d.cd(handler->SystemWorkingPath())) { LOG(VB_GENERAL, LOG_ERR, LOC + QString("Failed to change to specified Working Directory: %1") .arg(handler->SystemWorkingPath())); } } LOG(VB_GENERAL, LOG_INFO, LOC + QString("Launching Game : %1 : %2") .arg(handler->SystemName()) .arg(exec)); GetMythUI()->AddCurrentLocation(QString("MythGame %1 ( %2 )").arg(handler->SystemName()).arg(exec)); QStringList cmdlist = exec.split(";"); if (cmdlist.count() > 0) { for (QStringList::Iterator cmd = cmdlist.begin(); cmd != cmdlist.end(); ++cmd ) { LOG(VB_GENERAL, LOG_INFO, LOC + QString("Executing : %1").arg(*cmd)); myth_system(*cmd, kMSProcessEvents); } } else { LOG(VB_GENERAL, LOG_INFO, LOC + QString("Executing : %1").arg(exec)); myth_system(exec, kMSProcessEvents); } GetMythUI()->RemoveCurrentLocation(); (void)d.cd(savedir); }