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

View File

@@ -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)

View File

@@ -1910,7 +1910,7 @@ const char *default_configfile =
"NetHack Defaults";
#else
#if defined(MSDOS) || defined(WIN32)
"defaults.nh";
CONFIG_FILE;
#else
"NetHack.cnf";
#endif

View File

@@ -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);
}