Add option to delete orphaned files

Renamed --galaxy-delete-orphans to --delete-orphans and made it also work with --check-orphans
This commit is contained in:
Sude 2023-10-13 20:29:09 +03:00
parent 73d18dcc60
commit 89724cd3d3
3 changed files with 13 additions and 4 deletions

View File

@ -53,7 +53,7 @@ struct DownloadConfig
bool bIgnoreDLCCount; bool bIgnoreDLCCount;
bool bDuplicateHandler; bool bDuplicateHandler;
bool bGalaxyDependencies; bool bGalaxyDependencies;
bool bGalaxyDeleteOrphans; bool bDeleteOrphans;
}; };
struct gameSpecificConfig struct gameSpecificConfig

View File

@ -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") ("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") ("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()) ("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") ("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") ("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") ("reset-config", bpo::value<bool>(&Globals::globalConfig.bResetConfig)->zero_tokens()->default_value(false), "Reset config settings to default")
@ -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") ("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()) ("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-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); options_cli_all.add(options_cli_no_cfg).add(options_cli_cfg).add(options_cli_experimental);

View File

@ -1773,6 +1773,15 @@ void Downloader::checkOrphans()
{ {
for (unsigned int i = 0; i < orphans.size(); ++i) for (unsigned int i = 0; i < orphans.size(); ++i)
{ {
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; std::cout << orphans[i] << std::endl;
} }
} }
@ -3945,7 +3954,7 @@ void Downloader::galaxyInstallGameById(const std::string& product_id, int build_
std::cout << "\t" << orphans.size() << " orphaned files" << std::endl; std::cout << "\t" << orphans.size() << " orphaned files" << std::endl;
for (unsigned int i = 0; i < orphans.size(); ++i) 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::string filepath = orphans[i];
std::cout << "Deleting " << filepath << std::endl; std::cout << "Deleting " << filepath << std::endl;