Index: cfgmgr/cfgmgr.c |
— | — | @@ -32,6 +32,7 @@ |
33 | 33 | #include <tchar.h>
|
34 | 34 | #include <math.h>
|
35 | 35 | #include <stdarg.h>
|
| 36 | +#include "inih/ini.h"
|
36 | 37 |
|
37 | 38 | TCHAR regkeyglobal[] = _T("Software\\DXGL\\Global");
|
38 | 39 | TCHAR regkeybase[] = _T("Software\\DXGL\\");
|
— | — | @@ -756,6 +757,36 @@ |
757 | 758 | return newregname;
|
758 | 759 | }
|
759 | 760 |
|
| 761 | +void GetDefaultConfig(DXGLCFG *cfg)
|
| 762 | +{
|
| 763 | + ZeroMemory(cfg, sizeof(DXGLCFG));
|
| 764 | + cfg->DPIScale = 1;
|
| 765 | + cfg->AddModes = 1;
|
| 766 | +}
|
| 767 | +
|
| 768 | +void ReadINICallback(DXGLCFG *cfg, const char *section, const char *name,
|
| 769 | + const char *value)
|
| 770 | +{
|
| 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;
|
| 774 | +}
|
| 775 | +
|
| 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)
|
| 783 | +{
|
| 784 | + TCHAR inipath[MAX_PATH + 10];
|
| 785 | + GetModuleFileName(NULL, inipath, MAX_PATH);
|
| 786 | + GetDirFromPath(inipath);
|
| 787 | + _tcscat(inipath, _T("\\dxgl.ini"));
|
| 788 | + INIPARSE(inipath, ReadINICallback, cfg);
|
| 789 | +}
|
| 790 | +
|
760 | 791 | void GetCurrentConfig(DXGLCFG *cfg, BOOL initial)
|
761 | 792 | {
|
762 | 793 | HKEY hKey;
|
— | — | @@ -790,6 +821,7 @@ |
791 | 822 | sha256string[256 / 4] = 0;
|
792 | 823 | _tcscat(regkey,sha256string);
|
793 | 824 | GetGlobalConfig(cfg, initial);
|
| 825 | + ReadINI(cfg, FALSE);
|
794 | 826 | if (initial) RegOpenKeyEx(HKEY_CURRENT_USER, regkey, 0, KEY_READ, &hKey);
|
795 | 827 | else RegCreateKeyEx(HKEY_CURRENT_USER,regkey,0,NULL,0,KEY_ALL_ACCESS,NULL,&hKey,NULL);
|
796 | 828 | if (hKey)
|
Index: cfgmgr/cfgmgr.vcxproj |
— | — | @@ -149,11 +149,13 @@ |
150 | 150 | <ItemGroup>
|
151 | 151 | <ClInclude Include="cfgmgr.h" />
|
152 | 152 | <ClInclude Include="crc32.h" />
|
| 153 | + <ClInclude Include="inih\ini.h" />
|
153 | 154 | <ClInclude Include="LibSha256.h" />
|
154 | 155 | </ItemGroup>
|
155 | 156 | <ItemGroup>
|
156 | 157 | <ClCompile Include="cfgmgr.c" />
|
157 | 158 | <ClCompile Include="crc32.c" />
|
| 159 | + <ClCompile Include="inih\ini.c" />
|
158 | 160 | <ClCompile Include="LibSha256.c" />
|
159 | 161 | </ItemGroup>
|
160 | 162 | <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
Index: cfgmgr/cfgmgr.vcxproj.filters |
— | — | @@ -13,6 +13,12 @@ |
14 | 14 | <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
15 | 15 | <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
16 | 16 | </Filter>
|
| 17 | + <Filter Include="Source Files\inih">
|
| 18 | + <UniqueIdentifier>{52f34bb7-dc10-4142-b67d-6720e9be7d4c}</UniqueIdentifier>
|
| 19 | + </Filter>
|
| 20 | + <Filter Include="Header Files\inih">
|
| 21 | + <UniqueIdentifier>{e547f87f-ed45-4367-8baf-ad2ddbbd5100}</UniqueIdentifier>
|
| 22 | + </Filter>
|
17 | 23 | </ItemGroup>
|
18 | 24 | <ItemGroup>
|
19 | 25 | <None Include="ReadMe.txt" />
|
— | — | @@ -27,6 +33,9 @@ |
28 | 34 | <ClInclude Include="LibSha256.h">
|
29 | 35 | <Filter>Header Files</Filter>
|
30 | 36 | </ClInclude>
|
| 37 | + <ClInclude Include="inih\ini.h">
|
| 38 | + <Filter>Header Files\inih</Filter>
|
| 39 | + </ClInclude>
|
31 | 40 | </ItemGroup>
|
32 | 41 | <ItemGroup>
|
33 | 42 | <ClCompile Include="crc32.c">
|
— | — | @@ -38,5 +47,8 @@ |
39 | 48 | <ClCompile Include="LibSha256.c">
|
40 | 49 | <Filter>Source Files</Filter>
|
41 | 50 | </ClCompile>
|
| 51 | + <ClCompile Include="inih\ini.c">
|
| 52 | + <Filter>Source Files\inih</Filter>
|
| 53 | + </ClCompile>
|
42 | 54 | </ItemGroup>
|
43 | 55 | </Project> |
\ No newline at end of file |
Index: cfgmgr/inih/ini.c |
— | — | @@ -206,6 +206,22 @@ |
207 | 207 | return error; |
208 | 208 | } |
209 | 209 | |
| 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 | + |
210 | 226 | /* An ini_reader function to read the next line from a string buffer. This |
211 | 227 | is the fgets() equivalent used by ini_parse_string(). */ |
212 | 228 | static char* ini_reader_string(char* str, int num, void* stream) { |
Index: cfgmgr/inih/ini.h |
— | — | @@ -22,6 +22,11 @@ |
23 | 23 | #define INI_HANDLER_LINENO 0 |
24 | 24 | #endif |
25 | 25 | |
| 26 | +/* Nonzero to compile ini_parse_unicode, zero to skip */ |
| 27 | +#ifndef INI_ENABLE_UNICODE |
| 28 | +#define INI_ENABLE_UNICODE 1 |
| 29 | +#endif |
| 30 | + |
26 | 31 | /* Typedef for prototype of handler function. */ |
27 | 32 | #if INI_HANDLER_LINENO |
28 | 33 | typedef int (*ini_handler)(void* user, const char* section, |
— | — | @@ -50,6 +55,26 @@ |
51 | 56 | */ |
52 | 57 | int ini_parse(const char* filename, ini_handler handler, void* user); |
53 | 58 | |
| 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 | + |
54 | 79 | /* Same as ini_parse(), but takes a FILE* instead of filename. This doesn't |
55 | 80 | close the file when it's finished -- the caller must do that. */ |
56 | 81 | int ini_parse_file(FILE* file, ini_handler handler, void* user); |