diff --git a/src/doomdef.h b/src/doomdef.h index 6c4f1fef3..fe6a5faa3 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -127,6 +127,7 @@ #ifdef LOGMESSAGES extern FILE *logstream; +extern char logfilename[1024]; #endif //#define DEVELOP // Disable this for release builds to remove excessive cheat commands and enable MD5 checking and stuff, all in one go. :3 diff --git a/src/sdl/i_main.c b/src/sdl/i_main.c index 70f582676..af34da8d1 100644 --- a/src/sdl/i_main.c +++ b/src/sdl/i_main.c @@ -23,10 +23,14 @@ #include "../m_misc.h"/* path shit */ #include "../i_system.h" -#ifdef __GNUC__ +#if defined (__GNUC__) || defined (__unix__) #include #endif +#ifdef __unix__ +#include +#endif + #include "time.h" // For log timestamps #ifdef HAVE_SDL @@ -48,6 +52,7 @@ extern int SDL_main(int argc, char *argv[]); #ifdef LOGMESSAGES FILE *logstream = NULL; +char logfilename[1024]; #endif #ifndef DOXYGEN @@ -117,7 +122,6 @@ int main(int argc, char **argv) #endif { const char *logdir = NULL; - char logfile[MAX_WADPATH]; myargc = argc; myargv = argv; /// \todo pull out path to exe from this string @@ -157,7 +161,7 @@ int main(int argc, char **argv) if (fileabs) { - strftime(logfile, sizeof logfile, format, timeinfo); + strftime(logfilename, sizeof logfilename, format, timeinfo); } else { @@ -168,32 +172,46 @@ int main(int argc, char **argv) if (M_IsPathAbsolute(reldir)) { - left = snprintf(logfile, sizeof logfile, + left = snprintf(logfilename, sizeof logfilename, "%s"PATHSEP, reldir); } else #ifdef DEFAULTDIR if (logdir) { - left = snprintf(logfile, sizeof logfile, + left = snprintf(logfilename, sizeof logfilename, "%s"PATHSEP DEFAULTDIR PATHSEP"%s"PATHSEP, logdir, reldir); } else #endif/*DEFAULTDIR*/ { - left = snprintf(logfile, sizeof logfile, + left = snprintf(logfilename, sizeof logfilename, "."PATHSEP"%s"PATHSEP, reldir); } #endif/*LOGMESSAGES*/ - strftime(&logfile[left], sizeof logfile - left, format, timeinfo); + strftime(&logfilename[left], sizeof logfilename - left, + format, timeinfo); } - M_MkdirEachUntil(logfile, + M_MkdirEachUntil(logfilename, M_PathParts(logdir) - 1, - M_PathParts(logfile) - 1, 0755); + M_PathParts(logfilename) - 1, 0755); - logstream = fopen(logfile, "wt"); +#ifdef __unix__ + logstream = fopen(logfilename, "w"); +#ifdef DEFAULTDIR + if (symlink(logfilename, + va("%s/"DEFAULTDIR"/latest-log.txt", logdir)) == -1) +#else + if (symlink(logfilename, va("%s/latest-log.txt", logdir)) == -1) +#endif/*DEFAULTDIR*/ + { + I_OutputMsg("Error symlinking latest-log.txt: %s\n", strerror(errno)); + } +#else/*__unix__*/ + logstream = fopen("latest-log.txt", "wt+"); +#endif/*__unix__*/ } //I_OutputMsg("I_StartupSystem() ...\n"); @@ -222,7 +240,7 @@ int main(int argc, char **argv) D_SRB2Main(); #ifdef LOGMESSAGES if (!M_CheckParm("-nolog")) - CONS_Printf("Logfile: %s\n", logfile); + CONS_Printf("Logfile: %s\n", logfilename); #endif CONS_Printf("Entering main game loop...\n"); // never return diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index 13fb25bea..355131f3b 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -2377,6 +2377,48 @@ void I_RemoveExitFunc(void (*func)()) } } +#ifndef __unix__ +static void Shittycopyerror(const char *name) +{ + I_OutputMsg( + "Error copying log file: %s: %s\n", + name, + strerror(errno) + ); +} + +static void Shittylogcopy(void) +{ + char buf[8192]; + FILE *fp; + int n; + if (fseek(logstream, 0, SEEK_SET) == -1) + { + Shittycopyerror("fseek"); + } + else if (( fp = fopen(logfilename, "wt") )) + { + while (( n = fread(buf, 1, sizeof buf, logstream) )) + { + if (fwrite(buf, 1, n, fp) < n) + { + Shittycopyerror("fwrite"); + break; + } + } + if (ferror(logstream)) + { + Shittycopyerror("fread"); + } + fclose(fp); + } + else + { + Shittycopyerror(logfilename); + } +} +#endif/*__unix__*/ + // // Closes down everything. This includes restoring the initial // palette and video mode, and removing whatever mouse, keyboard, and @@ -2395,6 +2437,9 @@ void I_ShutdownSystem(void) if (logstream) { I_OutputMsg("I_ShutdownSystem(): end of logstream.\n"); +#ifndef __unix__ + Shittylogcopy(); +#endif fclose(logstream); logstream = NULL; }