DXGL r722 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r721‎ | r722 | r723 >
Date:15:39, 10 July 2017
Author:admin
Status:new
Tags:
Comment:
Implement INI options NoWriteRegistry and OverrideDefaults.
Revert rejected PR from inih.
Modified paths:
  • /cfgmgr/ReadMe.txt (modified) (history)
  • /cfgmgr/cfgmgr.c (modified) (history)
  • /cfgmgr/cfgmgr.h (modified) (history)
  • /cfgmgr/inih/ini.c (modified) (history)
  • /cfgmgr/inih/ini.h (modified) (history)
  • /dxgl-example.ini (modified) (history)

Diff [purge]

Index: cfgmgr/ReadMe.txt
@@ -1,5 +1,17 @@
22 Struct DXGLCFG
33
 4+member NoWriteRegistry
 5+INI Entry NoWriteRegistry
 6+INI Group system
 7+Does not have a registry value.
 8+If nonzero, DXGL will not write a profile to the registry.
 9+
 10+member OverrideDefaults
 11+INI Entry OverrideDefaults
 12+INI Group system
 13+Does not have a registry value.
 14+If nonzero, ignores registry settings from Global section of registry.
 15+
416 Member scaler
517 INI Entry ScalingMode
618 INI Group display
@@ -34,7 +46,9 @@
3547 If nonzero, switches screen color depth if requested by the application.
3648 Recommended setting is off. DXGL handles color depth conversion internally.
3749
38 -Member AllColorDepths
 50+Member AddColorDepths
 51+INI Entry AllColorDepths
 52+INI Group display
3953 REG_DWORD HKCU\DXGL\Profiles\<app>\AllColorDepths
4054 [DEPRECATED FOR DXGLCFG2]Enable all color depths, even if unsupported by the system
4155 Valid settings:
@@ -42,6 +56,8 @@
4357 1 - On
4458
4559 Member AddColorDepths
 60+INI Entry AddColorDepths
 61+INI Group display
4662 REG_DWORD HKCU\DXGL\Profiles\<app>\AddColorDepths
4763 Adds color depths, even if unsupported by the system
4864 Bit-mapped variable
@@ -53,7 +69,9 @@
5470 8 - Add 24-bit modes
5571 16 - Add 32-bit modes
5672
57 -Member ExtraModes
 73+Member AddModes
 74+INI Entry ExtraModes
 75+INI Group display
