| 47 | } |
| 48 | |
| 49 | void CheckIfRedistInstalled() |
| 50 | { |
| 51 | // Before doing any actions, check if VC redist is installed, because otherwise it can |
| 52 | // silently crash at any moment. Still allows to run the game in any case, even if user |
| 53 | // decides not to install redistributables. |
| 54 | |
| 55 | const char* redistKey = |
| 56 | #ifdef _WIN64 |
| 57 | R"(SOFTWARE\Microsoft\VisualStudio\14.0\VC\Runtimes\x64)"; |
| 58 | #else |
| 59 | R"(SOFTWARE\Microsoft\VisualStudio\14.0\VC\Runtimes\x86)"; |
| 60 | #endif |
| 61 | |
| 62 | HKEY hKey; |
| 63 | LSTATUS result = RegOpenKeyExA(HKEY_LOCAL_MACHINE, redistKey, 0, KEY_READ, &hKey); |
| 64 | if (result == ERROR_SUCCESS) |
| 65 | { |
| 66 | DWORD majorVersion = 0; |
| 67 | DWORD minorVersion = 0; |
| 68 | DWORD dataSize = sizeof(DWORD); |
| 69 | |
| 70 | if (RegQueryValueExA(hKey, "Major", NULL, NULL, (LPBYTE)&majorVersion, &dataSize) == ERROR_SUCCESS && |
| 71 | RegQueryValueExA(hKey, "Minor", NULL, NULL, (LPBYTE)&minorVersion, &dataSize) == ERROR_SUCCESS) |
| 72 | { |
| 73 | RegCloseKey(hKey); |
| 74 | |
| 75 | if (majorVersion >= 14 && minorVersion >= 40) |
| 76 | { |
| 77 | HMODULE hModule = LoadLibraryW(L"vcruntime140.dll"); |
| 78 | if (hModule != NULL) |
| 79 | { |
| 80 | FreeLibrary(hModule); |
| 81 | return; |
| 82 | } |
| 83 | } |
| 84 | } |
| 85 | else |
| 86 | { |
| 87 | RegCloseKey(hKey); |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | const char* redistUrl = |
| 92 | #ifdef _WIN64 |
| 93 | R"(https://aka.ms/vs/17/release/vc_redist.x64.exe)"; |
| 94 | #else |
| 95 | R"(https://aka.ms/vs/17/release/vc_redist.x86.exe)"; |
| 96 | #endif |
| 97 | |
| 98 | const char* message = "TombEngine requires Visual C++ 2015-2022 Redistributable to be installed. Would you like to download it now?"; |
| 99 | int msgBoxResult = MessageBoxA(NULL, message, "Missing libraries", MB_ICONWARNING | MB_OKCANCEL); |
| 100 | |
| 101 | if (msgBoxResult == IDOK) |
| 102 | { |
| 103 | HINSTANCE hResult = ShellExecuteA(NULL, "open", redistUrl, NULL, NULL, SW_SHOWNORMAL); |
| 104 | |
| 105 | if ((intptr_t)hResult <= 32) |
| 106 | { |