XYplorer Updater - Rev. 3 / 2012/08/25
Posted: 17 Jun 2012 17:39
[This first post gets updated from time to time, particularly when a new revision is released. You are strongly advised to read this post carefully!]
I publish here the script I'm currently using for updating quickly and easily XYplorer.
So far works fine and the logic behind seems solid to me. I hope the comments are clear enough too to give you a nice base to start from, in case you want to customize it.
How does it work: quite simply
It first connects to the internet to read the current major version number and build the most recent url string from which downloading a beta. The script compares then the last time the zip package was uploaded to the server with the last update time that led to a successful update, in order to see if the newly to-be-downloaded file represents a real update. If so then the dirty job starts: a core batch file is created and run just before closing XYplorer (you can see what it does by looking the comments below).
Tested on:
* Windows XP SP3 x32 ITA
* Windows 7 Ultimate SP1 x64 ITA
Requirements:
* XYplorer with
- scripting enabled
- permanent variables remembered across sessions
- (suggested) multiple instances execution disabled
* Internet connection
* Zip file reader (I use WinRAR in my case)
* PsKill, part of the PsTools suite, freely downloadable here http://technet.microsoft.com/en-us/sysi ... s/bb896683
* cURL, freely downloadable here http://curl.haxx.se/
* (suggested) Firewall opened for both XYplorer.exe and curl.exe at least with the following criteria (COMODO Internet Security notation)
- Allow TCP out from any MAC address to IP 80.237.132.225 where source port is any and destination port is 80
Notes:
*
I absolutely take no responsibility for whatever damage, direct or indirect, the usage of this script may cause. This code is provided as-is, use at your own risk. You are advised.
*
Never trigger an update when a file transfer, or any other sort of activity involving data handling, is in progress. Data loss may occur.
*
Beware of function #182. I know there're users who don't want their settings to be saved but I do, so you better comment that line out if you're one of them.
* Almost all the script operates inside XYplorer folder explicitly: the exceptions are PsKill and cURL (which in my case reside in a folder named CLI on the same level of XYplorer's folder) and WinRAR executable. Except for WinRAR, every other path not contained in <xypath> is referred to relatively to <xypath>. You are advised to change those path accordingly to your system configuration.
* This script is not talkative on purpose: I wanted something streamlined and direct because I tend to know what I'm doing. Adding messages and so on is up to you, if you feel so. But I won't do it.
* This script is able to perform the update even when multiple instances of XYplorer are running; however multiple instances mean multiple possible settings to be saved, too. With this script only the current, focused instance gets its settings saved. Keep this in mind.
* Why using a separate utility to shut XYplorer down? Due to timing reasons. The batch file must be started by a running XYplorer. Since batch file are quite fast in their execution, my experience shows that there's an high probability (higher than 65%, and not influenced by CPU speed) that the unzipping takes place while XYplorer is still running (this means XYplorer.exe is locked and can't be overwritten/updated). A solution would be using the pause command in the batch file, but that's not available on Windows XP. Plus multiple instances would be next problem. Using PsKill takes care of both of them.
Possible future updates:
* Switching to VBS for the out-of-XY scripted execution, which should give the ability to terminate XYplorer natively i.e. without using third part utilities, and even gracefully, i.e. sending an Alt+F4.
Changelog:
* Rev. 0 / 2012/06/17: the very first version.
* Rev. 1 / 2012/06/18: changed the way the new version is identified (thanks to nas8e9), added cURL to the requirements, great code reorganization (removal of nasty nested if-loops).
* Rev. 2 / 2012/06/19: moved all the hardcoded variables on top, for easier customization.
* Rev. 3 / 2012/08/25: tweaked the underlying logic so to always get the latest beta available, without updating to a major version first.
Special thanks to:
* nas8e9, for suggesting a great idea for saving plenty of bandwidth (efficiency increased by over 1,200,000%!).
I publish here the script I'm currently using for updating quickly and easily XYplorer.
So far works fine and the logic behind seems solid to me. I hope the comments are clear enough too to give you a nice base to start from, in case you want to customize it.
How does it work: quite simply
It first connects to the internet to read the current major version number and build the most recent url string from which downloading a beta. The script compares then the last time the zip package was uploaded to the server with the last update time that led to a successful update, in order to see if the newly to-be-downloaded file represents a real update. If so then the dirty job starts: a core batch file is created and run just before closing XYplorer (you can see what it does by looking the comments below).
Tested on:
* Windows XP SP3 x32 ITA
* Windows 7 Ultimate SP1 x64 ITA
Requirements:
* XYplorer with
- scripting enabled
- permanent variables remembered across sessions
- (suggested) multiple instances execution disabled
* Internet connection
* Zip file reader (I use WinRAR in my case)
* PsKill, part of the PsTools suite, freely downloadable here http://technet.microsoft.com/en-us/sysi ... s/bb896683
* cURL, freely downloadable here http://curl.haxx.se/
* (suggested) Firewall opened for both XYplorer.exe and curl.exe at least with the following criteria (COMODO Internet Security notation)
- Allow TCP out from any MAC address to IP 80.237.132.225 where source port is any and destination port is 80
Notes:
*
*
*
* Almost all the script operates inside XYplorer folder explicitly: the exceptions are PsKill and cURL (which in my case reside in a folder named CLI on the same level of XYplorer's folder) and WinRAR executable. Except for WinRAR, every other path not contained in <xypath> is referred to relatively to <xypath>. You are advised to change those path accordingly to your system configuration.
* This script is not talkative on purpose: I wanted something streamlined and direct because I tend to know what I'm doing. Adding messages and so on is up to you, if you feel so. But I won't do it.
* This script is able to perform the update even when multiple instances of XYplorer are running; however multiple instances mean multiple possible settings to be saved, too. With this script only the current, focused instance gets its settings saved. Keep this in mind.
* Why using a separate utility to shut XYplorer down? Due to timing reasons. The batch file must be started by a running XYplorer. Since batch file are quite fast in their execution, my experience shows that there's an high probability (higher than 65%, and not influenced by CPU speed) that the unzipping takes place while XYplorer is still running (this means XYplorer.exe is locked and can't be overwritten/updated). A solution would be using the pause command in the batch file, but that's not available on Windows XP. Plus multiple instances would be next problem. Using PsKill takes care of both of them.
Possible future updates:
* Switching to VBS for the out-of-XY scripted execution, which should give the ability to terminate XYplorer natively i.e. without using third part utilities, and even gracefully, i.e. sending an Alt+F4.
Changelog:
* Rev. 0 / 2012/06/17: the very first version.
* Rev. 1 / 2012/06/18: changed the way the new version is identified (thanks to nas8e9), added cURL to the requirements, great code reorganization (removal of nasty nested if-loops).
* Rev. 2 / 2012/06/19: moved all the hardcoded variables on top, for easier customization.
* Rev. 3 / 2012/08/25: tweaked the underlying logic so to always get the latest beta available, without updating to a major version first.
* nas8e9, for suggesting a great idea for saving plenty of bandwidth (efficiency increased by over 1,200,000%!).
Code: Select all
global $pski, $zpsw, $bat, $txt, $zip; //initialize all these variables as globals (i.e. accessible by "_Routine")
$curl = "<xypath>\..\CLI\curl.exe"; //full path to cURL utility
$pski = "<xypath>\..\CLI\pskill.exe"; //full path to PsKill utility
$zpsw = """C:\Programmi\WinRAR\WinRAR.exe"" x -y"; //full path to the preferred .zip handler *plus* command line switches to perform a silent and in-place extraction. Beware of quotes!!!
$meok = "Versione già aggiornata!"; //message that indicates you're running the last possible (beta) version
$meko = "Il server non è raggiungibile. Ritentare in seguito."; //message that indicates a server-side connectivity problem
$bat = "XYplorer"; //name *without extension* of the batch file
$txt = "XYplorer"; //name *without extension* of the text file
$zip = "XYplorer"; //name *without extension* of the update 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.
*/
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 = substr(readurl("http://www.xyplorer.com/version.php"), 0, 5); //obtain the current major version number from the web and turn it in the xx.yy form
$du = "http://www.xyplorer.com/download/xyplorer_".$vers."_beta_noinstall.zip"; //set the url from which the update will be downloaded
$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
$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 ($hc != $ok) { //if the HTTP request isn't successful...
echo $meko; //...display a message that warns about a possible server-side connectivity problem...
end; //...and terminate script execution
}
if ($lm != $p_lm) { //if the last modification appears to be different than what XYplorer remembers...
$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 $meok; //...display a message that says you're already bleeding edge :)
};
"_Routine"
global $pski, $zpsw, $bat, $txt, $zip; //make all these variables accessible inside here
$batch = <<<WIN_CLI
@echo off
color 70
title %~n0
cd /d "%~dp0"
start "" /wait /separate "$pski" "XYplorer.exe" /accepteula
start "" /wait /separate "$pski" "XYcopy.exe" /accepteula
start "" /wait /separate $zpsw "$zip"
start "" /separate "XYplorer.exe"
del "$zip"
del "$txt"
del "$bat"
WIN_CLI;
/*
The batch file (written above 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).
*/
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