ali@24: var WshShell = WScript.CreateObject("WScript.Shell"); ali@24: var ScriptPath = WScript.ScriptFullName.replace(/\\[^\\]*$/, ""); ali@24: var FileSystemObject = new ActiveXObject("Scripting.FileSystemObject"); ali@24: ali@24: function RunSetup(args) ali@24: { ali@24: var OKButton = 0, ErrorIcon = 16, ForReading = 1; ali@24: var path, command, i, ExecObject, text; ali@24: path = FileSystemObject.BuildPath(ScriptPath, "setup.exe"); ali@24: command = "\"" + path + "\""; ali@24: for(i = 0; i < args.Length; i++) ali@24: command += " \"" + args.Item(i) + "\""; ali@24: ExecObject = WshShell.Exec(command); ali@24: if (!ExecObject.StdErr.AtEndOfStream) ali@24: { ali@24: text = "Setup failed for an unexpected reason. Please report " ali@24: + "the following error to support@city-occupational.co.uk:\n\n" ali@24: + ExecObject.StdErr.ReadAll(); ali@24: WshShell.Popup(text, 0, "Setup failed", OKButton + ErrorIcon); ali@24: return false; ali@24: } ali@24: else if (ExecObject.ExitCode) ali@24: { ali@24: text = "Setup failed without giving a reason. Please report " ali@24: + "this to support@city-occupational.co.uk"; ali@24: WshShell.Popup(text, 0, "Setup failed", OKButton + ErrorIcon); ali@24: return false; ali@24: } ali@24: return true; ali@24: } ali@24: ali@24: function Install() ali@24: { ali@24: var path; ali@24: path = FileSystemObject.BuildPath(ScriptPath, "pre-inst.exe"); ali@24: WshShell.Run("\"" + path + "\"" + " --post \"wscript.exe" ali@24: + " \\\"" + WScript.ScriptFullName + "\\\"" ali@24: + " --post %INSTALL_PREFIX% %TEST_RESULT%\"", ali@24: 7, true); ali@24: } ali@24: ali@24: function Uninstall() ali@24: { ali@24: var path; ali@24: path = FileSystemObject.BuildPath(ScriptPath, "pre-inst.exe"); ali@24: WshShell.Run("\"" + path + "\"" + " -u --post \"wscript.exe" ali@24: + " \\\"" + WScript.ScriptFullName + "\\\"" + " --postun\"", 7, true); ali@24: } ali@24: ali@24: function PostInstall() ali@24: { ali@24: var OKButton = 0, InfoIcon = 64, text; ali@24: var test_result, install_prefix, path, args; ali@24: install_prefix = WScript.Arguments.Item(1); ali@24: test_result = WScript.Arguments.Item(2); ali@24: if (test_result == "pass") ali@24: { ali@24: path = FileSystemObject.BuildPath(install_prefix, ali@24: "bin\\app-manager.exe"); ali@24: WshShell.Run("\"" + path + "\" --setup \"" + ScriptPath + "\""); ali@24: } ali@24: else ali@24: { ali@24: args = { Length:0, Item:function(){return nil} }; ali@24: if (RunSetup(args)) ali@24: { ali@24: text = "Software installation completed successfully."; ali@24: WshShell.Popup(text, 0, "Software Installation", ali@24: OKButton + InfoIcon); ali@24: } ali@24: } ali@24: } ali@24: ali@24: function PostUninstall() ali@24: { ali@24: var args = { Length:1, Item:function(){return "-u"} }; ali@24: var OKButton = 0, InfoIcon = 64, text; ali@24: if (RunSetup(args)) ali@24: { ali@24: text = "Uninstall completed successfully."; ali@24: WshShell.Popup(text, 0, "Uninstall", OKButton + InfoIcon); ali@24: } ali@24: } ali@24: ali@24: if (WScript.Arguments.Length < 1) ali@24: Install() ali@24: else if (WScript.Arguments.Item(0) == "-u") ali@24: Uninstall() ali@24: else if (WScript.Arguments.Length >= 3 && WScript.Arguments.Item(0) == "--post") ali@24: PostInstall() ali@24: else if (WScript.Arguments.Item(0) == "--postun") ali@24: PostUninstall()