ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

vmwinst.c
Go to the documentation of this file.
00001 /*
00002  * ReactOS VMware(r) driver installation utility
00003  * Copyright (C) 2004 ReactOS Team
00004  *
00005  * This library is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU Lesser General Public
00007  * License as published by the Free Software Foundation; either
00008  * version 2.1 of the License, or (at your option) any later version.
00009  *
00010  * This library is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Lesser General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Lesser General Public
00016  * License along with this library; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00018  *
00019  * VMware is a registered trademark of VMware, Inc.
00020  *
00021  * COPYRIGHT:   See COPYING in the top level directory
00022  * PROJECT:     ReactOS VMware(r) driver installation utility
00023  * FILE:        subsys/system/vmwinst/vmwinst.c
00024  * PROGRAMMERS: Thomas Weidenmueller (w3seek@users.sourceforge.net)
00025  *              Klemens Friedl (frik85@hotmail.com)
00026  */
00027 #include <windows.h>
00028 #include <commctrl.h>
00029 #include <newdev.h>
00030 #include <stdio.h>
00031 #include <string.h>
00032 #include <pseh/pseh2.h>
00033 #include "vmwinst.h"
00034 #include <debug.h>
00035 
00036 extern VOID CALLBACK InstallHinfSectionW(HWND hwnd, HINSTANCE ModuleHandle,
00037                                          PCWSTR CmdLineBuffer, INT nCmdShow);
00038 
00039 
00040 HINSTANCE hAppInstance;
00041 BOOL StartVMwConfigWizard, DriverFilesFound, ActivateVBE = FALSE, UninstallDriver = FALSE;
00042 
00043 static WCHAR DestinationDriversPath[MAX_PATH+1];
00044 static WCHAR CDDrive = L'\0';
00045 static WCHAR PathToVideoDrivers60[MAX_PATH+1] = L"X:\\program files\\VMWare\\VMWare Tools\\Drivers\\video\\2k\\32bit\\";
00046 static WCHAR PathToVideoDrivers55[MAX_PATH+1] = L"X:\\program files\\VMware\\VMware Tools\\Drivers\\video\\winnt2k\\32Bit\\";
00047 static WCHAR PathToVideoDrivers45[MAX_PATH+1] = L"X:\\program files\\VMware\\VMware Tools\\Drivers\\video\\winnt2k\\";
00048 static WCHAR PathToVideoDrivers40[MAX_PATH+1] = L"X:\\video\\winnt2k\\";
00049 static WCHAR DestinationPath[MAX_PATH+1];
00050 static WCHAR *vmx_fb = L"vmx_fb.dll";
00051 static WCHAR *vmx_mode = L"vmx_mode.dll";
00052 static WCHAR *vmx_mode_v6 = L"vmx mode.dll";
00053 static WCHAR *vmx_svga = L"vmx_svga.sys";
00054 
00055 static WCHAR *SrcPath = PathToVideoDrivers45;
00056 
00057 static HANDLE hInstallationThread = NULL;
00058 static HWND hInstallationNotifyWnd = NULL;
00059 static LONG AbortInstall = 0;
00060 #define WM_INSTABORT        (WM_USER + 2)
00061 #define WM_INSTCOMPLETE     (WM_USER + 3)
00062 #define WM_INSTSTATUSUPDATE (WM_USER + 4)
00063 
00064 /* Helper functions */
00065 BOOL
00066 DetectVMware(int *Version)
00067 {
00068     int magic, ver;
00069 
00070     magic = 0;
00071     ver = 0;
00072 
00073     _SEH2_TRY
00074     {
00075         /* Try using a VMware I/O port. If not running in VMware this'll throw an
00076         exception! */
00077 #if defined(__GNUC__)
00078         __asm__ __volatile__("inl  %%dx, %%eax"
00079             : "=a" (ver), "=b" (magic)
00080             : "0" (0x564d5868), "d" (0x5658), "c" (0xa));
00081 #elif defined(_MSC_VER) && defined(_M_IX86)
00082         __asm
00083         {
00084             push ebx
00085             mov  ecx, 0xa
00086             mov  edx, 0x5658
00087             mov  eax, 0x564d5868
00088             in   eax, dx
00089             mov  [ver],   eax
00090             mov  [magic], ebx
00091             pop  ebx
00092         }
00093 #elif defined(_MSC_VER) && defined(_M_AMD64)
00094     DPRINT1("DetectVMware stub\n");
00095     return FALSE;
00096 #else
00097 #error TODO
00098 #endif
00099     }
00100     _SEH2_EXCEPT(_SEH2_GetExceptionCode() == EXCEPTION_PRIV_INSTRUCTION ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH)
00101     {
00102         return FALSE;
00103     }
00104     _SEH2_END;
00105 
00106     if(magic == 0x564d5868)
00107     {
00108         *Version = ver;
00109         return TRUE;
00110     }
00111 
00112     return FALSE;
00113 }
00114 
00115 /* try to open the file */
00116 static BOOL
00117 DoesFileExist(WCHAR *Path, WCHAR *File)
00118 {
00119     WCHAR FileName[MAX_PATH + 1];
00120     HANDLE FileHandle;
00121 
00122     FileName[0] = L'\0';
00123     wcscat(FileName, Path);
00124     wcscat(FileName, File);
00125 
00126     FileHandle = CreateFile(FileName, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
00127 
00128     if(FileHandle == INVALID_HANDLE_VALUE)
00129     {
00130         /* If it was a sharing violation the file must already exist */
00131         return GetLastError() == ERROR_SHARING_VIOLATION;
00132     }
00133 
00134     if(GetFileSize(FileHandle, NULL) <= 0)
00135     {
00136         CloseHandle(FileHandle);
00137         return FALSE;
00138     }
00139 
00140     CloseHandle(FileHandle);
00141     return TRUE;
00142 }
00143 
00144 static VOID
00145 CenterWindow(HWND hWnd)
00146 {
00147     HWND hWndParent;
00148     RECT rcParent;
00149     RECT rcWindow;
00150 
00151     hWndParent = GetParent(hWnd);
00152     if (hWndParent == NULL)
00153         hWndParent = GetDesktopWindow();
00154 
00155     GetWindowRect(hWndParent, &rcParent);
00156     GetWindowRect(hWnd, &rcWindow);
00157 
00158     SetWindowPos(hWnd,
00159         HWND_TOP,
00160         ((rcParent.right - rcParent.left) - (rcWindow.right - rcWindow.left)) / 2,
00161         ((rcParent.bottom - rcParent.top) - (rcWindow.bottom - rcWindow.top)) / 2,
00162         0,
00163         0,
00164         SWP_NOSIZE);
00165 }
00166 
00167 
00168 /* Find the drive with the inserted VMware cd-rom */
00169 static BOOL
00170 IsVMwareCDInDrive(WCHAR *Drv)
00171 {
00172 #if CHECKDRIVETYPE
00173     static WCHAR Drive[4] = L"X:\\";
00174 #endif
00175     WCHAR Current;
00176 
00177     *Drv = L'\0';
00178     for(Current = 'C'; Current <= 'Z'; Current++)
00179     {
00180 #if CHECKDRIVETYPE
00181         Drive[0] = Current;
00182         if(GetDriveType(Drive) == DRIVE_CDROM)
00183         {
00184 #endif
00185             PathToVideoDrivers60[0] = Current;
00186             PathToVideoDrivers55[0] = Current;
00187             PathToVideoDrivers40[0] = Current;
00188             PathToVideoDrivers45[0] = Current;
00189             if(SetCurrentDirectory(PathToVideoDrivers60))
00190                 SrcPath = PathToVideoDrivers60;
00191             else if(SetCurrentDirectory(PathToVideoDrivers55))
00192                 SrcPath = PathToVideoDrivers55;
00193             else if(SetCurrentDirectory(PathToVideoDrivers45))
00194                 SrcPath = PathToVideoDrivers45;
00195             else if(SetCurrentDirectory(PathToVideoDrivers40))
00196                 SrcPath = PathToVideoDrivers40;
00197             else
00198             {
00199                 SetCurrentDirectory(DestinationPath);
00200                 continue;
00201             }
00202 
00203             if(DoesFileExist(SrcPath, vmx_fb) &&
00204                 (DoesFileExist(SrcPath, vmx_mode) || DoesFileExist(SrcPath, vmx_mode_v6)) &&
00205                 DoesFileExist(SrcPath, vmx_svga))
00206             {
00207                 *Drv = Current;
00208                 return TRUE;
00209             }
00210 #if CHECKDRIVETYPE
00211         }
00212 #endif
00213     }
00214 
00215     return FALSE;
00216 }
00217 
00218 static BOOL
00219 LoadResolutionSettings(DWORD *ResX, DWORD *ResY, DWORD *ColDepth)
00220 {
00221     HKEY hReg;
00222     DWORD Type, Size = sizeof(DWORD);
00223 
00224     if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,
00225         L"SYSTEM\\CurrentControlSet\\Services\\vmx_svga\\Device0",
00226         0, KEY_QUERY_VALUE, &hReg) != ERROR_SUCCESS)
00227     {
00228         DEVMODE CurrentDevMode;
00229 
00230         /* If this key is absent, just get current settings */
00231         memset(&CurrentDevMode, 0, sizeof(CurrentDevMode));
00232         CurrentDevMode.dmSize = sizeof(CurrentDevMode);
00233         if (EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &CurrentDevMode) == TRUE)
00234         {
00235             *ColDepth = CurrentDevMode.dmBitsPerPel;
00236             *ResX = CurrentDevMode.dmPelsWidth;
00237             *ResY = CurrentDevMode.dmPelsHeight;
00238 
00239             return TRUE;
00240         }
00241     }
00242 
00243     if(RegQueryValueEx(hReg, L"DefaultSettings.BitsPerPel", 0, &Type, (BYTE*)ColDepth, &Size) != ERROR_SUCCESS ||
00244         Type != REG_DWORD)
00245     {
00246         *ColDepth = 8;
00247         Size = sizeof(DWORD);
00248     }
00249 
00250     if(RegQueryValueEx(hReg, L"DefaultSettings.XResolution", 0, &Type, (BYTE*)ResX, &Size) != ERROR_SUCCESS ||
00251         Type != REG_DWORD)
00252     {
00253         *ResX = 640;
00254         Size = sizeof(DWORD);
00255     }
00256 
00257     if(RegQueryValueEx(hReg, L"DefaultSettings.YResolution", 0, &Type, (BYTE*)ResY, &Size) != ERROR_SUCCESS ||
00258         Type != REG_DWORD)
00259     {
00260         *ResY = 480;
00261     }
00262 
00263     RegCloseKey(hReg);
00264     return TRUE;
00265 }
00266 
00267 static BOOL
00268 IsVmwSVGAEnabled(VOID)
00269 {
00270     HKEY hReg;
00271     DWORD Type, Size, Value;
00272 
00273     if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,
00274         L"SYSTEM\\CurrentControlSet\\Services\\vmx_svga",
00275         0, KEY_QUERY_VALUE, &hReg) != ERROR_SUCCESS)
00276     {
00277         return FALSE;
00278     }
00279     Size = sizeof(DWORD);
00280     if(RegQueryValueEx(hReg, L"Start", 0, &Type, (BYTE*)&Value, &Size) != ERROR_SUCCESS ||
00281         Type != REG_DWORD)
00282     {
00283         RegCloseKey(hReg);
00284         return FALSE;
00285     }
00286 
00287     RegCloseKey(hReg);
00288     return (Value == 1);
00289 }
00290 
00291 
00292 
00293 static BOOL
00294 SaveResolutionSettings(DWORD ResX, DWORD ResY, DWORD ColDepth)
00295 {
00296     HKEY hReg;
00297     DWORD VFreq = 85;
00298 
00299     if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,
00300         L"SYSTEM\\CurrentControlSet\\Services\\vmx_svga\\Device0",
00301         0, KEY_SET_VALUE, &hReg) != ERROR_SUCCESS)
00302     {
00303         return FALSE;
00304     }
00305     if(RegSetValueEx(hReg, L"DefaultSettings.BitsPerPel", 0, REG_DWORD, (BYTE*)&ColDepth, sizeof(DWORD)) != ERROR_SUCCESS)
00306     {
00307         RegCloseKey(hReg);
00308         return FALSE;
00309     }
00310 
00311     if(RegSetValueEx(hReg, L"DefaultSettings.XResolution", 0, REG_DWORD, (BYTE*)&ResX, sizeof(DWORD)) != ERROR_SUCCESS)
00312     {
00313         RegCloseKey(hReg);
00314         return FALSE;
00315     }
00316 
00317     if(RegSetValueEx(hReg, L"DefaultSettings.YResolution", 0, REG_DWORD, (BYTE*)&ResY, sizeof(DWORD)) != ERROR_SUCCESS)
00318     {
00319         RegCloseKey(hReg);
00320         return FALSE;
00321     }
00322 
00323     if(RegSetValueEx(hReg, L"DefaultSettings.VRefresh", 0, REG_DWORD, (BYTE*)&VFreq, sizeof(DWORD)) != ERROR_SUCCESS)
00324     {
00325         RegCloseKey(hReg);
00326         return FALSE;
00327     }
00328 
00329     RegCloseKey(hReg);
00330     return TRUE;
00331 }
00332 
00333 static BOOL
00334 EnableDriver(WCHAR *Key, BOOL Enable)
00335 {
00336     DWORD Value;
00337     HKEY hReg;
00338 
00339     Value = (Enable ? 1 : 4);
00340 
00341     if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, Key, 0, KEY_SET_VALUE, &hReg) != ERROR_SUCCESS)
00342     {
00343         return FALSE;
00344     }
00345     if(RegSetValueEx(hReg, L"Start", 0, REG_DWORD, (BYTE*)&Value, sizeof(DWORD)) != ERROR_SUCCESS)
00346     {
00347         RegCloseKey(hReg);
00348         return FALSE;
00349     }
00350 
00351     RegCloseKey(hReg);
00352     return TRUE;
00353 }
00354 
00355 /* Activate the vmware driver and deactivate the others */
00356 static BOOL
00357 EnableVmwareDriver(BOOL VBE, BOOL VGA, BOOL VMX)
00358 {
00359     if(!EnableDriver(L"SYSTEM\\CurrentControlSet\\Services\\VBE", VBE))
00360     {
00361         return FALSE;
00362     }
00363     if(!EnableDriver(L"SYSTEM\\CurrentControlSet\\Services\\vga", VGA))
00364     {
00365         return FALSE;
00366     }
00367     if(!EnableDriver(L"SYSTEM\\CurrentControlSet\\Services\\vmx_svga", VMX))
00368     {
00369         return FALSE;
00370     }
00371 
00372     return TRUE;
00373 }
00374 
00375 /* GUI */
00376 
00377 
00378 /* Property page dialog callback */
00379 static INT_PTR CALLBACK
00380 PageWelcomeProc(
00381                 HWND hwndDlg,
00382                 UINT uMsg,
00383                 WPARAM wParam,
00384                 LPARAM lParam
00385                 )
00386 {
00387     LPNMHDR pnmh = (LPNMHDR)lParam;
00388     switch(uMsg)
00389     {
00390     case WM_NOTIFY:
00391         {
00392             HWND hwndControl;
00393 
00394             /* Center the wizard window */
00395             hwndControl = GetParent(hwndDlg);
00396             CenterWindow (hwndControl);
00397 
00398             switch(pnmh->code)
00399             {
00400             case PSN_SETACTIVE:
00401                 {
00402                     PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_NEXT);
00403                     break;
00404                 }
00405             case PSN_WIZNEXT:
00406                 {
00407                     if(DriverFilesFound)
00408                     {
00409                         SetWindowLongPtr(hwndDlg, DWL_MSGRESULT, IDD_CONFIG);
00410                         return TRUE;
00411                     }
00412                     break;
00413                 }
00414             }
00415             break;
00416         }
00417     }
00418     return FALSE;
00419 }
00420 
00421 /* Property page dialog callback */
00422 static INT_PTR CALLBACK
00423 PageInsertDiscProc(
00424                    HWND hwndDlg,
00425                    UINT uMsg,
00426                    WPARAM wParam,
00427                    LPARAM lParam
00428                    )
00429 {
00430     switch(uMsg)
00431     {
00432     case WM_NOTIFY:
00433         {
00434             LPNMHDR pnmh = (LPNMHDR)lParam;
00435             switch(pnmh->code)
00436             {
00437             case PSN_SETACTIVE:
00438                 PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_BACK | PSWIZB_NEXT);
00439                 break;
00440             case PSN_WIZNEXT:
00441                 SetWindowLongPtr(hwndDlg, DWL_MSGRESULT, IDD_INSTALLING_VMWARE_TOOLS);
00442                 break;
00443             }
00444             break;
00445         }
00446     }
00447     return FALSE;
00448 }
00449 
00450 static VOID
00451 InstTerminateInstaller(BOOL Wait)
00452 {
00453     if(hInstallationThread != NULL)
00454     {
00455         if(Wait)
00456         {
00457             InterlockedExchange((LONG*)&AbortInstall, 2);
00458             WaitForSingleObject(hInstallationThread, INFINITE);
00459         }
00460         else
00461         {
00462             InterlockedExchange((LONG*)&AbortInstall, 1);
00463         }
00464     }
00465 }
00466 
00467 static DWORD WINAPI
00468 InstInstallationThread(LPVOID lpParameter)
00469 {
00470     HANDLE hThread;
00471     WCHAR InfFileName[1024];
00472     BOOL DriveAvailable;
00473     int DrivesTested = 0;
00474 
00475     if(AbortInstall != 0) goto done;
00476     PostMessage(hInstallationNotifyWnd, WM_INSTSTATUSUPDATE, IDS_SEARCHINGFORCDROM, 0);
00477 
00478     while(AbortInstall == 0)
00479     {
00480         Sleep(500);
00481         DriveAvailable = IsVMwareCDInDrive(&CDDrive);
00482         if(DriveAvailable)
00483             break;
00484         if(DrivesTested++ > 20)
00485         {
00486             PostMessage(hInstallationNotifyWnd, WM_INSTABORT, IDS_FAILEDTOLOCATEDRIVERS, 0);
00487             goto cleanup;
00488         }
00489     }
00490 
00491     if(AbortInstall != 0) goto done;
00492     PostMessage(hInstallationNotifyWnd, WM_INSTSTATUSUPDATE, IDS_COPYINGFILES, 0);
00493 
00494     wcscpy(InfFileName, SrcPath);
00495     wcscat(InfFileName, L"vmx_svga.inf");
00496     DPRINT1("Calling UpdateDriverForPlugAndPlayDevices()\n");
00497     if (!UpdateDriverForPlugAndPlayDevices(
00498         hInstallationNotifyWnd,
00499         L"PCI\\VEN_15AD&DEV_0405&SUBSYS_040515AD&REV_00",
00500         InfFileName,
00501         0,
00502         NULL))
00503     {
00504         AbortInstall = 1;
00505     }
00506     else
00507     {
00508         AbortInstall = 0;
00509     }
00510 
00511 done:
00512     switch(AbortInstall)
00513     {
00514     case 0:
00515         SendMessage(hInstallationNotifyWnd, WM_INSTCOMPLETE, 0, 0);
00516         break;
00517     case 1:
00518         SendMessage(hInstallationNotifyWnd, WM_INSTABORT, 0, 0);
00519         break;
00520     }
00521 
00522 cleanup:
00523     hThread = InterlockedExchangePointer((PVOID*)&hInstallationThread, 0);
00524     if(hThread != NULL)
00525     {
00526         CloseHandle(hThread);
00527     }
00528     return 0;
00529 }
00530 
00531 static BOOL
00532 InstStartInstallationThread(HWND hwndNotify)
00533 {
00534     if(hInstallationThread == NULL)
00535     {
00536         DWORD ThreadId;
00537         hInstallationNotifyWnd = hwndNotify;
00538         AbortInstall = 0;
00539         hInstallationThread = CreateThread(NULL,
00540             0,
00541             InstInstallationThread,
00542             NULL,
00543             CREATE_SUSPENDED,
00544             &ThreadId);
00545         if(hInstallationThread == NULL)
00546         {
00547             return FALSE;
00548         }
00549 
00550         ResumeThread(hInstallationThread);
00551         return TRUE;
00552     }
00553 
00554     return FALSE;
00555 }
00556 
00557 /* Property page dialog callback */
00558 static INT_PTR CALLBACK
00559 PageInstallingProc(
00560                    HWND hwndDlg,
00561                    UINT uMsg,
00562                    WPARAM wParam,
00563                    LPARAM lParam
00564                    )
00565 {
00566     switch(uMsg)
00567     {
00568     case WM_NOTIFY:
00569         {
00570             LPNMHDR pnmh = (LPNMHDR)lParam;
00571             switch(pnmh->code)
00572             {
00573             case PSN_SETACTIVE:
00574                 SetDlgItemText(hwndDlg, IDC_INSTALLINGSTATUS, L"");
00575                 SendDlgItemMessage(hwndDlg, IDC_INSTALLINGPROGRESS, PBM_SETMARQUEE, TRUE, 50);
00576                 PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_BACK);
00577                 InstStartInstallationThread(hwndDlg);
00578                 break;
00579             case PSN_RESET:
00580                 InstTerminateInstaller(TRUE);
00581                 break;
00582             case PSN_WIZBACK:
00583                 if(hInstallationThread != NULL)
00584                 {
00585                     PropSheet_SetWizButtons(GetParent(hwndDlg), 0);
00586                     InstTerminateInstaller(FALSE);
00587                     SetWindowLongPtr(hwndDlg, DWL_MSGRESULT, -1);
00588                     return -1;
00589                 }
00590                 else
00591                 {
00592                     SendDlgItemMessage(hwndDlg, IDC_INSTALLINGPROGRESS, PBM_SETMARQUEE, FALSE, 0);
00593                     SetWindowLongPtr(hwndDlg, DWL_MSGRESULT, IDD_INSERT_VMWARE_TOOLS);
00594                 }
00595                 break;
00596             }
00597             break;
00598         }
00599     case WM_INSTABORT:
00600         /* go back in case we aborted the installation thread */
00601         SendDlgItemMessage(hwndDlg, IDC_INSTALLINGPROGRESS, PBM_SETMARQUEE, FALSE, 0);
00602         PropSheet_SetCurSelByID(GetParent(hwndDlg), IDD_INSERT_VMWARE_TOOLS);
00603         if(wParam != 0)
00604         {
00605             WCHAR Msg[1024];
00606             LoadString(hAppInstance, wParam, Msg, sizeof(Msg) / sizeof(WCHAR));
00607             MessageBox(GetParent(hwndDlg), Msg, NULL, MB_ICONWARNING);
00608         }
00609         break;
00610     case WM_INSTCOMPLETE:
00611         SendDlgItemMessage(hwndDlg, IDC_INSTALLINGPROGRESS, PBM_SETMARQUEE, FALSE, 0);
00612         PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_BACK | PSWIZB_NEXT);
00613         PropSheet_SetCurSelByID(GetParent(hwndDlg), IDD_CONFIG);
00614         break;
00615     case WM_INSTSTATUSUPDATE:
00616         {
00617             WCHAR Msg[1024];
00618             LoadString(hAppInstance, wParam, Msg, sizeof(Msg) / sizeof(WCHAR));
00619             SetDlgItemText(hwndDlg, IDC_INSTALLINGSTATUS, Msg);
00620             break;
00621         }
00622     }
00623     return FALSE;
00624 }
00625 
00626 /* Property page dialog callback */
00627 static INT_PTR CALLBACK
00628 PageInstallFailedProc(
00629                       HWND hwndDlg,
00630                       UINT uMsg,
00631                       WPARAM wParam,
00632                       LPARAM lParam
00633                       )
00634 {
00635     switch(uMsg)
00636     {
00637     case WM_NOTIFY:
00638         {
00639             LPNMHDR pnmh = (LPNMHDR)lParam;
00640             switch(pnmh->code)
00641             {
00642             case PSN_SETACTIVE:
00643                 PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_FINISH);
00644                 break;
00645             }
00646             break;
00647         }
00648     }
00649     return FALSE;
00650 }
00651 
00652 static void
00653 FillComboBox(HWND Dlg, int idComboBox, int From, int To)
00654 {
00655     int i;
00656     WCHAR Text[256];
00657 
00658     for(i = From; i <= To; i++)
00659     {
00660         if(LoadString(hAppInstance, i, Text, 255) > 0)
00661         {
00662             SendDlgItemMessage(Dlg, idComboBox, CB_ADDSTRING, 0, (LPARAM)Text);
00663         }
00664     }
00665 }
00666 
00667 typedef struct
00668 {
00669     int ControlID;
00670     int ResX;
00671     int ResY;
00672 } MAPCTLRES;
00673 
00674 /* Property page dialog callback */
00675 static INT_PTR CALLBACK
00676 PageConfigProc(
00677                HWND hwndDlg,
00678                UINT uMsg,
00679                WPARAM wParam,
00680                LPARAM lParam
00681                )
00682 {
00683     LPNMHDR pnmh = (LPNMHDR)lParam;
00684     switch(uMsg)
00685     {
00686     case WM_INITDIALOG:
00687         {
00688             DWORD ResX = 0, ResY = 0, ColDepth = 0;
00689             int cbSel;
00690 
00691             FillComboBox(hwndDlg, IDC_COLORQUALITY, 10001, 10003);
00692             if(LoadResolutionSettings(&ResX, &ResY, &ColDepth))
00693             {
00694                 SendDlgItemMessage(hwndDlg, ResX + ResY, BM_SETCHECK, BST_CHECKED, 0);
00695                 switch(ColDepth)
00696                 {
00697                 case 8:
00698                     cbSel = 0;
00699                     break;
00700                 case 16:
00701                     cbSel = 1;
00702                     break;
00703                 case 32:
00704                     cbSel = 2;
00705                     break;
00706                 default:
00707                     cbSel = -1;
00708                     break;
00709                 }
00710                 SendDlgItemMessage(hwndDlg, IDC_COLORQUALITY, CB_SETCURSEL, cbSel, 0);
00711             }
00712             break;
00713         }
00714     case WM_NOTIFY:
00715         {
00716             HWND hwndControl;
00717 
00718             /* Center the wizard window */
00719             hwndControl = GetParent(hwndDlg);
00720             CenterWindow (hwndControl);
00721 
00722             switch(pnmh->code)
00723             {
00724             case PSN_SETACTIVE:
00725                 {
00726                     PropSheet_SetWizButtons(GetParent(hwndDlg), ((StartVMwConfigWizard || DriverFilesFound) ? PSWIZB_FINISH | PSWIZB_BACK : PSWIZB_FINISH));
00727                     break;
00728                 }
00729             case PSN_WIZBACK:
00730                 {
00731                     if(StartVMwConfigWizard)
00732                     {
00733                         SetWindowLongPtr(hwndDlg, DWL_MSGRESULT, IDD_CHOOSEACTION);
00734                         return TRUE;
00735                     }
00736                     if(DriverFilesFound)
00737                     {
00738                         SetWindowLongPtr(hwndDlg, DWL_MSGRESULT, IDD_WELCOMEPAGE);
00739                         return TRUE;
00740                     }
00741                     break;
00742                 }
00743             case PSN_WIZFINISH:
00744                 {
00745                     DWORD rx = 800, ry = 600, cd = 32;
00746                     int i;
00747                     static MAPCTLRES Resolutions[11] = {
00748                         {540, 640, 480},
00749                         {1400, 800, 600},
00750                         {1792, 1024, 768},
00751                         {2016, 1152, 864},
00752                         {2240, 1280, 960},
00753                         {2304, 1280, 1024},
00754                         {2450, 1400, 1050},
00755                         {2800, 1600, 1200},
00756                         {3136, 1792, 1344},
00757                         {3248, 1856, 1392},
00758                         {3360, 1920, 1440}
00759                     };
00760                     for(i = 0; i < 11; i++)
00761                     {
00762                         if(SendDlgItemMessage(hwndDlg, Resolutions[i].ControlID, BM_GETCHECK, 0, 0) == BST_CHECKED)
00763                         {
00764                             rx = Resolutions[i].ResX;
00765                             ry = Resolutions[i].ResY;
00766                             break;
00767                         }
00768                     }
00769 
00770                     switch(SendDlgItemMessage(hwndDlg, IDC_COLORQUALITY, CB_GETCURSEL, 0, 0))
00771                     {
00772                     case 0:
00773                         cd = 8;
00774                         break;
00775                     case 1:
00776                         cd = 16;
00777                         break;
00778                     case 2:
00779                         cd = 32;
00780                         break;
00781                     }
00782 
00783                     SaveResolutionSettings(rx, ry, cd);
00784                     break;
00785                 }
00786             }
00787             break;
00788         }
00789     }
00790     return FALSE;
00791 }
00792 
00793 /* Property page dialog callback */
00794 static INT_PTR CALLBACK
00795 PageChooseActionProc(
00796                      HWND hwndDlg,
00797                      UINT uMsg,
00798                      WPARAM wParam,
00799                      LPARAM lParam
00800                      )
00801 {
00802     switch(uMsg)
00803     {
00804     case WM_INITDIALOG:
00805         SendDlgItemMessage(hwndDlg, IDC_CONFIGSETTINGS, BM_SETCHECK, BST_CHECKED, 0);
00806         break;
00807     case WM_NOTIFY:
00808         {
00809             LPNMHDR pnmh = (LPNMHDR)lParam;
00810             switch(pnmh->code)
00811             {
00812             case PSN_SETACTIVE:
00813                 PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_NEXT);
00814                 break;
00815             case PSN_WIZBACK:
00816                 {
00817                     SetWindowLongPtr(hwndDlg, DWL_MSGRESULT, IDD_CHOOSEACTION);
00818                     return TRUE;
00819                 }
00820             case PSN_WIZNEXT:
00821                 {
00822                     static ULONG SelPage[4] = {IDD_CONFIG, IDD_SELECTDRIVER, IDD_SELECTDRIVER, IDD_CHOOSEACTION};
00823                     int i;
00824 
00825                     for(i = IDC_CONFIGSETTINGS; i <= IDC_UNINSTALL; i++)
00826                     {
00827                         if(SendDlgItemMessage(hwndDlg, i, BM_GETCHECK, 0, 0) == BST_CHECKED)
00828                         {
00829                             break;
00830                         }
00831                     }
00832 
00833                     UninstallDriver = (i == IDC_UNINSTALL);
00834 
00835                     SetWindowLongPtr(hwndDlg, DWL_MSGRESULT, SelPage[i - IDC_CONFIGSETTINGS]);
00836                     return TRUE;
00837                 }
00838             }
00839             break;
00840         }
00841     }
00842     return FALSE;
00843 }
00844 
00845 /* Property page dialog callback */
00846 static INT_PTR CALLBACK
00847 PageSelectDriverProc(
00848                      HWND hwndDlg,
00849                      UINT uMsg,
00850                      WPARAM wParam,
00851                      LPARAM lParam
00852                      )
00853 {
00854     switch(uMsg)
00855     {
00856     case WM_INITDIALOG:
00857         SendDlgItemMessage(hwndDlg, IDC_VBE, BM_SETCHECK, BST_CHECKED, 0);
00858         break;
00859     case WM_NOTIFY:
00860         {
00861             LPNMHDR pnmh = (LPNMHDR)lParam;
00862             switch(pnmh->code)
00863             {
00864             case PSN_SETACTIVE:
00865                 PropSheet_SetWizButtons(GetParent(hwndDlg), (UninstallDriver ? PSWIZB_NEXT | PSWIZB_BACK : PSWIZB_BACK | PSWIZB_FINISH));
00866                 break;
00867             case PSN_WIZBACK:
00868                 {
00869                     SetWindowLongPtr(hwndDlg, DWL_MSGRESULT, IDD_CHOOSEACTION);
00870                     return TRUE;
00871                 }
00872             case PSN_WIZNEXT:
00873                 {
00874                     ActivateVBE = (SendDlgItemMessage(hwndDlg, IDC_VBE, BM_GETCHECK, 0, 0) == BST_CHECKED);
00875 
00876                     if(UninstallDriver)
00877                     {
00878                         return FALSE;
00879                     }
00880                     return TRUE;
00881                 }
00882             case PSN_WIZFINISH:
00883                 {
00884                     if(UninstallDriver)
00885                     {
00886                         return FALSE;
00887                     }
00888                     ActivateVBE = (SendDlgItemMessage(hwndDlg, IDC_VBE, BM_GETCHECK, 0, 0) == BST_CHECKED);
00889                     if(!EnableVmwareDriver(ActivateVBE,
00890                         TRUE,
00891                         FALSE))
00892                     {
00893                         WCHAR Msg[1024];
00894                         LoadString(hAppInstance, (ActivateVBE ? IDS_FAILEDTOSELVBEDRIVER : IDS_FAILEDTOSELVGADRIVER), Msg, sizeof(Msg) / sizeof(WCHAR));
00895                         MessageBox(GetParent(hwndDlg), Msg, NULL, MB_ICONWARNING);
00896                         SetWindowLongPtr(hwndDlg, DWL_MSGRESULT, IDD_SELECTDRIVER);
00897                         return TRUE;
00898                     }
00899                     break;
00900                 }
00901             }
00902             break;
00903         }
00904     }
00905     return FALSE;
00906 }
00907 
00908 static VOID
00909 ShowUninstNotice(HWND Owner)
00910 {
00911     WCHAR Msg[1024];
00912     LoadString(hAppInstance, IDS_UNINSTNOTICE, Msg, sizeof(Msg) / sizeof(WCHAR));
00913     MessageBox(Owner, Msg, NULL, MB_ICONINFORMATION);
00914 }
00915 
00916 static INT_PTR CALLBACK
00917 PageDoUninstallProc(
00918                     HWND hwndDlg,
00919                     UINT uMsg,
00920                     WPARAM wParam,
00921                     LPARAM lParam
00922                     )
00923 {
00924     switch(uMsg)
00925     {
00926     case WM_NOTIFY:
00927         {
00928             LPNMHDR pnmh = (LPNMHDR)lParam;
00929             switch(pnmh->code)
00930             {
00931             case PSN_SETACTIVE:
00932                 PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_BACK | PSWIZB_FINISH);
00933                 break;
00934             case PSN_WIZFINISH:
00935                 {
00936                     if(UninstallDriver)
00937                     {
00938                         if(!EnableVmwareDriver(ActivateVBE,
00939                             TRUE,
00940                             FALSE))
00941                         {
00942                             WCHAR Msg[1024];
00943                             LoadString(hAppInstance, (ActivateVBE ? IDS_FAILEDTOSELVBEDRIVER : IDS_FAILEDTOSELVGADRIVER), Msg, sizeof(Msg) / sizeof(WCHAR));
00944                             MessageBox(GetParent(hwndDlg), Msg, NULL, MB_ICONWARNING);
00945                             SetWindowLongPtr(hwndDlg, DWL_MSGRESULT, IDD_SELECTDRIVER);
00946                             return TRUE;
00947                         }
00948                         ShowUninstNotice(GetParent(hwndDlg));
00949                     }
00950                     return FALSE;
00951                 }
00952             }
00953             break;
00954         }
00955     }
00956     return FALSE;
00957 }
00958 
00959 static LONG
00960 CreateWizard(VOID)
00961 {
00962     PROPSHEETHEADER psh;
00963     HPROPSHEETPAGE ahpsp[8];
00964     PROPSHEETPAGE psp;
00965     WCHAR Caption[1024];
00966 
00967     LoadString(hAppInstance, IDS_WIZARD_NAME, Caption, sizeof(Caption) / sizeof(TCHAR));
00968 
00969     /* Create the Welcome page */
00970     ZeroMemory (&psp, sizeof(PROPSHEETPAGE));
00971     psp.dwSize = sizeof(PROPSHEETPAGE);
00972     psp.dwFlags = PSP_DEFAULT | PSP_HIDEHEADER;
00973     psp.hInstance = hAppInstance;
00974     psp.pfnDlgProc = PageWelcomeProc;
00975     psp.pszTemplate = MAKEINTRESOURCE(IDD_WELCOMEPAGE);
00976     ahpsp[0] = CreatePropertySheetPage(&psp);
00977 
00978     /* Create the INSERT_VMWARE_TOOLS page */
00979     psp.dwFlags = PSP_DEFAULT | PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
00980     psp.pszHeaderTitle = MAKEINTRESOURCE(IDD_INSERT_VMWARE_TOOLSTITLE);
00981     psp.pszHeaderSubTitle = MAKEINTRESOURCE(IDD_INSERT_VMWARE_TOOLSSUBTITLE);
00982     psp.pszTemplate = MAKEINTRESOURCE(IDD_INSERT_VMWARE_TOOLS);
00983     psp.pfnDlgProc = PageInsertDiscProc;
00984     ahpsp[1] = CreatePropertySheetPage(&psp);
00985 
00986     /* Create the INSTALLING_VMWARE_TOOLS page */
00987     psp.dwFlags = PSP_DEFAULT | PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
00988     psp.pszHeaderTitle = MAKEINTRESOURCE(IDD_INSTALLING_VMWARE_TOOLSTITLE);
00989     psp.pszHeaderSubTitle = MAKEINTRESOURCE(IDD_INSTALLING_VMWARE_TOOLSSUBTITLE);
00990     psp.pszTemplate = MAKEINTRESOURCE(IDD_INSTALLING_VMWARE_TOOLS);
00991     psp.pfnDlgProc = PageInstallingProc;
00992     ahpsp[2] = CreatePropertySheetPage(&psp);
00993 
00994     /* Create the CONFIG page */
00995     psp.dwFlags = PSP_DEFAULT | PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
00996     psp.pszHeaderTitle = MAKEINTRESOURCE(IDD_CONFIGTITLE);
00997     psp.pszHeaderSubTitle = MAKEINTRESOURCE(IDD_CONFIGSUBTITLE);
00998     psp.pfnDlgProc = PageConfigProc;
00999     psp.pszTemplate = MAKEINTRESOURCE(IDD_CONFIG);
01000     ahpsp[3] = CreatePropertySheetPage(&psp);
01001 
01002     /* Create the INSTALLATION_FAILED page */
01003     psp.dwFlags = PSP_DEFAULT | PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
01004     psp.pszHeaderTitle = MAKEINTRESOURCE(IDD_INSTALLATION_FAILEDTITLE);
01005     psp.pszHeaderSubTitle = MAKEINTRESOURCE(IDD_INSTALLATION_FAILEDSUBTITLE);
01006     psp.pfnDlgProc = PageInstallFailedProc;
01007     psp.pszTemplate = MAKEINTRESOURCE(IDD_INSTALLATION_FAILED);
01008     ahpsp[4] = CreatePropertySheetPage(&psp);
01009 
01010     /* Create the CHOOSEACTION page */
01011     psp.dwFlags = PSP_DEFAULT | PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
01012     psp.pszHeaderTitle = MAKEINTRESOURCE(IDD_CHOOSEACTIONTITLE);
01013     psp.pszHeaderSubTitle = MAKEINTRESOURCE(IDD_CHOOSEACTIONSUBTITLE);
01014     psp.pfnDlgProc = PageChooseActionProc;
01015     psp.pszTemplate = MAKEINTRESOURCE(IDD_CHOOSEACTION);
01016     ahpsp[5] = CreatePropertySheetPage(&psp);
01017 
01018     /* Create the SELECTDRIVER page */
01019     psp.dwFlags = PSP_DEFAULT | PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
01020     psp.pszHeaderTitle = MAKEINTRESOURCE(IDD_SELECTDRIVERTITLE);
01021     psp.pszHeaderSubTitle = MAKEINTRESOURCE(IDD_SELECTDRIVERSUBTITLE);
01022     psp.pfnDlgProc = PageSelectDriverProc;
01023     psp.pszTemplate = MAKEINTRESOURCE(IDD_SELECTDRIVER);
01024     ahpsp[6] = CreatePropertySheetPage(&psp);
01025 
01026     /* Create the DOUNINSTALL page */
01027     psp.dwFlags = PSP_DEFAULT | PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
01028     psp.pszHeaderTitle = MAKEINTRESOURCE(IDD_DOUNINSTALLTITLE);
01029     psp.pszHeaderSubTitle = MAKEINTRESOURCE(IDD_DOUNINSTALLSUBTITLE);
01030     psp.pfnDlgProc = PageDoUninstallProc;
01031     psp.pszTemplate = MAKEINTRESOURCE(IDD_DOUNINSTALL);
01032     ahpsp[7] = CreatePropertySheetPage(&psp);
01033 
01034     /* Create the property sheet */
01035     psh.dwSize = sizeof(PROPSHEETHEADER);
01036     psh.dwFlags = PSH_WIZARD97 | PSH_WATERMARK | PSH_HEADER;
01037     psh.hInstance = hAppInstance;
01038     psh.hwndParent = NULL;
01039     psh.nPages = 7;
01040     psh.nStartPage = (StartVMwConfigWizard ? 5 : 0);
01041     psh.phpage = ahpsp;
01042     psh.pszbmWatermark = MAKEINTRESOURCE(IDB_WATERMARK);
01043     psh.pszbmHeader = MAKEINTRESOURCE(IDB_HEADER);
01044 
01045     /* Display the wizard */
01046     return (LONG)(PropertySheet(&psh) != -1);
01047 }
01048 
01049 int WINAPI
01050 wWinMain(HINSTANCE hInstance,
01051          HINSTANCE hPrevInstance,
01052          LPWSTR lpszCmdLine,
01053          int nCmdShow)
01054 {
01055 
01056     int Version;
01057     WCHAR *lc;
01058 
01059     hAppInstance = hInstance;
01060 
01061     if(!DetectVMware(&Version))
01062     {
01063         return 1;
01064     }
01065 
01066     lc = DestinationPath;
01067     lc += GetSystemDirectory(DestinationPath, MAX_PATH) - 1;
01068     if(lc >= DestinationPath && *lc != L'\\')
01069     {
01070         wcscat(DestinationPath, L"\\");
01071     }
01072     DestinationDriversPath[0] = L'\0';
01073     wcscat(DestinationDriversPath, DestinationPath);
01074     wcscat(DestinationDriversPath, L"drivers\\");
01075 
01076     SetCurrentDirectory(DestinationPath);
01077 
01078     DriverFilesFound = DoesFileExist(DestinationPath, vmx_fb) &&
01079         DoesFileExist(DestinationPath, vmx_mode) &&
01080         DoesFileExist(DestinationDriversPath, vmx_svga);
01081 
01082     StartVMwConfigWizard = DriverFilesFound && IsVmwSVGAEnabled();
01083 
01084     /* Show the wizard */
01085     CreateWizard();
01086 
01087     return 2;
01088 }
01089 

Generated on Sun May 27 2012 04:18:09 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.