More tweaks to how windows deals with directory paths.

This commit is contained in:
Bart House
2019-11-03 13:31:17 -08:00
parent 0b23cac8ab
commit f0707fee6e
4 changed files with 69 additions and 58 deletions

View File

@@ -398,6 +398,7 @@ E const char *const monexplain[], invisexplain[], *const oclass_names[];
#endif
E char *fqn_prefix[PREFIX_COUNT];
E boolean fqn_prefix_locked[PREFIX_COUNT];
#ifdef PREFIXES_IN_USE
E char *fqn_prefix_names[PREFIX_COUNT];
#endif

View File

@@ -286,6 +286,10 @@ char *fqn_prefix[PREFIX_COUNT] = { (char *) 0, (char *) 0, (char *) 0,
(char *) 0, (char *) 0, (char *) 0,
(char *) 0, (char *) 0, (char *) 0,
(char *) 0 };
boolean fqn_prefix_locked[PREFIX_COUNT] = { FALSE, FALSE, FALSE,
FALSE, FALSE, FALSE,
FALSE, FALSE, FALSE,
FALSE };
#ifdef PREFIXES_IN_USE
char *fqn_prefix_names[PREFIX_COUNT] = {

View File

@@ -2158,6 +2158,8 @@ int prefixid;
if (!bufp)
return;
if (fqn_prefix_locked[prefixid])
return;
/* Backward compatibility, ignore trailing ;n */
if ((ptr = index(bufp, ';')) != 0)
*ptr = '\0';
@@ -3196,7 +3198,7 @@ fopen_sym_file()
{
FILE *fp;
fp = fopen_datafile(SYMBOLS, "r", HACKPREFIX);
fp = fopen_datafile(SYMBOLS, "r", CONFIGPREFIX);
return fp;
}
@@ -3861,6 +3863,9 @@ assure_syscf_file()
{
int fd;
/* We are checking that the sysconf exists ... lock the path */
fqn_prefix_locked[SYSCONFPREFIX] = TRUE;
/*
* All we really care about is the end result - can we read the file?
* So just check that directly.

View File

@@ -97,13 +97,16 @@ void
build_known_folder_path(
const KNOWNFOLDERID * folder_id,
char * path,
size_t path_size)
size_t path_size,
boolean versioned)
{
get_known_folder_path(folder_id, path, path_size);
strcat(path, "\\NetHack\\");
create_directory(path);
strcat(path, "3.6\\");
create_directory(path);
if (versioned) {
strcat(path, "3.6\\");
create_directory(path);
}
}
void
@@ -190,51 +193,37 @@ set_default_prefix_locations(const char *programPath)
char *envp = NULL;
char *sptr = NULL;
static char hack_path[MAX_PATH];
static char executable_path[MAX_PATH];
static char nethack_profile_path[MAX_PATH];
static char nethack_per_user_data_path[MAX_PATH];
static char nethack_global_data_path[MAX_PATH];
static char sysconf_path[MAX_PATH];
static char profile_path[MAX_PATH];
static char versioned_profile_path[MAX_PATH];
static char versioned_user_data_path[MAX_PATH];
static char versioned_global_data_path[MAX_PATH];
strcpy(executable_path, get_executable_path());
append_slash(executable_path);
build_environment_path("NETHACKDIR", NULL, hack_path, sizeof(hack_path));
build_known_folder_path(&FOLDERID_Profile, profile_path,
sizeof(profile_path), FALSE);
if (hack_path[0] == '\0')
build_environment_path("HACKDIR", NULL, hack_path, sizeof(hack_path));
build_known_folder_path(&FOLDERID_Profile, nethack_profile_path,
sizeof(nethack_profile_path));
build_known_folder_path(&FOLDERID_Profile, versioned_profile_path,
sizeof(profile_path), TRUE);
build_known_folder_path(&FOLDERID_LocalAppData,
nethack_per_user_data_path, sizeof(nethack_per_user_data_path));
versioned_user_data_path, sizeof(versioned_user_data_path), TRUE);
build_known_folder_path(&FOLDERID_ProgramData,
nethack_global_data_path, sizeof(nethack_global_data_path));
versioned_global_data_path, sizeof(versioned_global_data_path), TRUE);
if (hack_path[0] == '\0')
strcpy(hack_path, nethack_profile_path);
fqn_prefix[LEVELPREFIX] = nethack_per_user_data_path;
fqn_prefix[SAVEPREFIX] = nethack_per_user_data_path;
fqn_prefix[BONESPREFIX] = nethack_global_data_path;
fqn_prefix[LEVELPREFIX] = versioned_user_data_path;
fqn_prefix[SAVEPREFIX] = versioned_user_data_path;
fqn_prefix[BONESPREFIX] = versioned_global_data_path;
fqn_prefix[DATAPREFIX] = executable_path;
fqn_prefix[SCOREPREFIX] = nethack_global_data_path;
fqn_prefix[LOCKPREFIX] = nethack_global_data_path;
fqn_prefix[CONFIGPREFIX] = nethack_profile_path;
fqn_prefix[HACKPREFIX] = hack_path;
fqn_prefix[TROUBLEPREFIX] = hack_path;
build_environment_path("COMMONPROGRAMFILES", "NetHack\\3.6", sysconf_path,
sizeof(sysconf_path));
if(!folder_file_exists(sysconf_path, SYSCF_FILE))
strcpy(sysconf_path, hack_path);
fqn_prefix[SYSCONFPREFIX] = sysconf_path;
fqn_prefix[SCOREPREFIX] = versioned_global_data_path;
fqn_prefix[LOCKPREFIX] = versioned_global_data_path;
fqn_prefix[CONFIGPREFIX] = profile_path;
fqn_prefix[HACKPREFIX] = versioned_profile_path;
fqn_prefix[TROUBLEPREFIX] = versioned_profile_path;
fqn_prefix[SYSCONFPREFIX] = versioned_global_data_path;
}
@@ -300,43 +289,51 @@ update_file(
}
void copy_config_content()
void copy_sysconf_content()
{
/* Keep templates up to date */
/* TODO: Update the package to store config file as .nethackrc */
update_file(fqn_prefix[CONFIGPREFIX], CONFIG_TEMPLATE,
fqn_prefix[DATAPREFIX], CONFIG_TEMPLATE, FALSE);
/* Using the SYSCONFPREFIX path, lock it so that it does not change */
fqn_prefix_locked[SYSCONFPREFIX] = TRUE;
update_file(fqn_prefix[SYSCONFPREFIX], SYSCF_TEMPLATE,
fqn_prefix[DATAPREFIX], SYSCF_TEMPLATE, FALSE);
/* If the required early game file does not exist, copy it */
copy_file(fqn_prefix[SYSCONFPREFIX], SYSCF_FILE,
fqn_prefix[DATAPREFIX], SYSCF_TEMPLATE);
}
void copy_config_content()
{
/* Using the CONFIGPREFIX path, lock it so that it does not change */
fqn_prefix_locked[CONFIGPREFIX] = TRUE;
/* Keep templates up to date */
update_file(fqn_prefix[CONFIGPREFIX], CONFIG_TEMPLATE,
fqn_prefix[DATAPREFIX], CONFIG_TEMPLATE, FALSE);
update_file(fqn_prefix[CONFIGPREFIX], SYMBOLS_TEMPLATE,
fqn_prefix[DATAPREFIX], SYMBOLS_TEMPLATE, FALSE);
/* If the required early game file does not exist, copy it */
/* NOTE: We never replace .nethackrc or sysconf */
copy_file(fqn_prefix[CONFIGPREFIX], CONFIG_FILE,
fqn_prefix[DATAPREFIX], CONFIG_TEMPLATE);
copy_file(fqn_prefix[SYSCONFPREFIX], SYSCF_FILE,
fqn_prefix[DATAPREFIX], SYSCF_TEMPLATE);
/* 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? */
update_file(fqn_prefix[HACKPREFIX], SYMBOLS,
update_file(fqn_prefix[CONFIGPREFIX], SYMBOLS,
fqn_prefix[DATAPREFIX], SYMBOLS_TEMPLATE, TRUE);
}
void
copy_hack_content()
{
nhassert(fqn_prefix_locked[HACKPREFIX]);
/* Keep Guidebook and opthelp up to date */
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_TEMPLATE,
fqn_prefix[DATAPREFIX], SYMBOLS_TEMPLATE, FALSE);
}
/*
@@ -407,22 +404,26 @@ _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);*/
chdir(fqn_prefix[HACKPREFIX]);
#endif
copy_config_content();
if (GUILaunched || IsDebuggerPresent())
getreturn_enabled = TRUE;
check_recordfile((char *) 0);
iflags.windowtype_deferred = TRUE;
copy_sysconf_content();
initoptions();
copy_config_content();
process_options(argc, argv);
/* Finished processing options, lock all directory paths */
for(int i = 0; i < PREFIX_COUNT; i++)
fqn_prefix_locked[i] = TRUE;
if (!validate_prefix_locations(failbuf)) {
raw_printf("Some invalid directory locations were specified:\n\t%s\n",
failbuf);
nethack_exit(EXIT_FAILURE);
}
process_options(argc, argv);
copy_hack_content();
/*