Index: cfgmgr/cfgmgr.cpp |
— | — | @@ -42,7 +42,7 @@ |
43 | 43 | timerid = SetTimer(hWnd, NULL, 5000, NULL);
|
44 | 44 | return TRUE;
|
45 | 45 | case WM_TIMER:
|
46 | | - if (wParam == timerid) EndDialog(hWnd, 0);
|
| 46 | + EndDialog(hWnd, 0);
|
47 | 47 | break;
|
48 | 48 | default:
|
49 | 49 | return FALSE;
|
— | — | @@ -82,11 +82,55 @@ |
83 | 83 | BOOL is64 = FALSE;
|
84 | 84 | if (iswow64) iswow64(GetCurrentProcess(), &is64);
|
85 | 85 | if (hKernel32) FreeLibrary(hKernel32);
|
86 | | - LRESULT error;
|
| 86 | + LRESULT error,error2;
|
87 | 87 | TCHAR filename[MAX_PATH + 1];
|
88 | 88 | TCHAR buffer[1024];
|
89 | 89 | TCHAR *bufferpos;
|
| 90 | + error = RegCreateKeyEx(HKEY_CURRENT_USER, _T("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\AppCompatFlags\\Layers"),
|
| 91 | + 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hKey, NULL);
|
| 92 | + if (error == ERROR_SUCCESS)
|
| 93 | + {
|
| 94 | + GetModuleFileName(NULL, filename, MAX_PATH);
|
| 95 | + ZeroMemory(buffer, 1024 * sizeof(TCHAR));
|
| 96 | + DWORD sizeout = 1024 * sizeof(TCHAR);
|
| 97 | + error2 = RegQueryValueEx(hKey, filename, NULL, NULL, (LPBYTE)buffer, &sizeout);
|
| 98 | + if (error2 == ERROR_SUCCESS)
|
| 99 | + {
|
| 100 | + if (_tcsstr(buffer,flag))
|
| 101 | + {
|
| 102 | + RegCloseKey(hKey);
|
| 103 | + return true;
|
| 104 | + }
|
| 105 | + else
|
| 106 | + {
|
| 107 | + _tcscat(buffer, _T(" "));
|
| 108 | + _tcscat(buffer, flag);
|
| 109 | + error2 = RegSetValueEx(hKey, filename, 0, REG_SZ, (BYTE*)buffer, (_tcslen(buffer) + 1)*sizeof(TCHAR));
|
| 110 | + if (error2 == ERROR_SUCCESS) ShowRestartDialog();
|
| 111 | + else
|
| 112 | + {
|
| 113 | + RegCloseKey(hKey);
|
| 114 | + return false;
|
| 115 | + }
|
| 116 | + }
|
| 117 | + }
|
| 118 | + else if (error2 == ERROR_FILE_NOT_FOUND)
|
| 119 | + {
|
| 120 | + error2 = RegSetValueEx(hKey, filename, 0, REG_SZ, (BYTE*)flag, (_tcslen(flag) + 1)*sizeof(TCHAR));
|
| 121 | + if (error2 == ERROR_SUCCESS) ShowRestartDialog();
|
| 122 | + else
|
| 123 | + {
|
| 124 | + RegCloseKey(hKey);
|
| 125 | + return false;
|
| 126 | + }
|
| 127 | + }
|
| 128 | + else
|
| 129 | + {
|
| 130 | + RegCloseKey(hKey);
|
| 131 | + return false;
|
| 132 | + }
|
90 | 133 |
|
| 134 | + }
|
91 | 135 | return false;
|
92 | 136 | }
|
93 | 137 |
|
— | — | @@ -105,11 +149,10 @@ |
106 | 150 | TCHAR buffer[1024];
|
107 | 151 | TCHAR *bufferpos;
|
108 | 152 | tstring writekey;
|
109 | | - bool accessdenied = false;
|
110 | 153 | // Check system first.
|
111 | | - if (is64) writekey.assign(_T("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\AppCompatFlags\\Layers"));
|
112 | | - else writekey.assign(_T("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\AppCompatFlags\\Layers"));
|
113 | | - error = RegOpenKeyEx(HKEY_LOCAL_MACHINE, writekey.c_str(), 0, KEY_READ, &hKey);
|
| 154 | + writekey.assign(_T("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\AppCompatFlags\\Layers"));
|
| 155 | + if (is64) error = RegOpenKeyEx(HKEY_LOCAL_MACHINE, writekey.c_str(), 0, KEY_READ | KEY_WOW64_64KEY, &hKey);
|
| 156 | + else error = RegOpenKeyEx(HKEY_LOCAL_MACHINE, writekey.c_str(), 0, KEY_READ, &hKey);
|
114 | 157 | if (error == ERROR_SUCCESS)
|
115 | 158 | {
|
116 | 159 | GetModuleFileName(NULL, filename, MAX_PATH);
|
— | — | @@ -120,8 +163,9 @@ |
121 | 164 | bufferpos = _tcsstr(buffer, flag);
|
122 | 165 | if (bufferpos)
|
123 | 166 | {
|
124 | | - memmove(bufferpos, bufferpos + _tcslen(flag), (_tcslen(bufferpos + _tcslen(flag)))*sizeof(TCHAR));
|
125 | | - error = RegOpenKeyEx(HKEY_LOCAL_MACHINE, writekey.c_str(), 0, KEY_WRITE, &hKeyWrite);
|
| 167 | + memmove(bufferpos, bufferpos + _tcslen(flag), (_tcslen(bufferpos + _tcslen(flag))+1)*sizeof(TCHAR));
|
| 168 | + if(is64) error = RegOpenKeyEx(HKEY_LOCAL_MACHINE, writekey.c_str(), 0, KEY_WRITE | KEY_WOW64_64KEY, &hKeyWrite);
|
| 169 | + else error = RegOpenKeyEx(HKEY_LOCAL_MACHINE, writekey.c_str(), 0, KEY_WRITE, &hKeyWrite);
|
126 | 170 | if (error == ERROR_SUCCESS)
|
127 | 171 | {
|
128 | 172 | error = RegSetValueEx(hKeyWrite, filename, 0, REG_SZ, (BYTE*)buffer, (_tcslen(bufferpos + _tcslen(flag)))*sizeof(TCHAR)+sizeof(TCHAR));
|
— | — | @@ -151,17 +195,11 @@ |
152 | 196 | WaitForSingleObject(info.hProcess, INFINITE);
|
153 | 197 | GetExitCodeProcess(info.hProcess, (LPDWORD)&error);
|
154 | 198 | }
|
155 | | - if (!error)
|
156 | | - {
|
157 | | - ShowRestartDialog();
|
158 | | - }
|
| 199 | + if (!error) ShowRestartDialog();
|
159 | 200 | else MessageBox(NULL, _T("Registry value could not be updated. Your program may crash as a result."), _T("Error"), MB_OK | MB_ICONWARNING);
|
160 | 201 | return false;
|
161 | 202 | }
|
162 | | - else if (error == ERROR_SUCCESS)
|
163 | | - {
|
164 | | - ShowRestartDialog();
|
165 | | - }
|
| 203 | + else if (error == ERROR_SUCCESS) ShowRestartDialog();
|
166 | 204 | }
|
167 | 205 | }
|
168 | 206 | RegCloseKey(hKey);
|
— | — | @@ -179,8 +217,8 @@ |
180 | 218 | bufferpos = _tcsstr(buffer, flag);
|
181 | 219 | if (bufferpos)
|
182 | 220 | {
|
183 | | - memmove(bufferpos, bufferpos + _tcslen(flag), (_tcslen(bufferpos + _tcslen(flag)))*sizeof(TCHAR));
|
184 | | - error = RegOpenKeyEx(HKEY_LOCAL_MACHINE, writekey.c_str(), 0, KEY_WRITE, &hKeyWrite);
|
| 221 | + memmove(bufferpos, bufferpos + _tcslen(flag), (_tcslen(bufferpos + _tcslen(flag))+1)*sizeof(TCHAR));
|
| 222 | + error = RegOpenKeyEx(HKEY_CURRENT_USER, writekey.c_str(), 0, KEY_WRITE, &hKeyWrite);
|
185 | 223 | if (error == ERROR_SUCCESS)
|
186 | 224 | {
|
187 | 225 | error = RegSetValueEx(hKeyWrite, filename, 0, REG_SZ, (BYTE*)buffer, (_tcslen(bufferpos + _tcslen(flag)))*sizeof(TCHAR)+sizeof(TCHAR));
|
— | — | @@ -560,7 +598,7 @@ |
561 | 599 | if (hSHCore) FreeLibrary(hSHCore);
|
562 | 600 | if (hUser32) FreeLibrary(hUser32);
|
563 | 601 | }
|
564 | | - DelCompatFlag(_T("DWM8and16BitMitigation"));
|
| 602 | + DelCompatFlag(_T("DWM8And16BitMitigation"));
|
565 | 603 | }
|
566 | 604 | }
|
567 | 605 | void GetGlobalConfig(DXGLCFG *cfg)
|