Don't reset options set in config file on --login

This commit is contained in:
Sude 2014-07-06 17:20:06 +03:00
parent 2aeca35097
commit ce26a4b020
2 changed files with 27 additions and 20 deletions

View File

@ -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)
{

View File

@ -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,24 +134,14 @@ int Downloader::login()
if (!gogAPI->login(email, password))
{
std::cout << "API: Login failed" << std::endl;
return 1;
return 0;
}
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;
return 1;
}
config.sToken = gogAPI->getToken();
config.sSecret = gogAPI->getSecret();
return 1;
}
}
}