Page 1 of 1

another XY updater

Posted: 04 Oct 2008 14:58
by graham
No way would I attempt to compete with Jacky but I have used this script to try out new scripting features and it works for me plus is good fun

Basic features
maintains (n, user choice) backups of main XY files and script folder
checks XY web site to get base current version & downloads update
unzip, update and re -load XY
see notes in script for other details

Code: Select all

"script to update XYPlorer to latest version"

        msg "update XYPlorer version",1; 
// see notes below 	
// save current exe,ini & dat files + scripts to Backup folder and rename with date
	#182;
	status "Backup current exe,ini&dat files + script files";
	copyto "<xypath>\Backup\v<xyver> (on <date yyyy.mm.dd_hh-nn-ss>)",  "<xypath>\XYplorer.exe|<xydata>\*.ini|<xydata>\*.dat|<xydata>\scripts";
        goto "<xypath>\Backup";

// get number of backups to keep (default 5), delete oldest if more
        input $nobu , "Total number of backups to keep", 5;
 	focus l;
        sel a;
        $selcnt=getinfo("CountSelected");
        $notodelete = eval("$selcnt - $nobu");   // compute nomber of oldest to delete
        copytext $notodelete;                    // store result

        $test = $selcnt > $nobu?  "more": "less";  // test if any to delete
        sub "_"."$test";
        
// more - delete oldest backup(s) and then get latest update	  
"_more" 
	set $notodelete, <clipboard>;      // retrieve number to delete
        #485; // refresh list
        sel a;
        sel +, $notodelete;
        delete 1, 0, ":list";

        #485;           // refresh list
        sel 1;          // display oldest backup 
	msg "5 Backups stored, oldest : <curname>, OK to download latest version?";
        sub _getnew;

"_less"  // less  - no old backups to delete, get latest update

     	sel 1;  // display oldest backup 
	msg "Oldest Backup stored, : <curname>, OK to download latest version?";
        sub _getnew;


"_getnew";   // get latest version for beta down load
             // create or clear temp dir & download latest version XY to temp dir
             // extract files in temp dir & copy to update XY using bat file
 

   // check for latest version of beta 
        status "Checking for latest version at www.XYplorer.com";
        internetflags "INTERNET_FLAG_NO_COOKIES", 1;
        readurl $a, "http://www.xyplorer.com/vercheck.php?version=?";
        strpos $pos, $a, "0000",0;
        incr $vpos,$pos,-5;
        substr $v, $a, $vpos, 4;  //get just the main version number
        msg "Latest XYplorer base version is $v, Continue to update using this base version ",1;
                 
   // create or clear temp dir
        copyto "<xypath>\XYtemp", "<xypath>\xyplorer.ini";  // create new C:\Program Files\XYplorer\XYtemp folder if needed   
        goto "<xypath>\XYtemp";
        focus l;
        sel a;
        delete 1, 0, ":list";   //clear files from temp folder
        wait 500;

   // download latest version   
        download "http://www.xyplorer.com/download/xyplorer_".$v."_beta_noinstall.zip", "<xypath>\XYtemp",o;
        wait 1000;
        goto "<xypath>\XYtemp";
        focus l;
        sel 1; 
        rename , "xylatest";
     
   // extract new files
        run '"C:\program files\7-zip\7z" e -y "c:\Program Files\XYplorer\XYtemp \xylatest.zip" -o"c:\Program Files\XYplorer\XYtemp"';
        goto "<xypath>\XYtemp";
        msg "Latest version download stored in <xypath>\XYtemp if needed, continue update to latest version",1; 
       
       

      //using bat file, update XYPlorer.exe, .hlp .tipoftheday.htm files & restart XYplorer    
        open "<xypath>\update XYplorer.bat";

//end script

/* notes
   to run this script it must be <xypath>\scripts dir  
   the path used throughout is C:\  (change this as required in the script)
   the script creates and uses a temp file (<xypath>/XYtemp) for the current down load which is retained
   Backups of XY are made and stored in <xypath>/Backup,  user choice on number of back ups
   Latest beta version checks XY site to get the base version before download
   extract files in script uses 7-zip, change if other
   update of xy files done using external .bat file (change as reqd.  note TSKILL is for XPWIN Home)
   .bat file (filed in <xypath> dir

  cd windows\system32
        TSKILL XYPlorer /a /v
        echo .
        pause
        copy "C:\Program Files\XYplorer\XYtemp\XYplorer.hlp"    "C:\Program Files\xyplorer\" /y 
        copy "C:\Program Files\XYplorer\XYtemp\TipOfTheDay.htm" "C:\Program Files\xyplorer\" /y  
        copy "C:\Program Files\XYplorer\XYtemp\XYplorer.exe"    "C:\Program Files\xyplorer\" /y 
        cd  \
        cd "program files\xyplorer"
        START XYplorer.exe
*/

Re: another XY updater

Posted: 06 Oct 2008 00:11
by lukescammell
I'd like to give this a go, but the biggest reason I won't right now is that all the paths are hard coded in. I'm not sure what's possible with XY script, but would it be possible to have some vars defined at the top of the script, where people can customise the XY and 7z paths once, quickly and easily? I, for one, use XY portably, so I can guarantee that neither XY nor 7zip will EVER be on the C: drive, and that's before you even get into 64bit windows and the abortion that is 64bit windows filing system...

Any chance of an update like that? I don't mind manually putting some relative paths in the top of the script once, but it would be a pig to have to put them in several times throughout the script. I'd imagine other people may feel similarly.

Re: another XY updater

Posted: 06 Oct 2008 20:03
by graham
I made this script for fun and for my needs thus the hard coded paths - that said, there are few changes needed to make it for a different path. Yes scripting can be engineered to do all that you want but there are times when it is simpler to change the code.

If you want something that is more versatile then Jacky's updater is much superior and I think covers what you are wanting.

Re: another XY updater

Posted: 08 Oct 2008 01:26
by lukescammell
Sorry, I didn't mean it to come across as a criticism if, I was just suggesting those as minor improvements. I assume that you want other people to use/benefit from your script otherwise you wouldn't have released it. :wink:

Re: another XY updater

Posted: 08 Oct 2008 15:22
by graham
It is good to get comment of any type so please don't apologise!

Actually, I the script as it stands is pretty flexible - the only areas that affect hard code paths are in the use of the un-zipper and the bat file. So I don't think there is much change needed if, say, you have all your data etc. on d:\. In most cases the path is coded as <xypath>.

One reason for publishing it here was to give covert awareness to a problem (I think) using scripting. As it is, one has to provide waiting time for other processes to complete. For example if you delete a file(s) in a script then this can take time and the script code takes no heed of this or wait until the 'delete process' is completed (confirmed) and this can cause problems in XYscripts. Jacky uses, as I have, msg commands to 'buy' time but all this seems hit and miss to me.

I may have this all wrong, I hope I do, but currently scripting cannot always happen as expected even though correctly coded.