-
Notifications
You must be signed in to change notification settings - Fork 32
/
CheckForUpdates.js
171 lines (149 loc) · 5.67 KB
/
CheckForUpdates.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
// ------------------------------------------------------------------------------------------------
// tabs=4
//
// ==================
// CheckForUpdates.js
// ==================
//
// This script reads the local versions of the Platform and optionally, the Platform
// Developer tools and Conform. Then it fetches the latest versions from the ASCOM
// website. For the Platform and each installed optional component, it then
// checks to see if a newer version is available. For the first one that is
// newer, it opens a web page for downloading it. The order it checks is the same
// order that one would install the components. Thus you can't install the later ones
// until you get the earlier ones installed. Platform first, etc.
//
// Author: Bob Denny <[email protected]>
//
// Edits:
// --------- --- ---------------------------------------------------------------------------
// 28-Apr-11 rbd Initial edit
// 29-Apr-11 rbd Add logic to try to get various versions of MS XMLHTTP component, newest
// to oldest order. Find the ASCOM registry data on both 32- and 64-bit
// systems. Make it obvious that you can come back here to go to the d/l
// page for the first of any remaining available updates.
// 02-May-11 rbd Fix case where conform and/or dev content not installed
// 13-May-11 rbd Change paths for final distribution places
// ------------------------------------------------------------------------------------------------
var POPTITLE = "Check ASCOM Updates";
var REMWEB = "https://download.ascom-standards.org/ver/";
var REGROOT64 = "HKLM\\Software\\Wow6432Node\\ASCOM\\Platform\\";
var REGROOT32 = "HKLM\\Software\\ASCOM\\Platform\\";
var PLATPAGE = "https://ascom-standards.org/Downloads/Index.htm";
var DEVPAGE = "https://ascom-standards.org/Downloads/PlatDevComponents.htm";
var CONFPAGE = "https://ascom-standards.org/Downloads/DevTools.htm";
var SH = new ActiveXObject("WScript.Shell");
//
// Compare "n.n.n.n" versions (strings), return true if second parameter
// string represents a newer version.
//
function isRemoteNewer(local, remote)
{
var lbits = local.split(".");
var rbits = remote.split(".");
for (var i = 0; i < 4; i++)
{
if (rbits[i] > lbits[i]) return true;
}
return false;
}
//
// Valiantly try to get an XMLHTTPRequest object.
//
function getXmlHttp()
{
//WScript.Echo("**try XMLHTTP.6.0");
try { return new ActiveXObject("Msxml2.XMLHTTP.6.0"); }
catch (e) {}
//WScript.Echo("**try XMLHTTP.5.0");
try { return new ActiveXObject("Msxml2.XMLHTTP.5.0"); }
catch (e) {}
//WScript.Echo("**try XMLHTTP.4.0");
try { return new ActiveXObject("Msxml2.XMLHTTP.4.0"); }
catch (e) {}
//WScript.Echo("**try XMLHTTP.3.0");
try { return new ActiveXObject("Msxml2.XMLHTTP.3.0"); }
catch (e) {}
//WScript.Echo("**try XMLHTTP");
try { return new ActiveXObject("Msxml2.XMLHTTP"); }
catch (e)
{
SN.Popup("Missing or damaged web component. Cannot check for updates.",
10, POPTITLE, 16);
WScript.Quit();
}
}
//
// Get local versions
//
var regRoot, pd, cv, dv, pv;
try { SH.RegRead(REGROOT64); regRoot = REGROOT64; }
catch(e) { regRoot = REGROOT32;}
//WScript.Echo("**using " + regRoot);
try { pd = SH.RegRead(regRoot); } // If this or next not here, major trouble!
catch(e) { SH.Popup("Fatal installer error, sorry.", 10, POPTITLE, 16); }
try { pv = SH.RegRead(regRoot + "Platform Version"); } // (should "never happen")
catch(e) { SH.Popup("Fatal installer error, sorry.", 10, POPTITLE, 16); }
try { cv = SH.RegRead(regRoot + "Conform Version"); } // Next 2 default to ""
catch(e) { cv = ""; }
try { dv = SH.RegRead(regRoot + "Developer Tools Version"); }
catch(e) { dv = ""; }
//
// Get remote versions. XMLHTTP will automatically use default proxy if any.
//
try
{
var http = getXmlHttp();
http.open("GET", REMWEB + "cv.txt", false);
http.send();
var rcv = http.responseText;
http.open("GET", REMWEB + "dv.txt", false);
http.send();
var rdv = http.responseText;
http.open("GET", REMWEB + "pv.txt", false);
http.send();
var rpv = http.responseText;
http = null;
}
catch(ex)
{
SH.Popup("Failed to contact the update server.\r\n" + ex.message + "Please try again later.",
10, POPTITLE, 16);
WScript.Quit();
}
var np = isRemoteNewer(pv, rpv);
var nd = (dv !== "") && isRemoteNewer(dv, rdv); // "" means not installed
var nc = (cv !== "") && isRemoteNewer(cv, rcv); // (see above)
if (!np && !nd && !nc)
{
SH.Popup("Everything is up to date.", 10, POPTITLE, 64);
WScript.Quit();
}
var i = 0;
var msg = "Updates are available for the following ASCOM components:\r\n";
if (np) { msg += "* ASCOM Platform (" + rpv + ")\r\n"; i += 1; }
if (nd) { msg += "* Developer Kit (" + rdv + ")\r\n"; i += 1; }
if (nc) { msg += "* Driver Conformance Checker (" + rcv + ")\r\n"; i += 1; }
if (i > 1) {
msg += "After downloading and installing the first one, re-run the checker " +
"to be taken to the download page for the next new component. Would you " +
"like to go to the download page for the first new component?"
} else {
msg += "Would you like to go to the download page for the new component?";
}
var ans = SH.Popup(msg, 0, POPTITLE, 36);
if (ans == 7) WScript.Quit();
if (np)
{
SH.Run(PLATPAGE);
WScript.Quit();
}
if (nd)
{
SH.Run(DEVPAGE);
WScript.Quit();
}
if (nc)
{
SH.Run(CONFPAGE);
}