//////////////////////////////////////////////////////////////////////////////// // // File Name: Setup.rul // // Description: InstallShield script // // Comments: This script was generated based on the selections you made in // the Project Wizard. Refer to the help topic entitled "Modify // the script that the Project Wizard generates" for information // on possible next steps. // //////////////////////////////////////////////////////////////////////////////// // Include header files #include "ifx.h" ////////////////////// string defines //////////////////////////// #define PRODUCT_REGISTRY_KEY "SOFTWARE\\NZDL\\GSDL" //////////////////// installation declarations /////////////////// // ---- script function prototypes ----- // your script function prototypes prototype rs(BYREF STRING); prototype WriteVersionFile(); prototype SetPermissions(); prototype CheckJava(); // your global variables STRING svAdminPassword; STRING svSetupType; STRING svInstallLocation; STRING javadir; // for _LaunchAppEx function #ifndef STILL_ACTIVE #define STILL_ACTIVE 0x00000103 #endif #if _ISCRIPT_VER < 0x600 #ifndef BYVAL #define BYVAL #endif #endif prototype _LaunchAppEx(STRING, STRING, NUMBER, NUMBER, NUMBER, BYREF NUMBER); prototype BOOL kernel32.CreateProcessA(POINTER, BYVAL STRING, POINTER, POINTER, BOOL, NUMBER, POINTER, POINTER, POINTER, POINTER); prototype BOOL kernel32.GetExitCodeProcess(NUMBER, POINTER); prototype NUMBER kernel32.WaitForSingleObject(NUMBER, NUMBER); prototype BOOL kernel32.CloseHandle(HWND); typedef STARTUPINFO begin NUMBER cb; POINTER lpReserved; POINTER lpDesktop; POINTER lpTitle; NUMBER dwX; NUMBER dwY; NUMBER dwXSize; NUMBER dwYSize; NUMBER dwXCountChars; NUMBER dwYCountChars; NUMBER dwFillAttribute; NUMBER dwFlags; NUMBER wShowWindow; POINTER lpReserved2; HWND hStdInput; HWND hStdOutput; HWND hStdError; end; typedef PROCESS_INFORMATION begin NUMBER hProcess; HWND hThread; NUMBER dwProcessId; NUMBER dwThreadId; end; ////////////////////////////////////////////////////////////////////////////// // // FUNCTION: OnFirstUIBefore // // EVENT: FirstUIBefore event is sent when installation is run for the first // time on given machine. In the handler installation usually displays // UI allowing end user to specify installation parameters. After this // function returns, FeatureTransferData is called to perform file // transfer. // /////////////////////////////////////////////////////////////////////////////// function OnFirstUIBefore() number nResult; string szTitle, szMsg, szField1; string szLicenseFile, szQuestion; string szDir; string szFeatures, szTargetdir; string svName; number nLevel; LIST listInfo; number nvSize; begin SHELL_OBJECT_FOLDER = @PRODUCT_NAME_; szDir = INSTALLDIR; Dlg_Start: // beginning of dialogs label Dlg_SdWelcome: szTitle = ""; szMsg = ""; nResult = SdWelcome( szTitle, szMsg ); if (nResult = BACK) goto Dlg_Start; Dlg_SdLicense: szLicenseFile = SUPPORTDIR ^ "LICENSEen.txt"; if (SELECTED_LANGUAGE = ISLANG_FRENCH_STANDARD) then szLicenseFile = SUPPORTDIR ^ "LICENSEfr.txt"; elseif (SELECTED_LANGUAGE = ISLANG_SPANISH_TRADITIONALSORT) then szLicenseFile = SUPPORTDIR ^ "LICENSEes.txt"; elseif (SELECTED_LANGUAGE = 1049) then szLicenseFile = SUPPORTDIR ^ "LICENSEru.txt"; endif; szTitle = ""; szMsg = ""; szQuestion = ""; nResult = SdLicense( szTitle, szMsg, szQuestion, szLicenseFile ); if (nResult = BACK) goto Dlg_SdWelcome; Dlg_SdAskDestPath: szTitle = ""; szMsg = ""; nResult = SdAskDestPath( szTitle, szMsg, szDir, 0 ); INSTALLDIR = szDir; svInstallLocation = szDir; if (nResult = BACK) goto Dlg_SdLicense; Dlg_SetupType: szTitle = ""; szMsg = ""; svSetupType = "LocalLibrary"; nResult = SdSetupTypeEx ( szTitle , szMsg , "" , svSetupType , 0 ); if (nResult = BACK) goto Dlg_SdAskDestPath; Dlg_SdFeatureTree: szTargetdir = INSTALLDIR; nLevel = 2; nvSize = 256; MsiGetProperty (ISMSI_HANDLE, "ISReleaseFlags", svName, nvSize); // show the full feature tree if doing a custom install or // just the list of collections if not if (svSetupType = "Custom") then szFeatures = ""; szTitle = ""; szMsg = ""; nResult = SdFeatureTree(szTitle, szMsg, szTargetdir, szFeatures, nLevel); elseif (svName % "CDROM_ONLY") then szFeatures = "Collections"; szTitle = @TEXT_SELECT_COLLECTIONS; szMsg = @TEXT_SELECT_COLLECTIONS_DESC; nResult = SdFeatureTree(szTitle, szMsg, szTargetdir, szFeatures, nLevel); endif; if (nResult = BACK) goto Dlg_SetupType; Dlg_SdDlgEdit1: // get the admin password from the user svAdminPassword = "admin"; // the default szTitle = @TEXT_ADMIN_PW; szMsg = @TEXT_ADMIN_PW_DESC; szField1 = @TEXT_PW; nResult = SdShowDlgEdit1(szTitle, szMsg, szField1, svAdminPassword); if (nResult = BACK) goto Dlg_SdFeatureTree; Enable(STATUSEX); return 0; end; ////////////////////////////////////////////////////////////////////////////// // // FUNCTION: OnFirstUIAfter // /////////////////////////////////////////////////////////////////////////////// function OnFirstUIAfter() begin // Store Greenstone version and install location in the registry RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE); RegDBCreateKeyEx(PRODUCT_REGISTRY_KEY, ""); RegDBSetKeyValueEx(PRODUCT_REGISTRY_KEY, "CurrentVersion", REGDB_STRING, @PRODUCT_VERSION, -1); RegDBSetKeyValueEx(PRODUCT_REGISTRY_KEY, "GSDLHOME", REGDB_STRING, INSTALLDIR, -1); // Write VERSION file for automatic updating in the future WriteVersionFile(); end; function WriteVersionFile() NUMBER nvSize; STRING svName; STRING versionfile; NUMBER nvFileHandle; NUMBER nvResult; STRING svResult; NUMBER linenum; begin nvSize = 256; MsiGetProperty (ISMSI_HANDLE, "ISReleaseFlags", svName, nvSize); versionfile = svInstallLocation ^ "VERSION"; OpenFileMode(FILE_MODE_APPEND); CreateFile(nvFileHandle, svInstallLocation, "VERSION"); FileInsertLine(versionfile, "Version: " + @PRODUCT_VERSION, 0, AFTER); if (svName % "CDROM_ONLY") then FileInsertLine(versionfile, "Media: CD", 1, AFTER); else FileInsertLine(versionfile, "Media: Web", 1, AFTER); endif; FileInsertLine(versionfile, "OS: Windows", 2, AFTER); if (SELECTED_LANGUAGE = ISLANG_ENGLISH_UNITEDSTATES) then FileInsertLine(versionfile, "Language: en", 3, AFTER); elseif (SELECTED_LANGUAGE = ISLANG_FRENCH_STANDARD) then FileInsertLine(versionfile, "Language: fr", 3, AFTER); elseif (SELECTED_LANGUAGE = ISLANG_SPANISH_TRADITIONALSORT) then FileInsertLine(versionfile, "Language: es", 3, AFTER); elseif (SELECTED_LANGUAGE = 1049) then // Russian FileInsertLine(versionfile, "Language: ru", 3, AFTER); endif; linenum = 4; FeatureGetData(MEDIA, "Documentation", FEATURE_FIELD_SELECTED, nvResult, svResult); if (nvResult != 0) then FileInsertLine(versionfile, "Option: Documentation", linenum, AFTER); linenum++; endif; FeatureGetData(MEDIA, "CollectionExport", FEATURE_FIELD_SELECTED, nvResult, svResult); if (nvResult != 0) then FileInsertLine(versionfile, "Option: Export to CD", linenum, AFTER); linenum++; endif; FeatureGetData(MEDIA, "LocalLibrary", FEATURE_FIELD_SELECTED, nvResult, svResult); if (nvResult != 0) then FileInsertLine(versionfile, "Option: Local Library", linenum, AFTER); linenum++; endif; FeatureGetData(MEDIA, "WebLibrary", FEATURE_FIELD_SELECTED, nvResult, svResult); if (nvResult != 0) then FileInsertLine(versionfile, "Option: Web Library", linenum, AFTER); linenum++; endif; FeatureGetData(MEDIA, "SourceCode", FEATURE_FIELD_SELECTED, nvResult, svResult); if (nvResult != 0) then FileInsertLine(versionfile, "Option: Source code", linenum, AFTER); linenum++; endif; CloseFile(nvFileHandle); end; /////////////////////////////////////////////////////////////////////////////// // // FUNCTION: OnMaintUIBefore // // EVENT: MaintUIBefore event is sent when end user runs installation that // has already been installed on the machine. Usually this happens // through Add/Remove Programs applet. In the handler, installation // usually displays UI allowing end user to modify existing installation // or uninstall application. After this function returns, // FeatureTransferData is called to perform file transfer. // /////////////////////////////////////////////////////////////////////////////// function OnMaintUIBefore() NUMBER nvSize, nvType; NUMBER nResult, nType; STRING szTitle, szMsg, svDir, svResult, szCaption; begin // MessageBox(@TEXT_INSTALLED_1 + "\n" + // @TEXT_INSTALLED_2 + "\n" + // @TEXT_INSTALLED_3, INFORMATION); // exit; // Read Greenstone install location from the registry RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE); RegDBGetKeyValueEx(PRODUCT_REGISTRY_KEY, "GSDLHOME", nvType, svInstallLocation, nvSize); Dlg_Start: Disable(BACKBUTTON); nType = SdWelcomeMaint(szTitle, szMsg, MODIFY); Enable(BACKBUTTON); if (nType = MODIFY) then szTitle = ""; szMsg = ""; nResult = SdFeatureTree(szTitle, szMsg, TARGETDIR, "", 2); if (nResult = BACK) goto Dlg_Start; WriteVersionFile(); elseif (nType = REPAIR) then ComponentReinstall(); elseif (nType = REMOVEALL) then svResult = SdLoadString(IFX_MAINTUI_MSG); szCaption = SdLoadString(IFX_ONMAINTUI_CAPTION); nResult = SprintfBox(MB_OKCANCEL,szCaption,"%s",svResult); if (nResult = IDCANCEL) goto Dlg_Start; ComponentRemoveAll(); // Delete version file DeleteFile(svInstallLocation ^ "VERSION"); // Delete (hopefully empty) Start Menu folder (for Win 95/98) DeleteFolderIcon(FOLDER_PROGRAMS, "Greenstone Digital Library"); endif; Enable(STATUSEX); end; /////////////////////////////////////////////////////////////////////////////// // // FUNCTION: OnEnd // // EVENT: End event is the last event. It is not sent if the installation // has been aborted. In this case Abort event is sent // /////////////////////////////////////////////////////////////////////////////// function OnEnd() NUMBER nvSize; STRING svName; begin if (MAINTENANCE = FALSE) then nvSize = 256; MsiGetProperty (ISMSI_HANDLE, "ISReleaseFlags", svName, nvSize); // Offer to install the JRE if this is a CD-ROM release if (svName % "CDROM_ONLY" && CheckJava() == FALSE) then if (AskYesNo(@TEXT_JAVA_RUNTIME, YES) == YES) then // Run the Java Runtime Environment installer LaunchAppAndWait(SRCDIR ^ "packages" ^ "j2re-1_4_2_03-windows-i586-p.exe", "", WAIT); endif; endif; // Offer to install ImageMagick if this is a CD-ROM release if (svName % "CDROM_ONLY") then if (AskYesNo(@TEXT_IMAGE_MAGICK, YES) == YES) then // Run the ImageMagick installer LaunchAppAndWait(SRCDIR ^ "packages" ^ "ImageMagick-5.5.7-Q8-windows-dll.exe", "", WAIT); endif; endif; // Offer to install the Organizer if this is a CD-ROM release // if (svName % "CDROM_ONLY") then // if (AskYesNo(@TEXT_COLLORG, YES) == YES) then // we need to wait for this to complete just in case setup causes // the system to be rebooted (which it will on some systems in some // cirtumstances) // LaunchAppAndWait(SRCDIR ^ "windows_utilities" ^ "Organizer.exe", "", WAIT); // endif; // endif; else endif; end; // turn any backslashes in string into forward slashes function rs(svString) NUMBER i; begin for i = 0 to StrLength(svString) if (svString[i] = '\\') then svString[i] = '/'; endif; endfor; end; // if running NT/2000 we need to make the collect and tmp // directories and some contents of the etc directory writable // by all users (otherwise certain functions will only work // if Greenstone is run by someone with admin privileges) function SetPermissions() STRING szProgram, szCmdLine, svResult; NUMBER nvExitCode, nvResult; begin GetSystemInfo( OS, nvResult, svResult ); if (nvResult = IS_WINDOWSNT) then szProgram = WINSYSDIR ^ "cmd.exe"; szCmdLine = "/c cacls \"" + INSTALLDIR ^ "tmp\" /E /G Everyone:F"; _LaunchAppEx(szProgram, szCmdLine, WAIT, SW_HIDE, 5000, nvExitCode); szCmdLine = "/c cacls \"" + INSTALLDIR ^ "collect\" /E /G Everyone:F"; _LaunchAppEx(szProgram, szCmdLine, WAIT, SW_HIDE, 5000, nvExitCode); szCmdLine = "/c cacls \"" + INSTALLDIR ^ "etc" ^ "error.txt\" /E /G Everyone:F"; _LaunchAppEx(szProgram, szCmdLine, WAIT, SW_HIDE, 5000, nvExitCode); szCmdLine = "/c cacls \"" + INSTALLDIR ^ "etc" ^ "key.db\" /E /G Everyone:F"; _LaunchAppEx(szProgram, szCmdLine, WAIT, SW_HIDE, 5000, nvExitCode); szCmdLine = "/c cacls \"" + INSTALLDIR ^ "etc" ^ "users.db\" /E /G Everyone:F"; _LaunchAppEx(szProgram, szCmdLine, WAIT, SW_HIDE, 5000, nvExitCode); szCmdLine = "/c cacls \"" + INSTALLDIR ^ "etc" ^ "main.cfg\" /E /G Everyone:F"; _LaunchAppEx(szProgram, szCmdLine, WAIT, SW_HIDE, 5000, nvExitCode); szCmdLine = "/c cacls \"" + INSTALLDIR ^ "etc" ^ "history.db\" /E /G Everyone:F"; _LaunchAppEx(szProgram, szCmdLine, WAIT, SW_HIDE, 5000, nvExitCode); szCmdLine = "/c cacls \"" + INSTALLDIR ^ "etc" ^ "usage.txt\" /E /G Everyone:F"; _LaunchAppEx(szProgram, szCmdLine, WAIT, SW_HIDE, 5000, nvExitCode); endif; end; function _LaunchAppEx(szProgram, szCmdLine, nWait, nShow, nTimeOut, nvExitCode) STARTUPINFO siData; PROCESS_INFORMATION piData; begin siData.cb = 68; siData.lpReserved = NULL; siData.lpDesktop = NULL; siData.lpTitle = NULL; siData.dwX = 0; siData.dwY = 0; siData.dwXSize = 0; siData.dwYSize = 0; siData.dwXCountChars = 0; siData.dwYCountChars = 0; siData.dwFillAttribute = 0; siData.dwFlags = 1; siData.wShowWindow = nShow; siData.lpReserved2 = NULL; siData.hStdInput = NULL; siData.hStdOutput = NULL; siData.hStdError = NULL; if (CreateProcessA(NULL, szProgram + " " + szCmdLine, NULL, NULL, TRUE, 0, NULL, NULL, &siData, &piData) = 0) then return (-1); endif; if ( nWait != WAIT ) then nvExitCode = 0; return 0; endif; WaitForSingleObject(piData.hProcess, nTimeOut); GetExitCodeProcess(piData.hProcess, &nvExitCode); CloseHandle(piData.hProcess); CloseHandle(piData.hThread); return 0; end; function CheckJava() string ProductKey, svValue; number nvType, nvSize, nResult; BOOL javaok; LIST listID; string svTmp; number nvTmp; begin RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE); // Start with the JDK to see if its installed javaok = FALSE; ProductKey = "SOFTWARE\\JavaSoft\\Java Development Kit"; if (RegDBGetKeyValueEx(ProductKey, "CurrentVersion", nvType, svValue, nvSize)=0) then // parse the version number and make sure it's at least version 1.4 listID = ListCreate(STRINGLIST); StrGetTokens (listID, svValue, "."); ListGetFirstString(listID, svTmp); StrToNum(nvTmp, svTmp); if (nvTmp>=1) then ListGetNextString(listID, svTmp); StrToNum(nvTmp, svTmp); if (nvTmp>=4) then javaok = TRUE; endif; endif; if (javaok) then javaok = FALSE; ProductKey = ProductKey + "\\" + svValue; if (RegDBGetKeyValueEx(ProductKey, "JavaHome", nvType, svValue, nvSize)=0) then javadir = svValue; javaok = TRUE; endif; endif; ListDestroy(listID); endif; // Failing that search for a more common JRE if (javaok=FALSE) then ProductKey = "SOFTWARE\\JavaSoft\\Java Runtime Environment"; if (RegDBGetKeyValueEx(ProductKey, "CurrentVersion", nvType, svValue, nvSize)=0) then // parse the version number and make sure it's at least version 1.4 listID = ListCreate(STRINGLIST); StrGetTokens (listID, svValue, "."); ListGetFirstString(listID, svTmp); StrToNum(nvTmp, svTmp); if (nvTmp>=1) then ListGetNextString(listID, svTmp); StrToNum(nvTmp, svTmp); if (nvTmp>=4) then javaok = TRUE; endif; endif; if (javaok) then javaok = FALSE; ProductKey = ProductKey + "\\" + svValue; if (RegDBGetKeyValueEx(ProductKey, "JavaHome", nvType, svValue, nvSize)=0) then javadir = svValue; javaok = TRUE; endif; endif; ListDestroy(listID); endif; endif; RegDBSetDefaultRoot(HKEY_CLASSES_ROOT); if (javaok=FALSE) then return FALSE; endif; if (javadir[0]="\"") then StrSub(javadir, javadir, 1, StrLength(javadir)); endif; nvTmp = StrLength(javadir); if (javadir[nvTmp]="\"") then StrSub(javadir, javadir, 0, StrLength(javadir)-1); endif; LongPathToShortPath(javadir); StrRemoveLastSlash(javadir); // nResult = SprintfBox(MB_OK, "Java location", "%s", javadir); return TRUE; end; #include "FeatureEvents.rul"