|
ali@24
|
1 |
var WshShell = WScript.CreateObject("WScript.Shell");
|
|
ali@24
|
2 |
var ScriptPath = WScript.ScriptFullName.replace(/\\[^\\]*$/, "");
|
|
ali@24
|
3 |
var FileSystemObject = new ActiveXObject("Scripting.FileSystemObject");
|
|
ali@24
|
4 |
|
|
ali@24
|
5 |
function RunUpdate(args)
|
|
ali@24
|
6 |
{
|
|
ali@24
|
7 |
var OKButton = 0, ErrorIcon = 16, ForReading = 1;
|
|
ali@24
|
8 |
var path, command, i, ExecObject, text;
|
|
ali@24
|
9 |
path = FileSystemObject.BuildPath(ScriptPath, "update.exe");
|
|
ali@24
|
10 |
command = "\"" + path + "\"";
|
|
ali@24
|
11 |
for(i = 0; i < args.Length; i++)
|
|
ali@24
|
12 |
command += " \"" + args.Item(i) + "\"";
|
|
ali@24
|
13 |
ExecObject = WshShell.Exec(command);
|
|
ali@24
|
14 |
if (!ExecObject.StdErr.AtEndOfStream)
|
|
ali@24
|
15 |
{
|
|
ali@24
|
16 |
text = "Update failed for an unexpected reason. Please report "
|
|
ali@24
|
17 |
+ "the following error to support@city-occupational.co.uk:\n\n"
|
|
ali@24
|
18 |
+ ExecObject.StdErr.ReadAll();
|
|
ali@24
|
19 |
WshShell.Popup(text, 0, "Update failed", OKButton + ErrorIcon);
|
|
ali@24
|
20 |
return false;
|
|
ali@24
|
21 |
}
|
|
ali@24
|
22 |
else if (ExecObject.ExitCode)
|
|
ali@24
|
23 |
{
|
|
ali@24
|
24 |
text = "Update failed without giving a reason. Please report "
|
|
ali@24
|
25 |
+ "this to support@city-occupational.co.uk";
|
|
ali@24
|
26 |
WshShell.Popup(text, 0, "Update failed", OKButton + ErrorIcon);
|
|
ali@24
|
27 |
return false;
|
|
ali@24
|
28 |
}
|
|
ali@24
|
29 |
return true;
|
|
ali@24
|
30 |
}
|
|
ali@24
|
31 |
|
|
ali@24
|
32 |
function Update()
|
|
ali@24
|
33 |
{
|
|
ali@24
|
34 |
var path;
|
|
ali@24
|
35 |
path = FileSystemObject.BuildPath(ScriptPath, "pre-inst.exe");
|
|
ali@24
|
36 |
WshShell.Run("\"" + path + "\"" + " --post \"wscript.exe"
|
|
ali@24
|
37 |
+ " \\\"" + WScript.ScriptFullName + "\\\""
|
|
ali@24
|
38 |
+ " --post %INSTALL_PREFIX% %TEST_RESULT%\"",
|
|
ali@24
|
39 |
7, true);
|
|
ali@24
|
40 |
}
|
|
ali@24
|
41 |
|
|
ali@24
|
42 |
function PostUpdate()
|
|
ali@24
|
43 |
{
|
|
ali@24
|
44 |
var OKButton = 0, InfoIcon = 64, text;
|
|
ali@24
|
45 |
var test_result, install_prefix, path, args;
|
|
ali@24
|
46 |
install_prefix = WScript.Arguments.Item(1);
|
|
ali@24
|
47 |
test_result = WScript.Arguments.Item(2);
|
|
ali@24
|
48 |
if (test_result == "pass")
|
|
ali@24
|
49 |
{
|
|
ali@24
|
50 |
path = FileSystemObject.BuildPath(install_prefix,
|
|
ali@24
|
51 |
"bin\\app-manager.exe");
|
|
ali@106
|
52 |
WshShell.Run("\"" + path + "\" --paths "
|
|
ali@106
|
53 |
+ "--update \"" + ScriptPath + "\"");
|
|
ali@24
|
54 |
}
|
|
ali@24
|
55 |
else
|
|
ali@24
|
56 |
{
|
|
ali@24
|
57 |
args = { Length:0, Item:function(){return nil} };
|
|
ali@24
|
58 |
if (RunUpdate(args))
|
|
ali@24
|
59 |
{
|
|
ali@24
|
60 |
text = "Software update completed successfully.";
|
|
ali@24
|
61 |
WshShell.Popup(text, 0, "Software Update", OKButton + InfoIcon);
|
|
ali@24
|
62 |
}
|
|
ali@24
|
63 |
}
|
|
ali@24
|
64 |
}
|
|
ali@24
|
65 |
|
|
ali@24
|
66 |
if (WScript.Arguments.Length < 1)
|
|
ali@24
|
67 |
Update()
|
|
ali@24
|
68 |
else if (WScript.Arguments.Length >= 3 && WScript.Arguments.Item(0) == "--post")
|
|
ali@24
|
69 |
PostUpdate()
|