2012-07-20 16:14:09 +00:00
|
|
|
#include "SystemData.h"
|
2012-08-08 00:50:45 +00:00
|
|
|
#include "XMLReader.h"
|
2012-07-20 16:14:09 +00:00
|
|
|
#include <boost/filesystem.hpp>
|
2012-07-21 19:06:24 +00:00
|
|
|
#include <fstream>
|
|
|
|
#include <stdlib.h>
|
2013-05-13 19:53:28 +00:00
|
|
|
#include <SDL_joystick.h>
|
2012-08-29 18:53:53 +00:00
|
|
|
#include "Renderer.h"
|
2012-10-13 18:29:53 +00:00
|
|
|
#include "AudioManager.h"
|
2013-05-22 17:11:10 +00:00
|
|
|
#include "VolumeControl.h"
|
2013-01-04 23:31:51 +00:00
|
|
|
#include "Log.h"
|
2013-01-08 02:24:59 +00:00
|
|
|
#include "InputManager.h"
|
2013-04-13 18:52:32 +00:00
|
|
|
#include <iostream>
|
2013-06-17 19:01:03 +00:00
|
|
|
#include "Settings.h"
|
2013-11-06 01:41:49 +00:00
|
|
|
#include "FileSorts.h"
|
2012-07-20 16:14:09 +00:00
|
|
|
|
2012-07-21 20:57:53 +00:00
|
|
|
std::vector<SystemData*> SystemData::sSystemVector;
|
|
|
|
|
2012-07-20 16:14:09 +00:00
|
|
|
namespace fs = boost::filesystem;
|
|
|
|
|
2013-10-26 19:07:30 +00:00
|
|
|
SystemData::SystemData(const std::string& name, const std::string& fullName, const std::string& startPath, const std::vector<std::string>& extensions,
|
2013-09-28 16:10:06 +00:00
|
|
|
const std::string& command, PlatformIds::PlatformId platformId)
|
2012-07-20 16:14:09 +00:00
|
|
|
{
|
|
|
|
mName = name;
|
2013-08-13 06:56:10 +00:00
|
|
|
mFullName = fullName;
|
|
|
|
mStartPath = startPath;
|
2012-07-27 16:58:27 +00:00
|
|
|
|
2013-01-04 23:31:51 +00:00
|
|
|
//expand home symbol if the startpath contains ~
|
2013-08-13 06:56:10 +00:00
|
|
|
if(mStartPath[0] == '~')
|
2013-01-04 23:31:51 +00:00
|
|
|
{
|
2013-08-13 06:56:10 +00:00
|
|
|
mStartPath.erase(0, 1);
|
|
|
|
mStartPath.insert(0, getHomePath());
|
|
|
|
}
|
2012-07-27 16:58:27 +00:00
|
|
|
|
2013-10-26 19:07:30 +00:00
|
|
|
mSearchExtensions = extensions;
|
2012-07-21 19:06:24 +00:00
|
|
|
mLaunchCommand = command;
|
2013-09-28 16:10:06 +00:00
|
|
|
mPlatformId = platformId;
|
2012-07-27 16:58:27 +00:00
|
|
|
|
2013-11-12 23:28:15 +00:00
|
|
|
mRootFolder = new FileData(FOLDER, mStartPath, this);
|
|
|
|
mRootFolder->metadata.set("name", mFullName);
|
2012-08-08 00:50:45 +00:00
|
|
|
|
2014-03-08 19:00:18 +00:00
|
|
|
if(!Settings::getInstance()->getBool("ParseGamelistOnly"))
|
2012-08-08 00:50:45 +00:00
|
|
|
populateFolder(mRootFolder);
|
|
|
|
|
2014-03-08 19:00:18 +00:00
|
|
|
if(!Settings::getInstance()->getBool("IgnoreGamelist"))
|
2012-08-11 04:17:52 +00:00
|
|
|
parseGamelist(this);
|
2012-08-08 00:50:45 +00:00
|
|
|
|
2013-11-06 01:41:49 +00:00
|
|
|
mRootFolder->sort(FileSorts::SortTypes.at(0));
|
2013-11-12 23:28:15 +00:00
|
|
|
|
2014-01-10 20:41:23 +00:00
|
|
|
loadTheme();
|
2012-07-20 16:14:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SystemData::~SystemData()
|
2012-07-21 19:06:24 +00:00
|
|
|
{
|
2013-06-28 12:54:14 +00:00
|
|
|
//save changed game data back to xml
|
2014-03-08 19:00:18 +00:00
|
|
|
if(!Settings::getInstance()->getBool("IgnoreGamelist"))
|
2013-11-06 01:41:49 +00:00
|
|
|
{
|
2013-06-28 12:54:14 +00:00
|
|
|
updateGamelist(this);
|
|
|
|
}
|
2013-11-06 01:41:49 +00:00
|
|
|
|
2012-07-27 16:58:27 +00:00
|
|
|
delete mRootFolder;
|
2012-07-21 19:06:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string strreplace(std::string& str, std::string replace, std::string with)
|
|
|
|
{
|
|
|
|
size_t pos = str.find(replace);
|
|
|
|
|
2012-09-23 21:01:56 +00:00
|
|
|
if(pos != std::string::npos)
|
|
|
|
return str.replace(pos, replace.length(), with.c_str(), with.length());
|
|
|
|
else
|
|
|
|
return str;
|
2012-07-21 19:06:24 +00:00
|
|
|
}
|
|
|
|
|
2013-11-06 01:41:49 +00:00
|
|
|
std::string escapePath(const boost::filesystem::path& path)
|
|
|
|
{
|
|
|
|
// a quick and dirty way to insert a backslash before most characters that would mess up a bash path;
|
|
|
|
// someone with regex knowledge should make this into a one-liner
|
|
|
|
std::string pathStr = path.generic_string();
|
|
|
|
|
|
|
|
const char* invalidChars = " '\"\\!$^&*(){}[]?;<>";
|
|
|
|
for(unsigned int i = 0; i < pathStr.length(); i++)
|
|
|
|
{
|
|
|
|
char c;
|
|
|
|
unsigned int charNum = 0;
|
|
|
|
do {
|
|
|
|
c = invalidChars[charNum];
|
|
|
|
if(pathStr[i] == c)
|
|
|
|
{
|
|
|
|
pathStr.insert(i, "\\");
|
|
|
|
i++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
charNum++;
|
|
|
|
} while(c != '\0');
|
|
|
|
}
|
|
|
|
|
|
|
|
return pathStr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SystemData::launchGame(Window* window, FileData* game)
|
2012-07-21 19:06:24 +00:00
|
|
|
{
|
2013-01-04 23:31:51 +00:00
|
|
|
LOG(LogInfo) << "Attempting to launch game...";
|
2012-07-21 19:06:24 +00:00
|
|
|
|
2013-05-21 08:40:01 +00:00
|
|
|
AudioManager::getInstance()->deinit();
|
2013-05-22 17:11:10 +00:00
|
|
|
VolumeControl::getInstance()->deinit();
|
2013-04-10 17:29:07 +00:00
|
|
|
window->deinit();
|
2012-08-29 18:53:53 +00:00
|
|
|
|
2012-07-21 19:06:24 +00:00
|
|
|
std::string command = mLaunchCommand;
|
|
|
|
|
2013-11-06 01:41:49 +00:00
|
|
|
const std::string rom = escapePath(game->getPath());
|
|
|
|
const std::string basename = game->getPath().stem().string();
|
|
|
|
const std::string rom_raw = game->getPath().string();
|
|
|
|
|
|
|
|
command = strreplace(command, "%ROM%", rom);
|
|
|
|
command = strreplace(command, "%BASENAME%", basename);
|
|
|
|
command = strreplace(command, "%ROM_RAW%", rom_raw);
|
2012-07-21 19:06:24 +00:00
|
|
|
|
2013-01-04 23:31:51 +00:00
|
|
|
LOG(LogInfo) << " " << command;
|
2013-04-13 18:52:32 +00:00
|
|
|
std::cout << "==============================================\n";
|
2012-10-28 23:07:05 +00:00
|
|
|
int exitCode = system(command.c_str());
|
2013-04-13 18:52:32 +00:00
|
|
|
std::cout << "==============================================\n";
|
2012-07-21 19:06:24 +00:00
|
|
|
|
2012-10-28 23:07:05 +00:00
|
|
|
if(exitCode != 0)
|
2013-01-04 23:31:51 +00:00
|
|
|
{
|
|
|
|
LOG(LogWarning) << "...launch terminated with nonzero exit code " << exitCode << "!";
|
|
|
|
}
|
2012-07-23 23:53:33 +00:00
|
|
|
|
2013-04-10 17:29:07 +00:00
|
|
|
window->init();
|
2013-05-22 17:11:10 +00:00
|
|
|
VolumeControl::getInstance()->init();
|
2013-05-21 08:40:01 +00:00
|
|
|
AudioManager::getInstance()->init();
|
2013-07-17 06:47:02 +00:00
|
|
|
window->normalizeNextUpdate();
|
2013-06-28 12:54:14 +00:00
|
|
|
|
2013-11-06 01:41:49 +00:00
|
|
|
//update number of times the game has been launched
|
|
|
|
int timesPlayed = game->metadata.getInt("playcount") + 1;
|
|
|
|
game->metadata.set("playcount", std::to_string(static_cast<long long>(timesPlayed)));
|
|
|
|
|
|
|
|
//update last played time
|
|
|
|
boost::posix_time::ptime time = boost::posix_time::second_clock::universal_time();
|
|
|
|
game->metadata.setTime("lastplayed", time);
|
2012-07-21 19:06:24 +00:00
|
|
|
}
|
|
|
|
|
2013-11-06 01:41:49 +00:00
|
|
|
void SystemData::populateFolder(FileData* folder)
|
2012-07-20 16:14:09 +00:00
|
|
|
{
|
2013-11-06 01:41:49 +00:00
|
|
|
const fs::path& folderPath = folder->getPath();
|
2012-07-27 16:58:27 +00:00
|
|
|
if(!fs::is_directory(folderPath))
|
2012-07-20 16:14:09 +00:00
|
|
|
{
|
2013-04-13 18:52:32 +00:00
|
|
|
LOG(LogWarning) << "Error - folder with path \"" << folderPath << "\" is not a directory!";
|
2012-07-20 16:14:09 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-11-06 01:41:49 +00:00
|
|
|
const std::string folderStr = folderPath.generic_string();
|
|
|
|
|
2013-04-13 21:33:18 +00:00
|
|
|
//make sure that this isn't a symlink to a thing we already have
|
|
|
|
if(fs::is_symlink(folderPath))
|
|
|
|
{
|
2013-04-13 22:30:57 +00:00
|
|
|
//if this symlink resolves to somewhere that's at the beginning of our path, it's gonna recurse
|
2013-11-06 01:41:49 +00:00
|
|
|
if(folderStr.find(fs::canonical(folderPath).generic_string()) == 0)
|
2013-04-13 21:33:18 +00:00
|
|
|
{
|
2013-04-13 22:30:57 +00:00
|
|
|
LOG(LogWarning) << "Skipping infinitely recursive symlink \"" << folderPath << "\"";
|
2013-04-13 21:33:18 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-26 19:07:30 +00:00
|
|
|
fs::path filePath;
|
|
|
|
std::string extension;
|
|
|
|
bool isGame;
|
2012-07-27 16:58:27 +00:00
|
|
|
for(fs::directory_iterator end, dir(folderPath); dir != end; ++dir)
|
2012-07-20 16:14:09 +00:00
|
|
|
{
|
2013-10-26 19:07:30 +00:00
|
|
|
filePath = (*dir).path();
|
2012-07-20 16:14:09 +00:00
|
|
|
|
2013-10-27 16:18:38 +00:00
|
|
|
if(filePath.stem().empty())
|
2012-08-11 01:29:51 +00:00
|
|
|
continue;
|
|
|
|
|
2013-05-27 17:13:38 +00:00
|
|
|
//this is a little complicated because we allow a list of extensions to be defined (delimited with a space)
|
|
|
|
//we first get the extension of the file itself:
|
2013-10-26 19:07:30 +00:00
|
|
|
extension = filePath.extension().string();
|
|
|
|
|
|
|
|
//fyi, folders *can* also match the extension and be added as games - this is mostly just to support higan
|
2013-05-27 17:13:38 +00:00
|
|
|
//see issue #75: https://github.com/Aloshi/EmulationStation/issues/75
|
2013-10-26 19:07:30 +00:00
|
|
|
|
|
|
|
isGame = false;
|
|
|
|
if(std::find(mSearchExtensions.begin(), mSearchExtensions.end(), extension) != mSearchExtensions.end())
|
|
|
|
{
|
2013-11-12 23:28:15 +00:00
|
|
|
FileData* newGame = new FileData(GAME, filePath.generic_string(), this);
|
2013-11-06 01:41:49 +00:00
|
|
|
folder->addChild(newGame);
|
2013-10-26 19:07:30 +00:00
|
|
|
isGame = true;
|
|
|
|
}
|
|
|
|
|
2013-05-27 17:13:38 +00:00
|
|
|
//add directories that also do not match an extension as folders
|
|
|
|
if(!isGame && fs::is_directory(filePath))
|
2012-07-20 16:14:09 +00:00
|
|
|
{
|
2013-11-12 23:28:15 +00:00
|
|
|
FileData* newFolder = new FileData(FOLDER, filePath.generic_string(), this);
|
2012-07-27 16:58:27 +00:00
|
|
|
populateFolder(newFolder);
|
2012-08-11 04:17:52 +00:00
|
|
|
|
|
|
|
//ignore folders that do not contain games
|
2013-11-06 01:41:49 +00:00
|
|
|
if(newFolder->getChildren().size() == 0)
|
2012-08-11 04:17:52 +00:00
|
|
|
delete newFolder;
|
|
|
|
else
|
2013-11-06 01:41:49 +00:00
|
|
|
folder->addChild(newFolder);
|
2012-07-20 16:14:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-21 20:57:53 +00:00
|
|
|
//creates systems from information located in a config file
|
2014-05-01 02:12:45 +00:00
|
|
|
bool SystemData::loadConfig()
|
2012-07-21 19:06:24 +00:00
|
|
|
{
|
2012-07-21 20:57:53 +00:00
|
|
|
deleteSystems();
|
2012-07-21 19:06:24 +00:00
|
|
|
|
2014-05-01 02:12:45 +00:00
|
|
|
std::string path = getConfigPath(false);
|
|
|
|
|
2013-08-13 06:56:10 +00:00
|
|
|
LOG(LogInfo) << "Loading system config file " << path << "...";
|
2012-07-21 19:06:24 +00:00
|
|
|
|
2013-07-09 10:37:37 +00:00
|
|
|
if(!fs::exists(path))
|
|
|
|
{
|
2014-05-01 02:12:45 +00:00
|
|
|
LOG(LogError) << "es_systems.cfg file does not exist!";
|
|
|
|
writeExampleConfig(getConfigPath(true));
|
2013-07-09 10:37:37 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-08-13 06:56:10 +00:00
|
|
|
pugi::xml_document doc;
|
|
|
|
pugi::xml_parse_result res = doc.load_file(path.c_str());
|
|
|
|
|
|
|
|
if(!res)
|
|
|
|
{
|
2014-05-01 02:12:45 +00:00
|
|
|
LOG(LogError) << "Could not parse es_systems.cfg file!";
|
2013-08-13 06:56:10 +00:00
|
|
|
LOG(LogError) << res.description();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//actually read the file
|
|
|
|
pugi::xml_node systemList = doc.child("systemList");
|
|
|
|
|
2014-01-07 22:57:30 +00:00
|
|
|
if(!systemList)
|
|
|
|
{
|
|
|
|
LOG(LogError) << "es_systems.cfg is missing the <systemList> tag!";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-08-13 06:56:10 +00:00
|
|
|
for(pugi::xml_node system = systemList.child("system"); system; system = system.next_sibling("system"))
|
2012-07-21 19:06:24 +00:00
|
|
|
{
|
2013-10-26 19:07:30 +00:00
|
|
|
std::string name, fullname, path, cmd;
|
2013-09-28 16:10:06 +00:00
|
|
|
PlatformIds::PlatformId platformId = PlatformIds::PLATFORM_UNKNOWN;
|
|
|
|
|
2013-08-13 06:56:10 +00:00
|
|
|
name = system.child("name").text().get();
|
|
|
|
fullname = system.child("fullname").text().get();
|
|
|
|
path = system.child("path").text().get();
|
2013-10-26 19:07:30 +00:00
|
|
|
|
|
|
|
//convert extensions list from a string into a vector of strings
|
|
|
|
const pugi::char_t* extStr = system.child("extension").text().get();
|
|
|
|
std::vector<std::string> extensions;
|
|
|
|
std::vector<char> buff(strlen(extStr) + 1);
|
|
|
|
strcpy(buff.data(), extStr);
|
|
|
|
char* ext = strtok(buff.data(), " ");
|
|
|
|
while(ext != NULL)
|
|
|
|
{
|
|
|
|
extensions.push_back(ext);
|
|
|
|
ext = strtok(NULL, " ");
|
|
|
|
}
|
|
|
|
|
2013-08-13 06:56:10 +00:00
|
|
|
cmd = system.child("command").text().get();
|
2013-09-28 16:10:06 +00:00
|
|
|
platformId = (PlatformIds::PlatformId)system.child("platformid").text().as_uint(PlatformIds::PLATFORM_UNKNOWN);
|
2013-08-13 06:56:10 +00:00
|
|
|
|
|
|
|
//validate
|
2013-10-26 19:07:30 +00:00
|
|
|
if(name.empty() || path.empty() || extensions.empty() || cmd.empty())
|
2012-07-21 19:06:24 +00:00
|
|
|
{
|
2013-08-13 06:56:10 +00:00
|
|
|
LOG(LogError) << "System \"" << name << "\" is missing name, path, extension, or command!";
|
|
|
|
continue;
|
|
|
|
}
|
2012-07-21 19:06:24 +00:00
|
|
|
|
2013-08-13 06:56:10 +00:00
|
|
|
//convert path to generic directory seperators
|
|
|
|
boost::filesystem::path genericPath(path);
|
|
|
|
path = genericPath.generic_string();
|
|
|
|
|
2013-10-26 19:07:30 +00:00
|
|
|
SystemData* newSys = new SystemData(name, fullname, path, extensions, cmd, platformId);
|
2013-11-06 01:41:49 +00:00
|
|
|
if(newSys->getRootFolder()->getChildren().size() == 0)
|
2013-08-13 06:56:10 +00:00
|
|
|
{
|
|
|
|
LOG(LogWarning) << "System \"" << name << "\" has no games! Ignoring it.";
|
|
|
|
delete newSys;
|
|
|
|
}else{
|
|
|
|
sSystemVector.push_back(newSys);
|
2012-07-21 19:06:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-09 10:37:37 +00:00
|
|
|
return true;
|
2012-07-21 20:57:53 +00:00
|
|
|
}
|
|
|
|
|
2013-07-09 10:37:37 +00:00
|
|
|
void SystemData::writeExampleConfig(const std::string& path)
|
2012-07-23 23:53:33 +00:00
|
|
|
{
|
|
|
|
std::ofstream file(path.c_str());
|
|
|
|
|
2013-08-13 06:56:10 +00:00
|
|
|
file << "<!-- This is the EmulationStation Systems configuration file.\n"
|
|
|
|
"All systems must be contained within the <systemList> tag.-->\n"
|
|
|
|
"\n"
|
|
|
|
"<systemList>\n"
|
|
|
|
" <!-- Here's an example system to get you started. -->\n"
|
|
|
|
" <system>\n"
|
|
|
|
"\n"
|
2013-08-28 19:39:29 +00:00
|
|
|
" <!-- A short name, used internally. Traditionally lower-case. -->\n"
|
|
|
|
" <name>nes</name>\n"
|
2013-08-13 06:56:10 +00:00
|
|
|
"\n"
|
|
|
|
" <!-- A \"pretty\" name, displayed in the header and such. -->\n"
|
|
|
|
" <fullname>Nintendo Entertainment System</fullname>\n"
|
|
|
|
"\n"
|
|
|
|
" <!-- The path to start searching for ROMs in. '~' will be expanded to $HOME or $HOMEPATH, depending on platform. -->\n"
|
|
|
|
" <path>~/roms/nes</path>\n"
|
|
|
|
"\n"
|
|
|
|
" <!-- A list of extensions to search for, delimited by a space. You MUST include the period! It's also case sensitive. -->\n"
|
|
|
|
" <extension>.nes .NES</extension>\n"
|
|
|
|
"\n"
|
|
|
|
" <!-- The shell command executed when a game is selected. A few special tags are replaced if found in a command:\n"
|
|
|
|
" %ROM% is replaced by a bash-special-character-escaped absolute path to the ROM.\n"
|
|
|
|
" %BASENAME% is replaced by the \"base\" name of the ROM. For example, \"/foo/bar.rom\" would have a basename of \"bar\". Useful for MAME.\n"
|
|
|
|
" %ROM_RAW% is the raw, unescaped path to the ROM. -->\n"
|
|
|
|
" <command>retroarch -L ~/cores/libretro-fceumm.so %ROM%</command>\n"
|
|
|
|
"\n"
|
|
|
|
" </system>\n"
|
|
|
|
"</systemList>\n";
|
2012-07-23 23:53:33 +00:00
|
|
|
|
|
|
|
file.close();
|
2013-07-09 10:37:37 +00:00
|
|
|
|
2013-08-13 06:56:10 +00:00
|
|
|
LOG(LogError) << "Example config written! Go read it at \"" << path << "\"!";
|
2012-07-23 23:53:33 +00:00
|
|
|
}
|
|
|
|
|
2012-07-21 20:57:53 +00:00
|
|
|
void SystemData::deleteSystems()
|
|
|
|
{
|
|
|
|
for(unsigned int i = 0; i < sSystemVector.size(); i++)
|
|
|
|
{
|
|
|
|
delete sSystemVector.at(i);
|
|
|
|
}
|
|
|
|
sSystemVector.clear();
|
2012-07-21 19:06:24 +00:00
|
|
|
}
|
2012-07-23 23:53:33 +00:00
|
|
|
|
2014-05-01 02:12:45 +00:00
|
|
|
std::string SystemData::getConfigPath(bool forWrite)
|
2012-07-23 23:53:33 +00:00
|
|
|
{
|
2014-05-01 02:12:45 +00:00
|
|
|
fs::path path = getHomePath() + "/.emulationstation/es_systems.cfg";
|
|
|
|
if(forWrite || fs::exists(path))
|
|
|
|
return path.generic_string();
|
2012-07-23 23:53:33 +00:00
|
|
|
|
2014-05-01 02:12:45 +00:00
|
|
|
return "/etc/emulationstation/es_systems.cfg";
|
2012-07-23 23:53:33 +00:00
|
|
|
}
|
2012-07-27 16:58:27 +00:00
|
|
|
|
2014-05-01 02:12:45 +00:00
|
|
|
std::string SystemData::getGamelistPath(bool forWrite) const
|
2012-07-27 16:58:27 +00:00
|
|
|
{
|
2013-11-06 01:41:49 +00:00
|
|
|
fs::path filePath;
|
2012-12-17 19:29:43 +00:00
|
|
|
|
2013-11-06 01:41:49 +00:00
|
|
|
filePath = mRootFolder->getPath() / "gamelist.xml";
|
2012-12-17 19:29:43 +00:00
|
|
|
if(fs::exists(filePath))
|
2013-11-06 01:41:49 +00:00
|
|
|
return filePath.generic_string();
|
2012-12-17 19:29:43 +00:00
|
|
|
|
2014-05-01 02:12:45 +00:00
|
|
|
filePath = getHomePath() + "/.emulationstation/gamelists/" + mName + "/gamelist.xml";
|
|
|
|
if(forWrite) // make sure the directory exists if we're going to write to it, or crashes will happen
|
|
|
|
fs::create_directories(filePath.parent_path());
|
|
|
|
if(forWrite || fs::exists(filePath))
|
|
|
|
return filePath.generic_string();
|
|
|
|
|
|
|
|
return "/etc/emulationstation/gamelists/" + mName + "/gamelist.xml";
|
2012-12-17 19:29:43 +00:00
|
|
|
}
|
|
|
|
|
2013-11-12 23:28:15 +00:00
|
|
|
std::string SystemData::getThemePath() const
|
|
|
|
{
|
2014-05-01 02:12:45 +00:00
|
|
|
// where we check for themes, in order:
|
|
|
|
// 1. [SYSTEM_PATH]/theme.xml
|
|
|
|
// 2. currently selected theme set
|
2013-11-12 23:28:15 +00:00
|
|
|
|
2014-05-01 02:12:45 +00:00
|
|
|
// first, check game folder
|
|
|
|
fs::path localThemePath = mRootFolder->getPath() / "theme.xml";
|
|
|
|
if(fs::exists(localThemePath))
|
|
|
|
return localThemePath.generic_string();
|
2013-11-12 23:28:15 +00:00
|
|
|
|
2014-05-01 02:12:45 +00:00
|
|
|
// not in game folder, try theme sets
|
|
|
|
return ThemeData::getThemeFromCurrentSet(mName).generic_string();
|
2013-11-12 23:28:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool SystemData::hasGamelist() const
|
2012-08-08 00:50:45 +00:00
|
|
|
{
|
2014-05-01 02:12:45 +00:00
|
|
|
return (fs::exists(getGamelistPath(false)));
|
2012-08-08 00:50:45 +00:00
|
|
|
}
|
2013-09-19 23:41:14 +00:00
|
|
|
|
2013-11-06 01:41:49 +00:00
|
|
|
unsigned int SystemData::getGameCount() const
|
2013-09-29 02:54:15 +00:00
|
|
|
{
|
2013-11-06 01:41:49 +00:00
|
|
|
return mRootFolder->getFilesRecursive(GAME).size();
|
2013-09-29 02:54:15 +00:00
|
|
|
}
|
2014-01-10 20:41:23 +00:00
|
|
|
|
|
|
|
void SystemData::loadTheme()
|
|
|
|
{
|
|
|
|
mTheme = std::make_shared<ThemeData>();
|
2014-05-01 02:12:45 +00:00
|
|
|
|
|
|
|
std::string path = getThemePath();
|
|
|
|
|
|
|
|
if(!fs::exists(path)) // no theme available for this platform
|
|
|
|
return;
|
|
|
|
|
2014-01-10 20:41:23 +00:00
|
|
|
try
|
|
|
|
{
|
2014-05-01 02:12:45 +00:00
|
|
|
mTheme->loadFile(path);
|
2014-01-10 20:41:23 +00:00
|
|
|
} catch(ThemeException& e)
|
|
|
|
{
|
|
|
|
LOG(LogError) << e.what();
|
|
|
|
mTheme = std::make_shared<ThemeData>(); // reset to empty
|
|
|
|
}
|
|
|
|
}
|