diff --git a/source/glest_game/menu/menu_state_keysetup.cpp b/source/glest_game/menu/menu_state_keysetup.cpp index ab7dd6a2..1591f500 100644 --- a/source/glest_game/menu/menu_state_keysetup.cpp +++ b/source/glest_game/menu/menu_state_keysetup.cpp @@ -202,11 +202,8 @@ void MenuStateKeysetup::mouseClick(int x, int y, MouseButton mouseButton){ Config &configKeys = Config::getInstance(std::pair(cfgMainKeys,cfgUserKeys)); string userKeysFile = configKeys.getFileName(true); -#ifdef WIN32 - int result = _unlink(userKeysFile.c_str()); -#else - int result = unlink(userKeysFile.c_str()); -#endif + + bool result = removeFile(userKeysFile.c_str()); if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] delete file [%s] returned %d\n",__FILE__,__FUNCTION__,__LINE__,userKeysFile.c_str(),result); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] delete file [%s] returned %d\n",__FILE__,__FUNCTION__,__LINE__,userKeysFile.c_str(),result); configKeys.reload(); diff --git a/source/shared_lib/include/graphics/model.h b/source/shared_lib/include/graphics/model.h index 97f11ac0..8f6cf505 100644 --- a/source/shared_lib/include/graphics/model.h +++ b/source/shared_lib/include/graphics/model.h @@ -139,7 +139,8 @@ public: void loadV2(const string &dir, FILE *f, TextureManager *textureManager,bool deletePixMapAfterLoad); void loadV3(const string &dir, FILE *f, TextureManager *textureManager,bool deletePixMapAfterLoad); void load(const string &dir, FILE *f, TextureManager *textureManager,bool deletePixMapAfterLoad); - void save(const string &dir, FILE *f, TextureManager *textureManager, string convertTextureToFormat); + void save(const string &dir, FILE *f, TextureManager *textureManager, + string convertTextureToFormat, std::map &textureDeleteList); void deletePixels(); diff --git a/source/shared_lib/include/platform/common/platform_common.h b/source/shared_lib/include/platform/common/platform_common.h index 076b7d0d..22cb7f72 100644 --- a/source/shared_lib/include/platform/common/platform_common.h +++ b/source/shared_lib/include/platform/common/platform_common.h @@ -148,6 +148,7 @@ bool StartsWith(const std::string &str, const std::string &key); bool EndsWith(const string &str, const string& key); string replaceAll(string& context, const string& from, const string& to); +bool removeFile(string file); void removeFolder(const string path); int getScreenW(); diff --git a/source/shared_lib/sources/graphics/model.cpp b/source/shared_lib/sources/graphics/model.cpp index 0e445414..211fa4a4 100644 --- a/source/shared_lib/sources/graphics/model.cpp +++ b/source/shared_lib/sources/graphics/model.cpp @@ -411,7 +411,8 @@ void Mesh::load(const string &dir, FILE *f, TextureManager *textureManager, } } -void Mesh::save(const string &dir, FILE *f, TextureManager *textureManager, string convertTextureToFormat) { +void Mesh::save(const string &dir, FILE *f, TextureManager *textureManager, + string convertTextureToFormat, std::map &textureDeleteList) { MeshHeader meshHeader; memset(&meshHeader, 0, sizeof(struct MeshHeader)); @@ -465,15 +466,21 @@ void Mesh::save(const string &dir, FILE *f, TextureManager *textureManager, stri if(convertTextureToFormat == "tga") { texture->getPixmap()->saveTga(file); + + textureDeleteList[texture->getPath()] = textureDeleteList[texture->getPath()] + 1; } else if(convertTextureToFormat == "bmp") { texture->getPixmap()->saveBmp(file); + + textureDeleteList[texture->getPath()] = textureDeleteList[texture->getPath()] + 1; } //else if(convertTextureToFormat == "jpg") { // texture->getPixmap()->saveJpg(file); //} else if(convertTextureToFormat == "png") { texture->getPixmap()->savePng(file); + + textureDeleteList[texture->getPath()] = textureDeleteList[texture->getPath()] + 1; } else { throw runtime_error("Unsuppoted texture format: [" + convertTextureToFormat + "]"); @@ -645,44 +652,6 @@ void Model::save(const string &path, string convertTextureToFormat) { } } -/*void Model::loadG3dOld(const string &path){ - try{ - FILE *f=fopen(path.c_str(),"rb"); - if (f==NULL){ - throw runtime_error("Error opening 3d model file"); - } - - string dir= cutLastFile(path); - - //read header - ModelHeaderOld modelHeader; - fread(&modelHeader, sizeof(ModelHeader), 1, f); - meshCount= modelHeader.meshCount; - - if(modelHeader.id[0]!='G' || modelHeader.id[1]!='3' || modelHeader.id[2]!='D'){ - throw runtime_error("Model: "+path+": is not a valid G3D model"); - } - - switch(modelHeader.version){ - case 3:{ - meshes= new Mesh[meshCount]; - for(uint32 i=0; i textureDeleteList; for(uint32 i = 0; i < meshCount; ++i) { - meshes[i].save(path, f, textureManager,convertTextureToFormat); + meshes[i].save(path, f, textureManager,convertTextureToFormat,textureDeleteList); } - } -/* - //version 3 - else if(fileHeader.version == 3) { - fwrite(&meshCount, sizeof(meshCount), 1, f); - for(uint32 i=0; i::iterator iterMap = textureDeleteList.begin(); + iterMap != textureDeleteList.end(); ++iterMap) { + } } - //version 2 - else if(fileHeader.version == 2) { - fwrite(&meshCount, sizeof(meshCount), 1, f); - for(uint32 i=0; i paths, string pathSearchStri string crcCacheFile = getFormattedCRCCacheFileName(cacheKeys); if(fileExists(crcCacheFile) == true) { -#ifdef WIN32 - int result = _unlink(crcCacheFile.c_str()); -#else - int result = unlink(crcCacheFile.c_str()); -#endif + + bool result = removeFile(crcCacheFile); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] fileitem [%s] result = %d\n",__FILE__,__FUNCTION__,__LINE__,crcCacheFile.c_str(),result); } } @@ -560,11 +553,7 @@ void clearFolderTreeContentsCheckSum(const string &path, const string filterFile } string crcCacheFile = getFormattedCRCCacheFileName(cacheKeys); if(fileExists(crcCacheFile) == true) { -#ifdef WIN32 - int result = _unlink(crcCacheFile.c_str()); -#else - int result = unlink(crcCacheFile.c_str()); -#endif + bool result = removeFile(crcCacheFile.c_str()); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] fileitem [%s] result = %d\n",__FILE__,__FUNCTION__,__LINE__,crcCacheFile.c_str(),result); } } @@ -722,11 +711,7 @@ void clearFolderTreeContentsCheckSumList(vector paths, string pathSearch } string crcCacheFile = getFormattedCRCCacheFileName(cacheKeys); if(fileExists(crcCacheFile) == true) { -#ifdef WIN32 - int result = _unlink(crcCacheFile.c_str()); -#else - int result = unlink(crcCacheFile.c_str()); -#endif + bool result = removeFile(crcCacheFile.c_str()); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] fileitem [%s] result = %d\n",__FILE__,__FUNCTION__,__LINE__,crcCacheFile.c_str(),result); } } @@ -876,11 +861,7 @@ void clearFolderTreeContentsCheckSumList(const string &path, const string filter } string crcCacheFile = getFormattedCRCCacheFileName(cacheKeys); if(fileExists(crcCacheFile) == true) { -#ifdef WIN32 - int result = _unlink(crcCacheFile.c_str()); -#else - int result = unlink(crcCacheFile.c_str()); -#endif + bool result = removeFile(crcCacheFile.c_str()); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] fileitem [%s] result = %d\n",__FILE__,__FUNCTION__,__LINE__,crcCacheFile.c_str(),result); } } @@ -1365,6 +1346,16 @@ bool executeShellCommand(string cmd) { return result; } +bool removeFile(string file) { +#ifdef WIN32 + int result = _unlink(file.c_str()); +#else + int result = unlink(file.c_str()); +#endif + + return (result == 0); +} + // ===================================== // ModeInfo // ===================================== diff --git a/source/shared_lib/sources/platform/posix/miniftpclient.cpp b/source/shared_lib/sources/platform/posix/miniftpclient.cpp index 1fc51698..6f7fc965 100644 --- a/source/shared_lib/sources/platform/posix/miniftpclient.cpp +++ b/source/shared_lib/sources/platform/posix/miniftpclient.cpp @@ -72,11 +72,8 @@ static size_t my_fwrite(void *buffer, size_t size, size_t nmemb, void *stream) { if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("===> FTP Client thread CANCELLED, deleting file for writing [%s]\n",fullFilePath.c_str()); SystemFlags::OutputDebug(SystemFlags::debugNetwork,"===> FTP Client thread CANCELLED, deleting file for writing [%s]\n",fullFilePath.c_str()); -#ifdef WIN32 - _unlink(fullFilePath.c_str()); -#else - unlink(fullFilePath.c_str()); -#endif + + removeFile(fullFilePath); return -1; } @@ -311,11 +308,7 @@ FTP_Client_ResultType FTPClientThread::getMapFromServer(string mapFileName, stri ftpfile.stream = NULL; } if(result != ftp_crt_SUCCESS) { -#ifdef WIN32 - _unlink(destFile.c_str()); -#else - unlink(destFile.c_str()); -#endif + removeFile(destFile); } return result;