Skip to content

Commit

Permalink
Add option to delete orphaned files
Browse files Browse the repository at this point in the history
Renamed --galaxy-delete-orphans to --delete-orphans and made it also work with --check-orphans
  • Loading branch information
Sude- committed Oct 13, 2023
1 parent 73d18dc commit 89724cd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ struct DownloadConfig
bool bIgnoreDLCCount;
bool bDuplicateHandler;
bool bGalaxyDependencies;
bool bGalaxyDeleteOrphans;
bool bDeleteOrphans;
};

struct gameSpecificConfig
Expand Down
2 changes: 1 addition & 1 deletion main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ int main(int argc, char *argv[])
("new", bpo::value<bool>(&Globals::globalConfig.bNew)->zero_tokens()->default_value(false), "List/download only games with new flag set")
("clear-update-flags", bpo::value<bool>(&bClearUpdateNotifications)->zero_tokens()->default_value(false), "Clear update notification flags")
("check-orphans", bpo::value<std::string>(&Globals::globalConfig.sOrphanRegex)->implicit_value(""), check_orphans_text.c_str())
("delete-orphans", bpo::value<bool>(&Globals::globalConfig.dlConf.bDeleteOrphans)->zero_tokens()->default_value(false), "Delete orphaned files during --check-orphans and --galaxy-install")
("status", bpo::value<bool>(&Globals::globalConfig.bCheckStatus)->zero_tokens()->default_value(false), "Show status of files\n\nOutput format:\nstatuscode gamename filename filesize filehash\n\nStatus codes:\nOK - File is OK\nND - File is not downloaded\nMD5 - MD5 mismatch, different version\nFS - File size mismatch, incomplete download\n\nSee also --no-fast-status-check option")
("save-config", bpo::value<bool>(&Globals::globalConfig.bSaveConfig)->zero_tokens()->default_value(false), "Create config file with current settings")
("reset-config", bpo::value<bool>(&Globals::globalConfig.bResetConfig)->zero_tokens()->default_value(false), "Reset config settings to default")
Expand Down Expand Up @@ -299,7 +300,6 @@ int main(int argc, char *argv[])
("galaxy-no-dependencies", bpo::value<bool>(&bNoGalaxyDependencies)->zero_tokens()->default_value(false), "Don't download dependencies during --galaxy-install")
("subdir-galaxy-install", bpo::value<std::string>(&Globals::globalConfig.dirConf.sGalaxyInstallSubdir)->default_value("%install_dir%"), galaxy_install_subdir_text.c_str())
("galaxy-cdn-priority", bpo::value<std::string>(&sGalaxyCDN)->default_value("edgecast,highwinds,akamai,lumen,gog_cdn"), galaxy_cdn_priority_text.c_str())
("galaxy-delete-orphans", bpo::value<bool>(&Globals::globalConfig.dlConf.bGalaxyDeleteOrphans)->zero_tokens()->default_value(false), "Delete orphaned files during --galaxy-install")
;

options_cli_all.add(options_cli_no_cfg).add(options_cli_cfg).add(options_cli_experimental);
Expand Down
13 changes: 11 additions & 2 deletions src/downloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1773,7 +1773,16 @@ void Downloader::checkOrphans()
{
for (unsigned int i = 0; i < orphans.size(); ++i)
{
std::cout << orphans[i] << std::endl;
if (Globals::globalConfig.dlConf.bDeleteOrphans)
{
std::string filepath = orphans[i];
std::cout << "Deleting " << filepath << std::endl;
if (boost::filesystem::exists(filepath))
if (!boost::filesystem::remove(filepath))
std::cerr << "Failed to delete " << filepath << std::endl;
}
else
std::cout << orphans[i] << std::endl;
}
}
else
Expand Down Expand Up @@ -3945,7 +3954,7 @@ void Downloader::galaxyInstallGameById(const std::string& product_id, int build_
std::cout << "\t" << orphans.size() << " orphaned files" << std::endl;
for (unsigned int i = 0; i < orphans.size(); ++i)
{
if (Globals::globalConfig.dlConf.bGalaxyDeleteOrphans)
if (Globals::globalConfig.dlConf.bDeleteOrphans)
{
std::string filepath = orphans[i];
std::cout << "Deleting " << filepath << std::endl;
Expand Down

0 comments on commit 89724cd

Please sign in to comment.