Fall back to executable path if we have trouble converting known path.

This commit is contained in:
Bart House
2020-01-25 17:07:45 -08:00
parent 24f2e098c5
commit 05455f7baa
2 changed files with 33 additions and 15 deletions
+1 -1
View File
@@ -25,7 +25,7 @@ Fixes to Post-3.6.4 Problems that Were Exposed Via git Repository
Platform- and/or Interface-Specific Fixes or Features Platform- and/or Interface-Specific Fixes or Features
----------------------------------------------------- -----------------------------------------------------
Windows OPTIONS=map_mode:fit_to_screen could cause a game start failure Windows OPTIONS=map_mode:fit_to_screen could cause a game start failure
Windows users with C-locale unmappable names could get game start failure
General New Features General New Features
-------------------- --------------------
+32 -14
View File
@@ -79,24 +79,34 @@ static struct stat hbuf;
extern char orgdir[]; extern char orgdir[];
void int
get_known_folder_path( get_known_folder_path(
const KNOWNFOLDERID * folder_id, const KNOWNFOLDERID * folder_id,
char * path char * path
, size_t path_size) , size_t path_size)
{ {
PWSTR wide_path; PWSTR wide_path;
if (FAILED(SHGetKnownFolderPath(folder_id, 0, NULL, &wide_path))) if (FAILED(SHGetKnownFolderPath(folder_id, 0, NULL, &wide_path))) {
error("Unable to get known folder path"); error("Unable to get known folder path");
return FALSE;
}
size_t converted; size_t converted;
errno_t err; errno_t err;
err = wcstombs_s(&converted, path, path_size, wide_path, path_size - 1); err = wcstombs_s(&converted, path, path_size, wide_path, _TRUNCATE);
CoTaskMemFree(wide_path); CoTaskMemFree(wide_path);
if (err != 0) error("Failed folder path string conversion"); if (err == STRUNCATE || err == EILSEQ) {
// silently handle this problem
return FALSE;
} else if (err != 0) {
error("Failed folder (%u) path string conversion, unexpected err = %d", folder_id->Data1, err);
return FALSE;
}
return TRUE;
} }
void void
@@ -108,14 +118,16 @@ create_directory(const char * path)
error("Unable to create directory '%s'", path); error("Unable to create directory '%s'", path);
} }
void int
build_known_folder_path( build_known_folder_path(
const KNOWNFOLDERID * folder_id, const KNOWNFOLDERID * folder_id,
char * path, char * path,
size_t path_size, size_t path_size,
boolean versioned) boolean versioned)
{ {
get_known_folder_path(folder_id, path, path_size); if(!get_known_folder_path(folder_id, path, path_size))
return FALSE;
strcat(path, "\\NetHack\\"); strcat(path, "\\NetHack\\");
create_directory(path); create_directory(path);
if (versioned) { if (versioned) {
@@ -123,6 +135,7 @@ build_known_folder_path(
VERSION_MAJOR, VERSION_MINOR); VERSION_MAJOR, VERSION_MINOR);
create_directory(path); create_directory(path);
} }
return TRUE;
} }
void void
@@ -250,17 +263,22 @@ set_default_prefix_locations(const char *programPath)
fqn_prefix[TROUBLEPREFIX] = portable_device_path; fqn_prefix[TROUBLEPREFIX] = portable_device_path;
fqn_prefix[DATAPREFIX] = executable_path; fqn_prefix[DATAPREFIX] = executable_path;
} else { } else {
build_known_folder_path(&FOLDERID_Profile, profile_path, if(!build_known_folder_path(&FOLDERID_Profile, profile_path,
sizeof(profile_path), FALSE); sizeof(profile_path), FALSE))
strcpy(profile_path, executable_path);
build_known_folder_path(&FOLDERID_Profile, versioned_profile_path, if(!build_known_folder_path(&FOLDERID_Profile, versioned_profile_path,
sizeof(profile_path), TRUE); sizeof(profile_path), TRUE))
strcpy(versioned_profile_path, executable_path);
build_known_folder_path(&FOLDERID_LocalAppData, if(!build_known_folder_path(&FOLDERID_LocalAppData,
versioned_user_data_path, sizeof(versioned_user_data_path), TRUE); versioned_user_data_path, sizeof(versioned_user_data_path), TRUE))
strcpy(versioned_user_data_path, executable_path);
if(!build_known_folder_path(&FOLDERID_ProgramData,
versioned_global_data_path, sizeof(versioned_global_data_path), TRUE))
strcpy(versioned_global_data_path, executable_path);
build_known_folder_path(&FOLDERID_ProgramData,
versioned_global_data_path, sizeof(versioned_global_data_path), TRUE);
fqn_prefix[SYSCONFPREFIX] = versioned_global_data_path; fqn_prefix[SYSCONFPREFIX] = versioned_global_data_path;
fqn_prefix[CONFIGPREFIX] = profile_path; fqn_prefix[CONFIGPREFIX] = profile_path;
fqn_prefix[HACKPREFIX] = versioned_profile_path; fqn_prefix[HACKPREFIX] = versioned_profile_path;