Proxy from command line arg

This commit is contained in:
Simon Robertshaw 2012-08-08 18:34:37 +01:00
parent 73a18998f6
commit 346e9d2168
3 changed files with 45 additions and 10 deletions

View File

@ -244,9 +244,12 @@ std::map<std::string, std::string> readArguments(int argc, char * argv[])
{ {
arguments["scale"] = std::string(argv[i]+6); arguments["scale"] = std::string(argv[i]+6);
} }
else if (!strncmp(argv[i], "proxy:", 6) && argv[i]+6) else if (!strncmp(argv[i], "proxy:", 6))
{ {
if(argv[i]+6)
arguments["proxy"] = std::string(argv[i]+6); arguments["proxy"] = std::string(argv[i]+6);
else
arguments["proxy"] = "false";
} }
else if (!strncmp(argv[i], "nohud", 5)) else if (!strncmp(argv[i], "nohud", 5))
{ {
@ -319,6 +322,27 @@ int main(int argc, char * argv[])
Client::Ref().SetPref("Scale", tempScale); Client::Ref().SetPref("Scale", tempScale);
} }
std::string proxyString = "";
if(arguments["proxy"].length())
{
if(arguments["proxy"] == "false")
{
proxyString = "";
Client::Ref().SetPref("Proxy", "");
}
else
{
proxyString = (arguments["proxy"]);
Client::Ref().SetPref("Proxy", arguments["proxy"]);
}
}
else if(Client::Ref().GetPrefString("Proxy", "").length())
{
proxyString = (Client::Ref().GetPrefString("Proxy", ""));
}
Client::Ref().Initialise(proxyString);
if(tempScale != 1 && tempScale != 2) if(tempScale != 1 && tempScale != 2)
tempScale = 1; tempScale = 1;

View File

@ -39,10 +39,10 @@ extern "C"
Client::Client(): Client::Client():
authUser(0, ""), authUser(0, ""),
updateAvailable(false) updateAvailable(false),
versionCheckRequest(NULL)
{ {
int i = 0; int i = 0;
std::string proxyString("");
for(i = 0; i < THUMB_CACHE_SIZE; i++) for(i = 0; i < THUMB_CACHE_SIZE; i++)
{ {
thumbnailCache[i] = NULL; thumbnailCache[i] = NULL;
@ -89,6 +89,10 @@ Client::Client():
} }
configFile.close(); configFile.close();
} }
}
void Client::Initialise(std::string proxyString)
{
if(GetPrefBool("version.update", false)==true) if(GetPrefBool("version.update", false)==true)
{ {
@ -96,15 +100,10 @@ Client::Client():
update_finish(); update_finish();
} }
proxyString = GetPrefString("proxy", "");
if(proxyString.length()) if(proxyString.length())
{ http_init((char*)proxyString.c_str());
http_init((char *)proxyString.c_str());
}
else else
{
http_init(NULL); http_init(NULL);
}
//Read stamps library //Read stamps library
std::ifstream stampsLib; std::ifstream stampsLib;
@ -125,6 +124,15 @@ Client::Client():
versionCheckRequest = http_async_req_start(NULL, SERVER "/Download/Version.json", NULL, 0, 1); versionCheckRequest = http_async_req_start(NULL, SERVER "/Download/Version.json", NULL, 0, 1);
} }
void Client::SetProxy(std::string proxy)
{
http_done();
if(proxy.length())
http_init((char*)proxy.c_str());
else
http_init(NULL);
}
std::vector<std::string> Client::DirectorySearch(std::string directory, std::string search, std::string extension) std::vector<std::string> Client::DirectorySearch(std::string directory, std::string search, std::string extension)
{ {
std::vector<std::string> extensions; std::vector<std::string> extensions;

View File

@ -88,6 +88,9 @@ public:
std::vector<unsigned char> ReadFile(std::string filename); std::vector<unsigned char> ReadFile(std::string filename);
void Initialise(std::string proxyString);
void SetProxy(std::string proxy);
void WriteFile(std::vector<unsigned char> fileData, std::string filename); void WriteFile(std::vector<unsigned char> fileData, std::string filename);
void WriteFile(std::vector<char> fileData, std::string filename); void WriteFile(std::vector<char> fileData, std::string filename);
bool FileExists(std::string filename); bool FileExists(std::string filename);