Add options to login separately to website and API

This commit is contained in:
Sude 2015-08-12 16:42:54 +03:00
parent 4c6ac86619
commit f51cca5dff
3 changed files with 47 additions and 28 deletions

View File

@ -24,7 +24,8 @@ class Config
bool bDownload;
bool bList;
bool bListDetails;
bool bLogin;
bool bLoginHTTP;
bool bLoginAPI;
bool bRepair;
bool bInstallers;
bool bExtras;

View File

@ -129,12 +129,13 @@ int main(int argc, char *argv[])
bool bNoTarGz = false;
bool bNoCover = false;
bool bNoPlatformDetection = false;
bool bLogin = false;
config.bReport = false;
// Commandline options (no config file)
options_cli_no_cfg.add_options()
("help,h", "Print help message")
("version", "Print version information")
("login", bpo::value<bool>(&config.bLogin)->zero_tokens()->default_value(false), "Login")
("login", bpo::value<bool>(&bLogin)->zero_tokens()->default_value(false), "Login")
("list", bpo::value<bool>(&config.bList)->zero_tokens()->default_value(false), "List games")
("list-details", bpo::value<bool>(&config.bListDetails)->zero_tokens()->default_value(false), "List games with detailed info")
("download", bpo::value<bool>(&config.bDownload)->zero_tokens()->default_value(false), "Download")
@ -152,6 +153,8 @@ int main(int argc, char *argv[])
("no-platform-detection", bpo::value<bool>(&bNoPlatformDetection)->zero_tokens()->default_value(false), "Don't try to detect supported platforms from game shelf.\nSkips the initial fast platform detection and detects the supported platforms from game details which is slower but more accurate.\nUseful in case platform identifier is missing for some games in the game shelf.\nUsing --platform with --list doesn't work with this option.")
("download-file", bpo::value<std::string>(&config.sFileIdString)->default_value(""), "Download a single file using fileid\nFormat: \"gamename/fileid\"\nThis option ignores all subdir options. The file is downloaded to directory specified with --directory option.")
("wishlist", bpo::value<bool>(&config.bShowWishlist)->zero_tokens()->default_value(false), "Show wishlist")
("login-api", bpo::value<bool>(&config.bLoginAPI)->zero_tokens()->default_value(false), "Login (API only)")
("login-website", bpo::value<bool>(&config.bLoginHTTP)->zero_tokens()->default_value(false), "Login (website only)")
;
// Commandline options (config file)
options_cli_cfg.add_options()
@ -346,6 +349,12 @@ int main(int argc, char *argv[])
if (bNoCover)
config.bCover = false;
if (bLogin)
{
config.bLoginAPI = true;
config.bLoginHTTP = true;
}
// Handle priority business
if (!config.sLanguagePriority.empty())
handle_priority("languages", config.sLanguagePriority, config.vLanguagePriority, config.iInstallerLanguage);
@ -415,7 +424,7 @@ int main(int argc, char *argv[])
int initResult = downloader.init();
int iLoginResult = 0;
if (config.bLogin || initResult == 1)
if (config.bLoginAPI || config.bLoginHTTP || initResult == 1)
{
iLoginResult = downloader.login();
if (iLoginResult == 0)

View File

@ -30,7 +30,7 @@ namespace bptime = boost::posix_time;
Downloader::Downloader(Config &conf)
{
this->config = conf;
if (config.bLogin && boost::filesystem::exists(config.sCookiePath))
if (config.bLoginHTTP && boost::filesystem::exists(config.sCookiePath))
if (!boost::filesystem::remove(config.sCookiePath))
std::cout << "Failed to delete " << config.sCookiePath << std::endl;
}
@ -89,7 +89,7 @@ int Downloader::init()
progressbar = new ProgressBar(config.bUnicode, config.bColor);
bool bInitOK = gogAPI->init(); // Initialize the API
if (!bInitOK || config.bLogin)
if (!bInitOK || config.bLoginHTTP || config.bLoginAPI)
return 1;
if (config.bCover && config.bDownload && !config.bUpdateCheck)
@ -133,6 +133,8 @@ int Downloader::login()
else
{
// Login to website
if (config.bLoginHTTP)
{
if (!HTTP_Login(email, password))
{
std::cout << "HTTP: Login failed" << std::endl;
@ -141,8 +143,13 @@ int Downloader::login()
else
{
std::cout << "HTTP: Login successful" << std::endl;
if (!config.bLoginAPI)
return 1;
}
}
// Login to API
if (config.bLoginAPI)
{
if (!gogAPI->login(email, password))
{
std::cout << "API: Login failed" << std::endl;
@ -157,6 +164,8 @@ int Downloader::login()
}
}
}
return 0;
}
void Downloader::updateCheck()
{