From: Holger Schemel Date: Wed, 26 Jul 2006 19:24:50 +0000 (+0200) Subject: rnd-20060726-6-src X-Git-Tag: 3.2.1^2~33 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=3b0023fd3eacaecffa0ae6c9107c11d3abd4ac6c;p=rocksndiamonds.git rnd-20060726-6-src * added Windows message box to direct to "stderr.txt" after error aborts --- diff --git a/ChangeLog b/ChangeLog index b00e1c84..54ede52f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,7 @@ holding "Ctrl" button pressed while scrolling the wheel * changed output file "stderr.txt" on Windows platform now always to be created in the R'n'D sub-directory of the personal documents directory + * added Windows message box to direct to "stderr.txt" after error aborts 2006-07-25 * improved general scrollbar handling (when jump-scrolling scrollbars) diff --git a/src/conftime.h b/src/conftime.h index c354faf7..2ceed3b0 100644 --- a/src/conftime.h +++ b/src/conftime.h @@ -1 +1 @@ -#define COMPILE_DATE_STRING "[2006-07-26 19:58]" +#define COMPILE_DATE_STRING "[2006-07-26 21:19]" diff --git a/src/init.c b/src/init.c index c975ec61..79e183ed 100644 --- a/src/init.c +++ b/src/init.c @@ -4874,5 +4874,8 @@ void CloseAllAndExit(int exit_value) CloseVideoDisplay(); ClosePlatformDependentStuff(); + if (exit_value != 0) + NotifyUserAboutErrorFile(); + exit(exit_value); } diff --git a/src/libgame/misc.c b/src/libgame/misc.c index 6c873440..c671d4b7 100644 --- a/src/libgame/misc.c +++ b/src/libgame/misc.c @@ -43,11 +43,7 @@ static void vfprintf_newline(FILE *stream, char *format, va_list ap) { -#if defined(PLATFORM_WIN32) || defined(PLATFORM_MSDOS) - char *newline = "\r\n"; -#else - char *newline = "\n"; -#endif + char *newline = STRING_NEWLINE; vfprintf(stream, format, ap); @@ -56,20 +52,15 @@ static void vfprintf_newline(FILE *stream, char *format, va_list ap) static void vprintf_error_ext(char *format, va_list ap, boolean print_newline) { - FILE *error = stderr; - -#if defined(PLATFORM_WIN32) || defined(PLATFORM_MSDOS) - if ((error = openErrorFile()) == NULL) - program.exit_function(1); -#endif + FILE *error_file = openErrorFile(); /* this returns at least 'stderr' */ if (print_newline) - vfprintf_newline(error, format, ap); + vfprintf_newline(error_file, format, ap); else - vfprintf(error, format, ap); + vfprintf(error_file, format, ap); - if (error != stderr) - fclose(error); + if (error_file != stderr) /* do not close stream 'stderr' */ + fclose(error_file); } static void vprintf_error(char *format, va_list ap) @@ -562,12 +553,10 @@ char *getHomeDir() static char *getLastPathSeparatorPtr(char *filename) { - char *last_separator = strrchr(filename, '/'); + char *last_separator = strrchr(filename, CHAR_PATH_SEPARATOR_UNIX); -#if !defined(PLATFORM_UNIX) if (last_separator == NULL) /* also try DOS/Windows variant */ - last_separator = strrchr(filename, '\\'); -#endif + last_separator = strrchr(filename, CHAR_PATH_SEPARATOR_DOS); return last_separator; } @@ -607,21 +596,23 @@ char *getBasePath(char *filename) char *getPath2(char *path1, char *path2) { + char *sep = STRING_PATH_SEPARATOR; char *complete_path = checked_malloc(strlen(path1) + 1 + strlen(path2) + 1); - sprintf(complete_path, "%s/%s", path1, path2); + sprintf(complete_path, "%s%s%s", path1, sep, path2); return complete_path; } char *getPath3(char *path1, char *path2, char *path3) { + char *sep = STRING_PATH_SEPARATOR; char *complete_path = checked_malloc(strlen(path1) + 1 + strlen(path2) + 1 + strlen(path3) + 1); - sprintf(complete_path, "%s/%s/%s", path1, path2, path3); + sprintf(complete_path, "%s%s%s%s%s", path1, sep, path2, sep, path3); return complete_path; } @@ -2907,48 +2898,32 @@ void FreeCustomArtworkLists(struct ArtworkListInfo *artwork_info) /* (now also added for Windows, to create files in user data directory) */ /* ------------------------------------------------------------------------- */ -#if defined(PLATFORM_WIN32) || defined(PLATFORM_MSDOS) - -#define ERROR_BASENAME "stderr.txt" - -static char *error_filename = NULL; - -#if defined(PLATFORM_WIN32) - -void initErrorFile() +char *getErrorFilename(char *basename) { - if (error_filename == NULL) - error_filename = getPath2(getUserDataDir(), ERROR_BASENAME); - - unlink(error_filename); + return getPath2(getUserDataDir(), basename); } -#elif defined(PLATFORM_MSDOS) - void initErrorFile() { - if (error_filename == NULL) - error_filename = ERROR_BASENAME; - - unlink(error_filename); + unlink(program.error_filename); } -#endif /* PLATFORM_MSDOS */ - FILE *openErrorFile() { - FILE *error_file = fopen(error_filename, MODE_APPEND); + FILE *error_file = stderr; - if (error_file == NULL) +#if defined(PLATFORM_WIN32) || defined(PLATFORM_MSDOS) + if ((error_file = fopen(program.error_filename, MODE_APPEND)) == NULL) fprintf_newline(stderr, "ERROR: cannot open file '%s' for appending!", - error_filename); + program.error_filename); +#endif return error_file; } void dumpErrorFile() { - FILE *error_file = fopen(error_filename, MODE_READ); + FILE *error_file = fopen(program.error_filename, MODE_READ); if (error_file != NULL) { @@ -2959,7 +2934,17 @@ void dumpErrorFile() } } -#endif /* PLATFORM_WIN32 || PLATFORM_MSDOS */ +void NotifyUserAboutErrorFile() +{ +#if defined(PLATFORM_WIN32) + char *title_text = getStringCat2(program.program_title, " Error Message"); + char *error_text = getStringCat2("The program was aborted due to an error; " + "for details, see the following error file:" + STRING_NEWLINE, program.error_filename); + + MessageBox(NULL, error_text, title_text, MB_OK); +#endif +} /* ------------------------------------------------------------------------- */ diff --git a/src/libgame/misc.h b/src/libgame/misc.h index 63ecf784..cc3ecf0a 100644 --- a/src/libgame/misc.h +++ b/src/libgame/misc.h @@ -188,11 +188,11 @@ void LoadArtworkConfig(struct ArtworkListInfo *); void ReloadCustomArtworkList(struct ArtworkListInfo *); void FreeCustomArtworkLists(struct ArtworkListInfo *); -#if !defined(PLATFORM_UNIX) +char *getErrorFilename(char *); void initErrorFile(); FILE *openErrorFile(); void dumpErrorFile(); -#endif +void NotifyUserAboutErrorFile(); void debug_print_timestamp(int, char *); diff --git a/src/libgame/system.c b/src/libgame/system.c index 1bc35d68..5aac42f8 100644 --- a/src/libgame/system.c +++ b/src/libgame/system.c @@ -93,6 +93,8 @@ void InitProgramInfo(char *argv0, program.version_major = VERSION_MAJOR(program_version); program.version_minor = VERSION_MINOR(program_version); program.version_patch = VERSION_PATCH(program_version); + + program.error_filename = getErrorFilename(ERROR_BASENAME); } void InitExitFunction(void (*exit_function)(int)) diff --git a/src/libgame/system.h b/src/libgame/system.h index 9d90cd99..8fe22e2d 100644 --- a/src/libgame/system.h +++ b/src/libgame/system.h @@ -333,6 +333,27 @@ #define SCOREFILE_EXTENSION "sco" #endif +#define ERROR_BASENAME "stderr.txt" + +#define CHAR_PATH_SEPARATOR_UNIX '/' +#define CHAR_PATH_SEPARATOR_DOS '\\' + +#define STRING_PATH_SEPARATOR_UNIX "/" +#define STRING_PATH_SEPARATOR_DOS "\\" + +#define STRING_NEWLINE_UNIX "\n" +#define STRING_NEWLINE_DOS "\r\n" + +#if defined(PLATFORM_WIN32) || defined(PLATFORM_MSDOS) +#define CHAR_PATH_SEPARATOR CHAR_PATH_SEPARATOR_DOS +#define STRING_PATH_SEPARATOR STRING_PATH_SEPARATOR_DOS +#define STRING_NEWLINE STRING_NEWLINE_DOS +#else +#define CHAR_PATH_SEPARATOR CHAR_PATH_SEPARATOR_UNIX +#define STRING_PATH_SEPARATOR STRING_PATH_SEPARATOR_UNIX +#define STRING_NEWLINE STRING_NEWLINE_UNIX +#endif + /* areas in bitmap PIX_DOOR */ /* meaning in PIX_DB_DOOR: (3 PAGEs) @@ -508,6 +529,8 @@ struct ProgramInfo char *cookie_prefix; char *filename_prefix; /* prefix to cut off from DOS filenames */ + char *error_filename; /* used instead of 'stderr' on some systems */ + int version_major; int version_minor; int version_patch;