DXGL r23 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r22‎ | r23 | r24 >
Date:19:23, 11 December 2011
Author:admin
Status:new
Tags:
Comment:
DXGL 0.1.0 Release.
Add support for deleting application profiles.
Modified paths:
  • /dxglcfg/dxglcfg.cpp (modified) (history)

Diff [purge]

Index: dxglcfg/dxglcfg.cpp
@@ -70,7 +70,7 @@
7171 bool tristate;
7272 TCHAR strdefault[] = _T("(global default)");
7373
74 -DWORD AddApp(LPTSTR path, bool copyfile, bool admin)
 74+DWORD AddApp(LPCTSTR path, bool copyfile, bool admin)
7575 {
7676 bool installed = false;
7777 bool dxgl_installdir = false;
@@ -141,6 +141,59 @@
142142 return 0;
143143 }
144144
 145+DWORD DelApp(LPCTSTR path, bool admin)
 146+{
 147+ bool installed = false;
 148+ bool dxgl_installdir = false;
 149+ tstring command;
 150+ bool old_dxgl = true;
 151+ DWORD sizeout = (MAX_PATH+1)*sizeof(TCHAR);
 152+ TCHAR installpath[MAX_PATH+1];
 153+ HKEY hKeyInstall;
 154+ LONG error = RegOpenKeyEx(HKEY_LOCAL_MACHINE,_T("Software\\DXGL"),0,KEY_READ,&hKeyInstall);
 155+ if(error == ERROR_SUCCESS)
 156+ {
 157+ dxgl_installdir = true;
 158+ error = RegQueryValueEx(hKeyInstall,_T("InstallDir"),NULL,NULL,(LPBYTE)installpath,&sizeout);
 159+ if(error == ERROR_SUCCESS) installed = true;
 160+ }
 161+ if(hKeyInstall) RegCloseKey(hKeyInstall);
 162+ if(!installed)
 163+ {
 164+ GetModuleFileName(NULL,installpath,MAX_PATH+1);
 165+ }
 166+ HMODULE hmod = LoadLibrary(path);
 167+ if(hmod)
 168+ {
 169+ if(!GetProcAddress(hmod,"IsDXGLDDraw")) old_dxgl = false;
 170+ FreeLibrary(hmod);
 171+ }
 172+ if(!DeleteFile(path))
 173+ {
 174+ error = GetLastError();
 175+ if(error == ERROR_FILE_NOT_FOUND) return 0;
 176+ if((error == ERROR_ACCESS_DENIED) && !admin)
 177+ {
 178+ command.assign(_T(" remove "));
 179+ command.append(path);
 180+ SHELLEXECUTEINFO shex;
 181+ ZeroMemory(&shex,sizeof(SHELLEXECUTEINFO));
 182+ shex.cbSize = sizeof(SHELLEXECUTEINFO);
 183+ shex.lpVerb = _T("runas");
 184+ _tcscat(installpath,_T("\\dxglcfg.exe"));
 185+ shex.lpFile = installpath;
 186+ shex.lpParameters = command.c_str();
 187+ ShellExecuteEx(&shex);
 188+ WaitForSingleObject(shex.hProcess,INFINITE);
 189+ DWORD exitcode;
 190+ GetExitCodeProcess(shex.hProcess,&exitcode);
 191+ return exitcode;
 192+ }
 193+ return error;
 194+ }
 195+ return 0;
 196+}
 197+
145198 void SaveChanges(HWND hWnd)
146199 {
147200 if(apps[0].dirty) SetGlobalConfig(&apps[0].cfg);
@@ -920,15 +973,45 @@
921974
922975 break;
923976 case IDC_REMOVE:
924 - if(!(GetWindowLong(GetDlgItem(hWnd,IDC_APPLY),GWL_STYLE) & WS_DISABLED))
 977+ if(MessageBox(hWnd,_T("Do you want to delete the selected application profile and remove DXGL from its installation folder(s)?"),
 978+ _T("Confirmation"),MB_YESNO|MB_ICONQUESTION) != IDYES) return false;
 979+ tstring regpath = _T("Software\\DXGL\\");
 980+ tstring regkey = *apps[current_app].regkey;
 981+ regpath.append(*apps[current_app].regkey);
 982+ RegOpenKeyEx(HKEY_CURRENT_USER,regpath.c_str(),0,KEY_READ,&hKey);
 983+ RegQueryValueEx(hKey,_T("InstallPaths"),NULL,NULL,NULL,&buffersize);
 984+ regbuffer = (LPTSTR)malloc(buffersize);
 985+ regbuffer[0] = regbuffer[1] = 0;
 986+ error = RegQueryValueEx(hKey,_T("InstallPaths"),NULL,NULL,(LPBYTE)regbuffer,&buffersize);
 987+ regbufferpos = 0;
 988+ bool failed = false;
 989+ while(1)
925990 {
926 - if(MessageBox(hWnd,_T("Do you want to delete the selected application profile and remove DXGL from its installation folder(s)?"),
927 - _T("Confirmation"),MB_YESNO|MB_ICONQUESTION) == IDNO) return false;
928 -
 991+ if((regbuffer[regbufferpos] == 0) || error != ERROR_SUCCESS) break;
 992+ if(regkey.rfind(_T("-")) != -1) regkey.resize(regkey.rfind(_T("-")));
 993+ path = tstring(((LPTSTR)regbuffer+regbufferpos))+tstring(_T("\\ddraw.dll"));
 994+ if(GetFileAttributes(path.c_str()) == INVALID_FILE_ATTRIBUTES)
 995+ {
 996+ regbufferpos += (_tcslen(regbuffer+regbufferpos)+1);
 997+ continue;
 998+ }
 999+ if(DelApp(path.c_str(),false)) failed = true;
 1000+ regbufferpos += (_tcslen(regbuffer+regbufferpos)+1);
9291001 }
930 - // Delete app profile
931 -
932 -
 1002+ RegCloseKey(hKey);
 1003+ if(!failed)
 1004+ {
 1005+ RegDeleteKey(HKEY_CURRENT_USER,regpath.c_str());
 1006+ if(!apps[current_app].icon_shared) DeleteObject(apps[current_app].icon);
 1007+ if(apps[current_app].name) delete apps[current_app].name;
 1008+ if(apps[current_app].regkey) delete apps[current_app].regkey;
 1009+ for(int i = current_app; i < appcount; i++)
 1010+ {
 1011+ apps[i] = apps[i+1];
 1012+ }
 1013+ appcount--;
 1014+ }
 1015+ SendDlgItemMessage(hWnd,IDC_APPS,LB_DELETESTRING,current_app,NULL);
9331016 break;
9341017 }
9351018 break;
@@ -955,6 +1038,10 @@
9561039 {
9571040 return AddApp(lpCmdLine+8,true,true);
9581041 }
 1042+ if(!_tcsnicmp(lpCmdLine,_T("remove "),7))
 1043+ {
 1044+ return DelApp(lpCmdLine+7,true);
 1045+ }
9591046 icc.dwSize = sizeof(icc);
9601047 icc.dwICC = ICC_WIN95_CLASSES;
9611048 HMODULE comctl32 = LoadLibrary(_T("comctl32.dll"));