mirror of
https://github.com/glest/glest-source.git
synced 2025-09-02 12:32:34 +02:00
- added scenarios to mod menu
This commit is contained in:
@@ -37,7 +37,8 @@ enum FTP_Client_CallbackType {
|
||||
ftp_cct_Map = 0,
|
||||
ftp_cct_Tileset = 1,
|
||||
ftp_cct_Techtree = 2,
|
||||
ftp_cct_DownloadProgress = 3
|
||||
ftp_cct_Scenario = 3,
|
||||
ftp_cct_DownloadProgress = 4
|
||||
};
|
||||
|
||||
class FTPClientCallbackInterface {
|
||||
@@ -64,6 +65,7 @@ protected:
|
||||
std::pair<string,string> mapsPath;
|
||||
std::pair<string,string> tilesetsPath;
|
||||
std::pair<string,string> techtreesPath;
|
||||
std::pair<string,string> scenariosPath;
|
||||
|
||||
Mutex mutexMapFileList;
|
||||
vector<pair<string,string> > mapFileList;
|
||||
@@ -74,6 +76,9 @@ protected:
|
||||
Mutex mutexTechtreeList;
|
||||
vector<pair<string,string> > techtreeList;
|
||||
|
||||
Mutex mutexScenarioList;
|
||||
vector<pair<string,string> > scenarioList;
|
||||
|
||||
void getMapFromServer(pair<string,string> mapFilename);
|
||||
pair<FTP_Client_ResultType,string> getMapFromServer(pair<string,string> mapFileName, string ftpUser, string ftpUserPassword);
|
||||
|
||||
@@ -83,6 +88,9 @@ protected:
|
||||
void getTechtreeFromServer(pair<string,string> techtreeName);
|
||||
pair<FTP_Client_ResultType,string> getTechtreeFromServer(pair<string,string> techtreeName, string ftpUser, string ftpUserPassword);
|
||||
|
||||
void getScenarioFromServer(pair<string,string> fileName);
|
||||
pair<FTP_Client_ResultType,string> getScenarioInternalFromServer(pair<string,string> fileName);
|
||||
|
||||
Mutex mutexProgressMutex;
|
||||
|
||||
string fileArchiveExtension;
|
||||
@@ -99,6 +107,7 @@ public:
|
||||
std::pair<string,string> mapsPath,
|
||||
std::pair<string,string> tilesetsPath,
|
||||
std::pair<string,string> techtreesPath,
|
||||
std::pair<string,string> scenariosPath,
|
||||
FTPClientCallbackInterface *pCBObject,
|
||||
string fileArchiveExtension,
|
||||
string fileArchiveExtractCommand,
|
||||
@@ -110,6 +119,7 @@ public:
|
||||
void addMapToRequests(string mapFilename,string URL="");
|
||||
void addTilesetToRequests(string tileSetName,string URL="");
|
||||
void addTechtreeToRequests(string techtreeName,string URL="");
|
||||
void addScenarioToRequests(string fileName,string URL="");
|
||||
|
||||
FTPClientCallbackInterface * getCallBackObject();
|
||||
void setCallBackObject(FTPClientCallbackInterface *value);
|
||||
|
@@ -203,6 +203,7 @@ FTPClientThread::FTPClientThread(int portNumber, string serverUrl,
|
||||
std::pair<string,string> mapsPath,
|
||||
std::pair<string,string> tilesetsPath,
|
||||
std::pair<string,string> techtreesPath,
|
||||
std::pair<string,string> scenariosPath,
|
||||
FTPClientCallbackInterface *pCBObject,
|
||||
string fileArchiveExtension,
|
||||
string fileArchiveExtractCommand,
|
||||
@@ -212,6 +213,7 @@ FTPClientThread::FTPClientThread(int portNumber, string serverUrl,
|
||||
this->mapsPath = mapsPath;
|
||||
this->tilesetsPath = tilesetsPath;
|
||||
this->techtreesPath = techtreesPath;
|
||||
this->scenariosPath = scenariosPath;
|
||||
this->pCBObject = pCBObject;
|
||||
|
||||
this->fileArchiveExtension = fileArchiveExtension;
|
||||
@@ -381,6 +383,14 @@ void FTPClientThread::addTechtreeToRequests(string techtreeName,string URL) {
|
||||
}
|
||||
}
|
||||
|
||||
void FTPClientThread::addScenarioToRequests(string fileName,string URL) {
|
||||
std::pair<string,string> item = make_pair(fileName,URL);
|
||||
MutexSafeWrapper safeMutex(&mutexScenarioList,string(__FILE__) + "_" + intToStr(__LINE__));
|
||||
if(std::find(scenarioList.begin(),scenarioList.end(),item) == scenarioList.end()) {
|
||||
scenarioList.push_back(item);
|
||||
}
|
||||
}
|
||||
|
||||
void FTPClientThread::getTilesetFromServer(pair<string,string> tileSetName) {
|
||||
bool findArchive = executeShellCommand(this->fileArchiveExtractCommand);
|
||||
|
||||
@@ -883,6 +893,56 @@ pair<FTP_Client_ResultType,string> FTPClientThread::getTechtreeFromServer(pair<
|
||||
|
||||
}
|
||||
|
||||
void FTPClientThread::getScenarioFromServer(pair<string,string> fileName) {
|
||||
pair<FTP_Client_ResultType,string> result = make_pair(ftp_crt_FAIL,"");
|
||||
bool findArchive = executeShellCommand(this->fileArchiveExtractCommand);
|
||||
if(findArchive == true) {
|
||||
result = getScenarioInternalFromServer(fileName);
|
||||
}
|
||||
|
||||
MutexSafeWrapper safeMutex(this->getProgressMutex(),string(__FILE__) + "_" + intToStr(__LINE__));
|
||||
if(this->pCBObject != NULL) {
|
||||
this->pCBObject->FTPClient_CallbackEvent(fileName.first,ftp_cct_Scenario,result,NULL);
|
||||
}
|
||||
}
|
||||
|
||||
pair<FTP_Client_ResultType,string> FTPClientThread::getScenarioInternalFromServer(pair<string,string> fileName) {
|
||||
// Root folder for the techtree
|
||||
string destRootFolder = this->scenariosPath.second;
|
||||
endPathWithSlash(destRootFolder);
|
||||
string destRootArchiveFolder = destRootFolder;
|
||||
destRootFolder += fileName.first;
|
||||
endPathWithSlash(destRootFolder);
|
||||
|
||||
string destFile = this->scenariosPath.second;
|
||||
endPathWithSlash(destFile);
|
||||
destFile += fileName.first;
|
||||
string destFileSaveAs = destFile + this->fileArchiveExtension;
|
||||
endPathWithSlash(destFile);
|
||||
|
||||
string remotePath = fileName.first + this->fileArchiveExtension;
|
||||
if(fileName.second != "") {
|
||||
remotePath = fileName.second;
|
||||
}
|
||||
|
||||
pair<FTP_Client_ResultType,string> result = getFileFromServer(fileName,
|
||||
remotePath, destFileSaveAs, "", "");
|
||||
|
||||
// Extract the archive
|
||||
if(result.first == ftp_crt_SUCCESS) {
|
||||
string extractCmd = getFullFileArchiveExtractCommand(this->fileArchiveExtractCommand,
|
||||
this->fileArchiveExtractCommandParameters, destRootArchiveFolder,
|
||||
destRootArchiveFolder + fileName.first + this->fileArchiveExtension);
|
||||
|
||||
if(executeShellCommand(extractCmd) == false) {
|
||||
result.first = ftp_crt_FAIL;
|
||||
result.second = "failed to extract archive!";
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
pair<FTP_Client_ResultType,string> FTPClientThread::getFileFromServer(pair<string,string> fileNameTitle,
|
||||
string remotePath, string destFileSaveAs,
|
||||
@@ -1082,6 +1142,18 @@ void FTPClientThread::execute() {
|
||||
safeMutex3.ReleaseLock();
|
||||
}
|
||||
|
||||
MutexSafeWrapper safeMutex4(&mutexScenarioList,string(__FILE__) + "_" + intToStr(__LINE__));
|
||||
if(scenarioList.size() > 0) {
|
||||
pair<string,string> file = scenarioList[0];
|
||||
scenarioList.erase(scenarioList.begin() + 0);
|
||||
safeMutex4.ReleaseLock();
|
||||
|
||||
getScenarioFromServer(file);
|
||||
}
|
||||
else {
|
||||
safeMutex4.ReleaseLock();
|
||||
}
|
||||
|
||||
if(this->getQuitStatus() == false) {
|
||||
sleep(25);
|
||||
}
|
||||
|
Reference in New Issue
Block a user