home *** CD-ROM | disk | FTP | other *** search
- // Microworks ObjectMate 2.6
- //
- // ObjectMate Installation
- //
- // Copyright 1992-94 Microworks Sydney, Australia.
- //
- // INSTALL.CPP
-
- /* Install is the installation initialization program. It expands the main
- * installation program MWINSTAL.EX_ into the Windows system subdirectory
- * and checks to see if there is an old version of SFX200.DLL. If it finds
- * one, or if SFX200.DLL is not found, it copies the new version into the
- * Windows system subdirectory. Like MWInstal, Install is a generic Windows
- * program to ensure the smallest possible executable file size.
- *
- * Files must be compressed with COMPRESS.EXE using the /r option followed by the
- * the files full path name. You can compress whole directories or all files with
- * the same extension using wild cards. For example, 'compress /r c:\temp\*.*'
- * compresses all the files in the c:\temp directory.
- *
- * When you compress a file with compress using the /r option, the original filename
- * is stored in the compressed file and is the file name returned by GetExpandedName.
- * You can specify the compressed file name at the time of compression but if you do
- * the original file name is not stored in the compressed file and must be specifed
- * at the time of expansion.
- */
-
- #include "install.h"
-
- // WinMain
-
- int PASCAL
- WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdParam, int nCmdShow)
- {
- char systemPath[MAXPATH];
- char systemDrive[MAXDRIVE];
- char systemDir[MAXDIR];
- DLGPROC splashproc;
- HINSTANCE hSFXLib;
- int i, usage;
-
- if (!hPrevInstance)
- {
- WNDCLASS wndclass;
- memset(&wndclass, 0, sizeof(WNDCLASS));
- wndclass.lpszClassName = "SPLASHDIALOG";
- wndclass.lpfnWndProc = (WNDPROC) DefaultProc;
- wndclass.cbClsExtra = 0;
- wndclass.cbWndExtra = DLGWINDOWEXTRA;
- wndclass.hInstance = hInstance;
- wndclass.hIcon = 0;
- wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
- wndclass.hbrBackground = 0;
- wndclass.lpszMenuName = 0;
- wndclass.style = 0;
- if (!RegisterClass(&wndclass)) exit(0);
- }
- else
- return 0;
-
- /* Retrieve the full path of install.exe and use it to extract the drive and
- * directory of the files to be installed.
- */
- char startApp[MAXPATH];
- GetModuleFileName(hInstance, startApp, MAXPATH - 1);
- fnsplit(startApp, FromDrive, FromDir, 0, 0);
- lstrcat(lstrcpy(lpCmdParam, FromDrive), FromDir);
- if (lpCmdParam[lstrlen(lpCmdParam) - 1] == '\\')
- lpCmdParam[lstrlen(lpCmdParam) - 1] = '\0';
-
- /* Load lzexpand.dll to decompress the main installation program and
- * SFX200.DLL
- */
- SetErrorMode(SEM_NOOPENFILEERRORBOX);
- LZLib = LoadLibrary("lzexpand.dll");
- if (LZLib < HINSTANCE_ERROR)
- {
- ErrorMsg("Unable to load lzexpand.dll. Make sure this file is in your "
- "Windows system subdirectory and run Install again.");
- return 0;
- }
-
- /* Load dialog splash panel so user has something to look at while install
- * copies the main installation program and SFX200.DLL into Windows system
- * subdirectory.
- */
- splashproc = (DLGPROC) MakeProcInstance((FARPROC) SplashProc, hInstance);
- SplashWnd = CreateDialog(hInstance, "SPLASHDIALOG", 0, splashproc);
- ShowWindow(SplashWnd, nCmdShow);
- UpdateWindow(SplashWnd);
- HourGlass(TRUE);
-
- /* Get the drive and directory name for the Windows system
- * subdirectory.
- */
- GetSystemDirectory(systemPath, MAXPATH - 1);
- if (systemPath[lstrlen(systemPath) - 1] != '\\')
- {
- lstrcat(systemPath, "\\");
- }
- fnsplit(systemPath, systemDrive, systemDir, 0, 0);
-
- /* Check to see if he user has a old version of SFX200.DLL and if so,
- * if its loaded into memory remove it and load the new version of
- * SFX200.DLL.
- *
- * If SFX200.DLL was loaded into memory prior to installation, removing it
- * will cause the programs that use it to crash when the installation is
- * finished. To prevent this from happening Windows should be restarted.
- * If SFX200.DLL was not loaded into memory prior to installation, Windows
- * doesn't need to be restarted. lpCmdParam is used to pass this information
- * onto MWINSTAL.EXE.
- *
- * lpCmdParam passes the installation path to MWINSTAL.EXE, so it knows
- * where to find the installation files. At the beginning of WinMain the
- * terminal backslash was stripped from the installation directory path.
- * If SFX200.DLL was loaded into memory prior to installation the backslash
- * re appended.
- */
- hSFXLib = LoadLibrary("SFX200.DLL");
- if (hSFXLib >= HINSTANCE_ERROR)
- {
- UINT (far* lpfnGetSFXVersion)();
- (FARPROC) lpfnGetSFXVersion = GetProcAddress(hSFXLib, "GetSFXVersion");
- UINT version = (UINT)lpfnGetSFXVersion();
- if (version < SFXVERSION)
- {
- usage = GetModuleUsage(hSFXLib);
- if (usage > 1)
- lstrcat(lpCmdParam, "\\");
- for (i = 0; i < usage; i++)
- {
- FreeLibrary(hSFXLib);
- }
- goto LoadSFX200;
- }
- else
- goto NoLoadSFX200;
- }
- LoadSFX200:
- ExpandFile(systemDrive, systemDir, "SFX200.DL_");
-
- NoLoadSFX200:
- ExpandFile(systemDrive, systemDir, "MWINSTAL.EX_");
- FreeLibrary(LZLib);
- FreeLibrary(hSFXLib);
- ShowWindow(SplashWnd, SW_HIDE);
- if (ShellExecute(0, 0, "MWINSTAL.EXE", lpCmdParam, ".\\", SW_NORMAL) < HINSTANCE_ERROR)
- ErrorMsg("Unable to execute mwinstall.exe. You can run mwnstall.exe "
- "by specifying its directory path as a command line parameter.");
- DestroyWindow(SplashWnd);
- HourGlass(FALSE);
- return 0;
- }
-
- // DefaultProc
-
- long FAR PASCAL _export
- DefaultProc(HWND hDlg, UINT message, WPARAM wParam , LPARAM lParam)
- {
- return DefDlgProc(hDlg, message, wParam, lParam);
- }
-
- // SplashProc
-
- BOOL CALLBACK _export
- SplashProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
- {
- switch (message)
- {
- case WM_INITDIALOG:
- CenterWindow(hDlg);
- break;
-
- case WM_CTLCOLOR:
- switch (HIWORD(lParam))
- {
- case CTLCOLOR_STATIC:
- SetBkMode((HDC)wParam, TRANSPARENT);
- return (BOOL)GetStockObject(LTGRAY_BRUSH);
-
- case CTLCOLOR_DLG:
- return (BOOL)GetStockObject(LTGRAY_BRUSH);
-
- default:
- return FALSE;
- }
-
- case WM_DESTROY:
- PostQuitMessage(0);
- break;
-
- default:
- return FALSE;
- }
- return TRUE;
- }
-
- // CenterWindow
-
- void
- CenterWindow(HWND hWndCenter)
- {
- RECT center;
- RECT desktop;
- int x, y, w, h;
-
- GetWindowRect(GetDesktopWindow(), &desktop);
- GetWindowRect(hWndCenter, ¢er);
- w = (center.right - center.left);
- h = (center.bottom - center.top);
- x = ((desktop.right - desktop.left) - w) / 2;
- y = ((desktop.bottom - desktop.top) - h) / 2;
- MoveWindow(hWndCenter, x, y, w, h, TRUE);
- }
-
- // HourGlass
-
- void
- HourGlass(int on)
- {
- static HCURSOR hCursorSave;
- if (on)
- hCursorSave = SetCursor(LoadCursor(0, IDC_WAIT));
- else
- SetCursor(hCursorSave);
- }
-
- // ErrorMsg
-
- void
- ErrorMsg(char far* msg)
- {
- MessageBeep(MB_ICONSTOP);
- MessageBox(GetActiveWindow(), msg, "Installation Error", MB_ICONSTOP);
- }
-
- // ExpandFile
-
- int
- ExpandFile(char* drive, char* dir, char far* filename)
- {
- char src[MAXPATH];
- char dest[MAXPATH];
- char ExpandedFile[MAXFILE];
- char ExpandedExt[MAXEXT];
-
- /* Get the expanded file name
- */
- sprintf(src, "%s%s%s", FromDrive, FromDir, filename);
- if (GetExpandedName(src, dest) == -1)
- {
- char text[80];
- sprintf(text, "Unable to expand the file %s.\r\nIt's missing!", src);
- ErrorMsg(text);
- return FALSE;
- }
-
- /* Extract the expanded file name and extension and build the destination path
- */
- fnsplit(dest, 0, 0, ExpandedFile, ExpandedExt);
- sprintf(dest, "%s%s%s%s", drive, dir, ExpandedFile, ExpandedExt);
-
- OFSTRUCT ofSrc, ofDst;
- HFILE in = LZOpenFile(src, &ofSrc, OF_READ);
- if (in == -1)
- {
- ErrorMsg("Unable to open compressed file. Ensure that compressed installation "
- "files are in the same directroy as install.exe and run Install again.");
- return FALSE;
- }
- HFILE out = LZOpenFile(dest, &ofDst, OF_CREATE);
- if (out == -1)
- {
- ErrorMsg("Unable to create uncompressed file.");
- return FALSE;
- }
-
- /* Decompress the file
- */
- LZCopy(in, out);
- LZClose(in);
- LZClose(out);
- return TRUE;
- }
-
-