DXGL r414 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r413‎ | r414 | r415 >
Date:19:05, 30 March 2014
Author:admin
Status:new
Tags:
Comment:
Fix deleting compatibility flags.
Implement adding compatibility flags.
Modified paths:
  • /cfgmgr/cfgmgr.cpp (modified) (history)

Diff [purge]

Index: cfgmgr/cfgmgr.cpp
@@ -42,7 +42,7 @@
4343 timerid = SetTimer(hWnd, NULL, 5000, NULL);
4444 return TRUE;
4545 case WM_TIMER:
46 - if (wParam == timerid) EndDialog(hWnd, 0);
 46+ EndDialog(hWnd, 0);
4747 break;
4848 default:
4949 return FALSE;
@@ -82,11 +82,55 @@
8383 BOOL is64 = FALSE;
8484 if (iswow64) iswow64(GetCurrentProcess(), &is64);
8585 if (hKernel32) FreeLibrary(hKernel32);
86 - LRESULT error;
 86+ LRESULT error,error2;
8787 TCHAR filename[MAX_PATH + 1];
8888 TCHAR buffer[1024];
8989 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+ }
90133
 134+ }
91135 return false;
92136 }
93137
@@ -105,11 +149,10 @@
106150 TCHAR buffer[1024];
107151 TCHAR *bufferpos;
108152 tstring writekey;
109 - bool accessdenied = false;
110153 // 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);
114157 if (error == ERROR_SUCCESS)
115158 {
116159 GetModuleFileName(NULL, filename, MAX_PATH);
@@ -120,8 +163,9 @@
121164 bufferpos = _tcsstr(buffer, flag);
122165 if (bufferpos)
123166 {
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);
126170 if (error == ERROR_SUCCESS)
127171 {
128172 error = RegSetValueEx(hKeyWrite, filename, 0, REG_SZ, (BYTE*)buffer, (_tcslen(bufferpos + _tcslen(flag)))*sizeof(TCHAR)+sizeof(TCHAR));
@@ -151,17 +195,11 @@
152196 WaitForSingleObject(info.hProcess, INFINITE);
153197 GetExitCodeProcess(info.hProcess, (LPDWORD)&error);
154198 }
155 - if (!error)
156 - {
157 - ShowRestartDialog();
158 - }
 199+ if (!error) ShowRestartDialog();
159200 else MessageBox(NULL, _T("Registry value could not be updated. Your program may crash as a result."), _T("Error"), MB_OK | MB_ICONWARNING);
160201 return false;
161202 }
162 - else if (error == ERROR_SUCCESS)
163 - {
164 - ShowRestartDialog();
165 - }
 203+ else if (error == ERROR_SUCCESS) ShowRestartDialog();
166204 }
167205 }
168206 RegCloseKey(hKey);
@@ -179,8 +217,8 @@
180218 bufferpos = _tcsstr(buffer, flag);
181219 if (bufferpos)
182220 {
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);
185223 if (error == ERROR_SUCCESS)
186224 {
187225 error = RegSetValueEx(hKeyWrite, filename, 0, REG_SZ, (BYTE*)buffer, (_tcslen(bufferpos + _tcslen(flag)))*sizeof(TCHAR)+sizeof(TCHAR));
@@ -560,7 +598,7 @@
561599 if (hSHCore) FreeLibrary(hSHCore);
562600 if (hUser32) FreeLibrary(hUser32);
563601 }
564 - DelCompatFlag(_T("DWM8and16BitMitigation"));
 602+ DelCompatFlag(_T("DWM8And16BitMitigation"));
565603 }
566604 }
567605 void GetGlobalConfig(DXGLCFG *cfg)