Use cerr for password prompts, error messages, rolling status

messages, and other stuff that shouldn't clutter saved stdout.
Probably needs more work.
This commit is contained in:
Thomas J. Moore 2016-02-20 14:56:44 -06:00
parent f786e94970
commit c0735d5993
3 changed files with 108 additions and 108 deletions

View File

@ -209,7 +209,7 @@ int main(int argc, char *argv[])
{ {
if (!boost::filesystem::create_directories(path)) if (!boost::filesystem::create_directories(path))
{ {
std::cout << "Failed to create directory: " << path << std::endl; std::cerr << "Failed to create directory: " << path << std::endl;
return 1; return 1;
} }
} }
@ -219,7 +219,7 @@ int main(int argc, char *argv[])
{ {
if (!boost::filesystem::create_directories(path)) if (!boost::filesystem::create_directories(path))
{ {
std::cout << "Failed to create directory: " << path << std::endl; std::cerr << "Failed to create directory: " << path << std::endl;
return 1; return 1;
} }
} }
@ -229,7 +229,7 @@ int main(int argc, char *argv[])
{ {
if (!boost::filesystem::create_directories(path)) if (!boost::filesystem::create_directories(path))
{ {
std::cout << "Failed to create directory: " << path << std::endl; std::cerr << "Failed to create directory: " << path << std::endl;
return 1; return 1;
} }
} }
@ -239,7 +239,7 @@ int main(int argc, char *argv[])
std::ifstream ifs(config.sConfigFilePath.c_str()); std::ifstream ifs(config.sConfigFilePath.c_str());
if (!ifs) if (!ifs)
{ {
std::cout << "Could not open config file: " << config.sConfigFilePath << std::endl; std::cerr << "Could not open config file: " << config.sConfigFilePath << std::endl;
return 1; return 1;
} }
else else
@ -256,7 +256,7 @@ int main(int argc, char *argv[])
std::ifstream ifs(config.sBlacklistFilePath.c_str()); std::ifstream ifs(config.sBlacklistFilePath.c_str());
if (!ifs) if (!ifs)
{ {
std::cout << "Could not open blacklist file: " << config.sBlacklistFilePath << std::endl; std::cerr << "Could not open blacklist file: " << config.sBlacklistFilePath << std::endl;
return 1; return 1;
} }
else else
@ -363,13 +363,13 @@ int main(int argc, char *argv[])
if (config.iInstallerPlatform < GlobalConstants::PLATFORMS[0].id || config.iInstallerPlatform > platform_all) if (config.iInstallerPlatform < GlobalConstants::PLATFORMS[0].id || config.iInstallerPlatform > platform_all)
{ {
std::cout << "Invalid value for --platform" << std::endl; std::cerr << "Invalid value for --platform" << std::endl;
return 1; return 1;
} }
if (config.iInstallerLanguage < GlobalConstants::LANGUAGES[0].id || config.iInstallerLanguage > language_all) if (config.iInstallerLanguage < GlobalConstants::LANGUAGES[0].id || config.iInstallerLanguage > language_all)
{ {
std::cout << "Invalid value for --language" << std::endl; std::cerr << "Invalid value for --language" << std::endl;
return 1; return 1;
} }
@ -435,7 +435,7 @@ int main(int argc, char *argv[])
std::ofstream ofs(config.sConfigFilePath.c_str()); std::ofstream ofs(config.sConfigFilePath.c_str());
if (ofs) if (ofs)
{ {
std::cout << "Saving config: " << config.sConfigFilePath << std::endl; std::cerr << "Saving config: " << config.sConfigFilePath << std::endl;
for (bpo::variables_map::iterator it = vm.begin(); it != vm.end(); ++it) for (bpo::variables_map::iterator it = vm.begin(); it != vm.end(); ++it)
{ {
std::string option = it->first; std::string option = it->first;
@ -486,7 +486,7 @@ int main(int argc, char *argv[])
} }
else else
{ {
std::cout << "Failed to create config: " << config.sConfigFilePath << std::endl; std::cerr << "Failed to create config: " << config.sConfigFilePath << std::endl;
return 1; return 1;
} }
} }
@ -506,7 +506,7 @@ int main(int argc, char *argv[])
} }
else else
{ {
std::cout << "Failed to create config: " << config.sConfigFilePath << std::endl; std::cerr << "Failed to create config: " << config.sConfigFilePath << std::endl;
return 1; return 1;
} }
} }
@ -535,7 +535,7 @@ int main(int argc, char *argv[])
downloader.checkStatus(); downloader.checkStatus();
else else
{ // Show help message { // Show help message
std::cout << config.sVersionString << std::endl std::cerr << config.sVersionString << std::endl
<< options_cli_all << std::endl; << options_cli_all << std::endl;
} }

View File

