1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/update/update.js.in Fri Mar 08 13:50:07 2019 +0000
1.3 @@ -0,0 +1,68 @@
1.4 +var WshShell = WScript.CreateObject("WScript.Shell");
1.5 +var ScriptPath = WScript.ScriptFullName.replace(/\\[^\\]*$/, "");
1.6 +var FileSystemObject = new ActiveXObject("Scripting.FileSystemObject");
1.7 +
1.8 +function RunUpdate(args)
1.9 +{
1.10 + var OKButton = 0, ErrorIcon = 16, ForReading = 1;
1.11 + var path, command, i, ExecObject, text;
1.12 + path = FileSystemObject.BuildPath(ScriptPath, "update.exe");
1.13 + command = "\"" + path + "\"";
1.14 + for(i = 0; i < args.Length; i++)
1.15 + command += " \"" + args.Item(i) + "\"";
1.16 + ExecObject = WshShell.Exec(command);
1.17 + if (!ExecObject.StdErr.AtEndOfStream)
1.18 + {
1.19 + text = "Update failed for an unexpected reason. Please report "
1.20 + + "the following error to support@city-occupational.co.uk:\n\n"
1.21 + + ExecObject.StdErr.ReadAll();
1.22 + WshShell.Popup(text, 0, "Update failed", OKButton + ErrorIcon);
1.23 + return false;
1.24 + }
1.25 + else if (ExecObject.ExitCode)
1.26 + {
1.27 + text = "Update failed without giving a reason. Please report "
1.28 + + "this to support@city-occupational.co.uk";
1.29 + WshShell.Popup(text, 0, "Update failed", OKButton + ErrorIcon);
1.30 + return false;
1.31 + }
1.32 + return true;
1.33 +}
1.34 +
1.35 +function Update()
1.36 +{
1.37 + var path;
1.38 + path = FileSystemObject.BuildPath(ScriptPath, "pre-inst.exe");
1.39 + WshShell.Run("\"" + path + "\"" + " --post \"wscript.exe"
1.40 + + " \\\"" + WScript.ScriptFullName + "\\\""
1.41 + + " --post %INSTALL_PREFIX% %TEST_RESULT%\"",
1.42 + 7, true);
1.43 +}
1.44 +
1.45 +function PostUpdate()
1.46 +{
1.47 + var OKButton = 0, InfoIcon = 64, text;
1.48 + var test_result, install_prefix, path, args;
1.49 + install_prefix = WScript.Arguments.Item(1);
1.50 + test_result = WScript.Arguments.Item(2);
1.51 + if (test_result == "pass")
1.52 + {
1.53 + path = FileSystemObject.BuildPath(install_prefix,
1.54 + "bin\\app-manager.exe");
1.55 + WshShell.Run("\"" + path + "\" --update \"" + ScriptPath + "\"");
1.56 + }
1.57 + else
1.58 + {
1.59 + args = { Length:0, Item:function(){return nil} };
1.60 + if (RunUpdate(args))
1.61 + {
1.62 + text = "Software update completed successfully.";
1.63 + WshShell.Popup(text, 0, "Software Update", OKButton + InfoIcon);
1.64 + }
1.65 + }
1.66 +}
1.67 +
1.68 +if (WScript.Arguments.Length < 1)
1.69 + Update()
1.70 +else if (WScript.Arguments.Length >= 3 && WScript.Arguments.Item(0) == "--post")
1.71 + PostUpdate()