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