diff -r 000000000000 -r 4b52e95a0104 update/update.js.in --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/update/update.js.in Thu Jul 07 19:03:54 2016 +0100 @@ -0,0 +1,68 @@ +var WshShell = WScript.CreateObject("WScript.Shell"); +var ScriptPath = WScript.ScriptFullName.replace(/\\[^\\]*$/, ""); +var FileSystemObject = new ActiveXObject("Scripting.FileSystemObject"); + +function RunUpdate(args) +{ + var OKButton = 0, ErrorIcon = 16, ForReading = 1; + var path, command, i, ExecObject, text; + path = FileSystemObject.BuildPath(ScriptPath, "update.exe"); + command = "\"" + path + "\""; + for(i = 0; i < args.Length; i++) + command += " \"" + args.Item(i) + "\""; + ExecObject = WshShell.Exec(command); + if (!ExecObject.StdErr.AtEndOfStream) + { + text = "Update failed for an unexpected reason. Please report " + + "the following error to support@city-occupational.co.uk:\n\n" + + ExecObject.StdErr.ReadAll(); + WshShell.Popup(text, 0, "Update failed", OKButton + ErrorIcon); + return false; + } + else if (ExecObject.ExitCode) + { + text = "Update failed without giving a reason. Please report " + + "this to support@city-occupational.co.uk"; + WshShell.Popup(text, 0, "Update failed", OKButton + ErrorIcon); + return false; + } + return true; +} + +function Update() +{ + var path; + path = FileSystemObject.BuildPath(ScriptPath, "pre-inst.exe"); + WshShell.Run("\"" + path + "\"" + " --post \"wscript.exe" + + " \\\"" + WScript.ScriptFullName + "\\\"" + + " --post %INSTALL_PREFIX% %TEST_RESULT%\"", + 7, true); +} + +function PostUpdate() +{ + var OKButton = 0, InfoIcon = 64, text; + var test_result, install_prefix, path, args; + install_prefix = WScript.Arguments.Item(1); + test_result = WScript.Arguments.Item(2); + if (test_result == "pass") + { + path = FileSystemObject.BuildPath(install_prefix, + "bin\\app-manager.exe"); + WshShell.Run("\"" + path + "\" --update \"" + ScriptPath + "\""); + } + else + { + args = { Length:0, Item:function(){return nil} }; + if (RunUpdate(args)) + { + text = "Software update completed successfully."; + WshShell.Popup(text, 0, "Software Update", OKButton + InfoIcon); + } + } +} + +if (WScript.Arguments.Length < 1) + Update() +else if (WScript.Arguments.Length >= 3 && WScript.Arguments.Item(0) == "--post") + PostUpdate()