DXGL r797 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r796‎ | r797 | r798 >
Date:18:23, 1 April 2018
Author:admin
Status:new
Tags:
Comment:
Update help URL in help file.
Make DXGL installation migrate the DXGL Test profile to DXGL Config.
Modified paths:
  • /Help/index.html (modified) (history)
  • /cfgmgr/cfgmgr.c (modified) (history)
  • /cfgmgr/cfgmgr.h (modified) (history)
  • /dxglcfg/dxglcfg.cpp (modified) (history)

Diff [purge]

Index: Help/index.html
——@@ -1,4 +1,4 @@
2 -<!DOCTYPE html>
 2+<!DOCTYPE html>
33 <!--[if IE 6]>
44 <html id="ie6" lang="en-US" prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb#">
55 <![endif]-->
——@@ -31,13 +31,6 @@
3232 <h2 id="site-description"></h2>
3333 </hgroup>
3434 <img src="images/dxgl-header.png" width="940" height="198" alt="DXGL" />
35 - <div class="only-search with-image">
36 - <form method="get" id="searchform" action="https://www.dxgl.info/">
37 - <label for="s" class="assistive-text">Search</label>
38 - <input type="text" class="field" name="s" id="s" placeholder="Search" />
39 - <input type="submit" class="submit" name="submit" id="searchsubmit" value="Search" />
40 - </form>
41 - </div>
4235 </header><!-- #branding -->
4336
4437
——@@ -50,7 +43,7 @@
5144 </header><!-- .entry-header -->
5245 <div class="entry-content">
5346 Notice: Offline help is not currently available. To get help for DXGL please go to
54 - <a href="https://www.dxgl.info/help/">https://www.dxgl.info/help</a> to access the online help.
 47+ <a href="https://www.dxgl.info/help.php?v=0.5.13">https://www.dxgl.info/help.php?v=0.5.13</a> to access the online help.
5548 </div><!-- .entry-content -->
5649 <footer class="entry-meta">
5750 </footer><!-- .entry-meta -->
——@@ -61,7 +54,7 @@
6255 <footer id="colophon" role="contentinfo">
6356 <div id="supplementary" class="one">
6457 <div id="first" class="widget-area" role="complementary">
65 - <aside id="text-3" class="widget widget_text"><h3 class="widget-title">DXGL Copyright © 2011-2017 William Feely</h3>
 58+ <aside id="text-3" class="widget widget_text"><h3 class="widget-title">DXGL Copyright © 2011-2018 William Feely</h3>
