DXGL r743 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r742‎ | r743 | r744 >
Date:05:47, 10 September 2017
Author:admin
Status:new
Tags:
Comment:
Fix and verify NoOverwrite, NoUninstall, and BundledDDrawSHA256.
Sync UpgradeDXGL in dxglcfg2.c with dxglcfg.c
Modified paths:
  • /cfgmgr/cfgmgr.c (modified) (history)
  • /dxglcfg/dxglcfg.c (modified) (history)
  • /dxglcfg2/dxglcfg2.c (modified) (history)

Diff [purge]

Index: cfgmgr/cfgmgr.c
@@ -1402,6 +1402,8 @@
14031403 char buffer[512];
14041404 DWORD bytesread;
14051405 TCHAR path2[MAX_PATH + 1];
 1406+ options->NoOverwrite = FALSE;
 1407+ options->NoUninstall = FALSE;
14061408 ZeroMemory(options->sha256, 65*sizeof(char));
14071409 ZeroMemory(options->sha256comp, 65*sizeof(char));
14081410 _tcsncpy(path2, path, MAX_PATH + 1);
@@ -1413,11 +1415,6 @@
14141416 ini_parse_file(file, ReadINIOptionsCallback, options);
14151417 fclose(file);
14161418 }
1417 - else
1418 - {
1419 - options->NoOverwrite = FALSE;
1420 - options->NoUninstall = FALSE;
1421 - }
14221419 // Check for existing ddraw.dll and get SHA256 sum
14231420 if ((options->sha256comp[0] != 0) && !options->NoOverwrite)
14241421 {
@@ -1434,7 +1431,7 @@
14351432 {
14361433 while (1)
14371434 {
1438 - ReadFile(file, buffer, 512, &bytesread, NULL);
 1435+ ReadFile(file2, buffer, 512, &bytesread, NULL);
14391436 if (!bytesread) break;
14401437 Sha256Update(&sha_context, buffer, bytesread);
14411438 if (bytesread < 512) break;
Index: dxglcfg/dxglcfg.c
@@ -85,6 +85,7 @@
8686 BOOL installed = FALSE;
8787 BOOL dxgl_installdir = FALSE;
8888 BOOL old_dxgl = TRUE;
 89+ BOOL backupped = FALSE;
8990 TCHAR command[MAX_PATH + 37];
9091 SHELLEXECUTEINFO shex;
9192 DWORD exitcode;
@@ -142,10 +143,10 @@
143144 DirectDraw library in your game folder."), _T("Error"), MB_OK | MB_ICONERROR);
144145 return 0; // Continue to install registry key anyway
145146 }
146 - if (!memcmp(inioptions.sha256, inioptions.sha256comp, 64))
 147+ if ((inioptions.sha256[0] != 0) && !memcmp(inioptions.sha256, inioptions.sha256comp, 64))
147148 // Detected original ddraw matches INI hash
148149 {
149 - error = CopyFile(srcpath, backuppath, FALSE);
 150+ error = CopyFile(destpath, backuppath, FALSE);
150151 if (!error)
151152 {
152153 error = GetLastError();
@@ -166,8 +167,12 @@
167168 return exitcode;
168169 }
169170 }
 171+ else backupped = TRUE;
170172 }
 173+ error = SetErrorMode(SEM_FAILCRITICALERRORS);
 174+ SetErrorMode(error | SEM_FAILCRITICALERRORS);
171175 hmod = LoadLibrary(destpath);
 176+ SetErrorMode(error);
172177 if(hmod)
173178 {
174179 if(GetProcAddress(hmod,"IsDXGLDDraw") || force) old_dxgl = TRUE;
@@ -195,6 +200,10 @@
196201 error = CopyFile(srcpath, destpath, FALSE);
197202 goto error_loop;
198203 }
 204+ else
 205+ {
 206+ if (backupped) DeleteFile(backuppath);
 207+ }
199208 }
200209 }
201210 if((error == ERROR_ACCESS_DENIED) && !admin)
@@ -264,7 +273,10 @@
265274 shipped with a custom DirectDraw library."), _T("Warning"), MB_OK | MB_ICONWARNING);
266275 return 0; // Continue to delete registry profile.
267276 }
 277+ error = SetErrorMode(SEM_FAILCRITICALERRORS);
 278+ SetErrorMode(error | SEM_FAILCRITICALERRORS);
