Add disable-network command line argument

This commit is contained in:
jacob1 2019-07-22 22:46:32 -04:00
parent 7ad797275b
commit fb06e0028b
6 changed files with 40 additions and 32 deletions

View File

@ -337,6 +337,10 @@ std::map<ByteString, ByteString> readArguments(int argc, char * argv[])
i++;
break;
}
else if (!strncmp(argv[i], "disable-network", 16))
{
arguments["disable-network"] = "true";
}
}
return arguments;
}
@ -689,7 +693,11 @@ int main(int argc, char * argv[])
proxyString = (Client::Ref().GetPrefByteString("Proxy", ""));
}
Client::Ref().Initialise(proxyString);
bool disableNetwork = false;
if (arguments.find("disable-network") != arguments.end())
disableNetwork = true;
Client::Ref().Initialise(proxyString, disableNetwork);
// TODO: maybe bind the maximum allowed scale to screen size somehow
if(scale < 1 || scale > 10)

View File

@ -102,7 +102,7 @@ Client::Client():
firstRun = true;
}
void Client::Initialise(ByteString proxyString)
void Client::Initialise(ByteString proxyString, bool disableNetwork)
{
if (GetPrefBool("version.update", false))
{
@ -110,7 +110,8 @@ void Client::Initialise(ByteString proxyString)
update_finish();
}
http::RequestManager::Ref().Initialise(proxyString);
if (!disableNetwork)
http::RequestManager::Ref().Initialise(proxyString);
//Read stamps library
std::ifstream stampsLib;

View File

@ -114,7 +114,7 @@ public:
void SetMessageOfTheDay(String message);
String GetMessageOfTheDay();
void Initialise(ByteString proxyString);
void Initialise(ByteString proxyString, bool disableNetwork);
bool IsFirstRun();
int MakeDirectory(const char * dirname);

View File

@ -22,7 +22,11 @@ namespace http
#endif
{
easy = curl_easy_init();
RequestManager::Ref().AddRequest(this);
if (!RequestManager::Ref().AddRequest(this))
{
status = 604;
rm_finished = true;
}
}
Request::~Request()

View File

@ -14,19 +14,6 @@ namespace http
ByteString proxy;
ByteString user_agent;
RequestManager::RequestManager():
requests_added_to_multi(0),
requests_to_start(false),
requests_to_remove(false),
rt_shutting_down(false),
multi(NULL)
{
}
RequestManager::~RequestManager()
{
}
void RequestManager::Shutdown()
{
{
@ -35,11 +22,14 @@ namespace http
}
rt_cv.notify_one();
worker_thread.join();
curl_multi_cleanup(multi);
multi = NULL;
curl_global_cleanup();
if (initialized)
{
worker_thread.join();
curl_multi_cleanup(multi);
multi = NULL;
curl_global_cleanup();
}
}
void RequestManager::Initialise(ByteString Proxy)
@ -56,6 +46,7 @@ namespace http
user_agent = ByteString::Build("PowderToy/", SAVE_VERSION, ".", MINOR_VERSION, " (", IDENT_PLATFORM, "; ", IDENT_BUILD, "; M", MOD_ID, ") TPTPP/", SAVE_VERSION, ".", MINOR_VERSION, ".", BUILD_NUM, IDENT_RELTYPE, ".", SNAPSHOT_ID);
worker_thread = std::thread([this]() { Worker(); });
initialized = true;
}
void RequestManager::Worker()
@ -233,13 +224,16 @@ namespace http
}
}
void RequestManager::AddRequest(Request *request)
bool RequestManager::AddRequest(Request *request)
{
if (!initialized)
return false;
{
std::lock_guard<std::mutex> g(rt_mutex);
requests_to_add.insert(request);
}
rt_cv.notify_one();
return true;
}
void RequestManager::StartRequest(Request *request)

View File

@ -17,28 +17,29 @@ namespace http
{
std::thread worker_thread;
std::set<Request *> requests;
int requests_added_to_multi;
int requests_added_to_multi = 0;
std::set<Request *> requests_to_add;
bool requests_to_start;
bool requests_to_remove;
bool rt_shutting_down;
bool requests_to_start = false;
bool requests_to_remove = false;
bool initialized = false;
bool rt_shutting_down = false;
std::mutex rt_mutex;
std::condition_variable rt_cv;
CURLM *multi;
CURLM *multi = nullptr;
void Start();
void Worker();
void MultiAdd(Request *request);
void MultiRemove(Request *request);
void AddRequest(Request *request);
bool AddRequest(Request *request);
void StartRequest(Request *request);
void RemoveRequest(Request *request);
public:
RequestManager();
~RequestManager();
RequestManager() { }
~RequestManager() { }
void Initialise(ByteString proxy);
void Shutdown();