From f3f26d4da30e1fdcf678f6f320083af63455c6a3 Mon Sep 17 00:00:00 2001 From: Sude Date: Fri, 5 Apr 2013 21:19:03 +0300 Subject: [PATCH] Added redownload option to repair. --- main.cpp | 6 +++--- src/downloader.cpp | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/main.cpp b/main.cpp index d69c673..38eb85d 100644 --- a/main.cpp +++ b/main.cpp @@ -81,7 +81,7 @@ int main(int argc, char *argv[]) ("list", bpo::value(&config.bList)->zero_tokens()->default_value(false), "List games") ("list-details", bpo::value(&config.bListDetails)->zero_tokens()->default_value(false), "List games with detailed info") ("download", bpo::value(&config.bDownload)->zero_tokens()->default_value(false), "Download") - ("repair", bpo::value(&config.bRepair)->zero_tokens()->default_value(false), "Repair downloaded files") + ("repair", bpo::value(&config.bRepair)->zero_tokens()->default_value(false), "Repair downloaded files\nUse --repair --download to redownload files when filesizes don't match (possibly different version). This will delete the old file") ("game", bpo::value(&config.sGameRegex)->default_value(""), "Set regular expression filter\nfor download/list/repair (Perl syntax)\nAliases: \"all\", \"free\"") ("directory", bpo::value(&config.sDirectory)->default_value(""), "Set download directory") #ifndef ENVIRONMENT32 @@ -189,10 +189,10 @@ int main(int argc, char *argv[]) return result; else if (config.bUpdateCheck) // Update check has priority over download and list downloader.updateCheck(); - else if (config.bDownload) // Download games - downloader.download(); else if (config.bRepair) // Repair file downloader.repair(); + else if (config.bDownload) // Download games + downloader.download(); else if (config.bListDetails || config.bList) // Detailed list of games/extras downloader.listGames(); else diff --git a/src/downloader.cpp b/src/downloader.cpp index 37f074c..69fe936 100644 --- a/src/downloader.cpp +++ b/src/downloader.cpp @@ -657,6 +657,26 @@ int Downloader::repairFile(std::string url, std::string filepath, std::string xm { std::cout << "Filesizes don't match" << std::endl << "Incomplete download or different version" << std::endl; + if (this->config.bDownload) + { + fclose(outfile); + std::cout << "Redownloading file" << std::endl; + boost::filesystem::path path = filepath; + if (!boost::filesystem::remove(path)) + { + std::cout << "Failed to delete " << path << std::endl; + res = 0; + } + else + { + CURLcode result = this->downloadFile(url, filepath); + std::cout << std::endl; + if (result == CURLE_OK) + res = 1; + else + res = 0; + } + } return res; }