DXGL r945 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r944‎ | r945 | r946 >
Date:00:11, 3 September 2019
Author:admin
Status:new
Tags:
Comment:
Explicitly process profile lowercase paths as Unicode. This allows profile paths to be identical on Unicode and MBCS builds of DXGL provided the paths use ANSI-compatible characters.
Modified paths:
  • /cfgmgr/cfgmgr.c (modified) (history)
  • /cfgmgr/cfgmgr.h (modified) (history)

Diff [purge]

Index: cfgmgr/cfgmgr.c
@@ -60,6 +60,28 @@
6161
6262 static int ini_currentsection = 0;
6363
 64+void _tchartowchar(WCHAR *dest, TCHAR *src, int length)
 65+{
 66+#ifdef _UNICODE
 67+ wcsncpy(dest,src,length);
 68+#else
 69+ int length2 = length;
 70+ if(length == -1) length2 = strlen(src) + 1;
 71+ MultiByteToWideChar(CP_ACP,0,src,length,dest,length2);
 72+#endif
 73+}
 74+
 75+void _wchartotchar(TCHAR *dest, WCHAR *src, int length)
 76+{
 77+#ifdef _UNICODE
 78+ wcsncpy(dest,src,length);
 79+#else
 80+ int length2 = length;
 81+ if(length == -1) length2 = wcslen(src) + 1;
 82+ WideCharToMultiByte(CP_ACP,0,src,length,dest,length2,NULL,NULL);
 83+#endif
 84+}
 85+
