diff --git a/include/config.h b/include/config.h index b35806f..2058c31 100644 --- a/include/config.h +++ b/include/config.h @@ -47,6 +47,7 @@ struct DownloadConfig bool bSaveChangelogs; bool bSaveSerials; bool bSaveGameDetailsJson; + bool bSaveProductJson; bool bSaveLogo; bool bSaveIcon; bool bAutomaticXMLCreation; diff --git a/include/downloader.h b/include/downloader.h index c4c11a5..6c2945d 100644 --- a/include/downloader.h +++ b/include/downloader.h @@ -148,7 +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 saveJsonFile(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 29d1028..fc11d02 100644 --- a/include/gamedetails.h +++ b/include/gamedetails.h @@ -34,6 +34,7 @@ class gameDetails std::string changelog; std::string logo; std::string gameDetailsJson; + std::string productJson; void filterWithPriorities(const gameSpecificConfig& config); void makeFilepaths(const DirectoryConfig& config); std::string getSerialsFilepath(); @@ -41,6 +42,7 @@ class gameDetails std::string getIconFilepath(); std::string getChangelogFilepath(); std::string getGameDetailsJsonFilepath(); + std::string getProductJsonFilepath(); Json::Value getDetailsAsJson(); std::vector getGameFileVector(); std::vector getGameFileVectorFiltered(const unsigned int& iType); @@ -55,6 +57,7 @@ class gameDetails std::string iconFilepath; std::string changelogFilepath; std::string gameDetailsJsonFilepath; + std::string productJsonFilepath; }; #endif // GAMEDETAILS_H diff --git a/main.cpp b/main.cpp index dfb6544..ccdd892 100644 --- a/main.cpp +++ b/main.cpp @@ -261,7 +261,8 @@ 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-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-product-json", bpo::value(&Globals::globalConfig.dlConf.bSaveProductJson)->zero_tokens()->default_value(false), "Save product info JSON data from the API as-is to \"product.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 44984c3..1f19456 100644 --- a/src/downloader.cpp +++ b/src/downloader.cpp @@ -710,7 +710,13 @@ void Downloader::download() if (conf.dlConf.bSaveGameDetailsJson && !games[i].gameDetailsJson.empty()) { std::string filepath = games[i].getGameDetailsJsonFilepath(); - this->saveGameDetailsJson(games[i].gameDetailsJson, filepath); + this->saveJsonFile(games[i].gameDetailsJson, filepath); + } + + if (conf.dlConf.bSaveProductJson && !games[i].productJson.empty()) + { + std::string filepath = games[i].getProductJsonFilepath(); + this->saveJsonFile(games[i].productJson, filepath); } if ((conf.dlConf.iInclude & GlobalConstants::GFTYPE_DLC) && !games[i].dlcs.empty()) @@ -737,6 +743,11 @@ void Downloader::download() std::string filepath = games[i].dlcs[j].getChangelogFilepath(); this->saveChangelog(games[i].dlcs[j].changelog, filepath); } + if (conf.dlConf.bSaveProductJson && !games[i].dlcs[j].productJson.empty()) + { + std::string filepath = games[i].dlcs[j].getProductJsonFilepath(); + this->saveJsonFile(games[i].dlcs[j].productJson, filepath); + } } } @@ -2216,8 +2227,8 @@ void Downloader::updateCache() return; } -// Save game details JSON to file -void Downloader::saveGameDetailsJson(const std::string& json, const std::string& filepath) +// Save JSON data to file +void Downloader::saveJsonFile(const std::string& json, const std::string& filepath) { // Get directory from filepath boost::filesystem::path pathname = filepath; @@ -2245,7 +2256,7 @@ void Downloader::saveGameDetailsJson(const std::string& json, const std::string& std::ofstream ofs(filepath); if (ofs) { - std::cout << "Saving game details JSON: " << filepath << std::endl; + std::cout << "Saving JSON data: " << filepath << std::endl; ofs << json; ofs.close(); } @@ -3678,6 +3689,18 @@ void Downloader::getGameDetailsThread(Config config, const unsigned int& tid) game.filterWithPriorities(conf); game.filterWithType(conf.dlConf.iInclude); + if (conf.dlConf.bSaveProductJson && game.productJson.empty()) + game.productJson = product_info.toStyledString(); + + if (conf.dlConf.bSaveProductJson && game.dlcs.size()) { + for (unsigned int i = 0; i < game.dlcs.size(); ++i) { + if (game.dlcs[i].productJson.empty()) { + Json::Value dlc_info = galaxy->getProductInfo(game.dlcs[i].product_id); + game.dlcs[i].productJson = dlc_info.toStyledString(); + } + } + } + if ((conf.dlConf.bSaveSerials && game.serials.empty()) || (conf.dlConf.bSaveChangelogs && game.changelog.empty()) || (conf.dlConf.bSaveGameDetailsJson && game.gameDetailsJson.empty()) diff --git a/src/gamedetails.cpp b/src/gamedetails.cpp index 8c91663..48e6c3e 100644 --- a/src/gamedetails.cpp +++ b/src/gamedetails.cpp @@ -96,6 +96,7 @@ void gameDetails::makeFilepaths(const DirectoryConfig& config) 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); + this->productJsonFilepath = Util::makeFilepath(directory, "product.json", this->gamename, subdir, 0); for (unsigned int i = 0; i < this->installers.size(); ++i) { @@ -132,6 +133,7 @@ void gameDetails::makeFilepaths(const DirectoryConfig& config) this->dlcs[i].logoFilepath = Util::makeFilepath(directory, "logo" + logo_ext, this->gamename, subdir, 0, this->dlcs[i].gamename); this->dlcs[i].iconFilepath = Util::makeFilepath(directory, "icon" + icon_ext, this->gamename, subdir, 0, this->dlcs[i].gamename); this->dlcs[i].changelogFilepath = Util::makeFilepath(directory, "changelog_" + this->dlcs[i].gamename + ".html", this->gamename, subdir, 0); + this->dlcs[i].productJsonFilepath = Util::makeFilepath(directory, "product.json", this->gamename, subdir, 0, this->dlcs[i].gamename); for (unsigned int j = 0; j < this->dlcs[i].installers.size(); ++j) { subdir = config.bSubDirectories ? config.sDLCSubdir + "/" + config.sInstallersSubdir : ""; @@ -218,6 +220,11 @@ std::string gameDetails::getGameDetailsJsonFilepath() return this->gameDetailsJsonFilepath; } +std::string gameDetails::getProductJsonFilepath() +{ + return this->productJsonFilepath; +} + // Return vector containing all game files std::vector gameDetails::getGameFileVector() { diff --git a/src/util.cpp b/src/util.cpp index 7fab780..218f1c1 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -439,11 +439,13 @@ void Util::filepathReplaceReservedStrings(std::string& str, const std::string& g platform = "no_platform"; } - // Don't save artwork in "no_platform" folder - if (str.rfind("/icon.png") != std::string::npos || str.rfind("/logo.jpg") != std::string::npos) - { + // 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())