mirror of
https://github.com/HackHerz/pusher
synced 2025-12-06 02:10:19 +00:00
Writing config file with simpleini
This commit is contained in:
parent
65c1816b2f
commit
a0da807c23
1 changed files with 15 additions and 22 deletions
39
src/main.cpp
39
src/main.cpp
|
|
@ -11,7 +11,6 @@
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <fstream>
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
@ -79,6 +78,9 @@ int main(int argc, char **argv)
|
||||||
// Variables
|
// Variables
|
||||||
string message;
|
string message;
|
||||||
int id;
|
int id;
|
||||||
|
CSimpleIniA iniReader;
|
||||||
|
iniReader.SetUnicode();
|
||||||
|
|
||||||
|
|
||||||
// Request token
|
// Request token
|
||||||
if(tokenSwitch.getValue())
|
if(tokenSwitch.getValue())
|
||||||
|
|
@ -105,44 +107,32 @@ int main(int argc, char **argv)
|
||||||
token = buf.login(password);
|
token = buf.login(password);
|
||||||
|
|
||||||
|
|
||||||
// Write config
|
// Build config
|
||||||
ofstream dat_aus;
|
iniReader.SetValue("pusher", "username", username.c_str());
|
||||||
dat_aus.open(CONFIG_FILE, ios_base::out);
|
iniReader.SetValue("pusher", "appToken", token.c_str());
|
||||||
|
|
||||||
// Check if file is writable
|
// Check if file is writable
|
||||||
if(!dat_aus.is_open())
|
if(iniReader.SaveFile(CONFIG_FILE) < 0)
|
||||||
{
|
{
|
||||||
cout << "Try running pusher as root or save the following in "
|
cout << "Try running pusher as root or save the following in "
|
||||||
<< CONFIG_FILE << "\n" << endl;
|
<< CONFIG_FILE << "\n" << endl;
|
||||||
|
|
||||||
// Data
|
// Data
|
||||||
cout << "[pusher]" << endl;
|
string strData;
|
||||||
cout << "username=" << username << endl;
|
iniReader.Save(strData);
|
||||||
cout << "appToken=" << token << endl;
|
cout << strData << endl;
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
cout << "Success!" << endl;
|
cout << "Success!" << endl;
|
||||||
}
|
|
||||||
|
|
||||||
// Data
|
|
||||||
dat_aus << "[pusher]\n";
|
|
||||||
dat_aus << "username=" << username << "\n";
|
|
||||||
dat_aus << "appToken=" << token;
|
|
||||||
|
|
||||||
dat_aus.close();
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Load conf and check if token is specified
|
|
||||||
CSimpleIniA iniReader;
|
|
||||||
iniReader.SetUnicode();
|
|
||||||
|
|
||||||
// Check if reading is possible
|
// Check if reading of config is possible
|
||||||
if(iniReader.LoadFile(CONFIG_FILE) < 0)
|
if(iniReader.LoadFile(CONFIG_FILE) < 0)
|
||||||
{
|
{
|
||||||
cout << "Error" << endl;
|
cout << "Error" << endl;
|
||||||
|
|
@ -258,6 +248,7 @@ int main(int argc, char **argv)
|
||||||
catch (TCLAP::ArgException &e)
|
catch (TCLAP::ArgException &e)
|
||||||
{
|
{
|
||||||
cerr << "error: " << e.error() << " for arg " << e.argId() << endl;
|
cerr << "error: " << e.error() << " for arg " << e.argId() << endl;
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -265,6 +256,7 @@ int main(int argc, char **argv)
|
||||||
catch(PusherError& e)
|
catch(PusherError& e)
|
||||||
{
|
{
|
||||||
cout << "Error: " << e.what() << endl;
|
cout << "Error: " << e.what() << endl;
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -272,6 +264,7 @@ int main(int argc, char **argv)
|
||||||
catch(exception& e)
|
catch(exception& e)
|
||||||
{
|
{
|
||||||
cout << "Some kind of error occured: " << e.what() << endl;
|
cout << "Some kind of error occured: " << e.what() << endl;
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue