From 86473526b8eb2948744c1965bcc734ed211ce987 Mon Sep 17 00:00:00 2001 From: Bart House Date: Wed, 30 Oct 2019 19:17:03 -0700 Subject: [PATCH] Save a copy of the symbols file to symbols.save when updating. --- include/ntconf.h | 6 ++++++ src/files.c | 2 +- sys/winnt/windmain.c | 43 +++++++++++++++++++++++++++---------------- 3 files changed, 34 insertions(+), 17 deletions(-) diff --git a/include/ntconf.h b/include/ntconf.h index c38770e17..af84c3ef0 100644 --- a/include/ntconf.h +++ b/include/ntconf.h @@ -80,6 +80,12 @@ * objects being thrown when the hangup occurs. \ */ +#define CONFIG_FILE "defaults.nh" +#define CONFIG_TEMPLATE "defaults.template" +#define SYSCF_TEMPLATE "sysconf.template" +#define SYMBOLS_TEMPLATE "symbols.template" +#define GUIDEBOOK_FILE "Guidebook.txt" + /* Stuff to help the user with some common, yet significant errors */ #define INTERJECT_PANIC 0 #define INTERJECTION_TYPES (INTERJECT_PANIC + 1) diff --git a/src/files.c b/src/files.c index 7228cd7e8..f89e5e061 100644 --- a/src/files.c +++ b/src/files.c @@ -1910,7 +1910,7 @@ const char *default_configfile = "NetHack Defaults"; #else #if defined(MSDOS) || defined(WIN32) - "defaults.nh"; + CONFIG_FILE; #else "NetHack.cnf"; #endif diff --git a/sys/winnt/windmain.c b/sys/winnt/windmain.c index 1e140b0d6..f88fbaa37 100644 --- a/sys/winnt/windmain.c +++ b/sys/winnt/windmain.c @@ -301,7 +301,8 @@ update_file( const char * dst_folder, const char * dst_name, const char * src_folder, - const char * src_name) + const char * src_name, + BOOL save_copy) { char dst_path[MAX_PATH]; strcpy(dst_path, dst_folder); @@ -311,12 +312,20 @@ update_file( strcpy(src_path, src_folder); strcat(src_path, src_name); + char save_path[MAX_PATH]; + strcpy(save_path, dst_folder); + strcat(save_path, dst_name); + strcat(save_path, ".save"); + if(!file_exists(src_path)) error("Unable to copy file '%s' as it does not exist", src_path); if (!file_newer(src_path, dst_path)) return; + if (file_exists(dst_path) && save_copy) + CopyFileA(dst_path, save_path, FALSE); + BOOL success = CopyFileA(src_path, dst_path, FALSE); if(!success) error("Failed to update '%s' to '%s'", src_path, dst_path); @@ -325,37 +334,39 @@ update_file( void copy_config_content() { /* Keep templates up to date */ - update_file(fqn_prefix[CONFIGPREFIX], "defaults.tmp", - fqn_prefix[DATAPREFIX], "defaults.nh"); - update_file(fqn_prefix[SYSCONFPREFIX], "sysconf.tmp", - fqn_prefix[DATAPREFIX], SYSCF_FILE); + /* TODO: Update the package to store config file as .nethackrc */ + update_file(fqn_prefix[CONFIGPREFIX], CONFIG_TEMPLATE, + fqn_prefix[DATAPREFIX], CONFIG_FILE, FALSE); + update_file(fqn_prefix[SYSCONFPREFIX], SYSCF_TEMPLATE, + fqn_prefix[DATAPREFIX], SYSCF_FILE, FALSE); /* If the required early game file does not exist, copy it */ - copy_file(fqn_prefix[CONFIGPREFIX], "defaults.nh", - fqn_prefix[DATAPREFIX], "defaults.nh"); + /* NOTE: We never replace .nethackrc or sysconf */ + copy_file(fqn_prefix[CONFIGPREFIX], CONFIG_FILE, + fqn_prefix[DATAPREFIX], CONFIG_FILE); copy_file(fqn_prefix[SYSCONFPREFIX], SYSCF_FILE, fqn_prefix[DATAPREFIX], SYSCF_FILE); - /* If a required game file does not exist, copy it */ + /* Update symbols and save a copy if we are replacing */ /* TODO: Can't HACKDIR be changed during option parsing causing us to perhaps be checking options against the wrong symbols file? */ - copy_file(fqn_prefix[HACKPREFIX], SYMBOLS, - fqn_prefix[DATAPREFIX], SYMBOLS); + update_file(fqn_prefix[HACKPREFIX], SYMBOLS, + fqn_prefix[DATAPREFIX], SYMBOLS, TRUE); } void copy_hack_content() { /* Keep Guidebook and opthelp up to date */ - update_file(fqn_prefix[HACKPREFIX], "Guidebook.txt", - fqn_prefix[DATAPREFIX], "Guidebook.txt"); - update_file(fqn_prefix[HACKPREFIX], "opthelp", - fqn_prefix[DATAPREFIX], "opthelp"); + update_file(fqn_prefix[HACKPREFIX], GUIDEBOOK_FILE, + fqn_prefix[DATAPREFIX], GUIDEBOOK_FILE, FALSE); + update_file(fqn_prefix[HACKPREFIX], OPTIONFILE, + fqn_prefix[DATAPREFIX], OPTIONFILE, FALSE); /* Keep templates up to date */ - update_file(fqn_prefix[HACKPREFIX], "symbols.tmp", - fqn_prefix[DATAPREFIX], "symbols"); + update_file(fqn_prefix[HACKPREFIX], SYMBOLS_TEMPLATE, + fqn_prefix[DATAPREFIX], SYMBOLS, FALSE); }