mirror of
https://github.com/glest/glest-source.git
synced 2025-02-24 19:52:25 +01:00
- updated crc check for techtrees to also store date last updated and force an immediate refresh if the techtree has different CRC with server and was older than 1 day
This commit is contained in:
parent
7a501a4e26
commit
7bf40db4ce
@ -1058,6 +1058,21 @@ void MenuStateConnectedGame::update() {
|
|||||||
gameSettings->getTech() != "") {
|
gameSettings->getTech() != "") {
|
||||||
//console.addLine("Checking techtree CRC [" + gameSettings->getTech() + "]");
|
//console.addLine("Checking techtree CRC [" + gameSettings->getTech() + "]");
|
||||||
techCRC = getFolderTreeContentsCheckSumRecursively(config.getPathListForType(ptTechs,""), string("/") + gameSettings->getTech() + string("/*"), ".xml", NULL);
|
techCRC = getFolderTreeContentsCheckSumRecursively(config.getPathListForType(ptTechs,""), string("/") + gameSettings->getTech() + string("/*"), ".xml", NULL);
|
||||||
|
|
||||||
|
if(techCRC != 0 && techCRC != gameSettings->getTechCRC() &&
|
||||||
|
listBoxTechTree.getSelectedItemIndex() >= 0 &&
|
||||||
|
listBoxTechTree.getSelectedItem() != ITEM_MISSING) {
|
||||||
|
|
||||||
|
time_t now = time(NULL);
|
||||||
|
time_t lastUpdateDate = getFolderTreeContentsCheckSumRecursivelyLastGenerated(config.getPathListForType(ptTechs,""), string("/") + gameSettings->getTech() + string("/*"), ".xml");
|
||||||
|
|
||||||
|
const time_t REFRESH_CRC_DAY_SECONDS = 60 * 60 * 24;
|
||||||
|
if( lastUpdateDate <= 0 ||
|
||||||
|
difftime(time(NULL),lastUpdateDate) >= REFRESH_CRC_DAY_SECONDS) {
|
||||||
|
techCRC = getFolderTreeContentsCheckSumRecursively(config.getPathListForType(ptTechs,""), string("/") + gameSettings->getTech() + string("/*"), ".xml", NULL, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Test data synch
|
// Test data synch
|
||||||
//techCRC++;
|
//techCRC++;
|
||||||
lastCheckedCRCTechtreeValue = techCRC;
|
lastCheckedCRCTechtreeValue = techCRC;
|
||||||
|
@ -122,6 +122,7 @@ void setCRCCacheFilePath(string path);
|
|||||||
std::pair<string,string> getFolderTreeContentsCheckSumCacheKey(vector<string> paths, string pathSearchString, const string filterFileExt);
|
std::pair<string,string> getFolderTreeContentsCheckSumCacheKey(vector<string> paths, string pathSearchString, const string filterFileExt);
|
||||||
void clearFolderTreeContentsCheckSum(vector<string> paths, string pathSearchString, const string filterFileExt);
|
void clearFolderTreeContentsCheckSum(vector<string> paths, string pathSearchString, const string filterFileExt);
|
||||||
int32 getFolderTreeContentsCheckSumRecursively(vector<string> paths, string pathSearchString, const string filterFileExt, Checksum *recursiveChecksum,bool forceNoCache=false);
|
int32 getFolderTreeContentsCheckSumRecursively(vector<string> paths, string pathSearchString, const string filterFileExt, Checksum *recursiveChecksum,bool forceNoCache=false);
|
||||||
|
time_t getFolderTreeContentsCheckSumRecursivelyLastGenerated(vector<string> paths, string pathSearchString, const string filterFileExt);
|
||||||
|
|
||||||
std::pair<string,string> getFolderTreeContentsCheckSumCacheKey(const string &path, const string filterFileExt);
|
std::pair<string,string> getFolderTreeContentsCheckSumCacheKey(const string &path, const string filterFileExt);
|
||||||
void clearFolderTreeContentsCheckSum(const string &path, const string filterFileExt);
|
void clearFolderTreeContentsCheckSum(const string &path, const string filterFileExt);
|
||||||
|
@ -522,20 +522,23 @@ std::pair<string,string> getFolderTreeContentsCheckSumCacheKey(vector<string> pa
|
|||||||
return make_pair(cacheLookupId,cacheKey);
|
return make_pair(cacheLookupId,cacheKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool hasCachedFileCRCValue(string crcCacheFile, int32 &value) {
|
pair<bool,time_t> hasCachedFileCRCValue(string crcCacheFile, int32 &value) {
|
||||||
bool result = false;
|
//bool result = false;
|
||||||
|
pair<bool,time_t> result = make_pair(false,0);
|
||||||
if(fileExists(crcCacheFile) == true) {
|
if(fileExists(crcCacheFile) == true) {
|
||||||
FILE *fp = fopen(crcCacheFile.c_str(),"r");
|
FILE *fp = fopen(crcCacheFile.c_str(),"r");
|
||||||
if(fp != NULL) {
|
if(fp != NULL) {
|
||||||
time_t refreshDate = 0;
|
time_t refreshDate = 0;
|
||||||
int32 crcValue = 0;
|
int32 crcValue = 0;
|
||||||
int res = fscanf(fp,"%ld,%d",&refreshDate,&crcValue);
|
time_t lastUpdateDate = 0;
|
||||||
|
int res = fscanf(fp,"%ld,%d,%ld",&refreshDate,&crcValue,&lastUpdateDate);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
|
result.second = lastUpdateDate;
|
||||||
if( refreshDate > 0 &&
|
if( refreshDate > 0 &&
|
||||||
time(NULL) < refreshDate) {
|
time(NULL) < refreshDate) {
|
||||||
|
|
||||||
result = true;
|
result.first = true;
|
||||||
value = crcValue;
|
value = crcValue;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -566,13 +569,14 @@ void writeCachedFileCRCValue(string crcCacheFile, int32 &crcValue) {
|
|||||||
if(offset == 0) {
|
if(offset == 0) {
|
||||||
offset = 3;
|
offset = 3;
|
||||||
}
|
}
|
||||||
time_t refreshDate = time(NULL) + (REFRESH_CRC_DAY_SECONDS * offset);
|
time_t now = time(NULL);
|
||||||
|
time_t refreshDate = now + (REFRESH_CRC_DAY_SECONDS * offset);
|
||||||
|
|
||||||
struct tm *loctime = localtime (&refreshDate);
|
struct tm *loctime = localtime (&refreshDate);
|
||||||
char szBuf1[100]="";
|
char szBuf1[100]="";
|
||||||
strftime(szBuf1,100,"%Y-%m-%d %H:%M:%S",loctime);
|
strftime(szBuf1,100,"%Y-%m-%d %H:%M:%S",loctime);
|
||||||
|
|
||||||
fprintf(fp,"%ld,%d",refreshDate,crcValue);
|
fprintf(fp,"%ld,%d,%ld",refreshDate,crcValue,now);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("\n========== Writing CRC Cache offset [%d] refreshDate = %ld [%s], crcValue = %d, file [%s]\n",offset,refreshDate,szBuf1,crcValue,crcCacheFile.c_str());
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("\n========== Writing CRC Cache offset [%d] refreshDate = %ld [%s], crcValue = %d, file [%s]\n",offset,refreshDate,szBuf1,crcValue,crcCacheFile.c_str());
|
||||||
@ -601,6 +605,37 @@ void clearFolderTreeContentsCheckSum(vector<string> paths, string pathSearchStri
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
time_t getFolderTreeContentsCheckSumRecursivelyLastGenerated(vector<string> paths, string pathSearchString, const string filterFileExt) {
|
||||||
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("\n-------------- In [%s::%s Line: %d] Calculating CRC for [%s] -----------\n",__FILE__,__FUNCTION__,__LINE__,pathSearchString.c_str());
|
||||||
|
|
||||||
|
std::pair<string,string> cacheKeys = getFolderTreeContentsCheckSumCacheKey(paths, pathSearchString, filterFileExt);
|
||||||
|
string cacheLookupId = cacheKeys.first;
|
||||||
|
std::map<string,int32> &crcTreeCache = CacheManager::getCachedItem< std::map<string,int32> >(cacheLookupId);
|
||||||
|
|
||||||
|
string cacheKey = cacheKeys.second;
|
||||||
|
string crcCacheFile = getFormattedCRCCacheFileName(cacheKeys);
|
||||||
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("\n-------------- In [%s::%s Line: %d] looking for cached CRC file [%s] for [%s] -----------\n",__FILE__,__FUNCTION__,__LINE__,crcCacheFile.c_str(),pathSearchString.c_str());
|
||||||
|
|
||||||
|
int32 crcValue = 0;
|
||||||
|
pair<bool,time_t> crcResult = hasCachedFileCRCValue(crcCacheFile, crcValue);
|
||||||
|
if(crcResult.first == true) {
|
||||||
|
struct tm *loctime = localtime (&crcResult.second);
|
||||||
|
char szBuf1[100]="";
|
||||||
|
strftime(szBuf1,100,"%Y-%m-%d %H:%M:%S",loctime);
|
||||||
|
|
||||||
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] scanning folders found CACHED FILE for cacheKey [%s] last updated [%s]\n",__FILE__,__FUNCTION__,__LINE__,cacheKey.c_str(),szBuf1);
|
||||||
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("\n-------------- In [%s::%s Line: %d] scanning folders found CACHED FILE for cacheKey [%s] last updated [%s]\n",__FILE__,__FUNCTION__,__LINE__,cacheKey.c_str(),szBuf1);
|
||||||
|
|
||||||
|
return crcResult.second;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] scanning folders DID NOT FIND CACHED FILE checksum for cacheKey [%s]\n",__FILE__,__FUNCTION__,cacheKey.c_str());
|
||||||
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("\n-------------- In [%s::%s] scanning folders DID NOT FIND CACHED FILE checksum for cacheKey [%s]\n",__FILE__,__FUNCTION__,cacheKey.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
//finds all filenames like path and gets their checksum of all files combined
|
//finds all filenames like path and gets their checksum of all files combined
|
||||||
int32 getFolderTreeContentsCheckSumRecursively(vector<string> paths, string pathSearchString, const string filterFileExt, Checksum *recursiveChecksum, bool forceNoCache) {
|
int32 getFolderTreeContentsCheckSumRecursively(vector<string> paths, string pathSearchString, const string filterFileExt, Checksum *recursiveChecksum, bool forceNoCache) {
|
||||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("\n-------------- In [%s::%s Line: %d] Calculating CRC for [%s] -----------\n",__FILE__,__FUNCTION__,__LINE__,pathSearchString.c_str());
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("\n-------------- In [%s::%s Line: %d] Calculating CRC for [%s] -----------\n",__FILE__,__FUNCTION__,__LINE__,pathSearchString.c_str());
|
||||||
@ -624,7 +659,7 @@ int32 getFolderTreeContentsCheckSumRecursively(vector<string> paths, string path
|
|||||||
}
|
}
|
||||||
|
|
||||||
int32 crcValue = 0;
|
int32 crcValue = 0;
|
||||||
if(forceNoCache == false && hasCachedFileCRCValue(crcCacheFile, crcValue)) {
|
if(forceNoCache == false && hasCachedFileCRCValue(crcCacheFile, crcValue).first == true) {
|
||||||
crcTreeCache[cacheKey] = crcValue;
|
crcTreeCache[cacheKey] = crcValue;
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] scanning folders found CACHED FILE checksum = %d for cacheKey [%s] forceNoCache = %d\n",__FILE__,__FUNCTION__,__LINE__,crcTreeCache[cacheKey],cacheKey.c_str(),forceNoCache);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] scanning folders found CACHED FILE checksum = %d for cacheKey [%s] forceNoCache = %d\n",__FILE__,__FUNCTION__,__LINE__,crcTreeCache[cacheKey],cacheKey.c_str(),forceNoCache);
|
||||||
if(recursiveChecksum == NULL) {
|
if(recursiveChecksum == NULL) {
|
||||||
@ -706,7 +741,7 @@ int32 getFolderTreeContentsCheckSumRecursively(const string &path, const string
|
|||||||
}
|
}
|
||||||
|
|
||||||
int32 crcValue = 0;
|
int32 crcValue = 0;
|
||||||
if(forceNoCache == false && hasCachedFileCRCValue(crcCacheFile, crcValue)) {
|
if(forceNoCache == false && hasCachedFileCRCValue(crcCacheFile, crcValue).first == true) {
|
||||||
crcTreeCache[cacheKey] = crcValue;
|
crcTreeCache[cacheKey] = crcValue;
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] scanning folders found CACHED FILE checksum = %d for cacheKey [%s] forceNoCache = %d\n",__FILE__,__FUNCTION__,__LINE__,crcTreeCache[cacheKey],cacheKey.c_str(),forceNoCache);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] scanning folders found CACHED FILE checksum = %d for cacheKey [%s] forceNoCache = %d\n",__FILE__,__FUNCTION__,__LINE__,crcTreeCache[cacheKey],cacheKey.c_str(),forceNoCache);
|
||||||
if(recursiveChecksum == NULL) {
|
if(recursiveChecksum == NULL) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user