6486 /**
6587 * Gets the hexadecimal digit for a number; the number must be less than 16
6688 * or 0x10.
@@ -883,6 +905,7 @@
884906 TCHAR sha256string[65];
885907 TCHAR regkey[MAX_PATH + 80];
886908 TCHAR filename[MAX_PATH + 1];
 909+ WCHAR filename2[MAX_PATH + 1];
887910 HKEY hKey;
888911 LONG error;
889912 int i;
@@ -896,8 +919,9 @@
897920 i--;
898921 filename[i] = 0;
899922 _tcslwr(filename);
 923+ _tchartowchar(filename2,filename,-1);
900924 Sha256Initialise(&sha_context);
901 - Sha256Update(&sha_context, filename, (uint32_t)_tcslen(filename));
 925+ Sha256Update(&sha_context, filename2, (uint32_t)wcslen(filename2));
902926 Sha256Finalise(&sha_context, &sha256);
903927 for (i = 0; i < (256 / 8); i++)
904928 {
@@ -921,6 +945,7 @@
922946 SHA256_HASH sha256;
923947 TCHAR sha256string[65];
924948 TCHAR pathlwr[MAX_PATH + 1];
 949+ WCHAR pathlwr2[MAX_PATH + 1];
925950 HKEY hKey;
926951 DXGLCFG tmp;
927952 TCHAR regkey[MAX_PATH + 80];
@@ -931,8 +956,9 @@
932957 for (i = (int)_tcslen(pathlwr); (i > 0) && (pathlwr[i] != 92) && (pathlwr[i] != 47); i--);
933958 pathlwr[i] = 0;
934959 _tcslwr(pathlwr);
 960+ _tchartowchar(pathlwr2,pathlwr,-1);
935961 Sha256Initialise(&sha_context);
936 - Sha256Update(&sha_context, pathlwr, (uint32_t)_tcslen(pathlwr));
 962+ Sha256Update(&sha_context, pathlwr2, (uint32_t)wcslen(pathlwr2));
937963 Sha256Finalise(&sha_context, &sha256);
938964 for (i = 0; i < (256 / 8); i++)
939965 {
@@ -1602,6 +1628,7 @@
16031629 SHA256_HASH sha256;
16041630 TCHAR sha256string[65];
16051631 TCHAR filename[MAX_PATH+1];
 1632+ WCHAR filename2[MAX_PATH+1];
16061633 TCHAR regkey[MAX_PATH + 80];
16071634 size_t i;
16081635 BOOL DPIAwarePM = FALSE;
@@ -1620,8 +1647,9 @@
16211648 i--;
16221649 filename[i] = 0;
16231650 _tcslwr(filename);
 1651+ _tchartowchar(filename2, filename, -1);
16241652 Sha256Initialise(&sha_context);
1625 - Sha256Update(&sha_context, filename, (uint32_t)_tcslen(filename));
 1653+ Sha256Update(&sha_context, filename2, (uint32_t)wcslen(filename2));
16261654 Sha256Finalise(&sha_context, &sha256);
16271655 for (i = 0; i < (256 / 8); i++)
16281656 {
@@ -1850,6 +1878,7 @@
18511879 SHA256_HASH sha256;
18521880 TCHAR sha256string[65];
18531881 TCHAR installpath[MAX_PATH + 1];
 1882+ WCHAR installpath2[MAX_PATH + 1];
18541883 TCHAR profilepath[MAX_PATH + 80];
18551884 TCHAR destpath[MAX_PATH + 80];
18561885 LONG error;
@@ -1872,8 +1901,9 @@
18731902 if (error == ERROR_SUCCESS)
18741903 {
18751904 _tcslwr(installpath);
 1905+ _tchartowchar(installpath2, installpath, -1);
18761906 Sha256Initialise(&sha_context);
1877 - Sha256Update(&sha_context, installpath, (uint32_t)_tcslen(installpath));
 1907+ Sha256Update(&sha_context, installpath2, (uint32_t)wcslen(installpath2));
18781908 Sha256Finalise(&sha_context, &sha256);
18791909 for (i = 0; i < (256 / 8); i++)
18801910 {
@@ -1956,7 +1986,7 @@
19571987 /**
19581988 * Checks the registry configuration version and if outdated upgrades to
19591989 * the latest version - currently version 2
1960 - * Alpha version configuration is assumed to be version 0.
 1990+ * Pre-versioned configuration is assumed to be version 0.
19611991 */
19621992 void UpgradeConfig()
19631993 {
@@ -2108,8 +2138,8 @@
21092139 if (length)
21102140 {
21112141 _tcsncpy(oldkeys[oldconfigcount].InstallPath, ptr, MAX_PATH);
2112 - _tcsncpy(oldkeys[oldconfigcount].InstallPathLowercase, ptr, MAX_PATH);
2113 - _tcslwr(oldkeys[oldconfigcount].InstallPathLowercase);
 2142+ _tchartowchar(oldkeys[oldconfigcount].InstallPathLowercase, ptr, MAX_PATH);
 2143+ wcslwr(oldkeys[oldconfigcount].InstallPathLowercase);
21142144 _tcsncpy(oldkeys[oldconfigcount].OldKey, subkey, MAX_PATH);
21152145 if (!_tcscmp(subkey, _T("DXGLTestApp")))
21162146 {
@@ -2247,7 +2277,7 @@
22482278 ver1to2:
22492279 RegCloseKey(hKey);
22502280 // Version 1 to 2: Fix an incorrectly written AddColorDepths value
2251 - if (version >= 2) return; // If version is 2 no need to upgrade.
 2281+ if (version >= 2) goto ver2to3; // If version is 2 check for version 3.
22522282 // Fix up the global Add color depths
22532283 _tcscpy(regkey, regkeyglobal);
22542284 error = RegCreateKeyEx(HKEY_CURRENT_USER, regkey, 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hKey, NULL);
@@ -2305,6 +2335,8 @@
23062336 RegSetValueEx(hKey, _T("Configuration Version"), 0, REG_DWORD, (BYTE*)&sizeout, 4);
23072337 RegCloseKey(hKey);
23082338 }
 2339+ver2to3:
 2340+ return;
23092341 }
23102342
23112343 int ReadINIOptionsCallback(app_ini_options *options, const char *section, const char *name,
Index: cfgmgr/cfgmgr.h
@@ -126,7 +126,7 @@
127127 typedef struct
128128 {
129129 TCHAR InstallPath[MAX_PATH + 1];
130 - TCHAR InstallPathLowercase[MAX_PATH + 1];
 130+ WCHAR InstallPathLowercase[MAX_PATH + 1];
131131 TCHAR EXEFile[MAX_PATH + 1];
132132 TCHAR OldKey[MAX_PATH + 1];
133133 TCHAR crc32[9];