/*************************************************************************** * emulationstation.cpp * * Wed Jun 18 12:00:00 CEST 2017 * Copyright 2017 Lars Muldjord * muldjordlars@gmail.com ****************************************************************************/ /* * This file is part of skyscraper. * * skyscraper is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * skyscraper is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with skyscraper; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ #include "emulationstation.h" #include "xmlreader.h" #include "strtools.h" #include EmulationStation::EmulationStation() { } bool EmulationStation::loadOldGameList(const QString &gameListFileString) { // Load old game list entries so we can preserve metadata later when assembling xml XmlReader gameListReader; if(gameListReader.setFile(gameListFileString)) { oldEntries = gameListReader.getEntries(); return true; } return false; } bool EmulationStation::skipExisting(QList &gameEntries, QSharedPointer queue, const QString inputFolder) { gameEntries = oldEntries; printf("Resolving missing entries...\n"); int dots = 0; for(int a = 0; a < gameEntries.length(); ++a) { dots++; if(dots % 100 == 0) { printf("."); fflush(stdout); } QString filePath = gameEntries.at(a).path; // Make sure we readd the input path if the 'path' is relative if(filePath.left(1) == ".") { filePath.remove(0, 1); filePath.prepend(inputFolder); } QFileInfo current(filePath); for(int b = 0; b < queue->length(); ++b) { if(current.isFile()) { if(current.fileName() == queue->at(b).fileName()) { queue->removeAt(b); // We assume filename is unique, so break after getting first hit break; } } else if(current.isDir()) { // Use current.absoluteFilePath here since it is already a path. Otherwise it will use // the parent folder if(current.absoluteFilePath() == queue->at(b).absolutePath()) { queue->removeAt(b); // We assume filename is unique, so break after getting first hit break; } } } } return true; } void EmulationStation::preserveFromOld(GameEntry &entry) { foreach(GameEntry oldEntry, oldEntries) { QString oldFileName = oldEntry.path.mid(oldEntry.path.indexOf("/"), oldEntry.path.length()); QString fileName = entry.path.mid(entry.path.indexOf("/"), entry.path.length()); if(oldFileName == fileName) { if(entry.eSFavorite.isEmpty()) entry.eSFavorite = oldEntry.eSFavorite; if(entry.eSHidden.isEmpty()) entry.eSHidden = oldEntry.eSHidden; if(entry.eSPlayCount.isEmpty()) entry.eSPlayCount = oldEntry.eSPlayCount; if(entry.eSLastPlayed.isEmpty()) entry.eSLastPlayed = oldEntry.eSLastPlayed; if(entry.eSKidGame.isEmpty()) entry.eSKidGame = oldEntry.eSKidGame; if(entry.eSSortName.isEmpty()) entry.eSSortName = oldEntry.eSSortName; if(entry.developer.isEmpty()) entry.developer = oldEntry.developer; if(entry.publisher.isEmpty()) entry.publisher = oldEntry.publisher; if(entry.players.isEmpty()) entry.players = oldEntry.players; if(entry.description.isEmpty()) entry.description = oldEntry.description; if(entry.rating.isEmpty()) entry.rating = oldEntry.rating; if(entry.releaseDate.isEmpty()) entry.releaseDate = oldEntry.releaseDate; if(entry.tags.isEmpty()) entry.tags = oldEntry.tags; break; } } } void EmulationStation::assembleList(QString &finalOutput, const QList &gameEntries) { int dots = 0; // Always make dotMod at least 1 or it will give "floating point exception" when modulo int dotMod = gameEntries.length() * 0.1 + 1; if(dotMod == 0) dotMod = 1; finalOutput.append("\n\n"); foreach(GameEntry entry, gameEntries) { if(dots % dotMod == 0) { printf("."); fflush(stdout); } dots++; QString entryType = "game"; // Make sure we readd the input path if the 'path' is relative. This happens when user // skips entries. if(entry.path.left(1) == ".") { entry.path.remove(0, 1); entry.path.prepend(config->inputFolder); } QFileInfo entryInfo(entry.path); if(entryInfo.isFile()) { // Check if game is in subfolder and if it's a .cue or .m3u file. // If so, change entry to type. QString entryAbsolutePath = entryInfo.absolutePath(); if(entryAbsolutePath.count("/") == config->inputFolder.count("/") + 1) { QString entrySuffix = entryInfo.suffix(); if((entrySuffix == "cue" || entrySuffix == "m3u") && QDir(entryAbsolutePath, "*.cue *.m3u").count() == 1) { entryType = "folder"; entry.path = entryAbsolutePath; } } } else if(entryInfo.isDir()) { entryType = "folder"; } // Preserve certain data from old game list entry, but only for empty data preserveFromOld(entry); if(config->relativePaths) { entry.path.replace(config->inputFolder, "."); } finalOutput.append(" <" + entryType + ">\n"); finalOutput.append(" " + StrTools::xmlEscape(entry.path) + "\n"); if(config->brackets) { finalOutput.append(" " + StrTools::xmlEscape(entry.title + (entry.parNotes != ""?" " + entry.parNotes:"") + (entry.sqrNotes != ""?" " + entry.sqrNotes:"")) + "\n"); } else { finalOutput.append(" " + StrTools::xmlEscape(entry.title) + "\n"); } if(entry.coverFile.isEmpty()) { finalOutput.append(" \n"); } else { finalOutput.append(" " + (config->relativePaths?StrTools::xmlEscape(entry.coverFile).replace(config->inputFolder, "."):StrTools::xmlEscape(entry.coverFile)) + "\n"); } if(entry.screenshotFile.isEmpty()) { finalOutput.append(" \n"); } else { finalOutput.append(" " + (config->relativePaths?StrTools::xmlEscape(entry.screenshotFile).replace(config->inputFolder, "."):StrTools::xmlEscape(entry.screenshotFile)) + "\n"); } if(entry.marqueeFile.isEmpty()) { finalOutput.append(" \n"); } else { finalOutput.append(" " + (config->relativePaths?StrTools::xmlEscape(entry.marqueeFile).replace(config->inputFolder, "."):StrTools::xmlEscape(entry.marqueeFile)) + "\n"); } if(entry.videoFormat.isEmpty() || !config->videos) { finalOutput.append("