update the code for portable Windows configuration

Restrict which options in sysconf will be processed
when seeking PORTABLE_DEVICE_PATHS.
This commit is contained in:
nhmall
2026-05-10 21:11:17 -04:00
parent 2337a2bae5
commit 610bd839ee
4 changed files with 110 additions and 68 deletions
+6 -55
View File
@@ -44,10 +44,11 @@
*
*/
static char portable_device_path[MAX_PATH];
char portable_device_path[_MAX_PATH];
static boolean path_buffer_set = FALSE;
static char path_buffer[MAX_PATH];
extern boolean portable;
#ifndef SFCTOOL
/* runtime cursor display control switch */
@@ -88,9 +89,7 @@ int build_known_folder_path(const KNOWNFOLDERID *folder_id, char *path,
void build_environment_path(const char *env_str, const char *folder,
char *path, size_t path_size);
boolean folder_file_exists(const char *folder, const char *file_name);
boolean test_portable_config(const char *executable_path,
char *portable_device_path,
size_t portable_device_path_size);
/* The function pointer nt_kbhit contains a kbhit() equivalent
* which varies depending on which window port is active.
* For the tty port it is tty_kbhit() [from consoletty.c]
@@ -1042,9 +1041,8 @@ set_default_prefix_locations(const char *programPath UNUSED)
append_slash(executable_path);
#ifndef SFCTOOL
if (test_portable_config(executable_path, portable_device_path,
sizeof portable_device_path)) {
gf.fqn_prefix[SYSCONFPREFIX] = executable_path;
if (portable || (portable = check_for_portable_config())) {
gf.fqn_prefix[SYSCONFPREFIX] = portable_device_path;
gf.fqn_prefix[CONFIGPREFIX] = portable_device_path;
gf.fqn_prefix[HACKPREFIX] = portable_device_path;
gf.fqn_prefix[SAVEPREFIX] = portable_device_path;
@@ -1053,7 +1051,7 @@ set_default_prefix_locations(const char *programPath UNUSED)
gf.fqn_prefix[SCOREPREFIX] = portable_device_path;
gf.fqn_prefix[LOCKPREFIX] = portable_device_path;
gf.fqn_prefix[TROUBLEPREFIX] = portable_device_path;
gf.fqn_prefix[DATAPREFIX] = executable_path;
gf.fqn_prefix[DATAPREFIX] = portable_device_path;
} else {
#endif /* SFCTOOL */
if (!build_known_folder_path(&FOLDERID_Profile, profile_path,
@@ -1110,53 +1108,6 @@ append_slash(char *name)
}
void set_default_prefix_locations(const char *programPath);
boolean
test_portable_config(const char *executable_path, char *portable_device_path,
size_t portable_device_path_size)
{
int lth = 0;
const char *sysconf = "sysconf";
char tmppath[MAX_PATH];
boolean retval = FALSE,
save_initoptions_noterminate = iflags.initoptions_noterminate;
if (portable_device_path
&& folder_file_exists(executable_path, "sysconf")) {
/*
There is a sysconf file (not just sysconf.template) present in
the exe path, which is not the way NetHack is initially
distributed, so assume it means that the admin/installer wants to
override something, perhaps set up for a fully-portable
configuration that leaves no traces behind elsewhere on this
computer's hard drive - delve into that...
*/
*portable_device_path = '\0';
lth = sizeof tmppath - strlen(sysconf);
(void) strncpy(tmppath, executable_path, lth - 1);
tmppath[lth - 1] = '\0';
(void) strcat(tmppath, sysconf);
iflags.initoptions_noterminate = 1;
/* assure_syscf_file(); */
config_error_init(TRUE, tmppath, FALSE);
/* ... and _must_ parse correctly. */
if (read_config_file(tmppath, set_in_sysconf)
&& sysopt.portable_device_paths)
retval = TRUE;
(void) config_error_done();
iflags.initoptions_noterminate = save_initoptions_noterminate;
sysopt_release(); /* the real sysconf processing comes later */
}
if (retval) {
lth = strlen(executable_path);
if (lth <= (int) portable_device_path_size - 1)
Strcpy(portable_device_path, executable_path);
else
retval = FALSE;
}
return retval;
}
const char *
get_portable_device(void)