DXGL r422 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r421‎ | r422 | r423 >
Date:23:29, 7 April 2014
Author:admin
Status:new
Tags:
Comment:
Prevent initial ddraw.dll loading from installing a registry key.
Modified paths:
  • /cfgmgr/cfgmgr.cpp (modified) (history)
  • /cfgmgr/cfgmgr.h (modified) (history)
  • /dxglcfg/dxglcfg.cpp (modified) (history)

Diff [purge]

Index: cfgmgr/cfgmgr.cpp
@@ -604,10 +604,14 @@
605605 regkey.append(_T("-"));
606606 regkey.append(crcstr);
607607 }
608 - GetGlobalConfig(cfg);
609 - RegCreateKeyEx(HKEY_CURRENT_USER,regkey.c_str(),0,NULL,0,KEY_ALL_ACCESS,NULL,&hKey,NULL);
610 - ReadSettings(hKey,cfg,NULL,false,true,NULL);
611 - RegCloseKey(hKey);
 608+ GetGlobalConfig(cfg, initial);
 609+ if (initial) RegOpenKeyEx(HKEY_CURRENT_USER, regkey.c_str(), 0, KEY_READ, &hKey);
 610+ else RegCreateKeyEx(HKEY_CURRENT_USER,regkey.c_str(),0,NULL,0,KEY_ALL_ACCESS,NULL,&hKey,NULL);
 611+ if (hKey)
 612+ {
 613+ ReadSettings(hKey, cfg, NULL, false, true, NULL);
 614+ RegCloseKey(hKey);
 615+ }
612616 hKey = NULL;
613617 HMODULE hSHCore = NULL;
614618 HMODULE hUser32 = NULL;
@@ -645,23 +649,27 @@
646650 }
647651 DelCompatFlag(_T("DWM8And16BitMitigation"), initial);
648652 }
649 -void GetGlobalConfig(DXGLCFG *cfg)
 653+void GetGlobalConfig(DXGLCFG *cfg, bool initial)
650654 {
651655 HKEY hKey;
652656 ZeroMemory(cfg,sizeof(DXGLCFG));
653657 cfg->DPIScale = 1;
654 - RegCreateKeyEx(HKEY_CURRENT_USER,regkeyglobal,0,NULL,0,KEY_ALL_ACCESS,NULL,&hKey,NULL);
655 - ReadSettings(hKey,cfg,NULL,true,false,NULL);
656 - if(!cfg->Windows8Detected)
 658+ if (initial) RegOpenKeyEx(HKEY_CURRENT_USER, regkeyglobal, 0, KEY_READ, &hKey);
 659+ else RegCreateKeyEx(HKEY_CURRENT_USER, regkeyglobal, 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hKey, NULL);
 660+ if (hKey)
657661 {
658 - OSVERSIONINFO osver;
659 - osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
660 - GetVersionEx(&osver);
661 - if(osver.dwMajorVersion > 6) cfg->Windows8Detected = true;
662 - if((osver.dwMajorVersion == 6) && (osver.dwMinorVersion >= 2)) cfg->Windows8Detected = true;
663 - if(cfg->Windows8Detected) cfg->AllColorDepths = true;
 662+ ReadSettings(hKey, cfg, NULL, true, false, NULL);
 663+ if (!cfg->Windows8Detected)
 664+ {
 665+ OSVERSIONINFO osver;
 666+ osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
 667+ GetVersionEx(&osver);
 668+ if (osver.dwMajorVersion > 6) cfg->Windows8Detected = true;
 669+ if ((osver.dwMajorVersion == 6) && (osver.dwMinorVersion >= 2)) cfg->Windows8Detected = true;
 670+ if (cfg->Windows8Detected) cfg->AllColorDepths = true;
 671+ }
 672+ RegCloseKey(hKey);
664673 }
665 - RegCloseKey(hKey);
666674 }
667675
668676 void GetConfig(DXGLCFG *cfg, DXGLCFG *mask, LPCTSTR name)
Index: cfgmgr/cfgmgr.h
@@ -45,7 +45,7 @@
4646 void ReadSettings(HKEY hKey, DXGLCFG *cfg, DXGLCFG *mask, bool global, bool dll, LPTSTR dir);
4747 void WriteSettings(HKEY hKey, const DXGLCFG *cfg, const DXGLCFG *mask, bool global);
4848 void GetCurrentConfig(DXGLCFG *cfg, bool initial);
49 -void GetGlobalConfig(DXGLCFG *cfg);
 49+void GetGlobalConfig(DXGLCFG *cfg, bool initial);
5050 void SetGlobalConfig(const DXGLCFG *cfg);
5151 void GetConfig(DXGLCFG *cfg, DXGLCFG *mask, LPCTSTR name);
5252 void SetConfig(const DXGLCFG *cfg, const DXGLCFG *mask, LPCTSTR name);
Index: dxglcfg/dxglcfg.cpp
@@ -460,7 +460,7 @@
461461 apps = (app_setting *)malloc(maxapps*sizeof(app_setting));
462462 apps[0].name = new tstring(_T("Global"));
463463 apps[0].regkey = new tstring(_T("Global"));
464 - GetGlobalConfig(&apps[0].cfg);
 464+ GetGlobalConfig(&apps[0].cfg, false);
465465 cfg = &apps[0].cfg;
466466 cfgmask = &apps[0].mask;
467467 dirty = &apps[0].dirty;