268279 hmod = LoadLibrary(path);
 280+ SetErrorMode(error);
269281 if(hmod)
270282 {
271283 if(!GetProcAddress(hmod,"IsDXGLDDraw")) old_dxgl = FALSE;
@@ -1687,11 +1699,14 @@
16881700 if (error == ERROR_FILE_EXISTS)
16891701 {
16901702 if (inioptions.NoOverwrite) continue;
1691 - if (!memcmp(inioptions.sha256, inioptions.sha256comp, 64))
 1703+ if ((inioptions.sha256[0] != 0) && !memcmp(inioptions.sha256, inioptions.sha256comp, 64))
16921704 // Detected original ddraw matches INI hash
16931705 CopyFile(srcpath, backuppath, FALSE);
16941706 old_dxgl = FALSE;
 1707+ error = SetErrorMode(SEM_FAILCRITICALERRORS);
 1708+ SetErrorMode(error | SEM_FAILCRITICALERRORS);
16951709 hmod = LoadLibrary(destpath);
 1710+ SetErrorMode(error);
16961711 if (hmod)
16971712 {
16981713 if (GetProcAddress(hmod, "IsDXGLDDraw")) old_dxgl = TRUE;
@@ -1786,7 +1801,10 @@
17871802 if (GetFileAttributes(destpath) != INVALID_FILE_ATTRIBUTES)
17881803 {
17891804 old_dxgl = FALSE;
 1805+ error = SetErrorMode(SEM_FAILCRITICALERRORS);
 1806+ SetErrorMode(error | SEM_FAILCRITICALERRORS);
17901807 hmod = LoadLibrary(destpath);
 1808+ SetErrorMode(error);
17911809 if (hmod)
17921810 {
17931811 if (GetProcAddress(hmod, "IsDXGLDDraw")) old_dxgl = TRUE;
Index: dxglcfg2/dxglcfg2.c
@@ -133,6 +133,7 @@
134134 BOOL installed = FALSE;
135135 BOOL dxgl_installdir = FALSE;
136136 BOOL old_dxgl = TRUE;
 137+ BOOL backupped = FALSE;
137138 TCHAR command[MAX_PATH + 37];
138139 SHELLEXECUTEINFO shex;
139140 DWORD exitcode;
@@ -190,10 +191,10 @@
191192 DirectDraw library in your game folder."), _T("Error"), MB_OK | MB_ICONERROR);
192193 return 0; // Continue to install registry key anyway
193194 }
194 - if (!memcmp(inioptions.sha256, inioptions.sha256comp, 64))
 195+ if ((inioptions.sha256[0] != 0) && !memcmp(inioptions.sha256, inioptions.sha256comp, 64))
195196 // Detected original ddraw matches INI hash
196197 {
197 - error = CopyFile(srcpath, backuppath, FALSE);
 198+ error = CopyFile(destpath, backuppath, FALSE);
198199 if (!error)
199200 {
200201 error = GetLastError();
@@ -214,8 +215,12 @@
215216 return exitcode;
216217 }
217218 }
 219+ else backupped = TRUE;
218220 }
 221+ error = SetErrorMode(SEM_FAILCRITICALERRORS);
 222+ SetErrorMode(error | SEM_FAILCRITICALERRORS);
219223 hmod = LoadLibrary(destpath);
 224+ SetErrorMode(error);
220225 if(hmod)
221226 {
222227 if(GetProcAddress(hmod,"IsDXGLDDraw") || force) old_dxgl = TRUE;
@@ -243,6 +248,10 @@
244249 error = CopyFile(srcpath, destpath, FALSE);
245250 goto error_loop;
246251 }
 252+ else
 253+ {
 254+ if (backupped) DeleteFile(backuppath);
 255+ }
247256 }
248257 }
249258 if((error == ERROR_ACCESS_DENIED) && !admin)
@@ -312,7 +321,10 @@
313322 shipped with a custom DirectDraw library."), _T("Warning"), MB_OK | MB_ICONWARNING);
314323 return 0; // Continue to delete registry profile.
315324 }
 325+ error = SetErrorMode(SEM_FAILCRITICALERRORS);
 326+ SetErrorMode(error | SEM_FAILCRITICALERRORS);
