DXGL r19 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r18‎ | r19 | r20 >
Date:02:57, 8 December 2011
Author:admin
Status:new
Tags:
Comment:
Write installation directory on install.
Give installed DXGLTest a specific key, to prevent duplicate entries in DXGLCfg when updating.
Modified paths:
  • /Installer/dxgl.nsi (modified) (history)
  • /cfgmgr/cfgmgr.cpp (modified) (history)
  • /dxglcfg/dxglcfg.cpp (modified) (history)
  • /dxglcfg/dxglcfg.rc (modified) (history)
  • /dxgltest/dxgltest.cpp (modified) (history)

Diff [purge]

Index: Installer/dxgl.nsi
@@ -124,7 +124,7 @@
125125 StrLen $5 $3
126126 IntOp $5 $5 + 1
127127 !ifdef NSIS_UNICODE
128 - IntOp $5 $5 * 2
 128+ IntOp $5 $5 + 2
129129 !endif
130130 IntOp $4 $4 + $5
131131 ;copy file here
@@ -151,6 +151,8 @@
152152 novc:
153153 MessageBox MB_OK|MB_ICONEXCLAMATION "DXGL will not work if the Visual C++ 2010 Runtime is not installed. Please install the Visual C++ 2010 Runtime before running DXGL."
154154 skipvcredist:
 155+ WriteRegStr HKLM "Software\DXGL" "InstallDir" "$INSTDIR"
 156+ ExecWait '"$INSTDIR\dxgltest.exe" install'
155157 SectionEnd
156158
157159 Section -AdditionalIcons
@@ -200,6 +202,7 @@
201203
202204 DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
203205 DeleteRegKey HKLM "${PRODUCT_DIR_REGKEY}"
 206+ DeleteRegKey HKLM "Software\DXGL"
204207
205208 StrCpy $8 0
206209 SetPluginUnload alwaysoff
Index: cfgmgr/cfgmgr.cpp
@@ -250,26 +250,57 @@
251251 return (LPTSTR)newregname.c_str();
252252 }
253253
 254+bool IsInstalledDXGLTest(LPCTSTR path)
 255+{
 256+ LRESULT err;
 257+ TCHAR dir[MAX_PATH+1];
 258+ TCHAR cmp[MAX_PATH+1];
 259+ _tcsncpy(dir,path,MAX_PATH);
 260+ GetDirFromPath(dir);
 261+ HKEY hKey;
 262+ DWORD sizeout = MAX_PATH*sizeof(TCHAR);
 263+ if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,_T("Software\\DXGL"),0,KEY_READ,&hKey) != ERROR_SUCCESS)
 264+ return false;
 265+ err = RegQueryValueEx(hKey,_T("InstallDir"),NULL,NULL,(LPBYTE)cmp,&sizeout);
 266+ if(err != ERROR_SUCCESS)
 267+ {
 268+ RegCloseKey(hKey);
 269+ return false;
 270+ }
 271+ RegCloseKey(hKey);
 272+ if(!_tcsnicmp(dir,cmp,MAX_PATH)) return true;
 273+ else return false;
 274+}
 275+
254276 void GetCurrentConfig(DXGLCFG *cfg)
255277 {
256278 HKEY hKey;
257279 unsigned long crc;
 280+ tstring regkey;
258281 FILE *file;
259282 TCHAR filename[MAX_PATH+1];
260283 TCHAR crcstr[10];
261284 GetModuleFileName(NULL,filename,MAX_PATH);
262 - file = _tfopen(filename,_T("rb"));
263 - if(file != NULL) Crc32_ComputeFile(file,&crc);
264 - else crc = 0;
265 - _itot(crc,crcstr,16);
266 - if(file) fclose(file);
267 - tstring regkey = regkeybase;
268 - int i;
269 - for(i = _tcslen(filename); (i > 0) && (filename[i] != 92) && (filename[i] != 47); i--);
270 - i++;
271 - regkey.append(&filename[i]);
272 - regkey.append(_T("-"));
273 - regkey.append(crcstr);
 285+ if(IsInstalledDXGLTest(filename))
 286+ {
 287+ regkey = regkeybase;
 288+ regkey.append(_T("DXGLTestApp"));
 289+ }
 290+ else
 291+ {
 292+ file = _tfopen(filename,_T("rb"));
 293+ if(file != NULL) Crc32_ComputeFile(file,&crc);
 294+ else crc = 0;
 295+ _itot(crc,crcstr,16);
 296+ if(file) fclose(file);
 297+ regkey = regkeybase;
 298+ int i;
 299+ for(i = _tcslen(filename); (i > 0) && (filename[i] != 92) && (filename[i] != 47); i--);
 300+ i++;
 301+ regkey.append(&filename[i]);
 302+ regkey.append(_T("-"));
 303+ regkey.append(crcstr);
 304+ }
274305 GetGlobalConfig(cfg);
275306 RegCreateKeyEx(HKEY_CURRENT_USER,regkey.c_str(),NULL,NULL,0,KEY_ALL_ACCESS,NULL,&hKey,NULL);
276307 ReadSettings(hKey,cfg,NULL,false,true,NULL);
Index: dxglcfg/dxglcfg.cpp
@@ -82,7 +82,7 @@
8383 LONG error = RegOpenKeyEx(HKEY_LOCAL_MACHINE,_T("Software\\DXGL"),0,KEY_READ,&hKeyInstall);
8484 if(error == ERROR_SUCCESS)
8585 {
86 - error = RegQueryValueEx(hKeyInstall,_T("InstallPath"),NULL,NULL,(LPBYTE)installpath,&sizeout);
 86+ error = RegQueryValueEx(hKeyInstall,_T("InstallDir"),NULL,NULL,(LPBYTE)installpath,&sizeout);
8787 if(error == ERROR_SUCCESS) installed = true;
8888 }
8989 if(hKeyInstall) RegCloseKey(hKeyInstall);
@@ -508,7 +508,8 @@
509509 maxapps += 128;
510510 apps = (app_setting *)realloc(apps,maxapps*sizeof(app_setting));
511511 }
512 - subkey = keyname;
 512+ if(!_tcscmp(keyname,_T("DXGLTestApp"))) subkey = _T("dxgltest.exe-0");
 513+ else subkey = keyname;
