Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenmain.cpp
Go to the documentation of this file.
00001 /* 00002 Copyright (c) 2006-2007 dogbert <dogber1@gmail.com> 00003 All rights reserved. 00004 00005 Redistribution and use in source and binary forms, with or without 00006 modification, are permitted provided that the following conditions 00007 are met: 00008 1. Redistributions of source code must retain the above copyright 00009 notice, this list of conditions and the following disclaimer. 00010 2. Redistributions in binary form must reproduce the above copyright 00011 notice, this list of conditions and the following disclaimer in the 00012 documentation and/or other materials provided with the distribution. 00013 3. The name of the author may not be used to endorse or promote products 00014 derived from this software without specific prior written permission. 00015 00016 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 00017 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00018 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 00019 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 00020 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 00021 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00022 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00023 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00024 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 00025 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00026 */ 00027 00028 #include "main.h" 00029 00030 00031 void PrintLastError(LPCSTR function) 00032 { 00033 LPVOID lpMsgBuf; 00034 DWORD errorid = GetLastError(); 00035 00036 FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, errorid, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 0, NULL ); 00037 MessageBox(NULL, (LPCSTR)lpMsgBuf, function, MB_ICONEXCLAMATION | MB_OK); 00038 LocalFree(lpMsgBuf); 00039 } 00040 00041 BOOL deleteCMIKeys() 00042 { 00043 HKEY key; 00044 unsigned int i; 00045 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"), NULL, KEY_SET_VALUE, &key) != ERROR_SUCCESS) { 00046 PrintLastError("RegOpenKeyEx()"); 00047 return FALSE; 00048 } 00049 for (i=0;i<NumberOfCMIKeys;i++) { 00050 RegDeleteValue(key, CMIKeys[i]); 00051 } 00052 RegCloseKey(key); 00053 return TRUE; 00054 } 00055 00056 BOOL CMIKeysExist() 00057 { 00058 HKEY key; 00059 unsigned int i; 00060 BOOL result = FALSE; 00061 LONG size; 00062 00063 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"), NULL, KEY_SET_VALUE, &key) != ERROR_SUCCESS) { 00064 PrintLastError("RegOpenKeyEx()"); 00065 return FALSE; 00066 } 00067 for (i=0;i<NumberOfCMIKeys;i++) { 00068 result |= (RegQueryValue(key, CMIKeys[i], NULL, &size) == ERROR_SUCCESS); 00069 } 00070 RegCloseKey(key); 00071 00072 return result; 00073 } 00074 00075 void writeUninstallerKeys() 00076 { 00077 TCHAR SysDir[MAX_PATH]; 00078 unsigned int len; 00079 HKEY key; 00080 00081 if (GetSystemDirectory(SysDir, sizeof(SysDir))==0) { 00082 PrintLastError("GetSystemDirectory()"); 00083 return; 00084 } 00085 len = strlen(SysDir); 00086 strcat(SysDir, Uninstaller); 00087 00088 if (RegCreateKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\CMIDriver"), NULL, NULL, REG_OPTION_NON_VOLATILE, KEY_SET_VALUE, NULL, &key, NULL) != ERROR_SUCCESS) { 00089 PrintLastError("RegCreateKeyEx()"); 00090 return; 00091 } 00092 RegSetValueEx(key, "DisplayName", NULL, REG_SZ, (BYTE*)&DisplayName, sizeof(DisplayName)); 00093 RegSetValueEx(key, "URLInfoAbout", NULL, REG_SZ, (BYTE*)&URLInfoAbout, sizeof(URLInfoAbout)); 00094 RegSetValueEx(key, "Publisher", NULL, REG_SZ, (BYTE*)&Publisher, sizeof(Publisher)); 00095 RegSetValueEx(key, "UninstallString", NULL, REG_SZ, (BYTE*)&SysDir, strlen(SysDir)); 00096 00097 SysDir[len] = 0; 00098 strcat(SysDir, DisplayIcon); 00099 RegSetValueEx(key, "DisplayIcon", NULL, REG_SZ, (BYTE*)&SysDir, strlen(SysDir)); 00100 00101 RegCloseKey(key); 00102 } 00103 00104 BOOL installDriver(HWND hWnd) 00105 { 00106 TCHAR DriverPath[MAX_PATH]; 00107 unsigned int i; 00108 00109 EnableWindow(GetDlgItem(hWnd, IDB_INSTALL), FALSE); 00110 00111 if (GetModuleFileName(NULL, DriverPath, MAX_PATH) == 0) { 00112 PrintLastError("DriverPackageInstall()"); 00113 EnableWindow(GetDlgItem(hWnd, IDB_INSTALL), TRUE); 00114 return FALSE; 00115 } 00116 *_tcsrchr(DriverPath, _T('\\')) = _T('\0'); 00117 *_tcscat(DriverPath, _T("\\CM8738.inf")); 00118 00119 for (i=0;i<devArraySize;i++) { 00120 if (UpdateDriverForPlugAndPlayDevices(hWnd, devIDs[i], DriverPath, INSTALLFLAG_FORCE, NULL)) { 00121 EnableWindow(GetDlgItem(hWnd, IDB_INSTALL), TRUE); 00122 return TRUE; 00123 } 00124 } 00125 00126 PrintLastError("DriverPackageInstall()"); 00127 EnableWindow(GetDlgItem(hWnd, IDB_INSTALL), TRUE); 00128 return FALSE; 00129 } 00130 00131 LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) 00132 { 00133 switch(msg) { 00134 case WM_CLOSE: 00135 DestroyWindow(hWnd); 00136 return TRUE; 00137 case WM_DESTROY: 00138 PostQuitMessage(0); 00139 return TRUE; 00140 case WM_COMMAND: 00141 if (LOWORD(wParam) == IDB_CLOSE) { 00142 PostQuitMessage(0); 00143 return TRUE; 00144 } 00145 if (LOWORD(wParam) == IDB_INSTALL) { 00146 if (installDriver(hWnd)) { 00147 if (CMIKeysExist()) { 00148 if (MessageBox(hWnd, "The driver has been successfully installed! Do you want to remove the remains of the official C-Media driver?", "Driver Installer", MB_ICONINFORMATION | MB_YESNO) == IDYES) { 00149 deleteCMIKeys(); 00150 } 00151 } else { 00152 MessageBox(hWnd, "The driver has been successfully installed!", "Driver Installer", MB_ICONINFORMATION); 00153 } 00154 writeUninstallerKeys(); 00155 PostQuitMessage(0); 00156 } 00157 00158 return TRUE; 00159 } 00160 } 00161 return 0; 00162 } 00163 00164 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) 00165 { 00166 WNDCLASSEX wce; 00167 HWND hWnd; 00168 MSG msg; 00169 00170 if (hWnd = FindWindow("cmiDriverInstaller", NULL)) { 00171 SetForegroundWindow(hWnd); 00172 return FALSE; 00173 } 00174 00175 hInst = hInstance; 00176 ZeroMemory(&wce, sizeof(WNDCLASSEX)); 00177 wce.cbSize = sizeof(WNDCLASSEX); 00178 wce.lpfnWndProc = DefDlgProc; 00179 wce.style = 0; 00180 wce.cbWndExtra = DLGWINDOWEXTRA; 00181 wce.hInstance = hInstance; 00182 wce.hCursor = LoadCursor(NULL, IDC_ARROW); 00183 wce.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1); 00184 wce.lpszClassName = "cmiDriverInstaller"; 00185 wce.lpszMenuName = NULL; 00186 wce.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APP_ICON)); 00187 wce.hIconSm = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APP_ICON)); 00188 if(!RegisterClassEx(&wce)) { 00189 PrintLastError("RegisterClassEx()"); 00190 return -1; 00191 } 00192 00193 hWnd = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_MAIN), NULL, (DLGPROC)WndProc, NULL); 00194 if (!hWnd) { 00195 PrintLastError("CreateDialogParam()"); 00196 return -1; 00197 } 00198 00199 while (GetMessage(&msg, (HWND) NULL, 0, 0)) { 00200 TranslateMessage(&msg); 00201 DispatchMessage(&msg); 00202 } 00203 return 0; 00204 } Generated on Sat May 26 2012 04:27:13 for ReactOS by
1.7.6.1
|