force compatibility modes on appropriate operating systems

This commit is contained in:
itsmattkc 2022-07-14 01:04:18 -07:00
parent e04a53fbe4
commit 0f12daa5ac
2 changed files with 52 additions and 13 deletions

View file

@ -2,6 +2,20 @@
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
<assemblyIdentity version="1.0.0.0" processorArchitecture="*" name="com.itsmattkc.Rebuilder" type="win32" />
<description>LEGO Island modding tool and launcher.</description>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- Windows 10 and Windows 11 -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
<!-- Windows 8.1 -->
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
<!-- Windows 8 -->
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
<!-- Windows 7 -->
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
<!-- Windows Vista -->
<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
</application>
</compatibility>
<dependency>
<dependentAssembly>
<assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="*" publicKeyToken="6595b64144ccf1df" language="*" />

View file

@ -2,9 +2,12 @@
#include <COMMDLG.H>
#include <SHLWAPI.H>
#include <STRING>
#include "../cmn/path.h"
#include "../res/resource.h"
typedef DWORD (WINAPI *GetLongPathName_t)(LPCSTR lpszShortPath, LPSTR lpszLongPath, DWORD cchBuffer);
HANDLE Launcher::Launch(HWND parent)
{
// Find the installation
@ -15,22 +18,44 @@ HANDLE Launcher::Launch(HWND parent)
}
// Set compatibility flags
HKEY hKey;
LPCTSTR str = TEXT("~ HIGHDPIAWARE 16BITCOLOR DWM8And16BitMitigation");
if (RegOpenKeyEx(HKEY_CURRENT_USER, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\AppCompatFlags\\Layers", 0, KEY_SET_VALUE, &hKey) == ERROR_SUCCESS) {
// Often we seem to get an 8.3 path which is not valid here, so resolve the full path now
TCHAR full_path[MAX_PATH];
GetLongPathName(filename, full_path, MAX_PATH);
MessageBoxA(0,full_path,0,0);
OSVERSIONINFO info;
ZeroMemory(&info, sizeof(OSVERSIONINFO));
info.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx(&info);
LONG ret = RegSetValueEx(hKey, full_path, 0, REG_SZ, (const BYTE *) str, strlen(str)+1);
if (ret != ERROR_SUCCESS) {
char buf[100];
sprintf(buf, "Failed to set compatibility flags: 0x%x. This may cause issues on newer versions of Windows.", ret);
MessageBox(parent, buf, 0, 0);
if (info.dwMajorVersion >= 5) {
HKEY hKey;
std::string compat = "~ HIGHDPIAWARE";
TCHAR configPath[MAX_PATH];
GetConfigFilename(configPath);
// If windowed, force a bit depth
if (!GetPrivateProfileInt(appName, "FullScreen", true, configPath)) {
if (info.dwMajorVersion >= 8) {
compat += " 16BITCOLOR";
} else {
compat += " 256COLOR";
}
compat += " DWM8And16BitMitigation";
}
RegCloseKey(hKey);
if (RegOpenKeyEx(HKEY_CURRENT_USER, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\AppCompatFlags\\Layers", 0, KEY_SET_VALUE, &hKey) == ERROR_SUCCESS) {
// Often we seem to get an 8.3 path which is not valid here, so resolve the full path now
TCHAR full_path[MAX_PATH];
GetLongPathName_t getLongPathName = (GetLongPathName_t) GetProcAddress(GetModuleHandle("KERNEL32.DLL"), "GetLongPathNameA");
getLongPathName(filename, full_path, MAX_PATH);
MessageBoxA(0,full_path,0,0);
LONG ret = RegSetValueEx(hKey, full_path, 0, REG_SZ, (const BYTE *) &compat[0], compat.size()+1);
if (ret != ERROR_SUCCESS) {
char buf[100];
sprintf(buf, "Failed to set compatibility flags: 0x%x. This may cause issues on newer versions of Windows.", ret);
MessageBox(parent, buf, 0, 0);
}
RegCloseKey(hKey);
}
}