mirror of
https://github.com/Sude-/lgogdownloader.git
synced 2024-11-20 11:49:17 +01:00
Don't reset options set in config file on --login
This commit is contained in:
parent
2aeca35097
commit
ce26a4b020
21
main.cpp
21
main.cpp
@ -21,6 +21,11 @@
|
||||
|
||||
namespace bpo = boost::program_options;
|
||||
|
||||
template<typename T> void set_vm_value(std::map<std::string, bpo::variable_value>& vm, const std::string& option, const T& value)
|
||||
{
|
||||
vm[option].value() = boost::any(value);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
Config config;
|
||||
@ -288,10 +293,22 @@ int main(int argc, char *argv[])
|
||||
Downloader downloader(config);
|
||||
int result = downloader.init();
|
||||
|
||||
int iLoginResult = 0;
|
||||
if (config.bLogin)
|
||||
return result;
|
||||
else if (config.bSaveConfig)
|
||||
{
|
||||
iLoginResult = result;
|
||||
if (iLoginResult == 0)
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (config.bSaveConfig || iLoginResult == 1)
|
||||
{
|
||||
if (iLoginResult == 1)
|
||||
{
|
||||
set_vm_value(vm, "token", downloader.config.sToken);
|
||||
set_vm_value(vm, "secret", downloader.config.sSecret);
|
||||
bpo::notify(vm);
|
||||
}
|
||||
std::ofstream ofs(config.sConfigFilePath.c_str());
|
||||
if (ofs)
|
||||
{
|
||||
|
@ -102,8 +102,8 @@ int Downloader::init()
|
||||
}
|
||||
|
||||
/* Login
|
||||
returns 1 if login fails
|
||||
returns 0 if successful
|
||||
returns 0 if login fails
|
||||
returns 1 if successful
|
||||
*/
|
||||
int Downloader::login()
|
||||
{
|
||||
@ -116,7 +116,7 @@ int Downloader::login()
|
||||
if (email.empty() || password.empty())
|
||||
{
|
||||
std::cout << "Email and/or password empty" << std::endl;
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -124,7 +124,7 @@ int Downloader::login()
|
||||
if (!HTTP_Login(email, password))
|
||||
{
|
||||
std::cout << "HTTP: Login failed" << std::endl;
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -134,26 +134,16 @@ int Downloader::login()
|
||||
if (!gogAPI->login(email, password))
|
||||
{
|
||||
std::cout << "API: Login failed" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "API: Login successful" << std::endl;
|
||||
// Save token and secret to config file
|
||||
std::ofstream ofs(config.sConfigFilePath.c_str());
|
||||
if (ofs)
|
||||
{
|
||||
ofs << "token = " << gogAPI->getToken() << std::endl << "secret = " << gogAPI->getSecret() << std::endl;
|
||||
ofs.close();
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Failed to create config: " << config.sConfigFilePath << std::endl;
|
||||
std::cout << "API: Login successful" << std::endl;
|
||||
config.sToken = gogAPI->getToken();
|
||||
config.sSecret = gogAPI->getSecret();
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Downloader::updateCheck()
|
||||
|
Loading…
Reference in New Issue
Block a user