I made a few changes so this works in a more general way with unzipping programs. Below is the configuration for 7zip.
I Also added a message in English. And a bit of reformatting comments to make them more readable.
Code: Select all
global $pski, $zpsw, $bat, $txt, $zip; //initialize all these variables as globals (i.e. accessible by "_Routine")
$curl = "<xypath>\Scripts\libs\curl\curl.exe"; //full path to cURL utility
$pski = "<xypath>\Scripts\libs\pskill\pskill.exe"; //full path to PsKill utility
//full path to the preferred .zip handler *plus* command line switches to perform
// a silent and in-place extraction. Beware of quotes!!!
// UnRar: x -y ""%zip%""
// 7zip : x ""%zip%"" -aoa -o""%dest%""
$zpsw = """G:\Utility\File\7zip\7z.exe"" x ""%zip%"" -aoa -o""%dest%""";
//message that indicates you're running the last possible beta version
// Uncommment the one appropriate for your language.
//$mesg = "Versione giĆ aggiornata!";
$mesg = "You already have the most recent beta version.";
// The following are filenames *without extension*.
// They are temporary and will be deleted at the end of the batch file execution.
$bat = "XYplorer"; // batch file to unzip the archive and close/restart XYplorer
$txt = "XYplorer"; // curl log file
$zip = "XYplorer"; // beta archive file
/*
Up above: the things that should be modified according to your system configuration and likes.
Down below: the "real" code. It shouldn't be edited unless really necessary.
*/
$bat = <xypath>."\".$bat.".".bat; //add path and proper extension to the batch file name
$txt = <xypath>."\".$txt.".".txt; //add path and proper extension to the text file name
$zip = <xypath>."\".$zip.".".zip; //add path and proper extension to the update file name
delete 0, 0, $bat; //delete silently and permanently unlikely remnants of any previous execution
delete 0, 0, $txt; //delete silently and permanently unlikely remnants of any previous execution
delete 0, 0, $zip; //delete silently and permanently unlikely remnants of any previous execution
perm $p_lm; //initialize the "last modified" permanent variable (truly needed upon first execution only)
$ok = "HTTP/1.1 200 OK"; //the "exit code" of a successful HTTP request
$vers = readurl("http://www.xyplorer.com/version.php"); //obtain the current major version number from the web
if (compare(<xyver>, $vers, "v") == -1) { //means the major version available is newer than the current running version
$du = "http://www.xyplorer.com/download/xyplorer_full_noinstall.zip"; //set the url from which the update (major version) will be downloaded
} else { //the major version available is not newer than the current running version, so a new beta *might* (conditional mood) be available
$vers = substr($vers, 0, 5); //turn the major version number in the xx.yy form
$du = "http://www.xyplorer.com/download/xyplorer_".$vers."_beta_noinstall.zip"; //set the url from which the update (beta version) will be downloaded
}
$comm = <<<WIN_CLI
cmd /c ""$curl" --head "$du" > "$txt""
WIN_CLI;
/*
Get the HTTP response and store it in the text file.
*/
run $comm,,1,2; //run the command described above. The shell window is minimized, and XY will wait until it has finished
$resp = readfile($txt); //read the above HTTP response in a variable
delete 0, 0, $txt; //delete the text file
$hc = gettoken ($resp, 1, <crlf>); //store the "HTTP "exit" code" (first line of the HTTP response)
$lm = gettoken ($resp, 4, <crlf>); //store the "last modified" time of the possibly-to-be-downloaded file on the server (fourth line of the HTTP response)
//if the HTTP request is successful *and* the last modification appears to be different than what XYplorer remembers...
if ($hc == $ok AND $lm != $p_lm) {
$p_lm = $lm; //...then store this new modification time...
download $du,$zip; //...download the update...
sub "_Routine"; //...and finally execute the "dirty work"
} else { //else...
echo $mesg; //...display a message that says you're already bleeding edge :)
};
/*
The batch file (written below with here-doc syntax) basically kills every instance of every executable
called "XYplorer.exe" and "XYcopy.exe". Then it unpacks the downloaded "XYplorer.zip", silently and in-place.
Finally, it starts XYplorer and deletes the downloaded .zip file, the .txt file if still present, and itself.
All in a nice black-on-grey shell window (good for myopia and/or astigmatism without burning your eyes).
*/
"_Routine"
global $pski, $zpsw, $bat, $txt, $zip; //make all these variables accessible inside here
replace $zpsw, $zpsw, "%zip%", $zip;
replace $zpsw, $zpsw, "%dest%", "<xypath>\";
$batch = <<<WIN_CLI
@echo off
color 70
title %~n0
cd /d "%~dp0"
start "Stopping XYplorer..." /b /wait "$pski" "XYplorer.exe"
start "Stopping XYplorer..." /b /wait "$pski" "XYcopy.exe"
start "Unzipping beta package..." /b /wait $zpsw
start "Restarting XYplorer..." /b /wait "XYplorer.exe"
del "$zip"
del "$txt"
del "$bat"
pause
WIN_CLI;
/*
Write batch file, save XYplorer settings, exit and restart XYplorer
*/
writefile($bat,$batch); //physically writes the batch file above
#182; //saves all XYplorer's settings
run """$bat""",,,2; //starts, in a minimized window, the batch file
#191; //shuts XYplorer down