void GameHandler::VerifyGameDB(GameHandler *handler) { int counter = 0; GameScanMap::Iterator iter; MSqlQuery query(MSqlQuery::InitCon()); query.prepare("SELECT romname,rompath,gamename FROM gamemetadata " "WHERE system = :SYSTEM"); query.bindValue(":SYSTEM",handler->SystemName()); if (!query.exec()) MythDB::DBError("GameHandler::VerifyGameDB - " "select", query); QString message = QObject::tr("Verifying %1 files") .arg(handler->SystemName()); CreateProgress(message); if (m_progressDlg) m_progressDlg->SetTotal(query.size()); // For every file we know about, check to see if it still exists. if (query.isActive() && query.size() > 0) { while (query.next()) { QString RomName = query.value(0).toString(); QString RomPath = query.value(1).toString(); QString GameName = query.value(2).toString(); if (RomName != QString::null) { if ((iter = m_GameMap.find(RomName)) != m_GameMap.end()) { // If it's both on disk and in the database we're done with it. m_GameMap.erase(iter); } else { // If it's only in the database add it to our list and mark it for // removal. m_GameMap[RomName] = GameScan(RomName,RomPath + "/" + RomName,inDatabase, GameName,RomPath); } } if (m_progressDlg) m_progressDlg->SetProgress(++counter); } } if (m_progressDlg) { m_progressDlg->Close(); m_progressDlg = NULL; } }
void GameHandler::processGames(GameHandler *handler) { QString thequery; int maxcount = 0; MSqlQuery query(MSqlQuery::InitCon()); if ((!handler->SystemRomPath().isEmpty()) && (handler->GameType() != "PC")) { QDir d(handler->SystemRomPath()); if (d.exists()) maxcount = buildFileCount(handler->SystemRomPath(),handler); else { LOG(VB_GENERAL, LOG_ERR, LOC + QString("ROM Path does not exist: %1") .arg(handler->SystemRomPath())); return; } } else maxcount = 100; if (handler->GameType() == "PC") { MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack"); QString message = QObject::tr("Scanning for %1 games...") .arg(handler->SystemName()); MythUIBusyDialog *busyDialog = new MythUIBusyDialog(message, popupStack, "gamescanbusy"); if (busyDialog->Create()) popupStack->AddScreen(busyDialog, false); else { delete busyDialog; busyDialog = NULL; } m_GameMap[handler->SystemCmdLine()] = GameScan(handler->SystemCmdLine(), handler->SystemCmdLine(), inFileSystem, handler->SystemName(), handler->SystemCmdLine().left(handler->SystemCmdLine().lastIndexOf(QRegExp("/")))); if (busyDialog) busyDialog->Close(); LOG(VB_GENERAL, LOG_INFO, LOC + QString("PC Game %1").arg(handler->SystemName())); } else { QString message = QObject::tr("Scanning for %1 games...") .arg(handler->SystemName()); CreateProgress(message); if (m_progressDlg) m_progressDlg->SetTotal(maxcount); int filecount = 0; buildFileList(handler->SystemRomPath(), handler, &filecount); if (m_progressDlg) { m_progressDlg->Close(); m_progressDlg = NULL; } } VerifyGameDB(handler); // If we still have some games in the list then update the database if (!m_GameMap.empty()) { InitMetaDataMap(handler->GameType()); UpdateGameDB(handler); romDB.clear(); handler->setRebuild(true); } else handler->setRebuild(false); }
void GameHandler::buildFileList(QString directory, GameHandler *handler, int* filecount) { QDir RomDir(directory); // If we can't read it's contents move on if (!RomDir.isReadable()) return; RomDir.setSorting( QDir:: DirsFirst | QDir::Name ); QFileInfoList List = RomDir.entryInfoList(); for (QFileInfoList::const_iterator it = List.begin(); it != List.end(); ++it) { QFileInfo Info = *it; QString RomName = Info.fileName(); QString GameName = Info.completeBaseName(); if (RomName == "." || RomName == "..") { continue; } if (Info.isDir()) { buildFileList(Info.filePath(), handler, filecount); continue; } else { if (handler->validextensions.count() > 0) { QRegExp r; r.setPattern("^" + Info.suffix() + "$"); r.setCaseSensitivity(Qt::CaseInsensitive); QStringList result; for (int x = 0; x < handler->validextensions.size(); x++) { QString extension = handler->validextensions.at(x); if (extension.contains(r)) result.append(extension); } if (result.isEmpty()) continue; } m_GameMap[RomName] = GameScan(RomName,Info.filePath(),inFileSystem, GameName, Info.absoluteDir().path()); LOG(VB_GENERAL, LOG_INFO, LOC + QString("Found ROM : (%1) - %2") .arg(handler->SystemName()).arg(RomName)); *filecount = *filecount + 1; if (m_progressDlg) m_progressDlg->SetProgress(*filecount); } } }