mirror of
https://github.com/glest/glest-source.git
synced 2025-08-13 20:03:58 +02:00
- better handling of mod menu threading when user has no internet connection
This commit is contained in:
@@ -139,11 +139,14 @@ MenuStateMods::MenuStateMods(Program *program, MainMenu *mainMenu) :
|
|||||||
|
|
||||||
GraphicComponent::applyAllCustomProperties(containerName);
|
GraphicComponent::applyAllCustomProperties(containerName);
|
||||||
|
|
||||||
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
// Start http meta data thread
|
// Start http meta data thread
|
||||||
modHttpServerThread = new SimpleTaskThread(this,0,200);
|
modHttpServerThread = new SimpleTaskThread(this,0,200);
|
||||||
modHttpServerThread->setUniqueID(__FILE__);
|
modHttpServerThread->setUniqueID(__FILE__);
|
||||||
modHttpServerThread->start();
|
modHttpServerThread->start();
|
||||||
|
|
||||||
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
// Setup File Transfer thread
|
// Setup File Transfer thread
|
||||||
findDirs(config.getPathListForType(ptTilesets), tilesetFiles);
|
findDirs(config.getPathListForType(ptTilesets), tilesetFiles);
|
||||||
findDirs(config.getPathListForType(ptTechs), techTreeFiles);
|
findDirs(config.getPathListForType(ptTechs), techTreeFiles);
|
||||||
@@ -178,22 +181,31 @@ MenuStateMods::MenuStateMods(Program *program, MainMenu *mainMenu) :
|
|||||||
string fileArchiveExtractCommand = config.getString("FileArchiveExtractCommand","");
|
string fileArchiveExtractCommand = config.getString("FileArchiveExtractCommand","");
|
||||||
string fileArchiveExtractCommandParameters = config.getString("FileArchiveExtractCommandParameters","");
|
string fileArchiveExtractCommandParameters = config.getString("FileArchiveExtractCommandParameters","");
|
||||||
|
|
||||||
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
ftpClientThread = new FTPClientThread(-1,"",
|
ftpClientThread = new FTPClientThread(-1,"",
|
||||||
mapsPath,tilesetsPath,techtreesPath,
|
mapsPath,tilesetsPath,techtreesPath,
|
||||||
this,fileArchiveExtension,fileArchiveExtractCommand,
|
this,fileArchiveExtension,fileArchiveExtractCommand,
|
||||||
fileArchiveExtractCommandParameters);
|
fileArchiveExtractCommandParameters);
|
||||||
ftpClientThread->start();
|
ftpClientThread->start();
|
||||||
|
|
||||||
|
|
||||||
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuStateMods::simpleTask(BaseThread *callingThread) {
|
void MenuStateMods::simpleTask(BaseThread *callingThread) {
|
||||||
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
MutexSafeWrapper safeMutexThreadOwner(callingThread->getMutexThreadOwnerValid(),string(__FILE__) + "_" + intToStr(__LINE__));
|
MutexSafeWrapper safeMutexThreadOwner(callingThread->getMutexThreadOwnerValid(),string(__FILE__) + "_" + intToStr(__LINE__));
|
||||||
if(callingThread->getQuitStatus() == true || safeMutexThreadOwner.isValidMutex() == false) {
|
if(callingThread->getQuitStatus() == true || safeMutexThreadOwner.isValidMutex() == false) {
|
||||||
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
Lang &lang= Lang::getInstance();
|
Lang &lang= Lang::getInstance();
|
||||||
Config &config = Config::getInstance();
|
Config &config = Config::getInstance();
|
||||||
string fileArchiveExtractCommand = config.getString("FileArchiveExtractCommand","");
|
string fileArchiveExtractCommand = config.getString("FileArchiveExtractCommand","");
|
||||||
@@ -208,23 +220,49 @@ void MenuStateMods::simpleTask(BaseThread *callingThread) {
|
|||||||
std::string tilesetsMetaData = "";
|
std::string tilesetsMetaData = "";
|
||||||
std::string mapsMetaData = "";
|
std::string mapsMetaData = "";
|
||||||
|
|
||||||
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
if(config.getString("Masterserver","") != "") {
|
if(config.getString("Masterserver","") != "") {
|
||||||
string baseURL = config.getString("Masterserver");
|
string baseURL = config.getString("Masterserver");
|
||||||
|
|
||||||
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d] About to call first http url..\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
CURL *handle = SystemFlags::initHTTP();
|
CURL *handle = SystemFlags::initHTTP();
|
||||||
techsMetaData = SystemFlags::getHTTP(baseURL + "showTechsForGlest.php",handle);
|
CURLcode curlResult = CURLE_OK;
|
||||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("techsMetaData [%s]\n",techsMetaData.c_str());
|
techsMetaData = SystemFlags::getHTTP(baseURL + "showTechsForGlest.php",handle,-1,&curlResult);
|
||||||
tilesetsMetaData = SystemFlags::getHTTP(baseURL + "showTilesetsForGlest.php",handle);
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("techsMetaData [%s] curlResult = %d\n",techsMetaData.c_str(),curlResult);
|
||||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("tilesetsMetaData [%s]\n",tilesetsMetaData.c_str());
|
|
||||||
mapsMetaData = SystemFlags::getHTTP(baseURL + "showMapsForGlest.php",handle);
|
if(callingThread->getQuitStatus() == true || safeMutexThreadOwner.isValidMutex() == false) {
|
||||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("mapsMetaData [%s]\n",mapsMetaData.c_str());
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(curlResult == CURLE_OK ||
|
||||||
|
(curlResult != CURLE_COULDNT_RESOLVE_HOST &&
|
||||||
|
curlResult != CURLE_COULDNT_CONNECT)) {
|
||||||
|
|
||||||
|
tilesetsMetaData = SystemFlags::getHTTP(baseURL + "showTilesetsForGlest.php",handle);
|
||||||
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("tilesetsMetaData [%s]\n",tilesetsMetaData.c_str());
|
||||||
|
|
||||||
|
if(callingThread->getQuitStatus() == true || safeMutexThreadOwner.isValidMutex() == false) {
|
||||||
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
mapsMetaData = SystemFlags::getHTTP(baseURL + "showMapsForGlest.php",handle);
|
||||||
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("mapsMetaData [%s]\n",mapsMetaData.c_str());
|
||||||
|
}
|
||||||
SystemFlags::cleanupHTTP(&handle);
|
SystemFlags::cleanupHTTP(&handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
if(callingThread->getQuitStatus() == true || safeMutexThreadOwner.isValidMutex() == false) {
|
if(callingThread->getQuitStatus() == true || safeMutexThreadOwner.isValidMutex() == false) {
|
||||||
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
tilesetListRemote.clear();
|
tilesetListRemote.clear();
|
||||||
Tokenize(tilesetsMetaData,tilesetListRemote,"\n");
|
Tokenize(tilesetsMetaData,tilesetListRemote,"\n");
|
||||||
|
|
||||||
@@ -268,10 +306,15 @@ void MenuStateMods::simpleTask(BaseThread *callingThread) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
if(callingThread->getQuitStatus() == true || safeMutexThreadOwner.isValidMutex() == false) {
|
if(callingThread->getQuitStatus() == true || safeMutexThreadOwner.isValidMutex() == false) {
|
||||||
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
techListRemote.clear();
|
techListRemote.clear();
|
||||||
Tokenize(techsMetaData,techListRemote,"\n");
|
Tokenize(techsMetaData,techListRemote,"\n");
|
||||||
|
|
||||||
@@ -332,10 +375,15 @@ void MenuStateMods::simpleTask(BaseThread *callingThread) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
if(callingThread->getQuitStatus() == true || safeMutexThreadOwner.isValidMutex() == false) {
|
if(callingThread->getQuitStatus() == true || safeMutexThreadOwner.isValidMutex() == false) {
|
||||||
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
mapListRemote.clear();
|
mapListRemote.clear();
|
||||||
Tokenize(mapsMetaData,mapListRemote,"\n");
|
Tokenize(mapsMetaData,mapListRemote,"\n");
|
||||||
|
|
||||||
@@ -394,9 +442,11 @@ void MenuStateMods::simpleTask(BaseThread *callingThread) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(callingThread->getQuitStatus() == true || safeMutexThreadOwner.isValidMutex() == false) {
|
if(callingThread->getQuitStatus() == true || safeMutexThreadOwner.isValidMutex() == false) {
|
||||||
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
int listBoxLength = 400;
|
int listBoxLength = 400;
|
||||||
@@ -418,7 +468,13 @@ void MenuStateMods::simpleTask(BaseThread *callingThread) {
|
|||||||
keyMapScrollBar.setVisibleSize(keyButtonsToRender);
|
keyMapScrollBar.setVisibleSize(keyButtonsToRender);
|
||||||
keyMapScrollBar.setVisibleStart(0);
|
keyMapScrollBar.setVisibleStart(0);
|
||||||
|
|
||||||
modHttpServerThread->signalQuit();
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
|
if(modHttpServerThread != NULL) {
|
||||||
|
modHttpServerThread->signalQuit();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
}
|
}
|
||||||
|
|
||||||
MapInfo MenuStateMods::loadMapInfo(string file) {
|
MapInfo MenuStateMods::loadMapInfo(string file) {
|
||||||
@@ -564,30 +620,47 @@ void MenuStateMods::refreshMaps() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MenuStateMods::~MenuStateMods() {
|
void MenuStateMods::cleanUp() {
|
||||||
clearUserButtons();
|
clearUserButtons();
|
||||||
|
|
||||||
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
if(modHttpServerThread != NULL) {
|
if(modHttpServerThread != NULL) {
|
||||||
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
modHttpServerThread->setThreadOwnerValid(false);
|
modHttpServerThread->signalQuit();
|
||||||
|
//modHttpServerThread->setThreadOwnerValid(false);
|
||||||
|
|
||||||
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
if( modHttpServerThread->shutdownAndWait() == true) {
|
if( modHttpServerThread->canShutdown(true) == true &&
|
||||||
|
modHttpServerThread->shutdownAndWait() == true) {
|
||||||
delete modHttpServerThread;
|
delete modHttpServerThread;
|
||||||
}
|
}
|
||||||
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
modHttpServerThread = NULL;
|
modHttpServerThread = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
if(ftpClientThread != NULL) {
|
if(ftpClientThread != NULL) {
|
||||||
ftpClientThread->setCallBackObject(NULL);
|
ftpClientThread->setCallBackObject(NULL);
|
||||||
if(ftpClientThread->shutdownAndWait() == true) {
|
if(ftpClientThread->shutdownAndWait() == true) {
|
||||||
delete ftpClientThread;
|
delete ftpClientThread;
|
||||||
ftpClientThread = NULL;
|
ftpClientThread = NULL;
|
||||||
}
|
}
|
||||||
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MenuStateMods::~MenuStateMods() {
|
||||||
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
|
cleanUp();
|
||||||
|
|
||||||
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
}
|
||||||
|
|
||||||
void MenuStateMods::clearUserButtons() {
|
void MenuStateMods::clearUserButtons() {
|
||||||
// Techs
|
// Techs
|
||||||
while(!keyTechButtons.empty()) {
|
while(!keyTechButtons.empty()) {
|
||||||
@@ -635,6 +708,7 @@ void MenuStateMods::mouseClick(int x, int y, MouseButton mouseButton) {
|
|||||||
showMessageBox(szBuf, lang.get("Question"), true);
|
showMessageBox(szBuf, lang.get("Question"), true);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
cleanUp();
|
||||||
mainMenu->setState(new MenuStateRoot(program, mainMenu));
|
mainMenu->setState(new MenuStateRoot(program, mainMenu));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@@ -133,6 +133,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
void cleanUp();
|
||||||
MapInfo loadMapInfo(string file);
|
MapInfo loadMapInfo(string file);
|
||||||
void showMessageBox(const string &text, const string &header, bool toggle);
|
void showMessageBox(const string &text, const string &header, bool toggle);
|
||||||
void clearUserButtons();
|
void clearUserButtons();
|
||||||
|
@@ -128,7 +128,7 @@ public:
|
|||||||
static void init(bool haveSpecialOutputCommandLineOption);
|
static void init(bool haveSpecialOutputCommandLineOption);
|
||||||
static SystemFlagsType & getSystemSettingType(DebugType type) { return (*debugLogFileList)[type]; }
|
static SystemFlagsType & getSystemSettingType(DebugType type) { return (*debugLogFileList)[type]; }
|
||||||
static size_t httpWriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data);
|
static size_t httpWriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data);
|
||||||
static std::string getHTTP(std::string URL,CURL *handle=NULL, int timeOut=-1);
|
static std::string getHTTP(std::string URL,CURL *handle=NULL, int timeOut=-1, CURLcode *savedResult=NULL);
|
||||||
static std::string escapeURL(std::string URL, CURL *handle=NULL);
|
static std::string escapeURL(std::string URL, CURL *handle=NULL);
|
||||||
|
|
||||||
static CURL *initHTTP();
|
static CURL *initHTTP();
|
||||||
|
@@ -103,7 +103,7 @@ std::string SystemFlags::escapeURL(std::string URL, CURL *handle) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string SystemFlags::getHTTP(std::string URL,CURL *handle,int timeOut) {
|
std::string SystemFlags::getHTTP(std::string URL,CURL *handle,int timeOut,CURLcode *savedResult) {
|
||||||
if(handle == NULL) {
|
if(handle == NULL) {
|
||||||
handle = SystemFlags::curl_handle;
|
handle = SystemFlags::curl_handle;
|
||||||
}
|
}
|
||||||
@@ -155,10 +155,15 @@ std::string SystemFlags::getHTTP(std::string URL,CURL *handle,int timeOut) {
|
|||||||
if(chunk.memory) {
|
if(chunk.memory) {
|
||||||
free(chunk.memory);
|
free(chunk.memory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(savedResult != NULL) {
|
||||||
|
*savedResult = result;
|
||||||
|
}
|
||||||
if(result != CURLE_OK) {
|
if(result != CURLE_OK) {
|
||||||
serverResponse = errbuf;
|
serverResponse = errbuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d] serverResponse [%s]\n",__FILE__,__FUNCTION__,__LINE__,serverResponse.c_str());
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d] serverResponse [%s]\n",__FILE__,__FUNCTION__,__LINE__,serverResponse.c_str());
|
||||||
|
|
||||||
return serverResponse;
|
return serverResponse;
|
||||||
|
Reference in New Issue
Block a user