add --save-product-json option

This commit is contained in:
nerdspice 2023-12-28 14:25:11 -05:00
parent 14ad9b9dbc
commit 71a299e80b
7 changed files with 47 additions and 10 deletions

View File

@ -47,6 +47,7 @@ struct DownloadConfig
bool bSaveChangelogs;
bool bSaveSerials;
bool bSaveGameDetailsJson;
bool bSaveProductJson;
bool bSaveLogo;
bool bSaveIcon;
bool bAutomaticXMLCreation;

View File

@ -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);

View File

@ -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<gameFile> getGameFileVector();
std::vector<gameFile> 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

View File

@ -261,7 +261,8 @@ int main(int argc, char *argv[])
("use-cache", bpo::value<bool>(&Globals::globalConfig.bUseCache)->zero_tokens()->default_value(false), ("Use game details cache"))
("cache-valid", bpo::value<int>(&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<bool>(&Globals::globalConfig.dlConf.bSaveSerials)->zero_tokens()->default_value(false), "Save serial numbers when downloading")
("save-game-details-json", bpo::value<bool>(&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<bool>(&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<bool>(&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<bool>(&Globals::globalConfig.dlConf.bSaveLogo)->zero_tokens()->default_value(false), "Save logo when downloading")
("save-icon", bpo::value<bool>(&Globals::globalConfig.dlConf.bSaveIcon)->zero_tokens()->default_value(false), "Save icon when downloading")
("ignore-dlc-count", bpo::value<std::string>(&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")

View File

@ -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())

View File

@ -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<gameFile> gameDetails::getGameFileVector()
{

View File

@ -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())