5876 REG_DWORD HKCU\DXGL\Profiles\<app>\ExtraModes
5977 [DEPRECATED FOR DXGLCFG2]Enable extra video modes, even if unsupported by the system
6078 Valid settings:
Index: cfgmgr/cfgmgr.c
@@ -759,32 +759,54 @@
760760
761761 void GetDefaultConfig(DXGLCFG *cfg)
762762 {
 763+ BOOL Windows8Detected = FALSE;
763764 ZeroMemory(cfg, sizeof(DXGLCFG));
764765 cfg->DPIScale = 1;
765766 cfg->AddModes = 1;
 767+ if (!cfg->Windows8Detected)
 768+ {
 769+ OSVERSIONINFO osver;
 770+ osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
 771+ GetVersionEx(&osver);
 772+ if (osver.dwMajorVersion > 6) Windows8Detected = TRUE;
 773+ if ((osver.dwMajorVersion == 6) && (osver.dwMinorVersion >= 2)) Windows8Detected = TRUE;
 774+ if (Windows8Detected) cfg->AddColorDepths = 1 | 4 | 16;
 775+ }
766776 }
767777
768 -void ReadINICallback(DXGLCFG *cfg, const char *section, const char *name,
 778+DWORD INIBoolValue(const char *value)
 779+{
 780+ DWORD ret = 1;
 781+ if (value[0] == 'F') ret = 0;
 782+ if (value[0] == 'f') ret = 0;
 783+ if (value[0] == '0') ret = 0;
 784+ return ret;
 785+}
 786+
 787+int ReadINICallback(DXGLCFG *cfg, const char *section, const char *name,
769788 const char *value)
770789 {
771 - // Macro based on example from the inih README.md
772 - #define MATCH(s, n) stricmp(section, s) == 0 && stricmp(name, n) == 0
773 - return;
 790+ if (!stricmp(section, "system"))
 791+ {
 792+ if (!stricmp(name, "NoWriteRegistry")) cfg->NoWriteRegistry = INIBoolValue(value);
 793+ if (!stricmp(name, "OverrideDefaults"))cfg->OverrideDefaults = INIBoolValue(value);
 794+ }
 795+ if (!stricmp(section, "display"))
 796+ {
 797+
 798+ }
 799+ return 1;
774800 }
775801
776 -#ifdef UNICODE
777 -#define INIPARSE ini_parse_unicode
778 -#else
779 -#define INIPARSE ini_parse
780 -#endif
781 -
782 -void ReadINI(DXGLCFG *cfg, BOOL retry)
 802+void ReadINI(DXGLCFG *cfg)
783803 {
 804+ FILE *file;
784805 TCHAR inipath[MAX_PATH + 10];
785806 GetModuleFileName(NULL, inipath, MAX_PATH);
786807 GetDirFromPath(inipath);
787808 _tcscat(inipath, _T("\\dxgl.ini"));
788 - INIPARSE(inipath, ReadINICallback, cfg);
 809+ file = _tfopen(inipath, _T("r"));
 810+ if (file) ini_parse_file(file, ReadINICallback, cfg);
789811 }
790812
791813 void GetCurrentConfig(DXGLCFG *cfg, BOOL initial)
@@ -821,9 +843,28 @@
822844 sha256string[256 / 4] = 0;
823845 _tcscat(regkey,sha256string);
824846 GetGlobalConfig(cfg, initial);
825 - ReadINI(cfg, FALSE);
 847+ ReadINI(cfg);
 848+ if (cfg->OverrideDefaults)
 849+ {
 850+ GetDefaultConfig(cfg);
 851+ ReadINI(cfg);
 852+ }
 853+ if (!cfg->Windows8Detected)
 854+ {
 855+ OSVERSIONINFO osver;
 856+ osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
 857+ GetVersionEx(&osver);
 858+ if (osver.dwMajorVersion > 6) cfg->Windows8Detected = TRUE;
 859+ if ((osver.dwMajorVersion == 6) && (osver.dwMinorVersion >= 2)) cfg->Windows8Detected = TRUE;
 860+ if (cfg->Windows8Detected) cfg->AddColorDepths = 1 | 4 | 16;
 861+ }
826862 if (initial) RegOpenKeyEx(HKEY_CURRENT_USER, regkey, 0, KEY_READ, &hKey);
827 - else RegCreateKeyEx(HKEY_CURRENT_USER,regkey,0,NULL,0,KEY_ALL_ACCESS,NULL,&hKey,NULL);
 863+ else
 864+ {
 865+ RegCreateKeyEx(HKEY_CURRENT_USER, regkeyglobal, 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hKey, NULL);
 866+ if (hKey) RegCloseKey(hKey);
 867+ RegCreateKeyEx(HKEY_CURRENT_USER, regkey, 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hKey, NULL);
 868+ }
828869 if (hKey)
829870 {
830871 ReadSettings(hKey, cfg, NULL, FALSE, TRUE, NULL);
@@ -865,24 +906,12 @@
866907 }
867908 void GetGlobalConfig(DXGLCFG *cfg, BOOL initial)
868909 {
869 - HKEY hKey;
870 - ZeroMemory(cfg,sizeof(DXGLCFG));
871 - cfg->DPIScale = 1;
872 - cfg->AddModes = 1;
873 - if (initial) RegOpenKeyEx(HKEY_CURRENT_USER, regkeyglobal, 0, KEY_READ, &hKey);
874 - else RegCreateKeyEx(HKEY_CURRENT_USER, regkeyglobal, 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hKey, NULL);
 910+ HKEY hKey = NULL;
 911+ GetDefaultConfig(cfg);
 912+ RegOpenKeyEx(HKEY_CURRENT_USER, regkeyglobal, 0, KEY_READ, &hKey);
875913 if (hKey)
876914 {
877915 ReadSettings(hKey, cfg, NULL, TRUE, FALSE, NULL);
878 - if (!cfg->Windows8Detected)
879 - {
880 - OSVERSIONINFO osver;
881 - osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
882 - GetVersionEx(&osver);
883 - if (osver.dwMajorVersion > 6) cfg->Windows8Detected = TRUE;
884 - if ((osver.dwMajorVersion == 6) && (osver.dwMinorVersion >= 2)) cfg->Windows8Detected = TRUE;
885 - if (cfg->Windows8Detected) cfg->AddColorDepths = 1 | 4 | 16;
886 - }
887916 RegCloseKey(hKey);
888917 }
889918 }
Index: cfgmgr/cfgmgr.h
@@ -25,30 +25,39 @@
2626
2727 typedef struct
2828 {
 29+ // [system]
 30+ DWORD NoWriteRegistry;
 31+ DWORD OverrideDefaults;
 32+ // [display]
2933 DWORD scaler;
3034 DWORD fullmode;
3135 BOOL colormode;
 36+ DWORD AddColorDepths;
 37+ DWORD AddModes;
 38+ DWORD SortModes;
 39+ // [scaling]
 40+ DWORD scalingfilter;
 41+ DWORD primaryscale;
 42+ float primaryscalex;
 43+ float primaryscaley;
 44+ float aspect;
 45+ DWORD DPIScale;
 46+ // [postprocess]
3247 DWORD postfilter;
3348 float postsizex;
3449 float postsizey;
35 - DWORD scalingfilter;
 50+ BOOL EnableShader;
 51+ TCHAR shaderfile[MAX_PATH + 1];
 52+ // [d3d]
3653 DWORD texfilter;
3754 DWORD anisotropic;
3855 DWORD msaa;
3956 DWORD aspect3d;
40 - DWORD primaryscale;
41 - float primaryscalex;
42 - float primaryscaley;
 57+ // [advanced]
4358 DWORD vsync;
44 - BOOL EnableShader;
45 - TCHAR shaderfile[MAX_PATH+1];
46 - DWORD SortModes;
47 - DWORD AddColorDepths;
48 - DWORD AddModes;
4959 DWORD TextureFormat;
5060 DWORD TexUpload;
51 - DWORD DPIScale;
52 - float aspect;
 61+ // internal
5362 BOOL Windows8Detected;
5463 } DXGLCFG;
5564
Index: cfgmgr/inih/ini.c
@@ -206,22 +206,6 @@
207207 return error;
208208 }
209209
210 -#if INI_ENABLE_UNICODE
211 -/* See documentation in header file. */
212 -int ini_parse_unicode(const wchar_t* filename, ini_handler handler, void* user)
213 -{
214 - FILE* file;
215 - int error;
216 -
217 - file = _wfopen(filename, L"r");
218 - if (!file)
219 - return -1;
220 - error = ini_parse_file(file, handler, user);
221 - fclose(file);
222 - return error;
223 -}
224 -#endif
225 -
226210 /* An ini_reader function to read the next line from a string buffer. This
227211 is the fgets() equivalent used by ini_parse_string(). */
228212 static char* ini_reader_string(char* str, int num, void* stream) {
Index: cfgmgr/inih/ini.h
@@ -22,11 +22,6 @@
2323 #define INI_HANDLER_LINENO 0
2424 #endif
2525
26 -/* Nonzero to compile ini_parse_unicode, zero to skip */
27 -#ifndef INI_ENABLE_UNICODE
28 -#define INI_ENABLE_UNICODE 1
29 -#endif
30 -
3126 /* Typedef for prototype of handler function. */
3227 #if INI_HANDLER_LINENO
3328 typedef int (*ini_handler)(void* user, const char* section,
@@ -55,26 +50,6 @@
5651 */
5752 int ini_parse(const char* filename, ini_handler handler, void* user);
5853
59 -/* Parse given INI-style file. May have [section]s, name=value pairs
60 - (whitespace stripped), and comments starting with ';' (semicolon). Section
61 - is "" if name=value pair parsed before any section heading. name:value
62 - pairs are also supported as a concession to Python's configparser.
63 -
64 - For each name=value pair parsed, call handler function with given user
65 - pointer as well as section, name, and value (data only valid for duration
66 - of handler call). Handler should return nonzero on success, zero on error.
67 -
68 - Returns 0 on success, line number of first error on parse error (doesn't
69 - stop on first error), -1 on file open error, or -2 on memory allocation
70 - error (only when INI_USE_STACK is zero).
71 -
72 - This version of the function loads an INI-style file from a Unicode path;
73 - however the callback still uses ANSI style strings.
74 -*/
75 -#if INI_ENABLE_UNICODE
76 -int ini_parse_unicode(const wchar_t* filename, ini_handler handler, void* user);
77 -#endif
78 -
7954 /* Same as ini_parse(), but takes a FILE* instead of filename. This doesn't
8055 close the file when it's finished -- the caller must do that. */
8156 int ini_parse_file(FILE* file, ini_handler handler, void* user);
Index: dxgl-example.ini
@@ -12,7 +12,10 @@
1313
1414 ; OverrideDefaults - Boolean
1515 ; If true, settings not set in the .ini file will not be read from the
16 -; settings in the user's registry but instead will use the default settings.
 16+; settings in the Global section of the user's registry but instead will use
 17+; the default settings. Users may still override these settings with a profile
 18+; in DXGL Config. If NoWriteRegistry is false, a profile will still be
 19+; created if it does not exist.
1720 ; If false, the settings in DXGL Config global section will be used as default.
1821 ; Default is false
1922 OverrideDefaults = false