From 7e6498df60b3f72922b89f0bea910b50c75bc8b5 Mon Sep 17 00:00:00 2001 From: Aloshi Date: Sun, 23 Sep 2012 16:01:56 -0500 Subject: [PATCH] Fixed a crash bug with launch commands missing %ROM%. Added relative path operator (".") support for gamelist.xml, in both game paths and image paths. --- changelog.txt | 4 ++++ src/Renderer_init_sdlgl.cpp | 2 +- src/SystemData.cpp | 15 ++++++++++----- src/XMLReader.cpp | 17 ++++++++++++++++- src/main.cpp | 9 +++++++-- 5 files changed, 38 insertions(+), 9 deletions(-) diff --git a/changelog.txt b/changelog.txt index 194d231d6..9ed5efe80 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,7 @@ +September 23 +-Fixed crash when "%ROM%" isn't present in a launch command. Not sure why you'd ever do this on purpose, but hey. +-Added relative path operator ("./") support for gamelist.xml, for both game paths and image paths. + September 16 -Fixed a bug with skipping over unicode characters. [X] will be displayed if the character is not standard ASCII (characters 32 to 127). diff --git a/src/Renderer_init_sdlgl.cpp b/src/Renderer_init_sdlgl.cpp index 6356eacc4..3263412bf 100644 --- a/src/Renderer_init_sdlgl.cpp +++ b/src/Renderer_init_sdlgl.cpp @@ -31,7 +31,7 @@ namespace Renderer SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); - sdlScreen = SDL_SetVideoMode(display_width, display_height, 16, SDL_OPENGL); //SDL_FULLSCREEN + sdlScreen = SDL_SetVideoMode(display_width, display_height, 16, SDL_OPENGL | SDL_FULLSCREEN); if(sdlScreen == NULL) { diff --git a/src/SystemData.cpp b/src/SystemData.cpp index ae5014f6d..92bbf6881 100644 --- a/src/SystemData.cpp +++ b/src/SystemData.cpp @@ -61,7 +61,10 @@ std::string strreplace(std::string& str, std::string replace, std::string with) { size_t pos = str.find(replace); - return str.replace(pos, replace.length(), with.c_str(), with.length()); + if(pos != std::string::npos) + return str.replace(pos, replace.length(), with.c_str(), with.length()); + else + return str; } void SystemData::launchGame(GameData* game) @@ -196,13 +199,15 @@ void SystemData::loadConfig() if(varName == "NAME") sysName = varValue; else if(varName == "PATH") - sysPath = varValue; - else if(varName == "EXTENSION") + { + if(varValue[varValue.length() - 1] == '/') + sysPath = varValue.substr(0, varValue.length() - 1); + else + sysPath = varValue; + }else if(varName == "EXTENSION") sysExtension = varValue; else if(varName == "COMMAND") sysCommand = varValue; - //else - // std::cout << "Warning reading config file - unknown variable name \"" << varName << "\", ignoring.\n"; //we have all our variables - create the system object if(!sysName.empty() && !sysPath.empty() &&!sysExtension.empty() && !sysCommand.empty()) diff --git a/src/XMLReader.cpp b/src/XMLReader.cpp index a0aff7352..3cb3d6c98 100644 --- a/src/XMLReader.cpp +++ b/src/XMLReader.cpp @@ -5,7 +5,6 @@ #include //this is obviously an incredibly inefficient way to go about searching -//some day I may change this to use hash tables or something //but I don't think it'll matter too much with the size of most collections GameData* searchFolderByPath(FolderData* folder, std::string const& path) { @@ -138,6 +137,13 @@ void parseGamelist(SystemData* system) std::string path = pathNode.text().get(); + //expand "." + if(path[0] == '.') + { + path.erase(0, 1); + path.insert(0, system->getRootFolder()->getPath()); + } + if(boost::filesystem::exists(path)) { GameData* game = searchFolderByPath(system->getRootFolder(), path); @@ -153,8 +159,17 @@ void parseGamelist(SystemData* system) if(gameNode.child("desc")) newDesc = gameNode.child("desc").text().get(); if(gameNode.child("image")) + { newImage = gameNode.child("image").text().get(); + //expand "." + if(newImage[0] == '.') + { + newImage.erase(0, 1); + newImage.insert(0, system->getRootFolder()->getPath()); + } + } + game->set(newName, newDesc, newImage); }else{ diff --git a/src/main.cpp b/src/main.cpp index a340cfbe0..f20f20ea6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -72,6 +72,7 @@ int main(int argc, char* argv[]) bool running = true; //desktop uses SDL to set up an OpenGL context, and has its own SDL window...so I #ifdefed here. + //this should be moved to the RPi init/deinit file //ALWAYS INITIALIZE VIDEO. It starts SDL's event system, and without it, input won't work. #ifdef _RPI_ @@ -79,12 +80,16 @@ int main(int argc, char* argv[]) { std::cerr << "Error - could not initialize SDL!\n"; std::cerr << " " << SDL_GetError() << "\n"; - std::cerr << "Are you in the 'video' and 'input' groups? Are you running with X closed? Is your firmware up to date?\n"; + std::cerr << "Are you in the 'video' and 'input' groups? Are you running with X closed? Is your firmware up to date? Are you using at least the 192/64 memory split?\n"; return 1; } SDL_Surface* sdlScreen = SDL_SetVideoMode(1, 1, 0, SDL_SWSURFACE); - std::cout << "Fake SDL window is " << sdlScreen->w << "x" << sdlScreen->h << "\n"; + if(sdlScreen == NULL) + { + std::cerr << "Error initializing SDL screen!\n"; + running = false; + } #endif bool renderInit = Renderer::init(width, height);