diff --git a/include/config.h b/include/config.h index 9850392..b35806f 100644 --- a/include/config.h +++ b/include/config.h @@ -46,6 +46,7 @@ struct DownloadConfig bool bRemoteXML; bool bSaveChangelogs; bool bSaveSerials; + bool bSaveGameDetailsJson; bool bSaveLogo; bool bSaveIcon; bool bAutomaticXMLCreation; diff --git a/include/downloader.h b/include/downloader.h index c7c1afe..c4c11a5 100644 --- a/include/downloader.h +++ b/include/downloader.h @@ -148,6 +148,7 @@ class Downloader static std::string getSerialsFromJSON(const Json::Value& json); void saveSerials(const std::string& serials, const std::string& filepath); static std::string getChangelogFromJSON(const Json::Value& json); + void saveGameDetailsJson(const std::string& json, const std::string& filepath); void saveChangelog(const std::string& changelog, const std::string& filepath); static void processDownloadQueue(Config conf, const unsigned int& tid); static void processCloudSaveDownloadQueue(Config conf, const unsigned int& tid); diff --git a/include/gamedetails.h b/include/gamedetails.h index f45f94a..29d1028 100644 --- a/include/gamedetails.h +++ b/include/gamedetails.h @@ -33,12 +33,14 @@ class gameDetails std::string serials; std::string changelog; std::string logo; + std::string gameDetailsJson; void filterWithPriorities(const gameSpecificConfig& config); void makeFilepaths(const DirectoryConfig& config); std::string getSerialsFilepath(); std::string getLogoFilepath(); std::string getIconFilepath(); std::string getChangelogFilepath(); + std::string getGameDetailsJsonFilepath(); Json::Value getDetailsAsJson(); std::vector getGameFileVector(); std::vector getGameFileVectorFiltered(const unsigned int& iType); @@ -52,6 +54,7 @@ class gameDetails std::string logoFilepath; std::string iconFilepath; std::string changelogFilepath; + std::string gameDetailsJsonFilepath; }; #endif // GAMEDETAILS_H diff --git a/main.cpp b/main.cpp index 468e772..dfb6544 100644 --- a/main.cpp +++ b/main.cpp @@ -261,6 +261,7 @@ int main(int argc, char *argv[]) ("use-cache", bpo::value(&Globals::globalConfig.bUseCache)->zero_tokens()->default_value(false), ("Use game details cache")) ("cache-valid", bpo::value(&Globals::globalConfig.iCacheValid)->default_value(2880), ("Set how long cached game details are valid (in minutes)\nDefault: 2880 minutes (48 hours)")) ("save-serials", bpo::value(&Globals::globalConfig.dlConf.bSaveSerials)->zero_tokens()->default_value(false), "Save serial numbers when downloading") + ("save-game-details-json", bpo::value(&Globals::globalConfig.dlConf.bSaveGameDetailsJson)->zero_tokens()->default_value(false), "Save game details JSON data AS-IS to \"game-details.json\"") ("save-logo", bpo::value(&Globals::globalConfig.dlConf.bSaveLogo)->zero_tokens()->default_value(false), "Save logo when downloading") ("save-icon", bpo::value(&Globals::globalConfig.dlConf.bSaveIcon)->zero_tokens()->default_value(false), "Save icon when downloading") ("ignore-dlc-count", bpo::value(&Globals::globalConfig.sIgnoreDLCCountRegex)->implicit_value(".*"), "Set regular expression filter for games to ignore DLC count information\nIgnoring DLC count information helps in situations where the account page doesn't provide accurate information about DLCs") diff --git a/src/downloader.cpp b/src/downloader.cpp index 0615922..44984c3 100644 --- a/src/downloader.cpp +++ b/src/downloader.cpp @@ -707,6 +707,12 @@ void Downloader::download() this->saveChangelog(games[i].changelog, filepath); } + if (conf.dlConf.bSaveGameDetailsJson && !games[i].gameDetailsJson.empty()) + { + std::string filepath = games[i].getGameDetailsJsonFilepath(); + this->saveGameDetailsJson(games[i].gameDetailsJson, filepath); + } + if ((conf.dlConf.iInclude & GlobalConstants::GFTYPE_DLC) && !games[i].dlcs.empty()) { for (unsigned int j = 0; j < games[i].dlcs.size(); ++j) @@ -2210,6 +2216,47 @@ void Downloader::updateCache() return; } +// Save game details JSON to file +void Downloader::saveGameDetailsJson(const std::string& json, const std::string& filepath) +{ + // Get directory from filepath + boost::filesystem::path pathname = filepath; + std::string directory = pathname.parent_path().string(); + + // Check that directory exists and create subdirectories + boost::filesystem::path path = directory; + if (boost::filesystem::exists(path)) + { + if (!boost::filesystem::is_directory(path)) + { + std::cout << path << " is not directory" << std::endl; + return; + } + } + else + { + if (!boost::filesystem::create_directories(path)) + { + std::cout << "Failed to create directory: " << path << std::endl; + return; + } + } + + std::ofstream ofs(filepath); + if (ofs) + { + std::cout << "Saving game details JSON: " << filepath << std::endl; + ofs << json; + ofs.close(); + } + else + { + std::cout << "Failed to create file: " << filepath << std::endl; + } + + return; +} + // Save serials to file void Downloader::saveSerials(const std::string& serials, const std::string& filepath) { @@ -3633,6 +3680,7 @@ void Downloader::getGameDetailsThread(Config config, const unsigned int& tid) if ((conf.dlConf.bSaveSerials && game.serials.empty()) || (conf.dlConf.bSaveChangelogs && game.changelog.empty()) + || (conf.dlConf.bSaveGameDetailsJson && game.gameDetailsJson.empty()) ) { Json::Value gameDetailsJSON; @@ -3648,6 +3696,9 @@ void Downloader::getGameDetailsThread(Config config, const unsigned int& tid) if (conf.dlConf.bSaveChangelogs && game.changelog.empty()) game.changelog = Downloader::getChangelogFromJSON(gameDetailsJSON); + + if (conf.dlConf.bSaveGameDetailsJson && game.gameDetailsJson.empty()) + game.gameDetailsJson = gameDetailsJSON.toStyledString(); } game.makeFilepaths(conf.dirConf); diff --git a/src/gamedetails.cpp b/src/gamedetails.cpp index fc8b0f8..8c91663 100644 --- a/src/gamedetails.cpp +++ b/src/gamedetails.cpp @@ -95,6 +95,7 @@ void gameDetails::makeFilepaths(const DirectoryConfig& config) this->logoFilepath = Util::makeFilepath(directory, "logo" + logo_ext, this->gamename, subdir, 0); this->iconFilepath = Util::makeFilepath(directory, "icon" + icon_ext, this->gamename, subdir, 0); this->changelogFilepath = Util::makeFilepath(directory, "changelog_" + gamename + ".html", this->gamename, subdir, 0); + this->gameDetailsJsonFilepath = Util::makeFilepath(directory, "game-details.json", this->gamename, subdir, 0); for (unsigned int i = 0; i < this->installers.size(); ++i) { @@ -212,6 +213,11 @@ std::string gameDetails::getChangelogFilepath() return this->changelogFilepath; } +std::string gameDetails::getGameDetailsJsonFilepath() +{ + return this->gameDetailsJsonFilepath; +} + // Return vector containing all game files std::vector gameDetails::getGameFileVector() { diff --git a/src/util.cpp b/src/util.cpp index e577e7f..7fab780 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -439,7 +439,7 @@ void Util::filepathReplaceReservedStrings(std::string& str, const std::string& g platform = "no_platform"; } - // Don't save artwork in "no_platform" folder + // Don't save artwork in "no_platform" folder if (str.rfind("/icon.png") != std::string::npos || str.rfind("/logo.jpg") != std::string::npos) { platform = "";