6659 </aside> </div><!-- #first .widget-area -->
6760 </div><!-- #supplementary -->
6861 </footer><!-- #colophon -->
Index: cfgmgr/cfgmgr.c
——@@ -1363,9 +1363,120 @@
13641364 }
13651365 }
13661366
 1367+// Checks for obsolete DXGL Test registry entry and renames it to DXGLCFG.
 1368+
 1369+void UpgradeDXGLTestToDXGLCfg()
 1370+{
 1371+ Sha256Context sha_context;
 1372+ SHA256_HASH sha256;
 1373+ TCHAR sha256string[65];
 1374+ TCHAR installpath[MAX_PATH + 1];
 1375+ TCHAR profilepath[MAX_PATH + 80];
 1376+ TCHAR destpath[MAX_PATH + 80];
 1377+ LONG error;
 1378+ DWORD sizeout = (MAX_PATH + 1) * sizeof(TCHAR);
 1379+ DWORD sizeout2;
 1380+ HKEY hKeyInstall = NULL;
 1381+ HKEY hKeyProfile = NULL;
 1382+ HKEY hKeyDest = NULL;
 1383+ DWORD numvalue;
 1384+ DWORD olddirsize = 1024;
 1385+ TCHAR *olddir = NULL;
 1386+ DWORD oldvaluesize = 1024;
 1387+ TCHAR *oldvalue = NULL;
 1388+ DWORD regtype;
 1389+ int i;
 1390+ error = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("Software\\DXGL"), 0, KEY_READ, &hKeyInstall);
 1391+ if (error == ERROR_SUCCESS)
 1392+ {
 1393+ error = RegQueryValueEx(hKeyInstall, _T("InstallDir"), NULL, NULL, (LPBYTE)installpath, &sizeout);
 1394+ if (error == ERROR_SUCCESS)
 1395+ {
 1396+ _tcslwr(installpath);
 1397+ Sha256Initialise(&sha_context);
 1398+ Sha256Update(&sha_context, installpath, _tcslen(installpath));
 1399+ Sha256Finalise(&sha_context, &sha256);
 1400+ for (i = 0; i < (256 / 8); i++)
 1401+ {
 1402+ sha256string[i * 2] = (TCHAR)hexdigit(sha256.bytes[i] >> 4);
 1403+ sha256string[(i * 2) + 1] = (TCHAR)hexdigit(sha256.bytes[i] & 0xF);
 1404+ }
 1405+ sha256string[256 / 4] = 0;
 1406+ _tcscpy(profilepath, _T("Software\\DXGL\\Profiles\\dxgltest.exe-"));
 1407+ _tcscat(profilepath, sha256string);
 1408+ _tcscpy(destpath, _T("Software\\DXGL\\Profiles\\dxglcfg.exe-"));
 1409+ _tcscat(destpath, sha256string);
 1410+ error = RegOpenKeyEx(HKEY_CURRENT_USER, profilepath, 0, KEY_READ, &hKeyProfile);
 1411+ if (error == ERROR_SUCCESS)
 1412+ {
 1413+ error = RegOpenKeyEx(HKEY_CURRENT_USER, destpath, 0, KEY_READ, &hKeyDest);
 1414+ if (error == ERROR_SUCCESS) // Clear spurious DXGLCfg entry
 1415+ {
 1416+ RegCloseKey(hKeyDest);
 1417+ RegDeleteKey(HKEY_CURRENT_USER, destpath);
 1418+ }
 1419+ // Copy over to new key
 1420+ error = RegCreateKeyEx(HKEY_CURRENT_USER, destpath, 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hKeyDest, NULL);
 1421+ if (error == ERROR_SUCCESS)
 1422+ {
 1423+ olddir = malloc(olddirsize);
 1424+ oldvalue = malloc(oldvaluesize);
 1425+ numvalue = 0;
 1426+ do
 1427+ {
 1428+ sizeout = olddirsize;
 1429+ sizeout2 = oldvaluesize;
 1430+ error = RegEnumValue(hKeyProfile, numvalue, olddir, &sizeout, NULL, &regtype, oldvalue, &sizeout2);
 1431+ if (error == ERROR_MORE_DATA)
 1432+ {
 1433+ if (sizeout > olddirsize)
 1434+ {
 1435+ olddirsize = sizeout;
 1436+ olddir = realloc(olddir, olddirsize);
 1437+ if (!olddir)
 1438+ {
 1439+ MessageBox(NULL, _T("Out of memory updating registry"), _T("Fatal error"), MB_ICONSTOP | MB_OK);
 1440+ ExitProcess(error);
 1441+ }
 1442+ }
 1443+ if (sizeout2 > oldvaluesize)
 1444+ {
 1445+ oldvaluesize = sizeout2;
 1446+ oldvalue = realloc(oldvalue, oldvaluesize);
 1447+ if (!oldvalue)
 1448+ {
 1449+ MessageBox(NULL, _T("Out of memory updating registry"), _T("Fatal error"), MB_ICONSTOP | MB_OK);
 1450+ ExitProcess(error);
 1451+ }
 1452+ }
 1453+ sizeout = olddirsize;
 1454+ sizeout2 = oldvaluesize;
 1455+ error = RegEnumValue(hKeyProfile, numvalue, olddir, &sizeout, NULL, &regtype, oldvalue, &sizeout2);
 1456+ }
 1457+ if (error == ERROR_SUCCESS)
 1458+ {
 1459+ if (_tcsnicmp(olddir, _T("InstallPaths"), sizeout))
 1460+ RegSetValueEx(hKeyDest, olddir, 0, regtype, oldvalue, sizeout2);
 1461+ }
 1462+ numvalue++;
 1463+ } while (error == ERROR_SUCCESS);
 1464+ RegCloseKey(hKeyDest);
 1465+ free(olddir);
 1466+ free(oldvalue);
 1467+ }
 1468+ // Delete old key
 1469+ RegCloseKey(hKeyProfile);
 1470+ RegDeleteKey(HKEY_CURRENT_USER, profilepath);
 1471+ }
 1472+ }
 1473+ }
 1474+ if (hKeyInstall) RegCloseKey(hKeyInstall);
 1475+}
 1476+
 1477+
13671478 /**
13681479 * Checks the registry configuration version and if outdated upgrades to
1369 - * the latest version - currently version 1
 1480+ * the latest version - currently version 2
13701481 * Alpha version configuration is assumed to be version 0.
13711482 */
13721483 void UpgradeConfig()
Index: cfgmgr/cfgmgr.h
——@@ -130,6 +130,7 @@
131131 void GetConfig(DXGLCFG *cfg, DXGLCFG *mask, LPCTSTR name);
132132 void SetConfig(const DXGLCFG *cfg, const DXGLCFG *mask, LPCTSTR name);
133133 void GetDirFromPath(LPTSTR path);
 134+void UpgradeDXGLTestToDXGLCfg();
134135 void UpgradeConfig();
135136 void ReadAppINIOptions(LPCTSTR path, app_ini_options *options);
136137 void SaveWindowSettings(const DXGLCFG *cfg);
Index: dxglcfg/dxglcfg.cpp
——@@ -4047,6 +4047,7 @@
40484048 if (!_tcsnicmp(lpCmdLine, _T("profile_install"), 15))
40494049 {
40504050 // FIXME: Remove DXGL Config profile
 4051+ UpgradeDXGLTestToDXGLCfg();
40514052 LPDIRECTDRAW lpdd;
40524053 DirectDrawCreate(NULL, &lpdd, NULL);
40534054 IDirectDraw_Release(lpdd);