513514 if(subkey.rfind(_T("-")) != -1) subkey.resize(subkey.rfind(_T("-")));
514515 error = RegOpenKeyEx(hKeyBase,keyname,0,KEY_READ,&hKey);
515516 buffersize = regbuffersize;
@@ -669,6 +670,8 @@
670671 cfg = &apps[current_app].cfg;
671672 cfgmask = &apps[current_app].mask;
672673 dirty = &apps[current_app].dirty;
 674+ if(current_app) EnableWindow(GetDlgItem(hWnd,IDC_REMOVE),true);
 675+ else EnableWindow(GetDlgItem(hWnd,IDC_REMOVE),false);
673676 // Set 3-state status
674677 if(current_app && !tristate)
675678 {
@@ -897,19 +900,11 @@
898901
899902 break;
900903 case IDC_REMOVE:
901 - if(!(GetWindowLong(hWnd,GWL_STYLE) & WS_DISABLED))
 904+ if(!(GetWindowLong(GetDlgItem(hWnd,IDC_APPLY),GWL_STYLE) & WS_DISABLED))
902905 {
903 - switch(MessageBox(hWnd,_T("Do you want to apply settings before continuing?\nIf you answer No, the unsaved settings will be discarded."),
904 - _T("Unsaved settings detected"),MB_YESNOCANCEL))
905 - {
906 - case IDYES:
907 - SaveChanges(hWnd);
908 - break;
909 - case IDNO:
910 - break;
911 - default:
912 - return false;
913 - }
 906+ if(MessageBox(hWnd,_T("Do you want to delete the selected application profile and remove DXGL from its installation folder(s)?"),
 907+ _T("Confirmation"),MB_YESNO|MB_ICONQUESTION) == IDNO) return false;
 908+
914909 }
915910 // Delete app profile
916911
Index: dxglcfg/dxglcfg.rc
@@ -39,7 +39,7 @@
4040 LISTBOX IDC_APPS, 4, 14, 181, 212, WS_TABSTOP | WS_VSCROLL | LBS_NOINTEGRALHEIGHT | LBS_OWNERDRAWFIXED | LBS_NOTIFY
4141 LTEXT "Applications", IDC_STATIC, 4, 4, 39, 8, SS_LEFT
4242 PUSHBUTTON "A&dd...", IDC_ADD, 4, 228, 90, 14
43 - PUSHBUTTON "&Remove", IDC_REMOVE, 96, 228, 90, 14
 43+ PUSHBUTTON "&Remove", IDC_REMOVE, 96, 228, 90, 14, WS_DISABLED
4444 GROUPBOX "Graphics", IDC_STATIC, 190, 4, 211, 184
4545 LTEXT "Video mode", IDC_STATIC, 195, 14, 38, 8, SS_LEFT
4646 COMBOBOX IDC_VIDMODE, 195, 24, 102, 30, CBS_DROPDOWNLIST | CBS_HASSTRINGS
Index: dxgltest/dxgltest.cpp
@@ -500,6 +500,13 @@
501501
502502 int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
503503 {
 504+ if(_tcsstr(lpCmdLine,_T(" install")))
 505+ {
 506+ LPDIRECTDRAW lpdd;
 507+ DirectDrawCreate(NULL,&lpdd,NULL);
 508+ lpdd->Release();
 509+ return 0;
 510+ }
504511 OSVERSIONINFO verinfo;
505512 verinfo.dwOSVersionInfoSize = sizeof(verinfo);
506513 GetVersionEx(&verinfo);