try and get file creation time in some cases on windoze builds
untested as of right now
This commit is contained in:
1 parent
bbc81e3cc8
commit
09e97b07f4
1 file changed
+43
-1
+43
-1
@@ -6719,6 +6719,17 @@ void G_LoadDemoInfo(menudemo_t *pdemo)
|
||||
|
||||
#if defined (_WIN32)
|
||||
#define PATHSEPSTR '\\'
|
||||
// return the file creation time
|
||||
// useful for demos that were renamed
|
||||
static long G_GetCreationTime(char *filepath)
|
||||
{
|
||||
struct stat fileinfo;
|
||||
|
||||
if (stat(filepath, &fileinfo) == 0)
|
||||
return fileinfo.st_ctime;
|
||||
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
#define PATHSEPSTR '/'
|
||||
#endif
|
||||
@@ -6731,7 +6742,6 @@ static char *G_GetDemoDate(menudemo_t *pdemo)
|
||||
// no mallocma balls... :c
|
||||
if (!datetime)
|
||||
{
|
||||
free(datetime);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -6742,11 +6752,20 @@ static char *G_GetDemoDate(menudemo_t *pdemo)
|
||||
|
||||
filename = strrchr(pdemo->filepath, PATHSEPSTR);
|
||||
|
||||
#if defined (_WIN32)
|
||||
if (!filename)
|
||||
{
|
||||
// if we cant get a filename try just getting the file create time
|
||||
file_time = G_GetCreationTime(pdemo->filepath);
|
||||
goto skipfilenametime;
|
||||
}
|
||||
#else
|
||||
if (!filename)
|
||||
{
|
||||
free(datetime);
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
filename = filename + 1; // filename, filename, filename, filename.....
|
||||
|
||||
@@ -6757,6 +6776,10 @@ static char *G_GetDemoDate(menudemo_t *pdemo)
|
||||
// convert it to long Zzz....
|
||||
file_time = strtol(timestr, NULL, 10);
|
||||
|
||||
#if defined (_WIN32)
|
||||
skipfilenametime:
|
||||
#endif
|
||||
|
||||
// then throw it into localtime to get an actual human readable format lmao
|
||||
struct tm tm_buf;
|
||||
localtime_r(&file_time, &tm_buf);
|
||||
@@ -6764,10 +6787,29 @@ static char *G_GetDemoDate(menudemo_t *pdemo)
|
||||
// cant believe we ended up in 1970
|
||||
if (tm_buf.tm_year <= 110)
|
||||
{
|
||||
#if defined (_WIN32)
|
||||
// uh ohh, we got an invalid time
|
||||
// try one more time getting the creation time
|
||||
file_time = G_GetCreationTime(pdemo->filepath);
|
||||
localtime_r(&file_time, &tm_buf);
|
||||
|
||||
if (tm_buf.tm_year <= 110)
|
||||
{
|
||||
free(datetime);
|
||||
return NULL;
|
||||
}
|
||||
else
|
||||
goto gotcreationtime;
|
||||
#else
|
||||
free(datetime);
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined (_WIN32)
|
||||
gotcreationtime:
|
||||
#endif
|
||||
|
||||
const char *format;
|
||||
|
||||
// US ppl are special (:
|
||||
|
||||
Reference in new issue
Block a user