316327 hmod = LoadLibrary(path);
 328+ SetErrorMode(error);
317329 if(hmod)
318330 {
319331 if(!GetProcAddress(hmod,"IsDXGLDDraw")) old_dxgl = FALSE;
@@ -1904,6 +1916,9 @@
19051917 TCHAR installpath[MAX_PATH + 1];
19061918 TCHAR srcpath[MAX_PATH + 1];
19071919 TCHAR destpath[MAX_PATH + 1];
 1920+ TCHAR inipath[MAX_PATH + 1];
 1921+ TCHAR backuppath[MAX_PATH + 1];
 1922+ app_ini_options inioptions;
19081923 HMODULE hmod;
19091924 UpgradeConfig();
19101925 regbuffersize = 1024;
@@ -1948,8 +1963,12 @@
19491964 if (regbuffer[0] != 0)
19501965 {
19511966 _tcsncpy(destpath, regbuffer, MAX_PATH + 1);
1952 - _tcscat(destpath, _T("\\"));
1953 - _tcscat(destpath, _T("ddraw.dll"));
 1967+ _tcscat(destpath, _T("\\ddraw.dll"));
 1968+ _tcsncpy(inipath, regbuffer, MAX_PATH + 1);
 1969+ _tcscat(inipath, _T("\\dxgl.ini"));
 1970+ _tcsncpy(backuppath, regbuffer, MAX_PATH + 1);
 1971+ _tcscat(backuppath, _T("\\ddraw.dll.dxgl-backup"));
 1972+ ReadAppINIOptions(inipath, &inioptions);
19541973 error = CopyFile(srcpath, destpath, TRUE);
19551974 if (!error)
19561975 {
@@ -1956,8 +1975,15 @@
19571976 error = GetLastError();
19581977 if (error == ERROR_FILE_EXISTS)
19591978 {
 1979+ if (inioptions.NoOverwrite) continue;
 1980+ if ((inioptions.sha256[0] != 0) && !memcmp(inioptions.sha256, inioptions.sha256comp, 64))
 1981+ // Detected original ddraw matches INI hash
 1982+ CopyFile(srcpath, backuppath, FALSE);
19601983 old_dxgl = FALSE;
 1984+ error = SetErrorMode(SEM_FAILCRITICALERRORS);
 1985+ SetErrorMode(error | SEM_FAILCRITICALERRORS);
19611986 hmod = LoadLibrary(destpath);
 1987+ SetErrorMode(error);
19621988 if (hmod)
19631989 {
19641990 if (GetProcAddress(hmod, "IsDXGLDDraw")) old_dxgl = TRUE;
@@ -2052,7 +2078,10 @@
20532079 if (GetFileAttributes(destpath) != INVALID_FILE_ATTRIBUTES)
20542080 {
20552081 old_dxgl = FALSE;
 2082+ error = SetErrorMode(SEM_FAILCRITICALERRORS);
 2083+ SetErrorMode(error | SEM_FAILCRITICALERRORS);
20562084 hmod = LoadLibrary(destpath);
 2085+ SetErrorMode(error);
20572086 if (hmod)
20582087 {
20592088 if (GetProcAddress(hmod, "IsDXGLDDraw")) old_dxgl = TRUE;