Page 2 of 2

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

Posted: 18 Jun 2012 15:35
by Marco
highend wrote: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.
1. Will do for Rev. 2.
2. Will do for Rev. 2.
3.a Comments are never unnecessary because there could be always someone who wants to modify the code but doesn't understand completely what each line does. If you don't like them you can strip them out with a simple regex-based find-and-replace ("\s//.*" for the inline comments and "/\*(.*?\r\n)*?\*/" for the block comments, by the way) in your text editor of choice.
3.b Will do for Rev. 2.
4. Well, I prefer XY to shut down properly, if timings permit so.

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

Posted: 18 Jun 2012 15:52
by j_c_hallgren
highend wrote: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.
Having it as zip is good for those who want to use it but having it inline here is halpful for those who want to refer to it for ideas on coding so while it takes a bit more time to do so, I'd suggest you do both methods if possible.

Oh, and know it's a non-USA thing, but having date in yyyy-mm-dd fmt is easier for us USA folks to read/follow (if we have to) than dd/mm/yyyy because we SO used to reading that as mm/dd/yyyy.

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

Posted: 18 Jun 2012 15:57
by Marco
j_c_hallgren wrote:Oh, and know it's a non-USA thing, but having date in yyyy-mm-dd fmt is easier for us USA folks to read/follow (if we have to) than dd/mm/yyyy because we SO used to reading that as mm/dd/yyyy.
ISO 8601 basically... ok! (that's the date format I use in XY too, btw)

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

Posted: 18 Jun 2012 16:10
by j_c_hallgren
Marco wrote:
j_c_hallgren wrote:Oh, and know it's a non-USA thing, but having date in yyyy-mm-dd fmt is easier for us USA folks to read/follow (if we have to) than dd/mm/yyyy because we SO used to reading that as mm/dd/yyyy.
ISO 8601 basically... ok! (that's the date format I use in XY too, btw)
I realize it's a minor thing but when I see 18/06/2012, I go :veryconfused: and have to read it backwards to make sense of it...having it as 2012-06-18 keeps MM and DD in the order that we all can read forwards, I think.

And this applies to thread title as well...BTW.

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

Posted: 18 Jun 2012 16:13
by admin
j_c_hallgren wrote:... when I see 18/06/2012, I go :veryconfused: ...
Yes, it could be the 18th of June or the 6th of Hexadecember... ;) :P

Re: XYplorer Updater - Rev. 2 / 2012/06/19

Posted: 25 Aug 2012 11:51
by drewkeller
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