This commit is contained in:
Sude 2024-01-14 11:43:13 +02:00
commit 70151a4d81
7 changed files with 64 additions and 1 deletions

View File

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

View File

@ -148,6 +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 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);

View File

@ -33,12 +33,14 @@ class gameDetails
std::string serials; std::string serials;
std::string changelog; std::string changelog;
std::string logo; std::string logo;
std::string gameDetailsJson;
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();
std::string getLogoFilepath(); std::string getLogoFilepath();
std::string getIconFilepath(); std::string getIconFilepath();
std::string getChangelogFilepath(); std::string getChangelogFilepath();
std::string getGameDetailsJsonFilepath();
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);
@ -52,6 +54,7 @@ class gameDetails
std::string logoFilepath; std::string logoFilepath;
std::string iconFilepath; std::string iconFilepath;
std::string changelogFilepath; std::string changelogFilepath;
std::string gameDetailsJsonFilepath;
}; };
#endif // GAMEDETAILS_H #endif // GAMEDETAILS_H

View File

@ -261,6 +261,7 @@ 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-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")

View File

@ -707,6 +707,12 @@ void Downloader::download()
this->saveChangelog(games[i].changelog, filepath); 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()) if ((conf.dlConf.iInclude & GlobalConstants::GFTYPE_DLC) && !games[i].dlcs.empty())
{ {
for (unsigned int j = 0; j < games[i].dlcs.size(); ++j) for (unsigned int j = 0; j < games[i].dlcs.size(); ++j)
@ -2210,6 +2216,47 @@ void Downloader::updateCache()
return; 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 // Save serials to file
void Downloader::saveSerials(const std::string& serials, const std::string& filepath) 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()) 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())
) )
{ {
Json::Value gameDetailsJSON; Json::Value gameDetailsJSON;
@ -3648,6 +3696,9 @@ void Downloader::getGameDetailsThread(Config config, const unsigned int& tid)
if (conf.dlConf.bSaveChangelogs && game.changelog.empty()) if (conf.dlConf.bSaveChangelogs && game.changelog.empty())
game.changelog = Downloader::getChangelogFromJSON(gameDetailsJSON); game.changelog = Downloader::getChangelogFromJSON(gameDetailsJSON);
if (conf.dlConf.bSaveGameDetailsJson && game.gameDetailsJson.empty())
game.gameDetailsJson = gameDetailsJSON.toStyledString();
} }
game.makeFilepaths(conf.dirConf); game.makeFilepaths(conf.dirConf);

View File

@ -95,6 +95,7 @@ void gameDetails::makeFilepaths(const DirectoryConfig& config)
this->logoFilepath = Util::makeFilepath(directory, "logo" + logo_ext, this->gamename, subdir, 0); 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->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);
for (unsigned int i = 0; i < this->installers.size(); ++i) for (unsigned int i = 0; i < this->installers.size(); ++i)
{ {
@ -212,6 +213,11 @@ std::string gameDetails::getChangelogFilepath()
return this->changelogFilepath; return this->changelogFilepath;
} }
std::string gameDetails::getGameDetailsJsonFilepath()
{
return this->gameDetailsJsonFilepath;
}
// Return vector containing all game files // Return vector containing all game files
std::vector<gameFile> gameDetails::getGameFileVector() std::vector<gameFile> gameDetails::getGameFileVector()
{ {

View File

@ -439,7 +439,7 @@ 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 artwork 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)
{ {
platform = ""; platform = "";