-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathOpenUpdater.xys
569 lines (536 loc) · 23.7 KB
/
OpenUpdater.xys
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
// -----------------------------------------------------------------------------
// - DO NOT CHANGE - The following four lines are for internal use
sub "_CheckForUpdates"; end TRUE;
"_Config"
global $updaterDir, $iniFile;
global $tempDir, $sequenceDirection, $ignoreCacheExpiration;
global $ignoreCacheExpiration, $xyver, $log;
// - DO NOT CHANGE (END) ---------------------------------------------------
// You can change the user configuration and test/debug sections below
// -------------------------------------------------------------------------
// --------- user configuration settings -----------------------------------
// OpenUpdater intends that you define your configuration settings in an
// .ini file, so you can replace this entire file without having to manually
// edit it again. The .ini file needs to be in a location where the OU menu
// script can find it (it defaults to the same folder as the menu file, but
// you can change the location in the menu file configuration section).
$tempDir = "<xydata>\temp\"; // the directory to use for downloading files
$updaterDir = "<xydata>\Scripts\OpenUpdater\"; // the directory where the OpenUpdater script is located
$sequenceDirection = 0; // how to list changes: 0 = lower to higher (older to newer), 1 = higher to lower
// --------- testing/debug settings ----------------------------------------
$ignoreCacheExpiration = 0; // for testing: 1 = always use a cached file to read the changelogs instead of downloading them
//$xyver = "11.60.0104"; // uncomment for testing a specific version
$log = $tempDir . "\OpenUpdater.log";
// - DO NOT CHANGE ---------------------------------------------------------
// The rest of this file is not intended to be changed, except for
// development work.
// -------------------------------------------------------------------------
global $BETA_CHANGELOG_URL;
$BETA_CHANGELOG_URL = "http://www.xyplorer.com/xyfc/viewtopic.php?t=4&start=0&sd=d";
global $officialChanges, $highestOfficialVersion, $downloadOfficialUrl;
global $betaChanges, $highestBetaVersion, $downloadBetaUrl;
global $allChanges, $downloadUrl, $downloadVersion, $zipFile;
global $messages;
$xyver = ($xyver == "") ? <xyver> : $xyver;
$messages = "";
"_CheckForUpdates"
sub _Config;
sub _CheckMinimumXyVersion;
sub _GetBetaChanges;
sub _GetOfficialChanges;
sub _MergeChanges;
sub _ShowUpdates;
sub _DownloadZip;
global $version, $downloadVersion; $version = $downloadVersion;
sub _UnzipInstall;
end TRUE;
"_CheckMinimumXyVersion"
global $xyver;
// There may be a more recent version that is necessary, but here's what I
// know:
// 8.40.0102: needed for new format of function calls using parentheses.
// 11.50.000: approx when OpenUpdater started life.
$minRequired = "8.40.0102";
$minKnownOk = "11.50.000";
if (compare($xyver, $minRequired, v) < 0) {
msg "Your version of XYplorer is too old to use this script." . chr(10) .
"Please update to the most recent release version manually.";
end TRUE;
} elseif (compare($xyver, $minKnownOk, v) < 0) {
msg "Your version of XYplorer is older than the minimum version known " .
"to work with this script." . chr(10) .
"It MIGHT work with your version, but if something strange happens, " .
"please update to the most recent release version manually.";
}
"_GetBetaChanges"
global $BETA_CHANGELOG_URL;
global $tempDir, $sequenceDirection;
global $officialChanges, $highestOfficialVersion, $downloadOfficialUrl;
global $betaChanges, $highestBetaVersion, $downloadBetaUrl;
global $messages;
global $xyver, $log;
$betaChanges = "";
global $cache, $url, $html; // _ReadCachedUrl variables
$cache = $tempDir . "beta.html";
$url = $BETA_CHANGELOG_URL;
sub _ReadCachedUrl;
$html = gettoken($html, 2, "</head>");
$t = writefile($log, $html, "o", "ta");
$html = regexreplace($html, "(\r\n|\r|\n)", " ");
// prepend changes until we reach a version that is smaller than our current version
$highestOfficialVersion = "";
$i = 1;
while(TRUE) {
$i++;
$text = gettoken($html, $i, "Re: Here's the new BETA");
if ($text == "") {
if ($betaChanges != "") {
$messages = $messages . "Your version is too old to list all beta change logs."; // . chr(10);
}
break;
}
$text = gettoken($text, 1, "<div class=""postbody"">");
$text = gettoken($text, 1, "No-Install Package");
$version = regexreplace($text, ".*\<code\>v(\d+([.]\d+)+).*", "$1");
if (compare($xyver, $version, v) >= 0) {
break;
}
$downloadUrl = regexreplace($text, ".*(http://www.xyplorer.com/download/xyplorer_[\d\w._]+?_noinstall\.zip).*", "$1");
$name = regexreplace($text, ".*?XYplorer ([^<]+).+", "$1");
$text = regexreplace($text, ".+<div class=""codecontent"">v(.*?)</div>.*", "$1");
$date = regexreplace($text, ".*(\d{4}.\d{2}.\d{2}.\d{2}.\d{2}).*", "$1");
$text = regexreplace($text, ".*?<br />( .+)", "$1");
$changes = replace($text, "$version - $date<br />", "");
$changes = replace($changes, "<br /></p>", "</p>");
if (strpos($name, "BETA") >= 0) {
$class = "beta";
$changes = regexreplace($changes, "(.*?)</code>.*", "$1");
if ($downloadBetaUrl == "") {
$highestBetaVersion = $version;
$downloadBetaUrl = $downloadUrl;
}
} else {
$class = "official";
if ($highestOfficialVersion == "") {
$highestOfficialVersion = $version;
$downloadOfficialUrl = "http://www.xyplorer.com/download/xyplorer_full_noinstall.zip";
}
}
$thisChange =
"<!-- entry --><!-- %$class% %$version% -->" . chr(10) .
"<h3 class=""$class"">$name - $version ($date)</h3>" . chr(10) .
"<p class=""$class code"">$changes</p>" . chr(10);
//$betaChanges;
if($sequenceDirection == 1) {
$betaChanges = $betaChanges . $thisChange;
} else {
$betaChanges = $thisChange . $betaChanges; // ascending
}
}
"_GetOfficialChanges"
global $tempDir, $sequenceDirection, $ignoreCacheExpiration;
global $officialChanges, $highestOfficialVersion, $downloadOfficialUrl;
global $xyver, $log;
// read the latest version from the web page
global $latestVersion;
sub _GetOfficialVersion;
// read the most recent version for which we have cached change logs
global $forceDownload, $forceReadCache;
$forceDownload = FALSE; $forceReadCache = TRUE;
sub _GetOfficialChangesCaching;
$c = compare($highestOfficialVersion, $latestVersion, v);
if ($c < 0 && ! $ignoreCacheExpiration) {
// need to update the cache so it includes the latest version change log
$forceDownload = TRUE; $forceReadCache = FALSE;
sub _GetOfficialChangesCaching;
}
"_GetOfficialVersion"
global $log;
global $latestVersion;
global $tempDir, $cache, $url, $html; // for caching
// read the download.php page for a quick check. This one is not cached.
$cache = $tempDir . "download.html";
$url = "http://www.xyplorer.com/download.php";
sub _ReadCachedUrl;
//$html = readurl(, , , 2);
$t = writefile($log, $html, "o");
$html = regexreplace($html, "(\r\n|\r|\n)", " ");
$latestVersion = regexreplace($html, ".*XYplorer (\d+?[.]\d{2}([.]\d{2,4})?).*", "$1");
"_GetOfficialChangesCaching"
global $tempDir, $sequenceDirection, $ignoreCacheExpiration;
global $officialChanges, $highestOfficialVersion, $downloadOfficialUrl;
global $xyver, $log;
$officialChanges = "";
if (! isset($highestOfficialVersion)) { $highestOfficialVersion = ""; }
status "Reading changelog for new official version", "progress";
// read the whatsnew page for release change logs (this is a long page)
global $cache, $url, $html, $forceDownload, $forceReadCache; // _ReadCachedUrl variables
$cache = $tempDir . "whatsnew.html";
$url = "http://www.xyplorer.com/whatsnew.php";
sub _ReadCachedUrl;
$html = gettoken($html, 2, "stuff content here");
// prepend changes until we reach a version that is smaller than our current version
$i = 1;
while(TRUE) {
$i++;
$text = gettoken($html, $i, "<a name=""v");
if ($text == "") { break; }
$version = gettoken($text, 1, """></a>");
// already have the latest or better official version
if (compare($xyver, $version, v) >= 0) {
if ($highestOfficialVersion == "" || compare($version, $highestOfficialVersion, v) > 0) {
$highestOfficialVersion = $version;
$downloadOfficialUrl = "";
}
break;
}
$changes = regexreplace($text, "^.*?(\d.*</a>).*$", "");
$changes = regexreplace($changes, "^.*?(<h3.*?</h3>).*$", "");
$changes = regexreplace($changes, "^.*?(<p.*?</p>).*$", "");
$changes = regexreplace($changes, "^.*?<div.*?>(.*)$", " * $1<br />");
$changes = regexreplace($changes, "^(.*)</div>$", "$1<br />");
$changes = regexreplace($changes, "^[ ]{6}(.*)$", " $1<br />");
$changes = regexreplace($changes, "^(.*<br\s?/?>)<br\s?/?>.*$", "$1");
$text = regexreplace($text, "(\r\n|\r|\n)", " ");
$t = writefile($log, $text, "o", "ta");
$name = regexreplace($text, ".*?<h3.*?>([^\d]+)\s\d.*</h3>.*", "$1");
$name = regexreplace($name, "What's new in", "Official Release");
$t = writefile($log, chr(10).$name, "a", "ta");
$date = regexreplace($text, ".*<p.*>(.*)</p>.*", "$1");
$text = gettoken($text, 2, "</p>");
$text = regexreplace($text, "\s+<div.+?>(.*</div>)\s+", " $1");
$changes = regexreplace($changes, "(\r\n|\r|\n)", " ");
$changes = replace($changes, " <b>", "* <b>");
$changes = replace($changes, "</div>", "<br />" . chr(10));
$changes = replace($changes, "<br />" . chr(10), "");
$thisChange =
"<!-- entry --><!-- %official% %$version% -->" . chr(10) .
"<h3 class='official'>$name - $version ($date)</h3>" . chr(10) .
"<p class='official code'>$changes</p>" . chr(10);
//$officialChanges;
if($sequenceDirection == 1) {
$officialChanges = $officialChanges . $thisChange;
} else {
$officialChanges = $thisChange . $officialChanges; // lower to higher
}
if ($highestOfficialVersion == "" || (compare($version, $highestOfficialVersion, v) > 0)) {
$highestOfficialVersion = $version;
$downloadOfficialUrl = "http://www.xyplorer.com/download/xyplorer_full_noinstall.zip";
}
}
$t = writefile($log, $officialChanges, "o", "ta");
"_MergeChanges"
global $sequenceDirection;
global $officialChanges, $highestOfficialVersion, $downloadOfficialUrl;
global $betaChanges, $highestBetaVersion, $downloadBetaUrl;
global $allChanges;
//writefile("beta_changes.html", $betaChanges);
//writefile("official_changes.html", $officialChanges);
$o = 2;
$b = 2;
$oVersion = "";
$bVersion = "";
$entrySep = "<!-- entry -->";
$replace = "<!-- %(.*[^?])% %(.*[^?])% -->";
$oText = gettoken($officialChanges, $o, $entrySep);
$bText = gettoken($betaChanges, $b, $entrySep);
while(TRUE) {
if ($oText == "" && $bText == "") { break; }
if ($oText == "") {
$oVersion = ($sequenceDirection == 0) ? "99.99.9999" : 0;
} else {
$oVersion = gettoken($oText, 1, chr(10));
$oVersion = regexreplace($oVersion, $replace, "$2");
}
if ($bText == "") {
$bVersion = ($sequenceDirection == 0) ? "99.99.9999" : 0;
} else {
$bVersion = gettoken($bText, 1, chr(10));
$bVersion = regexreplace($bVersion, $replace, "$2");
}
// ascending (0): add whichever has the lower version.
// descending (1): add whichever has the higher version.
// both: if versions are equal, use the one from the beta changelog
$c = compare($oVersion, $bVersion, v);
if ( ($sequenceDirection == 0 && $c < 0) || ($sequenceDirection == 1 && $c > 0) ) {
$allChanges = $allChanges . $oText;
$oText = gettoken($officialChanges, $o++, $entrySep);
} else {
$allChanges = $allChanges . $bText;
if ($c == 0) {
$oText = gettoken($officialChanges, $o++, $entrySep);
}
$bText = gettoken($betaChanges, $b++, $entrySep);
}
}
"_ShowUpdates"
global $BETA_CHANGELOG_URL;
global $officialChanges, $highestOfficialVersion, $downloadOfficialUrl;
global $betaChanges, $highestBetaVersion, $downloadBetaUrl;
global $allChanges, $response, $downloadUrl, $downloadVersion;
global $messages;
global $xyver, $tempDir, $log;
if ($allChanges == "") { $messages = "You already have the latest version." . chr(10) . $messages; }
if ($messages != "") {
$messages = regexreplace($messages, "(.+)", "<h2>$1</h2>");
$messages = "<div id=""messages"">" . $messages . "</div>";
}
$disclaimer = "<p>DISCLAIMER: The author of XYplorer recommends against the use of
updater scripts, which parse changelogs. If the format of the changelog
channges, the parsing might not be successful and you might not be aware
of all of the details.<br />
<a href='$BETA_CHANGELOG_URL'>The unparsed changelog may be viewed here.</a></p>";
$oMsg = "Update to v$highestOfficialVersion";
$bMsg = "Update to v$highestBetaVersion";
$buttons = "";
$officialIsHigher = compare($highestOfficialVersion, $highestBetaVersion, v) > 0;
$oHighest = ""; $bHighest = "";
if ($officialIsHigher) {
$oHighest = "highest";
} else {
$bHighest = "highest";
}
$oButton = (($highestOfficialVersion == "") || ($downloadOfficialUrl == "")) ? ("") : (
"<a href='xys: Update to official v$highestOfficialVersion' onclick='javascript:doit(""official"");' " .
"class='$oHighest official buttons' name='updateOfficial'>$oMsg</a>");
$bButton = ($highestBetaVersion == "") ? "" : (
"<a href='xys: Update to beta v$highestBetaVersion' onclick='javascript:doit(""beta"");' " .
"class='$bHighest beta buttons' name='updateBeta'>$bMsg</a>");
if ($officialIsHigher) {
$buttons = $oButton . " " . $bButton;
} else {
$buttons = $bButton . " " . $oButton;
}
$borderColor = "#C9C9C9";
$html = <<<HTML_DOC
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml2/DTD/xhtml1-strict.dtd">
<html><head><title>Update XYplorer</title>
<meta http-equiv="Content-Type" content="text/html;'.' charset=iso-8859-1">
<style type="text/css" rel="stylesheet">
/* This imageless css button was generated by CSSButtonGenerator.com */
.buttons {
-moz-box-shadow:inset 0px 1px 0px 0px #ffffff;
-webkit-box-shadow:inset 0px 1px 0px 0px #ffffff;
box-shadow:inset 0px 1px 0px 0px #ffffff;
background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #ededed), color-stop(1, #dfdfdf) );
background:-moz-linear-gradient( center top, #ededed 5%, #dfdfdf 100% );
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ededed', endColorstr='#dfdfdf');
background-color:#ededed;
-moz-border-radius:6px;
-webkit-border-radius:6px;
border-radius:6px;
border:1px solid #dcdcdc;
display:inline-block;
color:#777777;
font-family:'Segoe UI',Tahoma,Arial;
font-size:10px;
/* font-weight:bold; */
padding:6px 24px;
text-decoration:none;
text-shadow:1px 1px 0px #ffffff;
vertical-align: middle;
}.buttons:hover {
background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #dfdfdf), color-stop(1, #ededed) );
background:-moz-linear-gradient( center top, #dfdfdf 5%, #ededed 100% );
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#dfdfdf', endColorstr='#ededed');
background-color:#dfdfdf;
}.buttons:active {
position:relative;
top:1px;
}
body { padding: 0; margin: 0; font-size : 12px; font-family : verdana, arial, helvetica, sans-serif; background: white; color: black; }
#page { margin: 0.5em 0.5em 0.0em 0.5em; }
p { line-height: 1.25em; padding: 0px; margin-bottom:10px;}
h1 { padding: 0.2em 1em 0.5em 0.8em; background: #EEEEEE; color: #666666; border: 1px solid #C9C9C9; line-height: 1.5em; }
h2 { padding: 0.2em 1em 0.5em 0.8em; background: none; color: #666666; border: none; line-height: 1.5em; }
h3 { padding: 0.2em 1em 0.0em 0.8em; background: none; color: #666666; border: none; border-bottom: 1px dotted #C9C9C9; line-height: 1.5em; }
h1 { font-size: 150%; font-weight: bold; }
h2 { font-size: 125%; font-weight: normal; }
h3 { font-size: 125%; font-weight: normal; }
#disclaimer { font-size: 75%; padding: 5px; margin: 0 10px 10px 10px; background: #F8F8F8; color: #666666; border: 1px dotted #666666; }
#disclaimer p { margin:0; padding:0;}
#messages { padding: 0.2em 1em 0.5em 0.8em; margin: 0 10px 10px 10px; background: #FFEEEE; color: #666666; border: 1px solid #C9C9C9; }
#messages h2 { padding: 0; margin: 0; }
.official { color: #660000; }
.beta { color: #006600; }
#content { font-size: 100%; width: 650px; margin: 0 1em 0 1em; padding: 0; }
form { border:none; padding: 0px; margin: 0px; }
fieldset { border:none; padding:0px 0px 0px 0px; margin:0px; }
.button_panel { margin: 0px; padding: 10px 15px 10px 10px; background: #EDEDED; color: #000066; }
.highest { font-size: 150%; font-weight: bold; }
.code { margin: 2px 0 10px 0; font-family: Consolas, 'Courier New', monospace; }
#button_panel {
position: absolute; width: 100%; padding: 10px 0 5px 0;
padding-bottom: expression ( button_panel.height + 'px' );
top: expression( ( - button_panel.offsetHeight +
( document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight ) +
( ignoreMe = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ) ) + 'px' );
background: #EEEEEE; text-align: center; border: none; border-top: 2px solid #666666; }
#content { padding-bottom: expression( button_panel.offsetHeight + 'px' ); }
</style>
<script language="javascript">
function doit(name) {
document.getElementById('update'+name).href = "javascript:{}";
document.getElementById('updateType').value = name;
document.getElementById('UpdateForm').submit();
return false;
}
</script>
</head>
<body>
<div id="page">
<h1>XYplorer Changelog</h1>
<div id="disclaimer">$disclaimer</div>
$messages
<div id="content">
$allChanges
<p class="code">
Current : <xyver> $xyver</br>
Beta : $highestBetaVersion ($downloadBetaUrl)</br>
Official: $highestOfficialVersion ($downloadOfficialUrl)</br>
</p>
</div>
</div>
<form id="UpdateForm" name="UpdateForm" action="xys:Update"><fieldset>
<input type="hidden" id="updateType" name="updateType" />
<div id="button_panel">$buttons</div>
</fieldset></form>
</body></html>
HTML_DOC;
$t = writefile($tempDir."OpenUpdater_output.html", $html, "o");
$response = html($html, 750, 600, "Updates Available");
if ($response == "") { end TRUE; }
if (strpos($response, "beta") >= 0) {
$downloadUrl = $downloadBetaUrl;
$downloadVersion = $highestBetaVersion;
} elseif (strpos($response, "official") >= 0) {
$downloadUrl = $downloadOfficialUrl;
$downloadVersion = $highestOfficialVersion;
}
"_DownloadZip"
global $zipFile, $downloadUrl, $downloadVersion, $tempDir;
$tempDir = regexreplace($tempDir."\", "(.*)\\\\$", "$1\"); // ensure ends with one '/'
$zipFile = $tempDir . "xyplorer_" . $downloadVersion . "_noinstall.zip";
download($downloadUrl, $zipFile);
"_UnzipInstall"
global $version, $tempDir;
$selfPath = self("path");
$zipFile = $tempDir . "xyplorer_" . $version . "_noinstall.zip";
if (! exists($zipFile)) { msg("Could not find the zip file: " . chr(10) . $zipFile); end TRUE; }
// quote the path, but only path, not drive or file.exe (e.g. C:"\Program Files\XYplorer"\XYplorer.exe)
$drive = substr(<xypath>, 0, 2);
$path = substr(<xypath>, 2);
$cmd =
"cmd /c title Updating XYplorer to $version..." .
"&&prompt $&&echo Exiting XYplorer..." .
"&&ping -n 2 127.0.0.1 >nul&&echo." .
"&&echo Extracting XYplorer $version...&&echo." .
"&&cscript //nologo ""$selfPath\unzip.vbs"" /source:""$zipFile"" /dest:""<xypath>""&&echo." .
"&&echo Starting XYplorer...&&start ""XYplorer"" $drive""$path""\<xyexe>&&echo.".
"&&echo Done.";
run $cmd, <xypath>;
#192; // Exit (saves settings if "Save on Exit" is enabled)
"_GetFileAge"
global $inFile; // function inputs
global $fileAge; // function outputs
global $tempDir;
$timeFile = $tempDir . "time.txt";
writefile($timeFile, "Check modified timestamp to get UTC offset", "o");
$tempModified = Property( "Write", $timeFile);
$inModified = Property( "Write", $inFile);
$fileAge = datediff($inModified, $tempModified, "s");
"_ReadCachedUrl"
global $ignoreCacheExpiration;
global $url, $cache, $forceDownload, $forceReadCache; // function inputs
global $html; // function outputs
$cacheExpiration = 3600; // max age of cache (in seconds)
$fileAge = 99999; // just a number bigger than cache time
if (! $forceReadCache && exists($cache)) {
global $inFile, $fileAge;
$inFile = $cache;
sub _GetFileAge;
}
$expired = $ignoreCacheExpiration ? FALSE : $fileAge > $cacheExpiration;
if (exists($cache) &&
! $forceDownload == 1 &&
($forceReadCache == 1 || ! $expired) ) {
// cache is still young (or we are forcing to use it)... read it
$html = readfile($cache);
} else {
// cache is old or doesn't exist... create/refresh it
$html = readurl($url, , , 2);
$t = writefile($cache, $html, "o");
}
// reset these
$forceDownload = ""; $forceReadCache = "";
"_ClearCache"
global $tempDir;
sub _Config;
$files = "beta.html|download.html|whatsnew.html";
foreach($item, $files, "|") { delete(0, 0, $tempDir . $item); }
status("Done cleaning the cache.");
"_RevertOrUpgrade"
global $tempDir, $packages, $xyver;
sub _Config;
sub _GetDownloadedPackagesList;
$path = self("path");
$updater = $path."\OpenUpdater.xys";
$f = writefile($tempDir . "test.txt", $packages, "o");
$script = "";
foreach($item, $packages, <crlf>) {
if ($item == "") { continue; }
$c = compare($item, $xyver, v);
if ($c < 0) {
$file = '"Revert to v' . $item . '|:back "';
} elseif ($c > 0) {
$file = '"Upgrade to v' . $item . '|:goprev "';
}
if ($c == 0) {
$script = $script . "-<crlf>";
} else {
$script = $script . $file . ' global $version; $version="' . $item . '"; load("'.$updater.'", "_UnzipInstall");'.<crlf>;
}
}
$f = writefile($tempDir . "test.txt", $script, "o");
load($script, , "s");
"_CleanOldPackages"
global $tempDir, $packages;
sub _Config;
sub _GetDownloadedPackagesList;
$self = self("file");
$f = writefile($tempDir . "test.txt", $packages, "o");
$script = regexreplace ($packages, "^(.*?)\b$",
'"Clean v$1 and older|:del" global $version; $version="$1"; load("'.$self.'", "_CleanPackagesOlderThan");');
$f = writefile($tempDir . "test.txt", $script, "o");
load($script, , "s");
"_CleanPackagesOlderThan"
global $tempDir, $packages, $version;
sub _Config;
// create a list of files to delete
$files = "";
$count = 0;
foreach($item, $packages, <crlf>) {
if ($item == "") { continue; }
$c = compare($item, $version, v);
if ($c <= 0) {
$count++;
$item = $tempDir . "xyplorer_" . $item . "_noinstall.zip";
$files = ($files == "") ? ($item) : ($files . "|" . $item);
}
}
$f = writefile($tempDir . "test.txt", $files, "o");
if ($files == "") {
msg "Nothing was found to delete."
status("Aborted deleting files.");
} else {
msg("Are you sure you want to delete these files?<crlf><crlf>". $files, 1, "|");
delete(0, 0, $files);
status("Deleted $count files.");
}
// Get a list of the zip files in the temp folder, which we've downloaded and saved
// with a specific version number.
"_GetDownloadedPackagesList"
global $tempDir, $packages;
$files = listfolder($tempDir, "xyplorer_*.*.*_noinstall.zip");
$packages = report("{Name}<crlf>", $files);
$packages = regexreplace ($packages, "xyplorer_(.*?)_noinstall\.zip", "$1");