X-Git-Url: https://git.distorted.org.uk/u/mdw/putty/blobdiff_plain/5165dd4f26a619c4bf8577314599174cef66a977..fc9b052a2fc832ea8bc3efa9c79eba0f961830b2:/windows/winstore.c diff --git a/windows/winstore.c b/windows/winstore.c index aae5a4c6..66c7c759 100644 --- a/windows/winstore.c +++ b/windows/winstore.c @@ -150,17 +150,26 @@ void *open_settings_r(const char *sessionname) return (void *) sesskey; } -char *read_setting_s(void *handle, const char *key, char *buffer, int buflen) +char *read_setting_s(void *handle, const char *key) { DWORD type, size; - size = buflen; + char *ret; - if (!handle || - RegQueryValueEx((HKEY) handle, key, 0, - &type, buffer, &size) != ERROR_SUCCESS || + if (!handle) + return NULL; + + /* Find out the type and size of the data. */ + if (RegQueryValueEx((HKEY) handle, key, 0, + &type, NULL, &size) != ERROR_SUCCESS || + type != REG_SZ) + return NULL; + + ret = snewn(size+1, char); + if (RegQueryValueEx((HKEY) handle, key, 0, + &type, ret, &size) != ERROR_SUCCESS || type != REG_SZ) return NULL; - else - return buffer; + + return ret; } int read_setting_i(void *handle, const char *key, int defvalue) @@ -177,53 +186,64 @@ int read_setting_i(void *handle, const char *key, int defvalue) return val; } -int read_setting_fontspec(void *handle, const char *name, FontSpec *result) +FontSpec *read_setting_fontspec(void *handle, const char *name) { char *settingname; - FontSpec ret; + char *fontname; + int isbold, height, charset; + + fontname = read_setting_s(handle, name); + if (!fontname) + return NULL; - if (!read_setting_s(handle, name, ret.name, sizeof(ret.name))) - return 0; settingname = dupcat(name, "IsBold", NULL); - ret.isbold = read_setting_i(handle, settingname, -1); + isbold = read_setting_i(handle, settingname, -1); sfree(settingname); - if (ret.isbold == -1) return 0; + if (isbold == -1) return NULL; + settingname = dupcat(name, "CharSet", NULL); - ret.charset = read_setting_i(handle, settingname, -1); + charset = read_setting_i(handle, settingname, -1); sfree(settingname); - if (ret.charset == -1) return 0; + if (charset == -1) return NULL; + settingname = dupcat(name, "Height", NULL); - ret.height = read_setting_i(handle, settingname, INT_MIN); + height = read_setting_i(handle, settingname, INT_MIN); sfree(settingname); - if (ret.height == INT_MIN) return 0; - *result = ret; - return 1; + if (height == INT_MIN) return NULL; + + return fontspec_new(fontname, isbold, height, charset); } -void write_setting_fontspec(void *handle, const char *name, FontSpec font) +void write_setting_fontspec(void *handle, const char *name, FontSpec *font) { char *settingname; - write_setting_s(handle, name, font.name); + write_setting_s(handle, name, font->name); settingname = dupcat(name, "IsBold", NULL); - write_setting_i(handle, settingname, font.isbold); + write_setting_i(handle, settingname, font->isbold); sfree(settingname); settingname = dupcat(name, "CharSet", NULL); - write_setting_i(handle, settingname, font.charset); + write_setting_i(handle, settingname, font->charset); sfree(settingname); settingname = dupcat(name, "Height", NULL); - write_setting_i(handle, settingname, font.height); + write_setting_i(handle, settingname, font->height); sfree(settingname); } -int read_setting_filename(void *handle, const char *name, Filename *result) +Filename *read_setting_filename(void *handle, const char *name) { - return !!read_setting_s(handle, name, result->path, sizeof(result->path)); + char *tmp = read_setting_s(handle, name); + if (tmp) { + Filename *ret = filename_from_str(tmp); + sfree(tmp); + return ret; + } else + return NULL; } -void write_setting_filename(void *handle, const char *name, Filename result) +void write_setting_filename(void *handle, const char *name, Filename *result) { - write_setting_s(handle, name, result.path); + write_setting_s(handle, name, result->path); } void close_settings_r(void *handle) @@ -436,7 +456,10 @@ enum { DEL, OPEN_R, OPEN_W }; static int try_random_seed(char const *path, int action, HANDLE *ret) { if (action == DEL) { - remove(path); + if (!DeleteFile(path) && GetLastError() != ERROR_FILE_NOT_FOUND) { + nonfatal("Unable to delete '%s': %s", path, + win_strerror(GetLastError())); + } *ret = INVALID_HANDLE_VALUE; return FALSE; /* so we'll do the next ones too */ }