Merge 'NetHack-3.6' changes into NetHack-3.7-Jan2020

This commit is contained in:
nhmall
2020-01-25 22:17:42 -05:00
8 changed files with 55 additions and 21 deletions

View File

@@ -78,24 +78,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
@@ -107,14 +117,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) {
@@ -122,6 +134,7 @@ build_known_folder_path(
VERSION_MAJOR, VERSION_MINOR);
create_directory(path);
}
return TRUE;
}
void
@@ -249,17 +262,22 @@ set_default_prefix_locations(const char *programPath)
g.fqn_prefix[TROUBLEPREFIX] = portable_device_path;
g.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);
g.fqn_prefix[SYSCONFPREFIX] = versioned_global_data_path;
g.fqn_prefix[CONFIGPREFIX] = profile_path;
g.fqn_prefix[HACKPREFIX] = versioned_profile_path;