diff --git a/ui/xemu-os-utils-windows.c b/ui/xemu-os-utils-windows.c index da14b93b00..fa6959002e 100644 --- a/ui/xemu-os-utils-windows.c +++ b/ui/xemu-os-utils-windows.c @@ -25,51 +25,28 @@ static const char *get_windows_build_info(void) { - const char *buffer = NULL; - HKEY keyhandle; - WCHAR current_version[1024], current_build[1024], product_name[1024]; - WCHAR version_size = 1024, build_size = 1024, product_size = 1024; - - // If one of the registry open fails, return Windows as a fallback. - if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, - L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", 0, - KEY_QUERY_VALUE, &keyhandle) != ERROR_SUCCESS) - return NULL; + WCHAR current_build[1024], product_name[1024]; + WCHAR build_size = 1024, product_size = 1024; if (RegGetValueW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", L"ProductName", RRF_RT_REG_SZ, (LPVOID)NULL, &product_name, - (LPDWORD)&product_size) != ERROR_SUCCESS) - return NULL; - - if (RegGetValueW(HKEY_LOCAL_MACHINE, - L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", - L"CurrentVersion", RRF_RT_REG_SZ, (LPVOID)NULL, - ¤t_version, (LPDWORD)&version_size) != ERROR_SUCCESS) - return NULL; - - // If version number is 6.3/10.0 (8.1/10/11), get the build number from the - // DisplayVersion Registry. Reference: - // https://en.wikipedia.org/wiki/Windows_NT - if ((wcscmp(current_version, L"10.0") == 0) || - (wcscmp(current_version, L"6.3") == 0)) { - if (RegGetValueW(HKEY_LOCAL_MACHINE, - L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", - L"DisplayVersion", RRF_RT_REG_SZ, (LPVOID)NULL, - ¤t_build, - (LPDWORD)&build_size) != ERROR_SUCCESS) { - // If it's lower (Win 8 and below until Win XP) get the build descriptor - // from CSDVersion. - if (RegGetValueW(HKEY_LOCAL_MACHINE, - L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", - L"CSDVersion", RRF_RT_REG_SZ, (LPVOID)NULL, - ¤t_build, - (LPDWORD)&build_size) != ERROR_SUCCESS) - return NULL; - } + (LPDWORD)&product_size) != ERROR_SUCCESS) { + return "Windows"; } - RegCloseKey(keyhandle); - return g_strdup_printf("%ls %ls", product_name, current_build); + + if ((RegGetValueW(HKEY_LOCAL_MACHINE, + L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", + L"DisplayVersion", RRF_RT_REG_SZ, (LPVOID)NULL, + ¤t_build, (LPDWORD)&build_size) == ERROR_SUCCESS) || + (RegGetValueW(HKEY_LOCAL_MACHINE, + L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", + L"CSDVersion", RRF_RT_REG_SZ, (LPVOID)NULL, + ¤t_build, (LPDWORD)&build_size) == ERROR_SUCCESS)) { + g_strdup_printf("%ls %ls", product_name, current_build); + } + + return g_strdup_printf("%ls", product_name); } const char *xemu_get_os_info(void) @@ -78,11 +55,8 @@ const char *xemu_get_os_info(void) if (buffer == NULL) { buffer = get_windows_build_info(); - - if (buffer == NULL) { - buffer = "Windows"; - } } + return buffer; }