From d68a30bfb9dfcd2e6996e86c632c41ff2a3313ec Mon Sep 17 00:00:00 2001 From: nerdspice <49222223+nerdspice@users.noreply.github.com> Date: Wed, 22 Nov 2023 16:41:10 -0500 Subject: [PATCH] add --save-icon option --- include/config.h | 1 + include/gamedetails.h | 2 ++ main.cpp | 1 + src/downloader.cpp | 11 +++++++++++ src/gamedetails.cpp | 11 +++++++++++ 5 files changed, 26 insertions(+) diff --git a/include/config.h b/include/config.h index 12413ad..67da5f2 100644 --- a/include/config.h +++ b/include/config.h @@ -47,6 +47,7 @@ struct DownloadConfig bool bSaveChangelogs; bool bSaveSerials; bool bSaveLogo; + bool bSaveIcon; bool bAutomaticXMLCreation; bool bFreeSpaceCheck; diff --git a/include/gamedetails.h b/include/gamedetails.h index 555735a..f45f94a 100644 --- a/include/gamedetails.h +++ b/include/gamedetails.h @@ -37,6 +37,7 @@ class gameDetails void makeFilepaths(const DirectoryConfig& config); std::string getSerialsFilepath(); std::string getLogoFilepath(); + std::string getIconFilepath(); std::string getChangelogFilepath(); Json::Value getDetailsAsJson(); std::vector getGameFileVector(); @@ -49,6 +50,7 @@ class gameDetails private: std::string serialsFilepath; std::string logoFilepath; + std::string iconFilepath; std::string changelogFilepath; }; diff --git a/main.cpp b/main.cpp index 3676c9c..fb0883e 100644 --- a/main.cpp +++ b/main.cpp @@ -262,6 +262,7 @@ int main(int argc, char *argv[]) ("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-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") ("include", bpo::value(&sIncludeOptions)->default_value("all"), ("Select what to download/list/repair\n" + include_options_text).c_str()) ("exclude", bpo::value(&sExcludeOptions)->default_value(""), ("Select what not to download/list/repair\n" + include_options_text).c_str()) diff --git a/src/downloader.cpp b/src/downloader.cpp index a575707..681fee5 100644 --- a/src/downloader.cpp +++ b/src/downloader.cpp @@ -695,6 +695,12 @@ void Downloader::download() this->downloadFile(games[i].logo, filepath, "", games[i].gamename); } + if (conf.dlConf.bSaveIcon && !games[i].icon.empty()) + { + std::string filepath = games[i].getIconFilepath(); + this->downloadFile(games[i].icon, filepath, "", games[i].gamename); + } + if (conf.dlConf.bSaveChangelogs && !games[i].changelog.empty()) { std::string filepath = games[i].getChangelogFilepath(); @@ -715,6 +721,11 @@ void Downloader::download() std::string filepath = games[i].dlcs[j].getLogoFilepath(); this->downloadFile(games[i].dlcs[j].logo, filepath, "", games[i].dlcs[j].gamename); } + if (conf.dlConf.bSaveIcon && !games[i].dlcs[j].icon.empty()) + { + std::string filepath = games[i].dlcs[j].getIconFilepath(); + this->downloadFile(games[i].dlcs[j].icon, filepath, "", games[i].dlcs[j].gamename); + } if (conf.dlConf.bSaveChangelogs && !games[i].dlcs[j].changelog.empty()) { std::string filepath = games[i].dlcs[j].getChangelogFilepath(); diff --git a/src/gamedetails.cpp b/src/gamedetails.cpp index f73bfed..e2be559 100644 --- a/src/gamedetails.cpp +++ b/src/gamedetails.cpp @@ -83,12 +83,17 @@ void gameDetails::makeFilepaths(const DirectoryConfig& config) std::string directory = config.sDirectory + "/" + config.sGameSubdir + "/"; std::string subdir; std::string logo_ext = ".jpg"; // Assume jpg + std::string icon_ext = ".png"; // Assume png if (this->logo.rfind(".") != std::string::npos) logo_ext = this->logo.substr(this->logo.rfind(".")); + if (this->icon.rfind(".") != std::string::npos) + icon_ext = this->icon.substr(this->icon.rfind(".")); + this->serialsFilepath = Util::makeFilepath(directory, "serials.txt", 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->changelogFilepath = Util::makeFilepath(directory, "changelog_" + gamename + ".html", this->gamename, subdir, 0); for (unsigned int i = 0; i < this->installers.size(); ++i) @@ -124,6 +129,7 @@ void gameDetails::makeFilepaths(const DirectoryConfig& config) subdir = config.bSubDirectories ? config.sDLCSubdir + "/" + config.sInstallersSubdir : ""; this->dlcs[i].serialsFilepath = Util::makeFilepath(directory, "serials.txt", this->gamename, subdir, 0); this->dlcs[i].logoFilepath = Util::makeFilepath(directory, "logo" + logo_ext, this->gamename, subdir, 0); + this->dlcs[i].iconFilepath = Util::makeFilepath(directory, "icon" + icon_ext, this->gamename, subdir, 0); this->dlcs[i].changelogFilepath = Util::makeFilepath(directory, "changelog_" + this->dlcs[i].gamename + ".html", this->gamename, subdir, 0); for (unsigned int j = 0; j < this->dlcs[i].installers.size(); ++j) { @@ -196,6 +202,11 @@ std::string gameDetails::getLogoFilepath() return this->logoFilepath; } +std::string gameDetails::getIconFilepath() +{ + return this->iconFilepath; +} + std::string gameDetails::getChangelogFilepath() { return this->changelogFilepath;