- attempt to fix crc file bug

This commit is contained in:
Mark Vejvoda 2013-10-18 15:47:17 +00:00
parent 23552eb1a7
commit 9224a7e242
6 changed files with 71 additions and 4 deletions

View File

@ -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";
}

View File

@ -35,6 +35,7 @@ void initSpecialStrings();
string getCrashDumpFileName();
string getPlatformNameString();
string getSVNRevisionString();
string getRAWSVNRevisionString();
string getCompilerNameString();
string getNetworkVersionString();
string getNetworkVersionSVNString();

View File

@ -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)

View File

@ -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);

View File

@ -185,6 +185,11 @@ void findAll(const vector<string> &paths, const string &fileFilter, vector<strin
void findAll(const string &path, vector<string> &results, bool cutExtension=false, bool errorOnNotFound=true);
vector<string> getFolderTreeContentsListRecursively(const string &path, const string &filterFileExt, bool includeFolders=false, vector<string> *recursiveMap=NULL);
string getGameVersion();
string getGameSVNVersion();
void setGameVersion(string version);
void setGameSVNVersion(string svn);
string getCRCCacheFilePath();
void setCRCCacheFilePath(string path);

View File

@ -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<string,string> cacheKeys) {
string crcCacheFile = cacheKeys.first + cacheKeys.second;
return crcCacheFile;
@ -680,10 +696,37 @@ pair<bool,time_t> 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<bool,time_t> 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());