Save a copy of the symbols file to symbols.save when updating.

This commit is contained in:
Bart House
2019-10-30 19:17:03 -07:00
parent 33d00cf0e4
commit 86473526b8
3 changed files with 34 additions and 17 deletions
+6
View File
@@ -80,6 +80,12 @@
* objects being thrown when the hangup occurs. \ * 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 */ /* Stuff to help the user with some common, yet significant errors */
#define INTERJECT_PANIC 0 #define INTERJECT_PANIC 0
#define INTERJECTION_TYPES (INTERJECT_PANIC + 1) #define INTERJECTION_TYPES (INTERJECT_PANIC + 1)
+1 -1
View File
@@ -1910,7 +1910,7 @@ const char *default_configfile =
"NetHack Defaults"; "NetHack Defaults";
#else #else
#if defined(MSDOS) || defined(WIN32) #if defined(MSDOS) || defined(WIN32)
"defaults.nh"; CONFIG_FILE;
#else #else
"NetHack.cnf"; "NetHack.cnf";
#endif #endif
+27 -16
View File
@@ -301,7 +301,8 @@ update_file(
const char * dst_folder, const char * dst_folder,
const char * dst_name, const char * dst_name,
const char * src_folder, const char * src_folder,
const char * src_name) const char * src_name,
BOOL save_copy)
{ {
char dst_path[MAX_PATH]; char dst_path[MAX_PATH];
strcpy(dst_path, dst_folder); strcpy(dst_path, dst_folder);
@@ -311,12 +312,20 @@ update_file(
strcpy(src_path, src_folder); strcpy(src_path, src_folder);
strcat(src_path, src_name); 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)) if(!file_exists(src_path))
error("Unable to copy file '%s' as it does not exist", src_path); error("Unable to copy file '%s' as it does not exist", src_path);
if (!file_newer(src_path, dst_path)) if (!file_newer(src_path, dst_path))
return; return;
if (file_exists(dst_path) && save_copy)
CopyFileA(dst_path, save_path, FALSE);
BOOL success = CopyFileA(src_path, dst_path, FALSE); BOOL success = CopyFileA(src_path, dst_path, FALSE);
if(!success) error("Failed to update '%s' to '%s'", src_path, dst_path); if(!success) error("Failed to update '%s' to '%s'", src_path, dst_path);
@@ -325,37 +334,39 @@ update_file(
void copy_config_content() void copy_config_content()
{ {
/* Keep templates up to date */ /* Keep templates up to date */
update_file(fqn_prefix[CONFIGPREFIX], "defaults.tmp", /* TODO: Update the package to store config file as .nethackrc */
fqn_prefix[DATAPREFIX], "defaults.nh"); update_file(fqn_prefix[CONFIGPREFIX], CONFIG_TEMPLATE,
update_file(fqn_prefix[SYSCONFPREFIX], "sysconf.tmp", fqn_prefix[DATAPREFIX], CONFIG_FILE, FALSE);
fqn_prefix[DATAPREFIX], SYSCF_FILE); update_file(fqn_prefix[SYSCONFPREFIX], SYSCF_TEMPLATE,
fqn_prefix[DATAPREFIX], SYSCF_FILE, FALSE);
/* If the required early game file does not exist, copy it */ /* If the required early game file does not exist, copy it */
copy_file(fqn_prefix[CONFIGPREFIX], "defaults.nh", /* NOTE: We never replace .nethackrc or sysconf */
fqn_prefix[DATAPREFIX], "defaults.nh"); copy_file(fqn_prefix[CONFIGPREFIX], CONFIG_FILE,
fqn_prefix[DATAPREFIX], CONFIG_FILE);
copy_file(fqn_prefix[SYSCONFPREFIX], SYSCF_FILE, copy_file(fqn_prefix[SYSCONFPREFIX], SYSCF_FILE,
fqn_prefix[DATAPREFIX], 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 /* TODO: Can't HACKDIR be changed during option parsing
causing us to perhaps be checking options against the wrong causing us to perhaps be checking options against the wrong
symbols file? */ symbols file? */
copy_file(fqn_prefix[HACKPREFIX], SYMBOLS, update_file(fqn_prefix[HACKPREFIX], SYMBOLS,
fqn_prefix[DATAPREFIX], SYMBOLS); fqn_prefix[DATAPREFIX], SYMBOLS, TRUE);
} }
void void
copy_hack_content() copy_hack_content()
{ {
/* Keep Guidebook and opthelp up to date */ /* Keep Guidebook and opthelp up to date */
update_file(fqn_prefix[HACKPREFIX], "Guidebook.txt", update_file(fqn_prefix[HACKPREFIX], GUIDEBOOK_FILE,
fqn_prefix[DATAPREFIX], "Guidebook.txt"); fqn_prefix[DATAPREFIX], GUIDEBOOK_FILE, FALSE);
update_file(fqn_prefix[HACKPREFIX], "opthelp", update_file(fqn_prefix[HACKPREFIX], OPTIONFILE,
fqn_prefix[DATAPREFIX], "opthelp"); fqn_prefix[DATAPREFIX], OPTIONFILE, FALSE);
/* Keep templates up to date */ /* Keep templates up to date */
update_file(fqn_prefix[HACKPREFIX], "symbols.tmp", update_file(fqn_prefix[HACKPREFIX], SYMBOLS_TEMPLATE,
fqn_prefix[DATAPREFIX], "symbols"); fqn_prefix[DATAPREFIX], SYMBOLS, FALSE);
} }