@ -32,7 +32,7 @@ Downloader::Downloader(Config &conf)
this->config = conf; this->config = conf;
if (config.bLoginHTTP && boost::filesystem::exists(config.sCookiePath)) if (config.bLoginHTTP && boost::filesystem::exists(config.sCookiePath))
if (!boost::filesystem::remove(config.sCookiePath)) if (!boost::filesystem::remove(config.sCookiePath))
std::cout << "Failed to delete " << config.sCookiePath << std::endl; std::cerr << "Failed to delete " << config.sCookiePath << std::endl;
} }
Downloader::~Downloader() Downloader::~Downloader()
@ -105,7 +105,7 @@ int Downloader::init()
this->report_ofs.open(config.sReportFilePath); this->report_ofs.open(config.sReportFilePath);
if (!this->report_ofs) if (!this->report_ofs)
{ {
std::cout << "Failed to create " << config.sReportFilePath << std::endl; std::cerr << "Failed to create " << config.sReportFilePath << std::endl;
return 1; return 1;
} }
} }
@ -122,16 +122,16 @@ int Downloader::login()
char *pwd; char *pwd;
std::string email; std::string email;
if (!isatty(STDIN_FILENO)) { if (!isatty(STDIN_FILENO)) {
std::cout << "Unable to read email and password" << std::endl; std::cerr << "Unable to read email and password" << std::endl;
return 0; return 0;
} }
std::cout << "Email: "; std::cerr << "Email: ";
std::getline(std::cin,email); std::getline(std::cin,email);
pwd = getpass("Password: "); pwd = getpass("Password: ");
std::string password = (std::string)pwd; std::string password = (std::string)pwd;
if (email.empty() || password.empty()) if (email.empty() || password.empty())
{ {
std::cout << "Email and/or password empty" << std::endl; std::cerr << "Email and/or password empty" << std::endl;
return 0; return 0;
} }
else else
@ -141,12 +141,12 @@ int Downloader::login()
{ {
if (!HTTP_Login(email, password)) if (!HTTP_Login(email, password))
{ {
std::cout << "HTTP: Login failed" << std::endl; std::cerr << "HTTP: Login failed" << std::endl;
return 0; return 0;
} }
else else
{ {
std::cout << "HTTP: Login successful" << std::endl; std::cerr << "HTTP: Login successful" << std::endl;
if (!config.bLoginAPI) if (!config.bLoginAPI)
return 1; return 1;
} }
@ -156,12 +156,12 @@ int Downloader::login()
{ {
if (!gogAPI->login(email, password)) if (!gogAPI->login(email, password))
{ {
std::cout << "API: Login failed" << std::endl; std::cerr << "API: Login failed" << std::endl;
return 0; return 0;
} }
else else
{ {
std::cout << "API: Login successful" << std::endl; std::cerr << "API: Login successful" << std::endl;
config.sToken = gogAPI->getToken(); config.sToken = gogAPI->getToken();
config.sSecret = gogAPI->getSecret(); config.sSecret = gogAPI->getSecret();
return 1; return 1;
@ -227,7 +227,7 @@ int Downloader::getGameDetails()
if (config.sGameRegex == "all") if (config.sGameRegex == "all")
config.sGameRegex = ".*"; config.sGameRegex = ".*";
else if (config.sGameRegex == "free") else if (config.sGameRegex == "free")
std::cout << "Warning: regex alias \"free\" doesn't work with cached details" << std::endl; std::cerr << "Warning: regex alias \"free\" doesn't work with cached details" << std::endl;
int result = this->loadGameDetailsCache(); int result = this->loadGameDetailsCache();
if (result == 0) if (result == 0)
@ -245,13 +245,13 @@ int Downloader::getGameDetails()
{ {
if (result == 1) if (result == 1)
{ {
std::cout << "Cache doesn't exist." << std::endl; std::cerr << "Cache doesn't exist." << std::endl;
std::cout << "Create cache with --update-cache" << std::endl; std::cerr << "Create cache with --update-cache" << std::endl;
} }
else if (result == 3) else if (result == 3)
{ {
std::cout << "Cache is too old." << std::endl; std::cerr << "Cache is too old." << std::endl;
std::cout << "Update cache with --update-cache or use bigger --cache-valid" << std::endl; std::cerr << "Update cache with --update-cache or use bigger --cache-valid" << std::endl;
} }
return 1; return 1;
} }
@ -261,7 +261,7 @@ int Downloader::getGameDetails()
int updated = 0; int updated = 0;
for (unsigned int i = 0; i < gameItems.size(); ++i) for (unsigned int i = 0; i < gameItems.size(); ++i)
{ {
std::cout << "Getting game info " << i+1 << " / " << gameItems.size() << "\r" << std::flush; std::cerr << "Getting game info " << i+1 << " / " << gameItems.size() << "\r" << std::flush;
bool bHasDLC = !gameItems[i].dlcnames.empty(); bool bHasDLC = !gameItems[i].dlcnames.empty();
gameSpecificConfig conf; gameSpecificConfig conf;
@ -277,31 +277,31 @@ int Downloader::getGameDetails()
int iOptionsOverridden = Util::getGameSpecificConfig(gameItems[i].name, &conf); int iOptionsOverridden = Util::getGameSpecificConfig(gameItems[i].name, &conf);
if (iOptionsOverridden > 0) if (iOptionsOverridden > 0)
{ {
std::cout << std::endl << gameItems[i].name << " - " << iOptionsOverridden << " options overridden with game specific options" << std::endl; std::cerr << std::endl << gameItems[i].name << " - " << iOptionsOverridden << " options overridden with game specific options" << std::endl;
if (config.bVerbose) if (config.bVerbose)
{ {
if (conf.bIgnoreDLCCount) if (conf.bIgnoreDLCCount)
std::cout << "\tIgnore DLC count" << std::endl; std::cerr << "\tIgnore DLC count" << std::endl;
if (conf.bDLC != config.bDLC) if (conf.bDLC != config.bDLC)
std::cout << "\tDLC: " << (conf.bDLC ? "true" : "false") << std::endl; std::cerr << "\tDLC: " << (conf.bDLC ? "true" : "false") << std::endl;
if (conf.iInstallerLanguage != config.iInstallerLanguage) if (conf.iInstallerLanguage != config.iInstallerLanguage)
std::cout << "\tLanguage: " << Util::getOptionNameString(conf.iInstallerLanguage, GlobalConstants::LANGUAGES) << std::endl; std::cerr << "\tLanguage: " << Util::getOptionNameString(conf.iInstallerLanguage, GlobalConstants::LANGUAGES) << std::endl;
if (conf.vLanguagePriority != config.vLanguagePriority) if (conf.vLanguagePriority != config.vLanguagePriority)
{ {
std::cout << "\tLanguage priority:" << std::endl; std::cerr << "\tLanguage priority:" << std::endl;
for (unsigned int j = 0; j < conf.vLanguagePriority.size(); ++j) for (unsigned int j = 0; j < conf.vLanguagePriority.size(); ++j)
{ {
std::cout << "\t " << j << ": " << Util::getOptionNameString(conf.vLanguagePriority[j], GlobalConstants::LANGUAGES) << std::endl; std::cerr << "\t " << j << ": " << Util::getOptionNameString(conf.vLanguagePriority[j], GlobalConstants::LANGUAGES) << std::endl;
} }
} }
if (conf.iInstallerPlatform != config.iInstallerPlatform) if (conf.iInstallerPlatform != config.iInstallerPlatform)
std::cout << "\tPlatform: " << Util::getOptionNameString(conf.iInstallerPlatform, GlobalConstants::PLATFORMS) << std::endl; std::cerr << "\tPlatform: " << Util::getOptionNameString(conf.iInstallerPlatform, GlobalConstants::PLATFORMS) << std::endl;
if (conf.vPlatformPriority != config.vPlatformPriority) if (conf.vPlatformPriority != config.vPlatformPriority)
{ {
std::cout << "\tPlatform priority:" << std::endl; std::cerr << "\tPlatform priority:" << std::endl;
for (unsigned int j = 0; j < conf.vPlatformPriority.size(); ++j) for (unsigned int j = 0; j < conf.vPlatformPriority.size(); ++j)
{ {
std::cout << "\t " << j << ": " << Util::getOptionNameString(conf.vPlatformPriority[j], GlobalConstants::PLATFORMS) << std::endl; std::cerr << "\t " << j << ": " << Util::getOptionNameString(conf.vPlatformPriority[j], GlobalConstants::PLATFORMS) << std::endl;
} }
} }
} }
@ -411,19 +411,19 @@ int Downloader::getGameDetails()
} }
if (updated >= gogAPI->user.notifications_games) if (updated >= gogAPI->user.notifications_games)
{ // Gone through all updated games. No need to go through the rest. { // Gone through all updated games. No need to go through the rest.
std::cout << std::endl << "Got info for all updated games. Moving on..." << std::endl; std::cerr << std::endl << "Got info for all updated games. Moving on..." << std::endl;
break; break;
} }
} }
} }
else else
{ {
std::cout << gogAPI->getErrorMessage() << std::endl; std::cerr << gogAPI->getErrorMessage() << std::endl;
gogAPI->clearError(); gogAPI->clearError();
continue; continue;
} }
} }
std::cout << std::endl; std::cerr << std::endl;
return 0; return 0;
} }
@ -454,7 +454,7 @@ void Downloader::listGames()
if (config.blacklist.isBlacklisted(filepath)) if (config.blacklist.isBlacklisted(filepath))
{ {
if (config.bVerbose) if (config.bVerbose)
std::cout << "skipped blacklisted file " << filepath << std::endl; std::cerr << "skipped blacklisted file " << filepath << std::endl;
continue; continue;
} }
@ -480,7 +480,7 @@ void Downloader::listGames()
if (config.blacklist.isBlacklisted(filepath)) if (config.blacklist.isBlacklisted(filepath))
{ {
if (config.bVerbose) if (config.bVerbose)
std::cout << "skipped blacklisted file " << filepath << std::endl; std::cerr << "skipped blacklisted file " << filepath << std::endl;
continue; continue;
} }
@ -501,7 +501,7 @@ void Downloader::listGames()
if (config.blacklist.isBlacklisted(filepath)) if (config.blacklist.isBlacklisted(filepath))
{ {
if (config.bVerbose) if (config.bVerbose)
std::cout << "skipped blacklisted file " << filepath << std::endl; std::cerr << "skipped blacklisted file " << filepath << std::endl;
continue; continue;
} }
@ -526,7 +526,7 @@ void Downloader::listGames()
if (config.blacklist.isBlacklisted(filepath)) if (config.blacklist.isBlacklisted(filepath))
{ {
if (config.bVerbose) if (config.bVerbose)
std::cout << "skipped blacklisted file " << filepath << std::endl; std::cerr << "skipped blacklisted file " << filepath << std::endl;
continue; continue;
} }
@ -554,7 +554,7 @@ void Downloader::listGames()
if (config.blacklist.isBlacklisted(filepath)) if (config.blacklist.isBlacklisted(filepath))
{ {
if (config.bVerbose) if (config.bVerbose)
std::cout << "skipped blacklisted file " << filepath << std::endl; std::cerr << "skipped blacklisted file " << filepath << std::endl;
continue; continue;
} }
@ -571,7 +571,7 @@ void Downloader::listGames()
std::string filepath = games[i].dlcs[j].patches[k].getFilepath(); std::string filepath = games[i].dlcs[j].patches[k].getFilepath();
if (config.blacklist.isBlacklisted(filepath)) { if (config.blacklist.isBlacklisted(filepath)) {
if (config.bVerbose) if (config.bVerbose)
std::cout << "skipped blacklisted file " << filepath << std::endl; std::cerr << "skipped blacklisted file " << filepath << std::endl;
continue; continue;
} }
@ -587,7 +587,7 @@ void Downloader::listGames()
std::string filepath = games[i].dlcs[j].extras[k].getFilepath(); std::string filepath = games[i].dlcs[j].extras[k].getFilepath();
if (config.blacklist.isBlacklisted(filepath)) { if (config.blacklist.isBlacklisted(filepath)) {
if (config.bVerbose) if (config.bVerbose)
std::cout << "skipped blacklisted file " << filepath << std::endl; std::cerr << "skipped blacklisted file " << filepath << std::endl;
continue; continue;
} }
@ -630,7 +630,7 @@ void Downloader::repair()
if (config.blacklist.isBlacklisted(filepath)) if (config.blacklist.isBlacklisted(filepath))
{ {
if (config.bVerbose) if (config.bVerbose)
std::cout << "skipped blacklisted file " << filepath << std::endl; std::cerr << "skipped blacklisted file " << filepath << std::endl;
continue; continue;
} }
@ -641,7 +641,7 @@ void Downloader::repair()
XML = gogAPI->getXML(games[i].gamename, games[i].installers[j].id); XML = gogAPI->getXML(games[i].gamename, games[i].installers[j].id);
if (gogAPI->getError()) if (gogAPI->getError())
{ {
std::cout << gogAPI->getErrorMessage() << std::endl; std::cerr << gogAPI->getErrorMessage() << std::endl;
gogAPI->clearError(); gogAPI->clearError();
continue; continue;
} }
@ -654,7 +654,7 @@ void Downloader::repair()
std::string url = gogAPI->getInstallerLink(games[i].gamename, games[i].installers[j].id); std::string url = gogAPI->getInstallerLink(games[i].gamename, games[i].installers[j].id);
if (gogAPI->getError()) if (gogAPI->getError())
{ {
std::cout << gogAPI->getErrorMessage() << std::endl; std::cerr << gogAPI->getErrorMessage() << std::endl;
gogAPI->clearError(); gogAPI->clearError();
continue; continue;
} }
@ -674,14 +674,14 @@ void Downloader::repair()
if (config.blacklist.isBlacklisted(filepath)) if (config.blacklist.isBlacklisted(filepath))
{ {
if (config.bVerbose) if (config.bVerbose)
std::cout << "skipped blacklisted file " << filepath << std::endl; std::cerr << "skipped blacklisted file " << filepath << std::endl;
continue; continue;
} }
std::string url = gogAPI->getExtraLink(games[i].gamename, games[i].extras[j].id); std::string url = gogAPI->getExtraLink(games[i].gamename, games[i].extras[j].id);
if (gogAPI->getError()) if (gogAPI->getError())
{ {
std::cout << gogAPI->getErrorMessage() << std::endl; std::cerr << gogAPI->getErrorMessage() << std::endl;
gogAPI->clearError(); gogAPI->clearError();
continue; continue;
} }
@ -700,7 +700,7 @@ void Downloader::repair()
if (config.blacklist.isBlacklisted(filepath)) if (config.blacklist.isBlacklisted(filepath))
{ {
if (config.bVerbose) if (config.bVerbose)
std::cout << "skipped blacklisted file " << filepath << std::endl; std::cerr << "skipped blacklisted file " << filepath << std::endl;
continue; continue;
} }
@ -711,7 +711,7 @@ void Downloader::repair()
XML = gogAPI->getXML(games[i].gamename, games[i].patches[j].id); XML = gogAPI->getXML(games[i].gamename, games[i].patches[j].id);
if (gogAPI->getError()) if (gogAPI->getError())
{ {
std::cout << gogAPI->getErrorMessage() << std::endl; std::cerr << gogAPI->getErrorMessage() << std::endl;
gogAPI->clearError(); gogAPI->clearError();
} }
} }
@ -719,7 +719,7 @@ void Downloader::repair()
std::string url = gogAPI->getPatchLink(games[i].gamename, games[i].patches[j].id); std::string url = gogAPI->getPatchLink(games[i].gamename, games[i].patches[j].id);
if (gogAPI->getError()) if (gogAPI->getError())
{ {
std::cout << gogAPI->getErrorMessage() << std::endl; std::cerr << gogAPI->getErrorMessage() << std::endl;
gogAPI->clearError(); gogAPI->clearError();
continue; continue;
} }
@ -738,14 +738,14 @@ void Downloader::repair()
if (config.blacklist.isBlacklisted(filepath)) if (config.blacklist.isBlacklisted(filepath))
{ {
if (config.bVerbose) if (config.bVerbose)
std::cout << "skipped blacklisted file " << filepath << std::endl; std::cerr << "skipped blacklisted file " << filepath << std::endl;
continue; continue;
} }
std::string url = gogAPI->getLanguagePackLink(games[i].gamename, games[i].languagepacks[j].id); std::string url = gogAPI->getLanguagePackLink(games[i].gamename, games[i].languagepacks[j].id);
if (gogAPI->getError()) if (gogAPI->getError())
{ {
std::cout << gogAPI->getErrorMessage() << std::endl; std::cerr << gogAPI->getErrorMessage() << std::endl;
gogAPI->clearError(); gogAPI->clearError();
continue; continue;
} }
@ -766,7 +766,7 @@ void Downloader::repair()
if (config.blacklist.isBlacklisted(filepath)) if (config.blacklist.isBlacklisted(filepath))
{ {
if (config.bVerbose) if (config.bVerbose)
std::cout << "skipped blacklisted file " << filepath << std::endl; std::cerr << "skipped blacklisted file " << filepath << std::endl;
continue; continue;
} }
@ -777,7 +777,7 @@ void Downloader::repair()
XML = gogAPI->getXML(games[i].dlcs[j].gamename, games[i].dlcs[j].installers[k].id); XML = gogAPI->getXML(games[i].dlcs[j].gamename, games[i].dlcs[j].installers[k].id);
if (gogAPI->getError()) if (gogAPI->getError())
{ {
std::cout << gogAPI->getErrorMessage() << std::endl; std::cerr << gogAPI->getErrorMessage() << std::endl;
gogAPI->clearError(); gogAPI->clearError();
continue; continue;
} }
@ -790,7 +790,7 @@ void Downloader::repair()
std::string url = gogAPI->getInstallerLink(games[i].dlcs[j].gamename, games[i].dlcs[j].installers[k].id); std::string url = gogAPI->getInstallerLink(games[i].dlcs[j].gamename, games[i].dlcs[j].installers[k].id);
if (gogAPI->getError()) if (gogAPI->getError())
{ {
std::cout << gogAPI->getErrorMessage() << std::endl; std::cerr << gogAPI->getErrorMessage() << std::endl;
gogAPI->clearError(); gogAPI->clearError();
continue; continue;
} }
@ -807,7 +807,7 @@ void Downloader::repair()
std::string filepath = games[i].dlcs[j].patches[k].getFilepath(); std::string filepath = games[i].dlcs[j].patches[k].getFilepath();
if (config.blacklist.isBlacklisted(filepath)) { if (config.blacklist.isBlacklisted(filepath)) {
if (config.bVerbose) if (config.bVerbose)
std::cout << "skipped blacklisted file " << filepath << std::endl; std::cerr << "skipped blacklisted file " << filepath << std::endl;
continue; continue;
} }
@ -818,7 +818,7 @@ void Downloader::repair()
XML = gogAPI->getXML(games[i].dlcs[j].gamename, games[i].dlcs[j].patches[k].id); XML = gogAPI->getXML(games[i].dlcs[j].gamename, games[i].dlcs[j].patches[k].id);
if (gogAPI->getError()) if (gogAPI->getError())
{ {
std::cout << gogAPI->getErrorMessage() << std::endl; std::cerr << gogAPI->getErrorMessage() << std::endl;
gogAPI->clearError(); gogAPI->clearError();
} }
} }
@ -826,7 +826,7 @@ void Downloader::repair()
std::string url = gogAPI->getPatchLink(games[i].dlcs[j].gamename, games[i].dlcs[j].patches[k].id); std::string url = gogAPI->getPatchLink(games[i].dlcs[j].gamename, games[i].dlcs[j].patches[k].id);
if (gogAPI->getError()) if (gogAPI->getError())
{ {
std::cout << gogAPI->getErrorMessage() << std::endl; std::cerr << gogAPI->getErrorMessage() << std::endl;
gogAPI->clearError(); gogAPI->clearError();
continue; continue;
} }
@ -842,14 +842,14 @@ void Downloader::repair()
std::string filepath = games[i].dlcs[j].extras[k].getFilepath(); std::string filepath = games[i].dlcs[j].extras[k].getFilepath();
if (config.blacklist.isBlacklisted(filepath)) { if (config.blacklist.isBlacklisted(filepath)) {
if (config.bVerbose) if (config.bVerbose)
std::cout << "skipped blacklisted file " << filepath << std::endl; std::cerr << "skipped blacklisted file " << filepath << std::endl;
continue; continue;
} }
std::string url = gogAPI->getExtraLink(games[i].dlcs[j].gamename, games[i].dlcs[j].extras[k].id); std::string url = gogAPI->getExtraLink(games[i].dlcs[j].gamename, games[i].dlcs[j].extras[k].id);
if (gogAPI->getError()) if (gogAPI->getError())
{ {
std::cout << gogAPI->getErrorMessage() << std::endl; std::cerr << gogAPI->getErrorMessage() << std::endl;
gogAPI->clearError(); gogAPI->clearError();
continue; continue;
} }
@ -906,7 +906,7 @@ void Downloader::download()
if (config.blacklist.isBlacklisted(filepath)) if (config.blacklist.isBlacklisted(filepath))
{ {
if (config.bVerbose) if (config.bVerbose)
std::cout << "skipped blacklisted file " << filepath << std::endl; std::cerr << "skipped blacklisted file " << filepath << std::endl;
continue; continue;
} }
@ -914,7 +914,7 @@ void Downloader::download()
std::string url = gogAPI->getInstallerLink(games[i].gamename, games[i].installers[j].id); std::string url = gogAPI->getInstallerLink(games[i].gamename, games[i].installers[j].id);
if (gogAPI->getError()) if (gogAPI->getError())
{ {
std::cout << gogAPI->getErrorMessage() << std::endl; std::cerr << gogAPI->getErrorMessage() << std::endl;
gogAPI->clearError(); gogAPI->clearError();
continue; continue;
} }
@ -928,7 +928,7 @@ void Downloader::download()
XML = gogAPI->getXML(games[i].gamename, games[i].installers[j].id); XML = gogAPI->getXML(games[i].gamename, games[i].installers[j].id);
if (gogAPI->getError()) if (gogAPI->getError())
{ {
std::cout << gogAPI->getErrorMessage() << std::endl; std::cerr << gogAPI->getErrorMessage() << std::endl;
gogAPI->clearError(); gogAPI->clearError();
} }
} }
@ -949,7 +949,7 @@ void Downloader::download()
std::string url = gogAPI->getExtraLink(games[i].gamename, games[i].extras[j].id); std::string url = gogAPI->getExtraLink(games[i].gamename, games[i].extras[j].id);
if (gogAPI->getError()) if (gogAPI->getError())
{ {
std::cout << gogAPI->getErrorMessage() << std::endl; std::cerr << gogAPI->getErrorMessage() << std::endl;
gogAPI->clearError(); gogAPI->clearError();
continue; continue;
} }
@ -958,7 +958,7 @@ void Downloader::download()
if (config.blacklist.isBlacklisted(filepath)) if (config.blacklist.isBlacklisted(filepath))
{ {
if (config.bVerbose) if (config.bVerbose)
std::cout << "skipped blacklisted file " << filepath << std::endl; std::cerr << "skipped blacklisted file " << filepath << std::endl;
continue; continue;
} }
@ -993,7 +993,7 @@ void Downloader::download()
std::string url = gogAPI->getPatchLink(games[i].gamename, games[i].patches[j].id); std::string url = gogAPI->getPatchLink(games[i].gamename, games[i].patches[j].id);
if (gogAPI->getError()) if (gogAPI->getError())
{ {
std::cout << gogAPI->getErrorMessage() << std::endl; std::cerr << gogAPI->getErrorMessage() << std::endl;
gogAPI->clearError(); gogAPI->clearError();
continue; continue;
} }
@ -1002,7 +1002,7 @@ void Downloader::download()
if (config.blacklist.isBlacklisted(filepath)) if (config.blacklist.isBlacklisted(filepath))
{ {
if (config.bVerbose) if (config.bVerbose)
std::cout << "skipped blacklisted file " << filepath << std::endl; std::cerr << "skipped blacklisted file " << filepath << std::endl;
continue; continue;
} }
@ -1015,7 +1015,7 @@ void Downloader::download()
XML = gogAPI->getXML(games[i].gamename, games[i].patches[j].id); XML = gogAPI->getXML(games[i].gamename, games[i].patches[j].id);
if (gogAPI->getError()) if (gogAPI->getError())
{ {
std::cout << gogAPI->getErrorMessage() << std::endl; std::cerr << gogAPI->getErrorMessage() << std::endl;
gogAPI->clearError(); gogAPI->clearError();
} }
} }
@ -1036,7 +1036,7 @@ void Downloader::download()
std::string url = gogAPI->getLanguagePackLink(games[i].gamename, games[i].languagepacks[j].id); std::string url = gogAPI->getLanguagePackLink(games[i].gamename, games[i].languagepacks[j].id);
if (gogAPI->getError()) if (gogAPI->getError())
{ {
std::cout << gogAPI->getErrorMessage() << std::endl; std::cerr << gogAPI->getErrorMessage() << std::endl;
gogAPI->clearError(); gogAPI->clearError();
continue; continue;
} }
@ -1045,7 +1045,7 @@ void Downloader::download()
if (config.blacklist.isBlacklisted(filepath)) if (config.blacklist.isBlacklisted(filepath))
{ {
if (config.bVerbose) if (config.bVerbose)
std::cout << "skipped blacklisted file " << filepath << std::endl; std::cerr << "skipped blacklisted file " << filepath << std::endl;
continue; continue;
} }
@ -1058,7 +1058,7 @@ void Downloader::download()
XML = gogAPI->getXML(games[i].gamename, games[i].languagepacks[j].id); XML = gogAPI->getXML(games[i].gamename, games[i].languagepacks[j].id);
if (gogAPI->getError()) if (gogAPI->getError())
{ {
std::cout << gogAPI->getErrorMessage() << std::endl; std::cerr << gogAPI->getErrorMessage() << std::endl;
gogAPI->clearError(); gogAPI->clearError();
} }
} }
@ -1088,7 +1088,7 @@ void Downloader::download()
if (config.blacklist.isBlacklisted(filepath)) if (config.blacklist.isBlacklisted(filepath))
{ {
if (config.bVerbose) if (config.bVerbose)
std::cout << "skipped blacklisted file " << filepath << std::endl; std::cerr << "skipped blacklisted file " << filepath << std::endl;
continue; continue;
} }
@ -1096,7 +1096,7 @@ void Downloader::download()
std::string url = gogAPI->getInstallerLink(games[i].dlcs[j].gamename, games[i].dlcs[j].installers[k].id); std::string url = gogAPI->getInstallerLink(games[i].dlcs[j].gamename, games[i].dlcs[j].installers[k].id);
if (gogAPI->getError()) if (gogAPI->getError())
{ {
std::cout << gogAPI->getErrorMessage() << std::endl; std::cerr << gogAPI->getErrorMessage() << std::endl;
gogAPI->clearError(); gogAPI->clearError();
continue; continue;
} }
@ -1110,7 +1110,7 @@ void Downloader::download()
XML = gogAPI->getXML(games[i].dlcs[j].gamename, games[i].dlcs[j].installers[k].id); XML = gogAPI->getXML(games[i].dlcs[j].gamename, games[i].dlcs[j].installers[k].id);
if (gogAPI->getError()) if (gogAPI->getError())
{ {
std::cout << gogAPI->getErrorMessage() << std::endl; std::cerr << gogAPI->getErrorMessage() << std::endl;
gogAPI->clearError(); gogAPI->clearError();
} }
} }
@ -1130,7 +1130,7 @@ void Downloader::download()
if (config.blacklist.isBlacklisted(filepath)) if (config.blacklist.isBlacklisted(filepath))
{ {
if (config.bVerbose) if (config.bVerbose)
std::cout << "skipped blacklisted file " << filepath << std::endl; std::cerr << "skipped blacklisted file " << filepath << std::endl;
continue; continue;
} }
@ -1138,7 +1138,7 @@ void Downloader::download()
std::string url = gogAPI->getPatchLink(games[i].dlcs[j].gamename, games[i].dlcs[j].patches[k].id); std::string url = gogAPI->getPatchLink(games[i].dlcs[j].gamename, games[i].dlcs[j].patches[k].id);
if (gogAPI->getError()) if (gogAPI->getError())
{ {
std::cout << gogAPI->getErrorMessage() << std::endl; std::cerr << gogAPI->getErrorMessage() << std::endl;
gogAPI->clearError(); gogAPI->clearError();
continue; continue;
} }
@ -1152,7 +1152,7 @@ void Downloader::download()
XML = gogAPI->getXML(games[i].dlcs[j].gamename, games[i].dlcs[j].patches[k].id); XML = gogAPI->getXML(games[i].dlcs[j].gamename, games[i].dlcs[j].patches[k].id);
if (gogAPI->getError()) if (gogAPI->getError())
{ {
std::cout << gogAPI->getErrorMessage() << std::endl; std::cerr << gogAPI->getErrorMessage() << std::endl;
gogAPI->clearError(); gogAPI->clearError();
} }
} }
@ -1172,7 +1172,7 @@ void Downloader::download()
if (config.blacklist.isBlacklisted(filepath)) if (config.blacklist.isBlacklisted(filepath))
{ {
if (config.bVerbose) if (config.bVerbose)
std::cout << "skipped blacklisted file " << filepath << std::endl; std::cerr << "skipped blacklisted file " << filepath << std::endl;
continue; continue;
} }
@ -1180,7 +1180,7 @@ void Downloader::download()
std::string url = gogAPI->getExtraLink(games[i].dlcs[j].gamename, games[i].dlcs[j].extras[k].id); std::string url = gogAPI->getExtraLink(games[i].dlcs[j].gamename, games[i].dlcs[j].extras[k].id);
if (gogAPI->getError()) if (gogAPI->getError())
{ {
std::cout << gogAPI->getErrorMessage() << std::endl; std::cerr << gogAPI->getErrorMessage() << std::endl;
gogAPI->clearError(); gogAPI->clearError();
continue; continue;
} }
@ -1258,7 +1258,7 @@ CURLcode Downloader::downloadFile(const std::string& url, const std::string& fil
{ {
if (!boost::filesystem::is_directory(path)) if (!boost::filesystem::is_directory(path))
{ {
std::cout << path << " is not directory" << std::endl; std::cerr << path << " is not directory" << std::endl;
return res; return res;
} }
} }
@ -1266,7 +1266,7 @@ CURLcode Downloader::downloadFile(const std::string& url, const std::string& fil
{ {
if (!boost::filesystem::create_directories(path)) if (!boost::filesystem::create_directories(path))
{ {
std::cout << "Failed to create directory: " << path << std::endl; std::cerr << "Failed to create directory: " << path << std::endl;
return res; return res;
} }
} }
@ -1288,22 +1288,22 @@ CURLcode Downloader::downloadFile(const std::string& url, const std::string& fil
} }
else else
{ {
std::cout << "Failed to reopen " << filepath << std::endl; std::cerr << "Failed to reopen " << filepath << std::endl;
return res; return res;
} }
} }
else else
{ // File exists but is not the same version { // File exists but is not the same version
fclose(outfile); fclose(outfile);
std::cout << "Remote file is different, renaming local file" << std::endl; std::cerr << "Remote file is different, renaming local file" << std::endl;
std::string date_old = "." + bptime::to_iso_string(bptime::second_clock::local_time()) + ".old"; std::string date_old = "." + bptime::to_iso_string(bptime::second_clock::local_time()) + ".old";
boost::filesystem::path new_name = filepath + date_old; // Rename old file by appending date and ".old" to filename boost::filesystem::path new_name = filepath + date_old; // Rename old file by appending date and ".old" to filename
boost::system::error_code ec; boost::system::error_code ec;
boost::filesystem::rename(pathname, new_name, ec); // Rename the file boost::filesystem::rename(pathname, new_name, ec); // Rename the file
if (ec) if (ec)
{ {
std::cout << "Failed to rename " << filepath << " to " << new_name.string() << std::endl; std::cerr << "Failed to rename " << filepath << " to " << new_name.string() << std::endl;
std::cout << "Skipping file" << std::endl; std::cerr << "Skipping file" << std::endl;
return res; return res;
} }
else else
@ -1316,7 +1316,7 @@ CURLcode Downloader::downloadFile(const std::string& url, const std::string& fil
} }
else else
{ {
std::cout << "Failed to create " << filepath << std::endl; std::cerr << "Failed to create " << filepath << std::endl;
return res; return res;
} }
} }
@ -1332,7 +1332,7 @@ CURLcode Downloader::downloadFile(const std::string& url, const std::string& fil
} }
else else
{ {
std::cout << "Failed to create " << filepath << std::endl; std::cerr << "Failed to create " << filepath << std::endl;
return res; return res;
} }
} }
@ -1348,14 +1348,14 @@ CURLcode Downloader::downloadFile(const std::string& url, const std::string& fil
{ {
if (!boost::filesystem::is_directory(path)) if (!boost::filesystem::is_directory(path))
{ {
std::cout << path << " is not directory" << std::endl; std::cerr << path << " is not directory" << std::endl;
} }
} }
else else
{ {
if (!boost::filesystem::create_directories(path)) if (!boost::filesystem::create_directories(path))
{ {
std::cout << "Failed to create directory: " << path << std::endl; std::cerr << "Failed to create directory: " << path << std::endl;
} }
} }
std::ofstream ofs(local_xml_file.string().c_str()); std::ofstream ofs(local_xml_file.string().c_str());
@ -1366,7 +1366,7 @@ CURLcode Downloader::downloadFile(const std::string& url, const std::string& fil
} }
else else
{ {
std::cout << "Can't create " << local_xml_file.string() << std::endl; std::cerr << "Can't create " << local_xml_file.string() << std::endl;
} }
} }
} }
@ -1383,7 +1383,7 @@ CURLcode Downloader::downloadFile(const std::string& url, const std::string& fil
boost::filesystem::path path = filepath; boost::filesystem::path path = filepath;
if (boost::filesystem::exists(path)) if (boost::filesystem::exists(path))
if (!boost::filesystem::remove(path)) if (!boost::filesystem::remove(path))
std::cout << "Failed to delete " << path << std::endl; std::cerr << "Failed to delete " << path << std::endl;
} }
if (config.bReport) if (config.bReport)
@ -2481,7 +2481,7 @@ void Downloader::checkOrphans()
std::vector<std::string> orphans; std::vector<std::string> orphans;
for (unsigned int i = 0; i < games.size(); ++i) for (unsigned int i = 0; i < games.size(); ++i)
{ {
std::cout << "Checking for orphaned files " << i+1 << " / " << games.size() << "\r" << std::flush; std::cerr << "Checking for orphaned files " << i+1 << " / " << games.size() << "\r" << std::flush;
std::vector<boost::filesystem::path> filepath_vector; std::vector<boost::filesystem::path> filepath_vector;
try try
@ -2531,7 +2531,7 @@ void Downloader::checkOrphans()
std::string filepath = dir_iter->path().string(); std::string filepath = dir_iter->path().string();
if (config.blacklist.isBlacklisted(filepath.substr(pathlen))) { if (config.blacklist.isBlacklisted(filepath.substr(pathlen))) {
if (config.bVerbose) if (config.bVerbose)
std::cout << "skipped blacklisted file " << filepath << std::endl; std::cerr << "skipped ignorelisted file " << filepath << std::endl;
} else { } else {
boost::regex expression(config.sOrphanRegex); // Limit to files matching the regex boost::regex expression(config.sOrphanRegex); // Limit to files matching the regex
boost::match_results<std::string::const_iterator> what; boost::match_results<std::string::const_iterator> what;
@ -2544,7 +2544,7 @@ void Downloader::checkOrphans()
} }
} }
else else
std::cout << paths[j] << " does not exist" << std::endl; std::cerr << paths[j] << " does not exist" << std::endl;
} }
} }
catch (const boost::filesystem::filesystem_error& ex) catch (const boost::filesystem::filesystem_error& ex)
@ -3092,7 +3092,7 @@ std::vector<gameDetails> Downloader::getGameDetailsFromJsonNode(Json::Value root
conf.vLanguagePriority = config.vLanguagePriority; conf.vLanguagePriority = config.vLanguagePriority;
conf.vPlatformPriority = config.vPlatformPriority; conf.vPlatformPriority = config.vPlatformPriority;
if (Util::getGameSpecificConfig(game.gamename, &conf) > 0) if (Util::getGameSpecificConfig(game.gamename, &conf) > 0)
std::cout << game.gamename << " - Language: " << conf.iInstallerLanguage << ", Platform: " << conf.iInstallerPlatform << ", DLC: " << (conf.bDLC ? "true" : "false") << std::endl; std::cerr << game.gamename << " - Language: " << conf.iInstallerLanguage << ", Platform: " << conf.iInstallerPlatform << ", DLC: " << (conf.bDLC ? "true" : "false") << std::endl;
for (unsigned int j = 0; j < nodes.size(); ++j) for (unsigned int j = 0; j < nodes.size(); ++j)
{ {

View File

@ -64,7 +64,7 @@ std::string Util::getFileHash(const std::string& filename, unsigned hash_id)
rhash_library_init(); rhash_library_init();
int i = rhash_file(hash_id, filename.c_str(), digest); int i = rhash_file(hash_id, filename.c_str(), digest);
if (i < 0) if (i < 0)
std::cout << "LibRHash error: " << strerror(errno) << std::endl; std::cerr << "LibRHash error: " << strerror(errno) << std::endl;
else else
rhash_print_bytes(result, digest, rhash_get_digest_size(hash_id), RHPR_HEX); rhash_print_bytes(result, digest, rhash_get_digest_size(hash_id), RHPR_HEX);
@ -79,7 +79,7 @@ std::string Util::getChunkHash(unsigned char *chunk, uintmax_t chunk_size, unsig
rhash_library_init(); rhash_library_init();
int i = rhash_msg(hash_id, chunk, chunk_size, digest); int i = rhash_msg(hash_id, chunk, chunk_size, digest);
if (i < 0) if (i < 0)
std::cout << "LibRHash error: " << strerror(errno) << std::endl; std::cerr << "LibRHash error: " << strerror(errno) << std::endl;
else else
rhash_print_bytes(result, digest, rhash_get_digest_size(hash_id), RHPR_HEX); rhash_print_bytes(result, digest, rhash_get_digest_size(hash_id), RHPR_HEX);
@ -104,7 +104,7 @@ int Util::createXML(std::string filepath, uintmax_t chunk_size, std::string xml_
boost::filesystem::path path = xml_dir; boost::filesystem::path path = xml_dir;
if (!boost::filesystem::exists(path)) { if (!boost::filesystem::exists(path)) {
if (!boost::filesystem::create_directories(path)) { if (!boost::filesystem::create_directories(path)) {
std::cout << "Failed to create directory: " << path << std::endl; std::cerr << "Failed to create directory: " << path << std::endl;
return res; return res;
} }
} }
@ -115,7 +115,7 @@ int Util::createXML(std::string filepath, uintmax_t chunk_size, std::string xml_
filesize = ftell(infile); filesize = ftell(infile);
rewind(infile); rewind(infile);
} else { } else {
std::cout << filepath << " doesn't exist" << std::endl; std::cerr << filepath << " doesn't exist" << std::endl;
return res; return res;
} }
@ -159,13 +159,13 @@ int Util::createXML(std::string filepath, uintmax_t chunk_size, std::string xml_
unsigned char *chunk = (unsigned char *) malloc(chunk_size * sizeof(unsigned char *)); unsigned char *chunk = (unsigned char *) malloc(chunk_size * sizeof(unsigned char *));
if (chunk == NULL) if (chunk == NULL)
{ {
std::cout << "Memory error" << std::endl; std::cerr << "Memory error" << std::endl;
return res; return res;
} }
size = fread(chunk, 1, chunk_size, infile); size = fread(chunk, 1, chunk_size, infile);
if (size != chunk_size) if (size != chunk_size)
{ {
std::cout << "Read error" << std::endl; std::cerr << "Read error" << std::endl;
free(chunk); free(chunk);
return res; return res;
} }
@ -204,7 +204,7 @@ int Util::createXML(std::string filepath, uintmax_t chunk_size, std::string xml_
fclose(xmlfile); fclose(xmlfile);
res = 1; res = 1;
} else { } else {
std::cout << "Can't create " << filenameXML << std::endl; std::cerr << "Can't create " << filenameXML << std::endl;
return res; return res;
} }
@ -311,8 +311,8 @@ int Util::getGameSpecificConfig(std::string gamename, gameSpecificConfig* conf,
} }
else else
{ {
std::cout << "Failed to parse game specific config " << filepath << std::endl; std::cerr << "Failed to parse game specific config " << filepath << std::endl;
std::cout << jsonparser->getFormattedErrorMessages() << std::endl; std::cerr << jsonparser->getFormattedErrorMessages() << std::endl;
} }
delete jsonparser; delete jsonparser;
if (json) if (json)
@ -370,7 +370,7 @@ void Util::setFilePermissions(const boost::filesystem::path& path, const boost::
boost::filesystem::permissions(path, permissions, ec); boost::filesystem::permissions(path, permissions, ec);
if (ec) if (ec)
{ {
std::cout << "Failed to set file permissions for " << path.string() << std::endl; std::cerr << "Failed to set file permissions for " << path.string() << std::endl;
} }
} }
} }