Fall back to executable path if we have trouble converting known path.
This commit is contained in:
@@ -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
|
||||
-----------------------------------------------------
|
||||
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
|
||||
--------------------
|
||||
|
||||
@@ -79,24 +79,34 @@ static struct stat hbuf;
|
||||
|
||||
extern char orgdir[];
|
||||
|
||||
void
|
||||
int
|
||||
get_known_folder_path(
|
||||
const KNOWNFOLDERID * folder_id,
|
||||
char * path
|
||||
, size_t path_size)
|
||||
{
|
||||
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");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
size_t converted;
|
||||
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);
|
||||
|
||||
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
|
||||
@@ -108,14 +118,16 @@ create_directory(const char * path)
|
||||
error("Unable to create directory '%s'", path);
|
||||
}
|
||||
|
||||
void
|
||||
int
|
||||
build_known_folder_path(
|
||||
const KNOWNFOLDERID * folder_id,
|
||||
char * path,
|
||||
size_t path_size,
|
||||
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\\");
|
||||
create_directory(path);
|
||||
if (versioned) {
|
||||
@@ -123,6 +135,7 @@ build_known_folder_path(
|
||||
VERSION_MAJOR, VERSION_MINOR);
|
||||
create_directory(path);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
@@ -250,17 +263,22 @@ set_default_prefix_locations(const char *programPath)
|
||||
fqn_prefix[TROUBLEPREFIX] = portable_device_path;
|
||||
fqn_prefix[DATAPREFIX] = executable_path;
|
||||
} else {
|
||||
build_known_folder_path(&FOLDERID_Profile, profile_path,
|
||||
sizeof(profile_path), FALSE);
|
||||
if(!build_known_folder_path(&FOLDERID_Profile, profile_path,
|
||||
sizeof(profile_path), FALSE))
|
||||
strcpy(profile_path, executable_path);
|
||||
|
||||
build_known_folder_path(&FOLDERID_Profile, versioned_profile_path,
|
||||
sizeof(profile_path), TRUE);
|
||||
if(!build_known_folder_path(&FOLDERID_Profile, versioned_profile_path,
|
||||
sizeof(profile_path), TRUE))
|
||||
strcpy(versioned_profile_path, executable_path);
|
||||
|
||||
build_known_folder_path(&FOLDERID_LocalAppData,
|
||||
versioned_user_data_path, sizeof(versioned_user_data_path), TRUE);
|
||||
if(!build_known_folder_path(&FOLDERID_LocalAppData,
|
||||
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[CONFIGPREFIX] = profile_path;
|
||||
fqn_prefix[HACKPREFIX] = versioned_profile_path;
|
||||
|
||||
Reference in New Issue
Block a user