XYplorer Updater - Rev. 3 / 2012/08/25

Discuss and share scripts and script files...
Marco
Posts: 2354
Joined: 27 Jun 2011 15:20

XYplorer Updater - Rev. 3 / 2012/08/25

Post by Marco »

[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.

:D :D :D Special thanks to:
* 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
Attachments
XYplorer Updater - Rev. 3.xys
(4.34 KiB) Downloaded 197 times
Last edited by Marco on 25 Aug 2012 11:51, edited 10 times in total.
Tag Backup - SimpleUpdater - XYplorer Messenger - The Unofficial XYplorer Archive - Everything in XYplorer
Don sees all [cit. from viewtopic.php?p=124094#p124094]

nas8e9
Posts: 2232
Joined: 21 Jun 2008 14:50

Re: XYplorer Updater

Post by nas8e9 »

In terms of economy and logic, it seems a bit wasteful to download a full copy of the latest beta version every time, just to check. I'm not very good with HTTP, but my download manager (GetRight) is able to ask the server first for just the last modification time of the file to be downloaded. I'm guessing that's just a bit of HTTP plain-text exchange.

By way of an example, this is what GetRight shows for a download:
-----StartRequest---------------2012/06/17-18:21:32-----
Looking up: mozilla.ftp.halifax.rwth-aachen.de
Connecting to: mozilla.ftp.halifax.rwth-aachen.de [137.226.34.43]

!!!! ----Header Sent----
>>>> GET /mozilla/thunderbird/releases/13.0.1/win32/en-US/Thunderbird%20Setup%2013.0.1.exe HTTP/1.1
Host: mozilla.ftp.halifax.rwth-aachen.de
Range: bytes=0-
User-Agent: GetRight/6.5
Accept: */*
Referer: http://mozilla.ftp.halifax.rwth-aachen. ... 13.0.1.exe
Accept-Encoding:

!!!! ----Header Recv----
HTTP/1.1 206 Partial Content
Server: nginx/1.0.0
Date: Sun, 17 Jun 2012 16:21:32 GMT
Content-Type: application/octet-stream
Content-Length: 18506296
Last-Modified: Fri, 15 Jun 2012 01:10:46 GMT
Connection: close
Content-Range: bytes 0-18506295/18506296
Apart from it being quicker (depending on your download speed), it would be kinder on Don's sever and in particular, his hosting bill. :)

Marco
Posts: 2354
Joined: 27 Jun 2011 15:20

Re: XYplorer Updater

Post by Marco »

nas8e9 wrote:In terms of economy and logic, it seems a bit wasteful to download a full copy of the latest beta version every time, just to check....
Apart from it being quicker (depending on your download speed), it would be kinder on Don's sever and in particular, his hosting bill. :)
I totally agree with you, but how can I implement such a thing? I'd like to keep this script as much self-contained/self-capable as possible, and in fact I'm not even happy with relying on a third-party utility to shut XY down, let alone installing a download manager just for that...
Tag Backup - SimpleUpdater - XYplorer Messenger - The Unofficial XYplorer Archive - Everything in XYplorer
Don sees all [cit. from viewtopic.php?p=124094#p124094]

nas8e9
Posts: 2232
Joined: 21 Jun 2008 14:50

Re: XYplorer Updater

Post by nas8e9 »

Marco wrote:I totally agree with you, but how can I implement such a thing? I'd like to keep this script as much self-contained/self-capable as possible, and in fact I'm not even happy with relying on a third-party utility to shut XY down, let alone installing a download manager just for that...
One possibility would be curl. It would be an additional utility, but the good news is that it's open-source and no-install, command line only.

For additional reference, please see here.

Filehero
Posts: 2713
Joined: 27 Feb 2012 18:50
Location: Windows 11@100%

Re: XYplorer Updater

Post by Filehero »

Hi Marco,

to me killing the XY processes is different from a controlled shutdown. Or did I miss something?
I'm not sure wether this is a safe approach.


Cheers,
Filehero

nas8e9
Posts: 2232
Joined: 21 Jun 2008 14:50

Re: XYplorer Updater

Post by nas8e9 »

Filehero wrote:to me killing the XY processes is different from a controlled shutdown. Or did I miss something?
I'm not sure wether this is a safe approach.
I think he thought of that:
Marco wrote:Notes:
...
* 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

Marco
Posts: 2354
Joined: 27 Jun 2011 15:20

Re: XYplorer Updater

Post by Marco »

nas8e9 wrote:
Filehero wrote:to me killing the XY processes is different from a controlled shutdown. Or did I miss something?
I'm not sure wether this is a safe approach.
I think he thought of that:
Marco wrote:Notes:
...
* 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
Exactly.

I'm taking a look at curl and I've already managed to get the last modified time you mentioned above. Thanks for the suggestion and let's see what I can come up with!
Tag Backup - SimpleUpdater - XYplorer Messenger - The Unofficial XYplorer Archive - Everything in XYplorer
Don sees all [cit. from viewtopic.php?p=124094#p124094]

Filehero
Posts: 2713
Joined: 27 Feb 2012 18:50
Location: Windows 11@100%

Re: XYplorer Updater

Post by Filehero »

nas8e9 wrote:I think he thought of that:
Marco wrote:Notes:
...
* 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
I'v read that. But the XY settings are only one concern. As far as I understood PSKill will/can interfere with #191;. Since I don't know what XY is doing here, I cannot exclude that it includes some maybe critical steps (releasing all kind of ressources, shared folders etc.). I rather wouldn't try that at work when I'm connected to my company's network. But I just might be panicking here, and Windows will assure no harm can be done.

Nevertheless, thanks for coding and sharing. :)

@Marco: Just saw your reply. How do you think about my point?


Filehero
Last edited by Filehero on 17 Jun 2012 19:23, edited 1 time in total.

nas8e9
Posts: 2232
Joined: 21 Jun 2008 14:50

Re: XYplorer Updater

Post by nas8e9 »

Filehero wrote:I'v read that. But the XY settings are only one concern. As far as I understood PSKill will/can interfere with #191;. Since I don't know what XY is doing here, I cannot exclude that it includes some maybe critical steps (releasing all kind of ressources, shared folders etc.). I rather wouldn't try that at work when I'm connected to my company's network. But I might be panicking here, and Windows will assure no harm can be done.
That's a question for Don, I think. My guess would be that unless a file operation (backgrounded or not) is in progress, terminating XYplorer.exe should be safe.

Marco
Posts: 2354
Joined: 27 Jun 2011 15:20

Re: XYplorer Updater

Post by Marco »

Filehero wrote:@Marco: Just saw your reply. How do you think about my point?


Filehero
It's a good point in fact.
Honestly the only problem I saw with killing XY was regarding the settings being saved/not saved, but your concerns are quite legit.
We should wait for Don insight.
Meanwhile I think: what problem might arise shutting down XY from the TaskManager (that's what pskill does, after all), provided that I've already saved all the settings I care and XYcopy is not running?
Tag Backup - SimpleUpdater - XYplorer Messenger - The Unofficial XYplorer Archive - Everything in XYplorer
Don sees all [cit. from viewtopic.php?p=124094#p124094]

Filehero
Posts: 2713
Joined: 27 Feb 2012 18:50
Location: Windows 11@100%

Re: XYplorer Updater

Post by Filehero »

Marco wrote:Meanwhile I think: what problem might arise shutting down XY from the TaskManager (that's what pskill does, after all), provided that I've already saved all the settings I care and XYcopy is not running?
Already asked that myself and haven't found one. :wink:

Let's hear what Don says once he stumbles over this thread.

Cheers,
Filehero

admin
Site Admin
Posts: 64886
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: XYplorer Updater

Post by admin »

If you kill XY in the middle of a foreground backup process, well, then you get only half of the backup.

Marco
Posts: 2354
Joined: 27 Jun 2011 15:20

Re: XYplorer Updater

Post by Marco »

admin wrote:If you kill XY in the middle of a foreground backup process, well, then you get only half of the backup.
Should I add such a warning to the notes in the introduction?
My idea is that a person that tries such a script has some tech knowledge and would never ever trigger an update while a file transfer is in progress, never ever.
But I better be safe than sorry...
Tag Backup - SimpleUpdater - XYplorer Messenger - The Unofficial XYplorer Archive - Everything in XYplorer
Don sees all [cit. from viewtopic.php?p=124094#p124094]

admin
Site Admin
Posts: 64886
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: XYplorer Updater - Rev. 1 / 18/06/2012

Post by admin »

Your script, your decision. :mrgreen:

highend
Posts: 14571
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: XYplorer Updater - Rev. 1 / 18/06/2012

Post by highend »

I'd make the file paths (for curl, pskill and winrar) configurable (either place them at the top or let the script save them as a .ini file on first start and read that file in on every run). Why? If you update the script, the user has to change the paths every time as well.

Please replace italian messages with english ones.

I'd remove all unnecessary comments in the script for a version, that you can attach to your post as a .zip file so that people don't have to copy & paste the code each time, you offer a new version but just download and extract it.

Why do you try to shut down XYplorer internally (#191) when you already started a .bat file, that will forcefully do the same? It's only a matter of milliseconds what ever is executed first.
One of my scripts helped you out? Please donate via Paypal

Post Reply