From 346e9d21689c9616dae3f3d858071b7181979663 Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Wed, 8 Aug 2012 18:34:37 +0100 Subject: [PATCH] Proxy from command line arg --- src/PowderToySDL.cpp | 28 ++++++++++++++++++++++++++-- src/client/Client.cpp | 24 ++++++++++++++++-------- src/client/Client.h | 3 +++ 3 files changed, 45 insertions(+), 10 deletions(-) diff --git a/src/PowderToySDL.cpp b/src/PowderToySDL.cpp index 0e01c66d1..82a6856ad 100644 --- a/src/PowderToySDL.cpp +++ b/src/PowderToySDL.cpp @@ -244,9 +244,12 @@ std::map readArguments(int argc, char * argv[]) { arguments["scale"] = std::string(argv[i]+6); } - else if (!strncmp(argv[i], "proxy:", 6) && argv[i]+6) + else if (!strncmp(argv[i], "proxy:", 6)) { - arguments["proxy"] = std::string(argv[i]+6); + if(argv[i]+6) + arguments["proxy"] = std::string(argv[i]+6); + else + arguments["proxy"] = "false"; } else if (!strncmp(argv[i], "nohud", 5)) { @@ -319,6 +322,27 @@ int main(int argc, char * argv[]) 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) tempScale = 1; diff --git a/src/client/Client.cpp b/src/client/Client.cpp index 64abe0e73..56d436b00 100644 --- a/src/client/Client.cpp +++ b/src/client/Client.cpp @@ -39,10 +39,10 @@ extern "C" Client::Client(): authUser(0, ""), - updateAvailable(false) + updateAvailable(false), + versionCheckRequest(NULL) { int i = 0; - std::string proxyString(""); for(i = 0; i < THUMB_CACHE_SIZE; i++) { thumbnailCache[i] = NULL; @@ -89,6 +89,10 @@ Client::Client(): } configFile.close(); } +} + +void Client::Initialise(std::string proxyString) +{ if(GetPrefBool("version.update", false)==true) { @@ -96,15 +100,10 @@ Client::Client(): update_finish(); } - proxyString = GetPrefString("proxy", ""); if(proxyString.length()) - { - http_init((char *)proxyString.c_str()); - } + http_init((char*)proxyString.c_str()); else - { http_init(NULL); - } //Read stamps library std::ifstream stampsLib; @@ -125,6 +124,15 @@ Client::Client(): 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 Client::DirectorySearch(std::string directory, std::string search, std::string extension) { std::vector extensions; diff --git a/src/client/Client.h b/src/client/Client.h index 9bb9d5f21..748c96ece 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -88,6 +88,9 @@ public: std::vector ReadFile(std::string filename); + void Initialise(std::string proxyString); + void SetProxy(std::string proxy); + void WriteFile(std::vector fileData, std::string filename); void WriteFile(std::vector fileData, std::string filename); bool FileExists(std::string filename);