2017-02-24 17:59:41 +00:00
|
|
|
#include "ppsspp_config.h"
|
2017-02-14 09:33:42 +00:00
|
|
|
|
2018-03-23 02:18:13 +00:00
|
|
|
#ifdef _WIN32
|
2017-02-14 09:33:42 +00:00
|
|
|
|
2018-09-30 07:00:40 +00:00
|
|
|
#if !PPSSPP_PLATFORM(UWP)
|
|
|
|
#pragma comment(lib, "version.lib")
|
|
|
|
#endif
|
|
|
|
|
2017-02-14 09:33:42 +00:00
|
|
|
#include <cstdint>
|
2018-10-30 22:57:54 +00:00
|
|
|
#include <vector>
|
2017-02-14 09:33:42 +00:00
|
|
|
#include "OSVersion.h"
|
|
|
|
#include "Common/CommonWindows.h"
|
|
|
|
|
2018-09-30 07:00:40 +00:00
|
|
|
bool GetVersionFromKernel32(uint32_t &major, uint32_t &minor, uint32_t &build) {
|
|
|
|
#if PPSSPP_PLATFORM(UWP)
|
|
|
|
return false;
|
|
|
|
#else
|
|
|
|
DWORD handle = 0;
|
|
|
|
DWORD verSize = GetFileVersionInfoSizeA("kernel32.dll", &handle);
|
|
|
|
if (verSize == 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
std::vector<char> verData(verSize);
|
|
|
|
if (GetFileVersionInfoW(L"kernel32.dll", 0, verSize, &verData[0]) == 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
VS_FIXEDFILEINFO *buf = nullptr;
|
|
|
|
uint32_t sz = 0;
|
|
|
|
if (VerQueryValueW(&verData[0], L"\\", (void **)&buf, &sz) == 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
major = buf->dwProductVersionMS >> 16;
|
|
|
|
minor = buf->dwProductVersionMS & 0xFFFF;
|
|
|
|
build = buf->dwProductVersionLS >> 16;
|
|
|
|
return true;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-02-23 09:40:55 +00:00
|
|
|
bool DoesVersionMatchWindows(uint32_t major, uint32_t minor, uint32_t spMajor, uint32_t spMinor, bool greater) {
|
2017-02-24 17:59:41 +00:00
|
|
|
#if PPSSPP_PLATFORM(UWP)
|
|
|
|
if (greater)
|
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return major >= 7;
|
|
|
|
#else
|
2018-09-30 07:00:40 +00:00
|
|
|
if (spMajor == 0 && spMinor == 0) {
|
|
|
|
// "Applications not manifested for Windows 10 will return the Windows 8 OS version value (6.2)."
|
|
|
|
// Try to use kernel32.dll instead, for Windows 10+. Doesn't do SP versions.
|
|
|
|
uint32_t actualMajor, actualMinor, actualBuild;
|
|
|
|
if (GetVersionFromKernel32(actualMajor, actualMinor, actualBuild)) {
|
|
|
|
if (greater)
|
2018-09-30 07:18:45 +00:00
|
|
|
return actualMajor > major || (major == actualMajor && actualMinor >= minor);
|
2018-09-30 07:00:40 +00:00
|
|
|
return major == actualMajor && minor == actualMinor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-14 09:33:42 +00:00
|
|
|
uint64_t conditionMask = 0;
|
|
|
|
OSVERSIONINFOEX osvi;
|
|
|
|
ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
|
|
|
|
|
|
|
|
osvi.dwOSVersionInfoSize = sizeof(osvi);
|
|
|
|
osvi.dwMajorVersion = major;
|
|
|
|
osvi.dwMinorVersion = minor;
|
|
|
|
osvi.wServicePackMajor = spMajor;
|
|
|
|
osvi.wServicePackMinor = spMinor;
|
2017-02-23 09:40:55 +00:00
|
|
|
uint32_t op = greater ? VER_GREATER_EQUAL : VER_EQUAL;
|
2017-02-14 09:33:42 +00:00
|
|
|
|
|
|
|
VER_SET_CONDITION(conditionMask, VER_MAJORVERSION, op);
|
|
|
|
VER_SET_CONDITION(conditionMask, VER_MINORVERSION, op);
|
|
|
|
VER_SET_CONDITION(conditionMask, VER_SERVICEPACKMAJOR, op);
|
|
|
|
VER_SET_CONDITION(conditionMask, VER_SERVICEPACKMINOR, op);
|
|
|
|
|
|
|
|
const uint32_t typeMask = VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR;
|
|
|
|
|
|
|
|
return VerifyVersionInfo(&osvi, typeMask, conditionMask) != FALSE;
|
2017-02-24 17:59:41 +00:00
|
|
|
#endif
|
2017-02-14 09:33:42 +00:00
|
|
|
}
|
|
|
|
|
2017-02-24 19:50:27 +00:00
|
|
|
bool IsVistaOrHigher() {
|
|
|
|
#if PPSSPP_PLATFORM(UWP)
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
OSVERSIONINFOEX osvi;
|
|
|
|
DWORDLONG dwlConditionMask = 0;
|
|
|
|
int op = VER_GREATER_EQUAL;
|
|
|
|
ZeroMemory(&osvi, sizeof(osvi));
|
|
|
|
osvi.dwOSVersionInfoSize = sizeof(osvi);
|
|
|
|
osvi.dwMajorVersion = 6; // Vista is 6.0
|
|
|
|
osvi.dwMinorVersion = 0;
|
|
|
|
|
|
|
|
VER_SET_CONDITION(dwlConditionMask, VER_MAJORVERSION, op);
|
|
|
|
VER_SET_CONDITION(dwlConditionMask, VER_MINORVERSION, op);
|
|
|
|
|
|
|
|
return VerifyVersionInfo(&osvi, VER_MAJORVERSION | VER_MINORVERSION, dwlConditionMask) != FALSE;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-02-14 09:33:42 +00:00
|
|
|
std::string GetWindowsVersion() {
|
2017-02-23 09:40:55 +00:00
|
|
|
const bool IsWindowsXPSP2 = DoesVersionMatchWindows(5, 1, 2, 0, false);
|
|
|
|
const bool IsWindowsXPSP3 = DoesVersionMatchWindows(5, 1, 3, 0, false);
|
|
|
|
const bool IsWindowsVista = DoesVersionMatchWindows(6, 0, 0, 0, false);
|
|
|
|
const bool IsWindowsVistaSP1 = DoesVersionMatchWindows(6, 0, 1, 0, false);
|
|
|
|
const bool IsWindowsVistaSP2 = DoesVersionMatchWindows(6, 0, 2, 0, false);
|
|
|
|
const bool IsWindows7 = DoesVersionMatchWindows(6, 1, 0, 0, false);
|
|
|
|
const bool IsWindows7SP1 = DoesVersionMatchWindows(6, 1, 1, 0, false);
|
|
|
|
const bool IsWindows8 = DoesVersionMatchWindows(6, 2, 0, 0, false);
|
|
|
|
const bool IsWindows8_1 = DoesVersionMatchWindows(6, 3, 0, 0, false);
|
2018-09-30 07:00:40 +00:00
|
|
|
const bool IsWindows10 = DoesVersionMatchWindows(10, 0, 0, 0, false);
|
2017-02-23 09:40:55 +00:00
|
|
|
|
|
|
|
if (IsWindowsXPSP2) return "Microsoft Windows XP, Service Pack 2";
|
|
|
|
if (IsWindowsXPSP3) return "Microsoft Windows XP, Service Pack 3";
|
|
|
|
if (IsWindowsVista) return "Microsoft Windows Vista";
|
|
|
|
if (IsWindowsVistaSP1) return "Microsoft Windows Vista, Service Pack 1";
|
|
|
|
if (IsWindowsVistaSP2) return "Microsoft Windows Vista, Service Pack 2";
|
|
|
|
if (IsWindows7) return "Microsoft Windows 7";
|
|
|
|
if (IsWindows7SP1) return "Microsoft Windows 7, Service Pack 1";
|
2018-09-30 07:00:40 +00:00
|
|
|
if (IsWindows8) return "Microsoft Windows 8";
|
2017-02-23 09:40:55 +00:00
|
|
|
if (IsWindows8_1) return "Microsoft Windows 8.1";
|
2018-09-30 07:00:40 +00:00
|
|
|
if (IsWindows10) return "Microsoft Windows 10";
|
2017-02-14 09:33:42 +00:00
|
|
|
return "Unsupported version of Microsoft Windows.";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string GetWindowsSystemArchitecture() {
|
|
|
|
SYSTEM_INFO sysinfo;
|
|
|
|
ZeroMemory(&sysinfo, sizeof(SYSTEM_INFO));
|
|
|
|
GetNativeSystemInfo(&sysinfo);
|
|
|
|
|
2019-05-03 21:40:27 +00:00
|
|
|
switch (sysinfo.wProcessorArchitecture) {
|
|
|
|
case PROCESSOR_ARCHITECTURE_INTEL:
|
2017-02-14 09:33:42 +00:00
|
|
|
return "(x86)";
|
2019-05-03 21:40:27 +00:00
|
|
|
case PROCESSOR_ARCHITECTURE_AMD64:
|
|
|
|
return "(x64)";
|
|
|
|
case PROCESSOR_ARCHITECTURE_ARM:
|
2017-02-14 09:33:42 +00:00
|
|
|
return "(ARM)";
|
2019-05-03 21:40:27 +00:00
|
|
|
case PROCESSOR_ARCHITECTURE_ARM64:
|
|
|
|
return "(ARM64)";
|
|
|
|
default:
|
2017-02-14 09:33:42 +00:00
|
|
|
return "(Unknown)";
|
2019-05-03 21:40:27 +00:00
|
|
|
}
|
2017-02-14 09:33:42 +00:00
|
|
|
}
|
|
|
|
|
2018-03-23 02:18:13 +00:00
|
|
|
#endif
|