diff --git a/include/gamedetails.h b/include/gamedetails.h index 59433e1..b887185 100644 --- a/include/gamedetails.h +++ b/include/gamedetails.h @@ -49,12 +49,12 @@ class gameDetails std::vector getGameFileVector(); std::vector getGameFileVectorFiltered(const unsigned int& iType); void filterWithType(const unsigned int& iType); + std::string makeCustomFilepath(const std::string& filename, const gameDetails& gd, const DirectoryConfig& dirConf); virtual ~gameDetails(); protected: void filterListWithPriorities(std::vector& list, const gameSpecificConfig& config); void filterListWithType(std::vector& list, const unsigned int& iType); std::string makeFilepath(const gameFile& gf, const DirectoryConfig& dirConf); - std::string makeCustomFilepath(const std::string& filename, const gameDetails& gd, const DirectoryConfig& dirConf); private: std::string serialsFilepath; std::string logoFilepath; diff --git a/include/util.h b/include/util.h index 730e9db..687705c 100644 --- a/include/util.h +++ b/include/util.h @@ -67,7 +67,6 @@ namespace Util int getGameSpecificConfig(std::string gamename, gameSpecificConfig* conf, std::string directory = std::string()); int replaceString(std::string& str, const std::string& to_replace, const std::string& replace_with); int replaceAllString(std::string& str, const std::string& to_replace, const std::string& replace_with); - void filepathReplaceReservedStrings(std::string& str, const std::string& gamename, const unsigned int& platformId = 0, const std::string& dlcname = ""); void setFilePermissions(const boost::filesystem::path& path, const boost::filesystem::perms& permissions); int getTerminalWidth(); void getManualUrlsFromJSON(const Json::Value &root, std::vector &urls); diff --git a/src/downloader.cpp b/src/downloader.cpp index dfdba94..42397ef 100644 --- a/src/downloader.cpp +++ b/src/downloader.cpp @@ -1712,8 +1712,7 @@ void Downloader::checkOrphans() } for (unsigned int j = 0; j < platformIds.size(); ++j) { - std::string directory = config.dirConf.sDirectory + "/" + config.dirConf.sGameSubdir + "/"; - Util::filepathReplaceReservedStrings(directory, games[i].gamename, platformIds[j]); + std::string directory = games[i].makeCustomFilepath("", games[i], config.dirConf); boost::filesystem::path path (directory); if (boost::filesystem::exists(path)) { diff --git a/src/util.cpp b/src/util.cpp index d88a602..b682449 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -371,72 +371,12 @@ int Util::replaceAllString(std::string& str, const std::string& to_replace, cons do { str.replace(str.begin()+pos, str.begin()+pos+to_replace.length(), replace_with); - - pos = str.find(to_replace, pos + to_replace.length()); + pos = str.find(to_replace); } while(pos != std::string::npos); return 1; } -void Util::filepathReplaceReservedStrings(std::string& str, const std::string& gamename, const unsigned int& platformId, const std::string& dlcname) -{ - std::string platform; - for (unsigned int i = 0; i < GlobalConstants::PLATFORMS.size(); ++i) - { - if ((platformId & GlobalConstants::PLATFORMS[i].id) == GlobalConstants::PLATFORMS[i].id) - { - platform = boost::algorithm::to_lower_copy(GlobalConstants::PLATFORMS[i].str); - break; - } - } - if (platform.empty()) - { - if (str.find("%gamename%/%platform%") != std::string::npos) - platform = ""; - else - platform = "no_platform"; - } - - // Don't save certain files in "no_platform" folder - if ( - str.rfind("/icon.png") != std::string::npos - || str.rfind("/logo.jpg") != std::string::npos - || str.rfind("/product.json") != std::string::npos - ) - platform = ""; - - std::string gamename_firstletter; - if (!gamename.empty()) - { - if (std::isdigit(gamename.front())) - gamename_firstletter = "0"; - else - gamename_firstletter = gamename.front(); - } - - if (str.find("%gamename_transformed%") != std::string::npos || str.find("%gamename_transformed_firstletter%") != std::string::npos) - { - std::string gamename_transformed = transformGamename(gamename); - std::string gamename_transformed_firstletter; - if (!gamename_transformed.empty()) - { - if (std::isdigit(gamename_transformed.front())) - gamename_transformed_firstletter = "0"; - else - gamename_transformed_firstletter = gamename_transformed.front(); - } - - while (Util::replaceString(str, "%gamename_transformed%", gamename_transformed)); - while (Util::replaceString(str, "%gamename_transformed_firstletter%", gamename_transformed_firstletter)); - } - - while (Util::replaceString(str, "%gamename_firstletter%", gamename_firstletter)); - while (Util::replaceString(str, "%gamename%", gamename)); - while (Util::replaceString(str, "%dlcname%", dlcname)); - while (Util::replaceString(str, "%platform%", platform)); - while (Util::replaceString(str, "//", "/")); // Replace any double slashes with single slash -} - void Util::setFilePermissions(const boost::filesystem::path& path, const boost::filesystem::perms& permissions) { if (boost::filesystem::exists(path))