From 9224a7e24217db06478d4c4fafa81a094942524c Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Fri, 18 Oct 2013 15:47:17 +0000 Subject: [PATCH] - attempt to fix crc file bug --- source/glest_game/facilities/game_util.cpp | 6 ++ source/glest_game/facilities/game_util.h | 1 + source/glest_game/game/game.cpp | 3 +- source/glest_game/main/main.cpp | 4 ++ .../include/platform/common/platform_common.h | 5 ++ .../platform/common/platform_common.cpp | 56 ++++++++++++++++++- 6 files changed, 71 insertions(+), 4 deletions(-) diff --git a/source/glest_game/facilities/game_util.cpp b/source/glest_game/facilities/game_util.cpp index 1dc520e8..1f2bfb46 100644 --- a/source/glest_game/facilities/game_util.cpp +++ b/source/glest_game/facilities/game_util.cpp @@ -29,14 +29,20 @@ namespace Glest { namespace Game { const char *mailString = " http://bugs.megaglest.org"; const string glestVersionString = "v3.8.0-dev"; #if defined(SVNVERSION) +const string SVN_RawRev = string(SVNVERSION); const string SVN_Rev = string("Rev: ") + string(SVNVERSION); #elif defined(SVNVERSIONHEADER) #include "svnversion.h" +const string SVN_RawRev = string(SVNVERSION); const string SVN_Rev = string("Rev: ") + string(SVNVERSION); #else +const string SVN_RawRev = "$4533$"; const string SVN_Rev = "$Rev$"; #endif +string getRAWSVNRevisionString() { + return SVN_RawRev; +} string getCrashDumpFileName(){ return "megaglest" + glestVersionString + ".dmp"; } diff --git a/source/glest_game/facilities/game_util.h b/source/glest_game/facilities/game_util.h index 6f0a96f6..8261b1cb 100644 --- a/source/glest_game/facilities/game_util.h +++ b/source/glest_game/facilities/game_util.h @@ -35,6 +35,7 @@ void initSpecialStrings(); string getCrashDumpFileName(); string getPlatformNameString(); string getSVNRevisionString(); +string getRAWSVNRevisionString(); string getCompilerNameString(); string getNetworkVersionString(); string getNetworkVersionSVNString(); diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index ac49713f..9e66f851 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -4940,8 +4940,9 @@ void Game::DumpCRCWorldLogIfRequired(string fileSuffix) { #endif logFile << "World CRC debug information:" << std::endl; logFile << "============================" << std::endl; - logFile << "Maximum framecount: " << world.getFaction(0)->getCRC_DetailsForWorldFrameCount() << std::endl; logFile << "Software version: " << glestVersionString << "-" << getCompilerNameString() << "-" << getSVNRevisionString() << std::endl; + logFile << "Maximum framecount: " << world.getFaction(0)->getCRC_DetailsForWorldFrameCount() << std::endl; + for(unsigned int worldFrameIndex = 0; worldFrameIndex < world.getFaction(0)->getCRC_DetailsForWorldFrameCount(); ++worldFrameIndex) { //factions (and their related info) diff --git a/source/glest_game/main/main.cpp b/source/glest_game/main/main.cpp index 02c9e532..037492b0 100644 --- a/source/glest_game/main/main.cpp +++ b/source/glest_game/main/main.cpp @@ -3661,6 +3661,9 @@ int glestMain(int argc, char** argv) { #endif } + setGameVersion(glestVersionString); + setGameSVNVersion(getRAWSVNRevisionString()); + if( hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_OPENGL_INFO]) == true || hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_SDL_INFO]) == true || hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_LUA_INFO]) == true || @@ -5229,6 +5232,7 @@ int glestMain(int argc, char** argv) { //int *foo = (int*)-1; // make a bad pointer //printf("%d\n", *foo); // causes segfault // END + bool startCRCPrecacheThread = config.getBool("PreCacheCRCThread","true"); //printf("### In [%s::%s Line: %d] precache thread enabled = %d SystemFlags::VERBOSE_MODE_ENABLED = %d\n",__FILE__,__FUNCTION__,__LINE__,startCRCPrecacheThread,SystemFlags::VERBOSE_MODE_ENABLED); if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] precache thread enabled = %d\n",__FILE__,__FUNCTION__,__LINE__,startCRCPrecacheThread); diff --git a/source/shared_lib/include/platform/common/platform_common.h b/source/shared_lib/include/platform/common/platform_common.h index cdc9d199..4ce7bca7 100644 --- a/source/shared_lib/include/platform/common/platform_common.h +++ b/source/shared_lib/include/platform/common/platform_common.h @@ -185,6 +185,11 @@ void findAll(const vector &paths, const string &fileFilter, vector &results, bool cutExtension=false, bool errorOnNotFound=true); vector getFolderTreeContentsListRecursively(const string &path, const string &filterFileExt, bool includeFolders=false, vector *recursiveMap=NULL); +string getGameVersion(); +string getGameSVNVersion(); +void setGameVersion(string version); +void setGameSVNVersion(string svn); + string getCRCCacheFilePath(); void setCRCCacheFilePath(string path); diff --git a/source/shared_lib/sources/platform/common/platform_common.cpp b/source/shared_lib/sources/platform/common/platform_common.cpp index bc9fb487..531a86d5 100644 --- a/source/shared_lib/sources/platform/common/platform_common.cpp +++ b/source/shared_lib/sources/platform/common/platform_common.cpp @@ -82,6 +82,9 @@ namespace Shared { namespace PlatformCommon { const time_t REFRESH_CRC_DAY_SECONDS = 60 * 60 * 24; static string crcCachePath = ""; +static string gameVersion = ""; +static string gameSVNVersion = ""; + namespace Private { bool shouldBeFullscreen = false; @@ -632,6 +635,19 @@ void setCRCCacheFilePath(string path) { crcCachePath = path; } +string getGameVersion() { + return gameVersion; +} +string getGameSVNVersion() { + return gameSVNVersion; +} +void setGameVersion(string version) { + gameVersion = version; +} +void setGameSVNVersion(string svn) { + gameSVNVersion = svn; +} + string getCRCCacheFileName(std::pair cacheKeys) { string crcCacheFile = cacheKeys.first + cacheKeys.second; return crcCacheFile; @@ -680,10 +696,37 @@ pair hasCachedFileCRCValue(string crcCacheFile, uint32 &value) { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Line: %d for Cache file [%s]\n",__FILE__,__FUNCTION__,__LINE__,crcCacheFile.c_str()); } - int readbytes = fscanf(fp,"%20ld,%20u,%20ld",&refreshDate,&crcValue,&lastUpdateDate); +// string getGameVersion() { +// return gameVersion; +// } +// string getGameSVNVersion() { +// return gameSVNVersion; +// } +// void setGameVersion(string version) { +// gameVersion = version; +// } +// void setGameSVNVersion(string svn) { +// gameSVNVersion = svn; +// } + + char gameVer[500]=""; + char svnVer[500]=""; + char actualFilePath[8096]=""; + int readbytes = fscanf(fp,"%20ld,%20u,%20ld\n%s\n%s\n%s", + &refreshDate, + &crcValue, + &lastUpdateDate, + &gameVer[0], + &svnVer[0], + &actualFilePath[0]); refreshDate = Shared::PlatformByteOrder::fromCommonEndian(refreshDate); crcValue = Shared::PlatformByteOrder::fromCommonEndian(crcValue); lastUpdateDate = Shared::PlatformByteOrder::fromCommonEndian(lastUpdateDate); + string readGameVer = Shared::PlatformByteOrder::fromCommonEndian(string(gameVer)); + string readSvnVer = Shared::PlatformByteOrder::fromCommonEndian(string(svnVer)); + string readActualFilePath = Shared::PlatformByteOrder::fromCommonEndian(string(actualFilePath)); + + printf("CRC readGameVer [%s] [%s]\n%s\n",readGameVer.c_str(),readSvnVer.c_str(),readActualFilePath.c_str()); if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Line: %d for Cache file [%s] readbytes = %d\n",__FILE__,__FUNCTION__,__LINE__,crcCacheFile.c_str(),readbytes); @@ -706,7 +749,8 @@ pair hasCachedFileCRCValue(string crcCacheFile, uint32 &value) { time_t tBadCRCDate = mktime( &future ); result.second = lastUpdateDate; - if( refreshDate > 0 && + if( readGameVer != "" && readSvnVer != "" && + refreshDate > 0 && refreshDate > tBadCRCDate && time(NULL) < refreshDate) { @@ -776,7 +820,13 @@ void writeCachedFileCRCValue(string crcCacheFile, uint32 &crcValue, string actua char szBuf1[100]=""; strftime(szBuf1,100,"%Y-%m-%d %H:%M:%S",loctime); - fprintf(fp,"%ld,%u,%ld\n%s",Shared::PlatformByteOrder::toCommonEndian(refreshDate),Shared::PlatformByteOrder::toCommonEndian(crcValue),Shared::PlatformByteOrder::toCommonEndian(now),actualFileName.c_str()); + fprintf(fp,"%20ld,%20u,%20ld\n%s\n%s\n%s", + Shared::PlatformByteOrder::toCommonEndian(refreshDate), + Shared::PlatformByteOrder::toCommonEndian(crcValue), + Shared::PlatformByteOrder::toCommonEndian(now), + Shared::PlatformByteOrder::toCommonEndian(gameVersion).c_str(), + Shared::PlatformByteOrder::toCommonEndian(gameSVNVersion).c_str(), + Shared::PlatformByteOrder::toCommonEndian(actualFileName).c_str()); fclose(fp); //if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"========== Writing CRC Cache offset [%d] refreshDate = %ld [%s], crcValue = %u, file [%s]\n",offset,refreshDate,szBuf1,crcValue,crcCacheFile.c_str());