diff --git a/include/config.h b/include/config.h index f3b2ded..38213a2 100644 --- a/include/config.h +++ b/include/config.h @@ -231,9 +231,6 @@ class Config // Download DownloadConfig dlConf; - // Galaxy - //GalaxyConfig galaxyConf; - // Directories DirectoryConfig dirConf; std::string sCacheDirectory; @@ -261,6 +258,8 @@ class Config // General strings std::string sVersionString; std::string sVersionNumber; + std::string sEmail; + std::string sPassword; GogAPIConfig apiConf; diff --git a/main.cpp b/main.cpp index 3d8720f..2e14e06 100644 --- a/main.cpp +++ b/main.cpp @@ -211,6 +211,8 @@ int main(int argc, char *argv[]) ("galaxy-install", bpo::value(&galaxy_product_id_install)->default_value(""), "Install game using product id") ("galaxy-show-builds", bpo::value(&galaxy_product_id_show_builds)->default_value(""), "Show game builds using product id") ("galaxy-platform", bpo::value(&sGalaxyPlatform)->default_value("w"), galaxy_platform_text.c_str()) + ("login-email", bpo::value(&Globals::globalConfig.sEmail)->default_value(""), "login email") + ("login-password", bpo::value(&Globals::globalConfig.sPassword)->default_value(""), "login password") ; options_cli_all.add(options_cli_no_cfg).add(options_cli_cfg); @@ -349,6 +351,32 @@ int main(int argc, char *argv[]) } } + if (bLogin || Globals::globalConfig.bLoginAPI || Globals::globalConfig.bLoginHTTP) + { + std::string login_conf = Globals::globalConfig.sConfigDirectory + "/login.txt"; + if (boost::filesystem::exists(login_conf)) + { + std::ifstream ifs(login_conf); + if (!ifs) + { + std::cerr << "Could not open login conf: " << login_conf << std::endl; + return 1; + } + else + { + std::string line; + std::vector lines; + while (!ifs.eof()) + { + std::getline(ifs, line); + lines.push_back(std::move(line)); + } + Globals::globalConfig.sEmail = lines[0]; + Globals::globalConfig.sPassword = lines[1]; + } + } + } + if (vm.count("chunk-size")) Globals::globalConfig.iChunkSize <<= 20; // Convert chunk size from bytes to megabytes diff --git a/src/downloader.cpp b/src/downloader.cpp index e477a9b..77cf16b 100644 --- a/src/downloader.cpp +++ b/src/downloader.cpp @@ -247,23 +247,32 @@ int Downloader::init() int Downloader::login() { std::string email; - if (!isatty(STDIN_FILENO)) { - std::cerr << "Unable to read email and password" << std::endl; - return 0; - } - std::cerr << "Email: "; - std::getline(std::cin,email); - std::string password; - std::cerr << "Password: "; - struct termios termios_old, termios_new; - tcgetattr(STDIN_FILENO, &termios_old); // Get current terminal attributes - termios_new = termios_old; - termios_new.c_lflag &= ~ECHO; // Set ECHO off - tcsetattr(STDIN_FILENO, TCSANOW, &termios_new); // Set terminal attributes - std::getline(std::cin, password); - tcsetattr(STDIN_FILENO, TCSANOW, &termios_old); // Restore old terminal attributes - std::cerr << std::endl; + + if (!Globals::globalConfig.sEmail.empty() && !Globals::globalConfig.sPassword.empty()) + { + email = Globals::globalConfig.sEmail; + password = Globals::globalConfig.sPassword; + } + else + { + if (!isatty(STDIN_FILENO)) { + std::cerr << "Unable to read email and password" << std::endl; + return 0; + } + std::cerr << "Email: "; + std::getline(std::cin,email); + + std::cerr << "Password: "; + struct termios termios_old, termios_new; + tcgetattr(STDIN_FILENO, &termios_old); // Get current terminal attributes + termios_new = termios_old; + termios_new.c_lflag &= ~ECHO; // Set ECHO off + tcsetattr(STDIN_FILENO, TCSANOW, &termios_new); // Set terminal attributes + std::getline(std::cin, password); + tcsetattr(STDIN_FILENO, TCSANOW, &termios_old); // Restore old terminal attributes + std::cerr << std::endl; + } if (email.empty() || password.empty()) {