diff options
| author | Simon Robertshaw <simon@hardwired.org.uk> | 2012-01-31 18:49:14 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2012-01-31 18:49:14 (GMT) |
| commit | 857b0cc1fc58f066acd59404d16ee5e566e20f00 (patch) | |
| tree | 7607fc43f3bdd63687dff39209f44defa48e6a35 /src/client/Client.cpp | |
| parent | 1d297cb57a338f2a9e34d0f16642afc6a83c1041 (diff) | |
| download | powder-857b0cc1fc58f066acd59404d16ee5e566e20f00.zip powder-857b0cc1fc58f066acd59404d16ee5e566e20f00.tar.gz | |
Load user information from preferences, fps display for testing
Diffstat (limited to 'src/client/Client.cpp')
| -rw-r--r-- | src/client/Client.cpp | 73 |
1 files changed, 68 insertions, 5 deletions
diff --git a/src/client/Client.cpp b/src/client/Client.cpp index 75b78c5..3706cf9 100644 --- a/src/client/Client.cpp +++ b/src/client/Client.cpp @@ -14,15 +14,11 @@ #include "search/Save.h" -#include "cajun/reader.h" -#include "cajun/writer.h" -#include "cajun/elements.h" - Client::Client(): authUser(0, "") { int i = 0; - http_init(NULL); + std::string proxyString(""); for(i = 0; i < THUMB_CACHE_SIZE; i++) { thumbnailCache[i] = NULL; @@ -33,14 +29,81 @@ Client::Client(): activeThumbRequestTimes[i] = 0; activeThumbRequestCompleteTimes[i] = 0; } + + //Read config + std::ifstream configFile; + configFile.open("powder.pref", ios::binary); + if(configFile) + { + int fsize = configFile.tellg(); + configFile.seekg(0, std::ios::end); + fsize = configFile.tellg() - fsize; + configFile.seekg(0, ios::beg); + if(fsize) + { + json::Reader::Read(configDocument, configFile); + try + { + authUser.ID = ((json::Number)(configDocument["User"]["ID"])).Value(); + authUser.SessionID = ((json::String)(configDocument["User"]["SessionID"])).Value(); + authUser.SessionKey = ((json::String)(configDocument["User"]["SessionKey"])).Value(); + authUser.Username = ((json::String)(configDocument["User"]["Username"])).Value(); + } + catch (json::Exception &e) + { + authUser = User(0, ""); + std::cerr << "Error: Client [Read User data from pref] " << e.what() << std::endl; + } + try + { + proxyString = ((json::String)(configDocument["Proxy"])).Value(); + } + catch (json::Exception &e) + { + proxyString = ""; + std::cerr << "Error: Client [Read Proxy from pref] " << e.what() << std::endl; + } + } + configFile.close(); + } + + if(proxyString.length()) + { + http_init((char *)proxyString.c_str()); + } + else + { + http_init(NULL); + } } Client::~Client() { ClearThumbnailRequests(); http_done(); + + //Save config + std::ofstream configFile; + configFile.open("powder.pref", ios::trunc); + if(configFile) + { + if(authUser.ID) + { + configDocument["User"]["ID"] = json::Number(authUser.ID); + configDocument["User"]["SessionID"] = json::String(authUser.SessionID); + configDocument["User"]["SessionKey"] = json::String(authUser.SessionKey); + configDocument["User"]["Username"] = json::String(authUser.Username); + } + else + { + configDocument["User"] = json::Null(); + } + json::Writer::Write(configDocument, configFile); + configFile.close(); + } } + void Client::SetAuthUser(User user) { authUser = user; |
