diff --git a/include/config.h b/include/config.h index 2058c31..e0c4ad8 100644 --- a/include/config.h +++ b/include/config.h @@ -252,6 +252,7 @@ class Config bool bPlatformDetection; #ifdef USE_QT_GUI_LOGIN bool bEnableLoginGUI; + bool bForceGUILogin; #endif bool bUseFastCheck; bool bTrustAPIForExtras; diff --git a/main.cpp b/main.cpp index bfe2b47..19fbcf8 100644 --- a/main.cpp +++ b/main.cpp @@ -204,6 +204,9 @@ int main(int argc, char *argv[]) ("help,h", "Print help message") ("version", "Print version information") ("login", bpo::value(&Globals::globalConfig.bLogin)->zero_tokens()->default_value(false), "Login") +#ifdef USE_QT_GUI_LOGIN + ("gui-login", bpo::value(&Globals::globalConfig.bForceGUILogin)->zero_tokens()->default_value(false), "Login (force GUI login)\nImplies --enable-login-gui") +#endif ("list", bpo::value(&sListFormat)->implicit_value("games"), list_format_text.c_str()) ("download", bpo::value(&Globals::globalConfig.bDownload)->zero_tokens()->default_value(false), "Download") ("repair", bpo::value(&Globals::globalConfig.bRepair)->zero_tokens()->default_value(false), "Repair downloaded files\nUse --repair --download to redownload files when filesizes don't match (possibly different version). Redownload will rename the old file (appends .old to filename)") @@ -460,6 +463,14 @@ int main(int argc, char *argv[]) } } + #ifdef USE_QT_GUI_LOGIN + if (Globals::globalConfig.bForceGUILogin) + { + Globals::globalConfig.bLogin = true; + Globals::globalConfig.bEnableLoginGUI = true; + } + #endif + if (Globals::globalConfig.bLogin) { std::string login_conf = Globals::globalConfig.sConfigDirectory + "/login.txt"; @@ -649,31 +660,31 @@ int main(int argc, char *argv[]) Downloader downloader; - int iLoginTries = 0; bool bLoginOK = false; // Login because --login was used if (Globals::globalConfig.bLogin) - bLoginOK = downloader.login(); - - bool bIsLoggedin = downloader.isLoggedIn(); - if (!bIsLoggedin) - Globals::globalConfig.bLogin = true; - - // Login because we are not logged in - while (iLoginTries++ < Globals::globalConfig.iRetries && !bIsLoggedin) { bLoginOK = downloader.login(); - if (bLoginOK) - { - bIsLoggedin = downloader.isLoggedIn(); - } } - - // Login failed, cleanup - if (!bLoginOK && !bIsLoggedin) + else { - return 1; + bool bIsLoggedin = downloader.isLoggedIn(); + if (!bIsLoggedin) + { + Globals::globalConfig.bLogin = true; + bLoginOK = downloader.login(); + if (bLoginOK) + { + bIsLoggedin = downloader.isLoggedIn(); + } + } + + // Login failed, cleanup + if (!bLoginOK && !bIsLoggedin) + { + return 1; + } } // Make sure that config file and cookie file are only readable/writable by owner diff --git a/src/downloader.cpp b/src/downloader.cpp index 486812c..e2b74d1 100644 --- a/src/downloader.cpp +++ b/src/downloader.cpp @@ -257,13 +257,17 @@ int Downloader::login() std::string email; std::string password; bool headless = false; + bool bForceGUI = false; + #ifdef USE_QT_GUI_LOGIN + bForceGUI = Globals::globalConfig.bForceGUILogin; + #endif if (!Globals::globalConfig.sEmail.empty() && !Globals::globalConfig.sPassword.empty()) { email = Globals::globalConfig.sEmail; password = Globals::globalConfig.sPassword; } - else + else if (!bForceGUI) { if (!isatty(STDIN_FILENO)) { /* Attempt to read this stuff from elsewhere */ @@ -291,7 +295,7 @@ int Downloader::login() } } - if ((email.empty() || password.empty()) && !headless) + if ((email.empty() || password.empty()) && (!headless && !bForceGUI)) { std::cerr << "Email and/or password empty" << std::endl; return 0; diff --git a/src/website.cpp b/src/website.cpp index ca83c20..6c5ea80 100644 --- a/src/website.cpp +++ b/src/website.cpp @@ -307,6 +307,10 @@ std::string Website::LoginGetAuthCode(const std::string& email, const std::strin { std::string auth_code; bool bRecaptcha = false; + bool bForceGUI = false; + #ifdef USE_QT_GUI_LOGIN + bForceGUI = Globals::globalConfig.bForceGUILogin; + #endif std::string auth_url = "https://auth.gog.com/auth?client_id=" + Globals::galaxyConf.getClientId() + "&redirect_uri=" + (std::string)curl_easy_escape(curlhandle, Globals::galaxyConf.getRedirectUri().c_str(), Globals::galaxyConf.getRedirectUri().size()) + "&response_type=code&layout=default&brand=gog"; @@ -322,11 +326,21 @@ std::string Website::LoginGetAuthCode(const std::string& email, const std::strin bRecaptcha = true; } - auth_code = this->LoginGetAuthCodeCurl(login_form_html, email, password); + // Try normal login if GUI is not forced + if (!bForceGUI) + { + auth_code = this->LoginGetAuthCodeCurl(login_form_html, email, password); + } #ifdef USE_QT_GUI_LOGIN - if (Globals::globalConfig.bEnableLoginGUI && auth_code.empty()) + if ((Globals::globalConfig.bEnableLoginGUI && auth_code.empty()) || bForceGUI) + { auth_code = this->LoginGetAuthCodeGUI(email, password); + + // If GUI is forced then stop here and don't offer browser login + if (bForceGUI) + return auth_code; + } #endif if (auth_code.empty() && bRecaptcha)