From 06a7fbdfcc575ba2697fcbce6408de6a3fdf2e37 Mon Sep 17 00:00:00 2001 From: Andrew Richards Date: Thu, 7 Nov 2024 11:14:05 +0000 Subject: [PATCH] Updated Sfx's FileLoader::GetFileDate() to use unix timestamps. --- Applications/Sfx/FileLoader.cpp | 20 ++------------ Applications/Sfx/FileLoader.h | 2 +- Applications/Sfx/Preprocessor.h | 4 +-- Applications/Sfx/Preprocessor.lpp | 4 +-- Applications/Sfx/Preprocessor.ypp | 2 +- Applications/Sfx/Sfx.cpp | 45 +++++-------------------------- 6 files changed, 15 insertions(+), 62 deletions(-) diff --git a/Applications/Sfx/FileLoader.cpp b/Applications/Sfx/FileLoader.cpp index 9154f65b..cf47fec4 100644 --- a/Applications/Sfx/FileLoader.cpp +++ b/Applications/Sfx/FileLoader.cpp @@ -196,17 +196,8 @@ void FileLoader::AcquireFileContents(void*& pointer, unsigned int& bytes, const fclose(fp); } -static double GetDayNumberFromDateTime(int year,int month,int day,int hour,int min,int sec) -{ - int D = 367*year - (7*(year + ((month+9)/12)))/4 + (275*month)/9 + day - 730531;//was +2451545 - double d=(double)D; - d+=(double)hour/24.0; - d+=(double)min/24.0/60.0; - d+=(double)sec/24.0/3600.0; - return d; -} -double FileLoader::GetFileDate(const char* filename_utf8) +uint64_t FileLoader::GetFileDate(const char *filename_utf8) { std::wstring filenamew=StringToWString(filename_utf8); #ifdef _MSC_VER @@ -218,14 +209,7 @@ double FileLoader::GetFileDate(const char* filename_utf8) #endif buf.st_mtime; time_t t = buf.st_mtime; - struct tm lt; - #ifdef _MSC_VER - gmtime_s(<,&t); - #else - gmtime_r(&t,<); - #endif - double datetime=GetDayNumberFromDateTime(1900+lt.tm_year,lt.tm_mon,lt.tm_mday,lt.tm_hour,lt.tm_min,lt.tm_sec); - return datetime; + return static_cast(t); } void FileLoader::ReleaseFileContents(void* pointer) diff --git a/Applications/Sfx/FileLoader.h b/Applications/Sfx/FileLoader.h index bab958db..e22de120 100644 --- a/Applications/Sfx/FileLoader.h +++ b/Applications/Sfx/FileLoader.h @@ -16,7 +16,7 @@ class FileLoader bool FileExists(const char *filename_utf8) const; const char *FindFileInPathStack(const char *filename_utf8,const std::vector &path_stack_utf8) const; void AcquireFileContents(void*& pointer, unsigned int& bytes, const char* filename_utf8,bool open_as_text); - double GetFileDate(const char* filename_utf8); + static uint64_t GetFileDate(const char* filename_utf8); void ReleaseFileContents(void* pointer); void Save(void* pointer, unsigned int bytes, const char* filename_utf8,bool save_as_text); }; diff --git a/Applications/Sfx/Preprocessor.h b/Applications/Sfx/Preprocessor.h index d1f31ca8..cd3ad161 100644 --- a/Applications/Sfx/Preprocessor.h +++ b/Applications/Sfx/Preprocessor.h @@ -28,14 +28,14 @@ struct MacroDefinition }; // prevent echoing of unprocessed chars: #define ECHO -extern double latest_datetime; +extern uint64_t latest_datetime; extern std::string latest_file; #undef PREPRO_STYPE #define PREPRO_STYPE PreprocessorType #undef PREPRO_DEBUG #define PREPRO_DEBUG 1 // These are the callback functions for file handling that we will send to the preprocessor. -extern FILE* (*prepro_open)(const char *filename_utf8,std::string &fullPathName,double &datetime); +extern FILE* (*prepro_open)(const char *filename_utf8,std::string &fullPathName,uint64_t &datetime); extern void (*prepro_close)(FILE *f); extern void Unput(int c); extern std::ostringstream preproOutput; diff --git a/Applications/Sfx/Preprocessor.lpp b/Applications/Sfx/Preprocessor.lpp index e9771570..03930af7 100644 --- a/Applications/Sfx/Preprocessor.lpp +++ b/Applications/Sfx/Preprocessor.lpp @@ -49,7 +49,7 @@ extern void prepro_warning(const char *s); extern void prepro_warning(const char *s,const char *file,int line); extern int prepro_get_lineno (); - FILE* (*prepro_open)(const char *filename_utf8,string &fullPathName,double &filedate)=NULL; + FILE* (*prepro_open)(const char *filename_utf8,string &fullPathName,uint64_t &filedate)=NULL; void (*prepro_close)(FILE *f)=NULL; std::ostringstream preproOutput; @@ -621,7 +621,7 @@ void Preprocess(int argc, char **argv) int newfile(const char *fn) { std::string fullPathName; - double datetime=0.0; + uint64_t datetime=0; FILE *f = prepro_open(fn,fullPathName,datetime); /* die if no file or no room */ diff --git a/Applications/Sfx/Preprocessor.ypp b/Applications/Sfx/Preprocessor.ypp index 3d04bdeb..e0ad5cb5 100644 --- a/Applications/Sfx/Preprocessor.ypp +++ b/Applications/Sfx/Preprocessor.ypp @@ -37,7 +37,7 @@ vector activeBlockStack; vector blockTestStack; extern int preproBracket; - double latest_datetime = 0.0; + uint64_t latest_datetime = 0; std::string latest_file; void ClearParserState() { diff --git a/Applications/Sfx/Sfx.cpp b/Applications/Sfx/Sfx.cpp index 832ca952..f80c50b1 100644 --- a/Applications/Sfx/Sfx.cpp +++ b/Applications/Sfx/Sfx.cpp @@ -79,45 +79,14 @@ typedef int errno_t; using namespace std; // These are the callback functions for file handling that we will send to the preprocessor. -//extern FILE* (*prepro_open)(const char *filename_utf8,std::string &fullPathName,double &time); +//extern FILE* (*prepro_open)(const char *filename_utf8,std::string &fullPathName,uint64_t &time); //extern void (*prepro_close)(FILE *f); + vector shaderPathsUtf8; FileLoader fileLoader; extern std::ostringstream preproOutput; -static double GetDayNumberFromDateTime(int year,int month,int day,int hour,int min,int sec) -{ - int D = 367*year - (7*(year + ((month+9)/12)))/4 + (275*month)/9 + day - 730531;//was +2451545 - double d=(double)D; - d+=(double)hour/24.0; - d+=(double)min/24.0/60.0; - d+=(double)sec/24.0/3600.0; - return d; -} - -double GetFileDate(const std::string &fullPathNameUtf8) -{ - wstring filenamew=StringToWString(fullPathNameUtf8); - #ifdef _MSC_VER - struct _stat64i32 buf; - _wstat(filenamew.c_str(), &buf); - #else - struct stat buf; - stat(fullPathNameUtf8.c_str(), &buf); - #endif - buf.st_mtime; - time_t t = buf.st_mtime; - struct tm lt; - #ifdef _MSC_VER - gmtime_s(<,&t); - #else - gmtime_r(&t,<); - #endif - double datetime=GetDayNumberFromDateTime(1900+lt.tm_year,lt.tm_mon,lt.tm_mday,lt.tm_hour,lt.tm_min,lt.tm_sec); - return datetime; -} - -FILE* OpenFile(const char *filename_utf8,std::string &fullPathNameUtf8,double &datetime) +FILE* OpenFile(const char *filename_utf8,std::string &fullPathNameUtf8,uint64_t &datetime) { fullPathNameUtf8 =fileLoader.FindFileInPathStack(filename_utf8,shaderPathsUtf8); if(!fullPathNameUtf8.length()) @@ -137,7 +106,7 @@ FILE* OpenFile(const char *filename_utf8,std::string &fullPathNameUtf8,double &d if(last_slash>0) path=path.substr(0,last_slash); shaderPathsUtf8.push_back(path); - datetime=GetFileDate(fullPathNameUtf8); + datetime=FileLoader::GetFileDate(fullPathNameUtf8.c_str()); return f; } @@ -626,13 +595,13 @@ bool sfxParseEffectFromFile(int effect, const char *file, const std::vectorplatformFilename); + uint64_t exe_datetime=FileLoader::GetFileDate(exeNameUtf8); + uint64_t platformfile_datetime=FileLoader::GetFileDate(config->platformFilename.c_str()); latest_datetime= std::max(exe_datetime,platformfile_datetime); latest_file=file; if (!preprocess(file, config->define, sfxOptions->disableLineWrites)) return false; - double output_filedatetime=GetFileDate(sfxoFilename); + uint64_t output_filedatetime = FileLoader::GetFileDate(sfxoFilename.c_str()); bool recompile=false; if(sfxOptions->force) {