mirror of
https://github.com/Sude-/lgogdownloader.git
synced 2024-11-20 11:49:17 +01:00
add --save-product-json option
This commit is contained in:
parent
14ad9b9dbc
commit
71a299e80b
@ -47,6 +47,7 @@ struct DownloadConfig
|
|||||||
bool bSaveChangelogs;
|
bool bSaveChangelogs;
|
||||||
bool bSaveSerials;
|
bool bSaveSerials;
|
||||||
bool bSaveGameDetailsJson;
|
bool bSaveGameDetailsJson;
|
||||||
|
bool bSaveProductJson;
|
||||||
bool bSaveLogo;
|
bool bSaveLogo;
|
||||||
bool bSaveIcon;
|
bool bSaveIcon;
|
||||||
bool bAutomaticXMLCreation;
|
bool bAutomaticXMLCreation;
|
||||||
|
@ -148,7 +148,7 @@ class Downloader
|
|||||||
static std::string getSerialsFromJSON(const Json::Value& json);
|
static std::string getSerialsFromJSON(const Json::Value& json);
|
||||||
void saveSerials(const std::string& serials, const std::string& filepath);
|
void saveSerials(const std::string& serials, const std::string& filepath);
|
||||||
static std::string getChangelogFromJSON(const Json::Value& json);
|
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);
|
void saveChangelog(const std::string& changelog, const std::string& filepath);
|
||||||
static void processDownloadQueue(Config conf, const unsigned int& tid);
|
static void processDownloadQueue(Config conf, const unsigned int& tid);
|
||||||
static void processCloudSaveDownloadQueue(Config conf, const unsigned int& tid);
|
static void processCloudSaveDownloadQueue(Config conf, const unsigned int& tid);
|
||||||
|
@ -34,6 +34,7 @@ class gameDetails
|
|||||||
std::string changelog;
|
std::string changelog;
|
||||||
std::string logo;
|
std::string logo;
|
||||||
std::string gameDetailsJson;
|
std::string gameDetailsJson;
|
||||||
|
std::string productJson;
|
||||||
void filterWithPriorities(const gameSpecificConfig& config);
|
void filterWithPriorities(const gameSpecificConfig& config);
|
||||||
void makeFilepaths(const DirectoryConfig& config);
|
void makeFilepaths(const DirectoryConfig& config);
|
||||||
std::string getSerialsFilepath();
|
std::string getSerialsFilepath();
|
||||||
@ -41,6 +42,7 @@ class gameDetails
|
|||||||
std::string getIconFilepath();
|
std::string getIconFilepath();
|
||||||
std::string getChangelogFilepath();
|
std::string getChangelogFilepath();
|
||||||
std::string getGameDetailsJsonFilepath();
|
std::string getGameDetailsJsonFilepath();
|
||||||
|
std::string getProductJsonFilepath();
|
||||||
Json::Value getDetailsAsJson();
|
Json::Value getDetailsAsJson();
|
||||||
std::vector<gameFile> getGameFileVector();
|
std::vector<gameFile> getGameFileVector();
|
||||||
std::vector<gameFile> getGameFileVectorFiltered(const unsigned int& iType);
|
std::vector<gameFile> getGameFileVectorFiltered(const unsigned int& iType);
|
||||||
@ -55,6 +57,7 @@ class gameDetails
|
|||||||
std::string iconFilepath;
|
std::string iconFilepath;
|
||||||
std::string changelogFilepath;
|
std::string changelogFilepath;
|
||||||
std::string gameDetailsJsonFilepath;
|
std::string gameDetailsJsonFilepath;
|
||||||
|
std::string productJsonFilepath;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // GAMEDETAILS_H
|
#endif // GAMEDETAILS_H
|
||||||
|
3
main.cpp
3
main.cpp
@ -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"))
|
("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)"))
|
("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-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-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")
|
("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")
|
("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")
|
||||||
|
@ -710,7 +710,13 @@ void Downloader::download()
|
|||||||
if (conf.dlConf.bSaveGameDetailsJson && !games[i].gameDetailsJson.empty())
|
if (conf.dlConf.bSaveGameDetailsJson && !games[i].gameDetailsJson.empty())
|
||||||
{
|
{
|
||||||
std::string filepath = games[i].getGameDetailsJsonFilepath();
|
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())
|
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();
|
std::string filepath = games[i].dlcs[j].getChangelogFilepath();
|
||||||
this->saveChangelog(games[i].dlcs[j].changelog, filepath);
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save game details JSON to file
|
// Save JSON data to file
|
||||||
void Downloader::saveGameDetailsJson(const std::string& json, const std::string& filepath)
|
void Downloader::saveJsonFile(const std::string& json, const std::string& filepath)
|
||||||
{
|
{
|
||||||
// Get directory from filepath
|
// Get directory from filepath
|
||||||
boost::filesystem::path pathname = filepath;
|
boost::filesystem::path pathname = filepath;
|
||||||
@ -2245,7 +2256,7 @@ void Downloader::saveGameDetailsJson(const std::string& json, const std::string&
|
|||||||
std::ofstream ofs(filepath);
|
std::ofstream ofs(filepath);
|
||||||
if (ofs)
|
if (ofs)
|
||||||
{
|
{
|
||||||
std::cout << "Saving game details JSON: " << filepath << std::endl;
|
std::cout << "Saving JSON data: " << filepath << std::endl;
|
||||||
ofs << json;
|
ofs << json;
|
||||||
ofs.close();
|
ofs.close();
|
||||||
}
|
}
|
||||||
@ -3678,6 +3689,18 @@ void Downloader::getGameDetailsThread(Config config, const unsigned int& tid)
|
|||||||
game.filterWithPriorities(conf);
|
game.filterWithPriorities(conf);
|
||||||
game.filterWithType(conf.dlConf.iInclude);
|
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())
|
if ((conf.dlConf.bSaveSerials && game.serials.empty())
|
||||||
|| (conf.dlConf.bSaveChangelogs && game.changelog.empty())
|
|| (conf.dlConf.bSaveChangelogs && game.changelog.empty())
|
||||||
|| (conf.dlConf.bSaveGameDetailsJson && game.gameDetailsJson.empty())
|
|| (conf.dlConf.bSaveGameDetailsJson && game.gameDetailsJson.empty())
|
||||||
|
@ -96,6 +96,7 @@ void gameDetails::makeFilepaths(const DirectoryConfig& config)
|
|||||||
this->iconFilepath = Util::makeFilepath(directory, "icon" + icon_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->changelogFilepath = Util::makeFilepath(directory, "changelog_" + gamename + ".html", this->gamename, subdir, 0);
|
||||||
this->gameDetailsJsonFilepath = Util::makeFilepath(directory, "game-details.json", 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)
|
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].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].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].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)
|
for (unsigned int j = 0; j < this->dlcs[i].installers.size(); ++j)
|
||||||
{
|
{
|
||||||
subdir = config.bSubDirectories ? config.sDLCSubdir + "/" + config.sInstallersSubdir : "";
|
subdir = config.bSubDirectories ? config.sDLCSubdir + "/" + config.sInstallersSubdir : "";
|
||||||
@ -218,6 +220,11 @@ std::string gameDetails::getGameDetailsJsonFilepath()
|
|||||||
return this->gameDetailsJsonFilepath;
|
return this->gameDetailsJsonFilepath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string gameDetails::getProductJsonFilepath()
|
||||||
|
{
|
||||||
|
return this->productJsonFilepath;
|
||||||
|
}
|
||||||
|
|
||||||
// Return vector containing all game files
|
// Return vector containing all game files
|
||||||
std::vector<gameFile> gameDetails::getGameFileVector()
|
std::vector<gameFile> gameDetails::getGameFileVector()
|
||||||
{
|
{
|
||||||
|
10
src/util.cpp
10
src/util.cpp
@ -439,11 +439,13 @@ void Util::filepathReplaceReservedStrings(std::string& str, const std::string& g
|
|||||||
platform = "no_platform";
|
platform = "no_platform";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't save artwork in "no_platform" folder
|
// Don't save certain files in "no_platform" folder
|
||||||
if (str.rfind("/icon.png") != std::string::npos || str.rfind("/logo.jpg") != std::string::npos)
|
if (
|
||||||
{
|
str.rfind("/icon.png") != std::string::npos
|
||||||
|
|| str.rfind("/logo.jpg") != std::string::npos
|
||||||
|
|| str.rfind("/product.json") != std::string::npos
|
||||||
|
)
|
||||||
platform = "";
|
platform = "";
|
||||||
}
|
|
||||||
|
|
||||||
std::string gamename_firstletter;
|
std::string gamename_firstletter;
|
||||||
if (!gamename.empty())
|
if (!gamename.empty())
|
||||||
|
Loading…
Reference in New Issue
Block a user