SimpleUpdater

Discuss and share scripts and script files...
Post Reply
serendipity
Posts: 3360
Joined: 07 May 2007 18:14
Location: NJ/NY

Re: SimpleUpdater

Post by serendipity »

klownboy wrote:Hey Filehero, it's been awhile. Yes, I just changed my icon over to the XYplorer logo as well. For anyone interested you can grab it by typing in http://www.xyplorer.com/favicon.ico into your address bar and then right click on the logo to save it to your drive.
Thanks,
Ken
There's also the bigger icon (256px) available at:
http://www.xyplorer.com/download/xyplor ... 21-256.png

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

Re: SimpleUpdater

Post by Filehero »

That's the one I'm using (well, shrinked it a bit..).

klownboy
Posts: 4397
Joined: 28 Feb 2012 19:27
Location: Windows 11, 25H2 Build 26200.7171 at 100% 2560x1440

Re: SimpleUpdater

Post by klownboy »

Thanks serendipity. I actually had the png one from somewhere out and about on the web. I had lost track of the fact that you can get most URL icons by using the site's main address followed with "\favicon.ico" at least if it shows up on your bookmarks or I should say favorites (in iExplorer).

serendipity
Posts: 3360
Joined: 07 May 2007 18:14
Location: NJ/NY

Re: SimpleUpdater

Post by serendipity »

Update:
Optimized.

SimpleUpdater v2:
WHAT's NEW?
version 2
1) Option to terminate script if XYcopy is running or notify if multiple instances of current XY are running.
- Setting $multiInstance to 1 will:
a) terminate XY if XYcopy is running in the current XY instance.
b) notify user if more than one instance of current XY is active. You can close additional instances yourself or allow script to kill them.
c) not kill XY or XYcopy started from different location.
- Setting $multiInstance to 0 is for those who never run multiple instances or xycopy while updating. Script runs slightly faster in this mode (1.5 seconds).
Note: With setting $multiInstance=0 this script cannot update XY if multiple instances of current XY are running. During update windows will show an error: Folder access denied. You can still close other instances and choose "Try again" to successfully update.
2) Now the update window displays 5 previous change logs (not just the last one). Variable $betas = number of change logs to display.


Note: if you dont want to save your settings then towards the end of the script change:
savesettings; //Save all settings
to
//savesettings; //Save all settings
SimpleUpdater v2.xys
(13.24 KiB) Downloaded 214 times

Code: Select all

//SimpleUpdater v2
/*
WHY SIMPLE?
1) No configuration, just copy this script to XY's scripts folder, thats it.

HOW IT WORKS:
1) Checks for beta or official release and shows the change log and an option to update.
2) Saves current configuration.
3) Downloads the XY zip file to scripts folder, closes XY (your config is saved already) and extracts downloaded files to XY folder.
4) Restarts XY.
Notes: 
1) temp folder and vbs file is created in XY's script folder which is later deleted. (No junk left behind).
2) If you already have a temp file in xyscripts folder it will be deleted. (change the temp folder location below)
3) As before, everything works as it is, you can change paths below in "User-defined parameters" section

WHAT TO DO:
1) Copy SimpleUpdater script to XY's script folder.
2) To test paste this in address bar: ::load SimpleUpdater;

WHAT's NEW?
version 2
1) Option to terminate script if XYcopy is running or notify if multiple instances of current XY are running. 
  - Setting $multiInstance to 1 will:
   a) terminate XY if XYcopy is running in the current XY instance. 
   b) notify user if more than one instance of current XY is active. You can close additional instances yourself or allow script to kill them.
   c) not kill XY or XYcopy started from different location. 
  - Setting $multiInstance to 0 is for those who never run multiple instances or xycopy while updating. Script runs slightly faster in this mode (1.5 seconds).
    Note: With setting $multiInstance=0 this script cannot update XY if multiple instances of current XY are running. During update windows will show an error: Folder access denied. You can still close other instances and choose "Try again" to successfully update.
2) Now the update window displays 5 previous change logs (not just the last one). Variable $betas = number of change logs to display.

*/

//Declare global variables
    global $downloadurl,$downloadpath,$downloadfile,$newver,$temp,$vbsfile, $closepids, $closepidfile,$multiInstance;

//User-defined Parameters
      $downloadpath="<xyscripts>";           //Path where new update will be downloaded (Default=<xyscripts>)
      $downloadfile="$downloadpath\xy.zip";  //File name of the downloaded file (Default=$downloadpath\xy.zip)
      $temp="<xyscripts>\temp";              //Temporary location where unzipped contents and vbs file will be stored (and deleted thereafter) (Default=5)
      $vbsfile="$temp\unzip.vbs";            //VBS file location (Default=<xyscripts>\temp)
      $betas=5;                              //Number of previous change logs to display in the update window (Default=5)
      $multiInstance=1;                      //See above (Default=1)


//Stop script if XY version is less than 09.60.0004
     end (<xyver> < "09.60.0004"), "This script needs XYplorer version 9.60.0004 or higher.";
     $ReadURL = readurl("http://www.xyplorer.com/xyfc/viewtopic.php?t=4&start=0&sd=d", , , 2);
//If no internet then script exits with a status message
     IF ($ReadURL==""){
                      status "No internet. Can't check for XY updates.","FF0000",alert;
                      end(1==1);                      
                      }  

//Read URL and get new version number and compare with current version
       $token=gettoken($ReadURL, 2, '<div class="codecontent">v'); 
       $newver =gettoken ($token, 1, " -"); 

     IF ($newver==<xyver>){
                        status "No updates, you have the latest version of XYplorer";
                        end(1==1);
                       }
     ELSE{
          Status "New XY version $newver available", "FF0000", "alert";     
         }      


//Stop if XYcopy is active
  IF (get ("XYcopy_Pending")!=0){ 
    echo "Cannot update, Copy operations pending."; 
    end 1==1;
    }

//Check if a other instances of XY are running and asks user input
  IF($multiInstance==1){    
  			$pidfile="<xyscripts>\pidfile.vbs";
  			$outpid="<xyscripts>\output.txt";
  			$closepidfile="$temp\closepidfile.vbs";


//Creates vbs script to retrieve process IDs of current XY instance and XY copy
  $pid=<<<pid
On Error Resume Next

processName = "XYplorer.exe"

QueryLine = "select * from win32_process where Name = " & """" & processName & """"

Computer = "."
Set OutFile = CreateObject("WScript.Shell")
Const ForAppending = 2
Set FileSystem = CreateObject("Scripting.FileSystemObject")
Set TextFile = FileSystem.OpenTextFile("$outpid", ForAppending, True)
'TextFile.WriteLine "Script for Win32_Process where processname=XYplorer.exe"
TextFile.WriteLine
Set WMIService = GetObject("winmgmts:\\" & Computer & "\root\cimv2")
Set Items = WMIService.ExecQuery(QueryLine, , 48)
For Each SubItems In Items
  TextFile.WriteLine "Caption: " & SubItems.Caption
  TextFile.WriteLine "CommandLine: " & SubItems.CommandLine
  TextFile.WriteLine "ProcessId: " & SubItems.ProcessId
Next

processName = "XYcopy.exe"

QueryLine = "select * from win32_process where Name = " & """" & processName & """"

Computer = "."
Set OutFile = CreateObject("WScript.Shell")
Set FileSystem = CreateObject("Scripting.FileSystemObject")
Set TextFile = FileSystem.OpenTextFile("$outpid", ForAppending, True)
'TextFile.WriteLine "Script for Win32_Process where processname=XYcopy.exe"
TextFile.WriteLine
Set WMIService = GetObject("winmgmts:\\" & Computer & "\root\cimv2")
Set Items = WMIService.ExecQuery(QueryLine, , 48)
For Each SubItems In Items
  TextFile.WriteLine "Caption: " & SubItems.Caption
  TextFile.WriteLine "CommandLine: " & SubItems.CommandLine
  TextFile.WriteLine "ProcessId: " & SubItems.ProcessId
Next

TextFile.Close

pid;
   
   writefile("$pidfile", "$pid"); //Write pid to file
   wait(1000);
   run """$pidfile""";
   wait(3000);
   $readpid= readfile("$outpid");
   
   delete 0,0, $pidfile;
   delete 0,0, $outpid;

//If XYcopy (belonging to current XY) is running, the script terminates. 
   $xycopy= gettoken($readpid, 2, "<xypath>\XYcopy.exe");
   $xycopymsg="";
   IF($xycopy!=""){
      end 1==1, "WARNING!! Cannot update while XYcopy is running! ";
      }

//Get PIDs of all instances belonging to current XY     
   $instance=2;
   $otherinstance= gettoken($readpid, $instance, "<xy>");
   $closepids="";
   
   WHILE($otherinstance!=""){
     $otherinstance= gettoken($otherinstance,2,"ProcessId: ");
     $newpid= gettoken($otherinstance,1,"<crlf>");

//Build vbs script to terminate XY instances if user agrees to
     $buildpids=<<<buildpids

Set objShell = CreateObject("WScript.Shell") 
Set objWmi = GetObject("winmgmts:") 
strWmiq = "select * from Win32_Process where ProcessId='$newpid'" 
Set objQResult = objWmi.Execquery(strWmiq) 
For Each objProcess In objQResult 
intRet = objProcess.Terminate(1) 
Next 


buildpids;

     $closepids= "$closepids<crlf>$buildpids";    
     $instance++;
     $otherinstance= gettoken($readpid, $instance, "<xy>");            
    }

    $instance=$instance-3;
    IF($instance<1){
     break;
    }

//Message if multiple instances active
    IF($instance==1){
                    $instancemessage= "$instance more instance of current XY is running.<br><br>Close it and click 'OK' to continue updating. <br>or<br>click 'OK' anyway to kill that instance and continue updating (settings from current instance will be saved). <br>or<br>click 'Cancel' to Stop Script.";
      }
    ELSE{
          $instancemessage= "$instance more instances of current XY are running.<br><br>Close them and click 'OK' to continue updating. <br>or<br>click 'OK' anyway to kill other instances and continue updating (settings from current instance will be saved). <br>or<br>click 'Cancel' to Stop Script.";
         }


    IF (confirm ("$instancemessage")==0){
                status "XY will not update until other instances are closed.", FF0000, alert;
                 end 1==1;
      	        }


  }



//Get update info  

   $count=0;
   $betafinal="";

       WHILE($count<$betas){
// Get previous beta change log
           $newtoken= gettoken($ReadURL, $count+2, 'the new BETA');  
           $downloadurl=gettoken($newtoken, 1, '" class="postlink"><span style="font-weight: bold">No-Install Package');
           $downloadurl=gettoken($downloadurl, 2, '(2) <a href="');          
           $betapretext= gettoken($newtoken, 1, '<br /></div><br />To <span style="font-weight: bold">download');
           $betatext= gettoken($betapretext, 2, 'Change Log');
           $betatext= gettoken(gettoken($newtoken, 1, '<br /></div><br />To <span style="font-weight: bold">download'), 2, 'Change Log');
     
  		IF($betatext==""){
                     		//Download Official release
                     		$betatext= gettoken($betapretext, 2, 'XYplorer Official Release');  
                     		$betatext= gettoken($betatext, 1, 'faq.php" class="postlink">FAQ</a>');
                     		$betatext= gettoken($betatext, 1, '<br /></div></div>');
                     		$betatext= gettoken($betatext, 2, 'class="codetitle"><b>Code:</b></div><div class="codecontent">');    
                     			IF($betatext==""){
                              				break;
                              				}          
                     		$betafinal="$betafinal<br><br><b><font color=Green>OFFICIAL RELEASE:</b><br>$betatext</font>";                     
                     		$downloadurl="http://www.xyplorer.com/download/xyplorer_full_noinstall.zip";
                     		}
  
  		ELSE {
        		$betatext= gettoken($betatext, 2, 'class="codetitle"><b>Code:</b></div><div class="codecontent">');
        		$betafinal="$betafinal<br><br><b>Change Log for the latest XYplorer BETA version:</b><br>$betatext";
       		     }
       			$count++;
     		 }

//Update window interface
  $Updatewindow=<<<Updatewindow

<style type="text/css" rel="stylesheet">
#mysubmit { background-color: #00CC00; border:0.01cm solid black; cursor= hand; font-size: 110%; font-family:Arial; color: #FFFFFF; 

height:30px;
    font-weight: bold;}
#body { background-color: #FFFFFF; border:medium none; font-size: 75%; font-family:Verdana,Arial,Helvetica;height:25px; color:#000066 }
</style>
                      <FORM NAME="UpdateXY" ACTION="xys: "><FIELDSET>
                      <Legend><INPUT TYPE=SUBMIT title="Update to v$newver" name="submit" id="mysubmit" value="Update to v$newver">
                      </Legend>
                      <p id="body">$betafinal</p>
                     </FIELDSET>
                     </FORM>
Updatewindow;
  Status "New XY version $newver available", "FF0000", "alert";  
  $Update= html ("$Updatewindow",600,600,"Update XYplorer");


  IF ($Update Like "?submit=Update*"){
                                  sub "_downloadXY";   
                                }

   ELSE{
        status "SimpleUpdater closed", FF0000, alert;
        end(1==1);
       }



//Subscript that downloads, extracts and updates XY
"_downloadXY"
//Declare global variables
  global $downloadurl,$downloadfile,$newver,$temp,$vbsfile, $closepids, $closepidfile,$multiInstance;
    
//If temp file already exists, it will be deleted.
   IF(exists($temp)==2){
      delete (0,0,$temp);
     }

   new ("<xyscripts>\temp","dir");
   new ("<xyscripts>\temp\extract","dir");


   IF($multiInstance==1){ 
   			writefile("$closepidfile", "$closepids"); //Write pid to file
                     }



//Create vbs file
// Copies zip contents to temp\extract folder, then moves extracted files to XY
//Note: copying contents directly to XY is possible, but at the cost of user having to click "Yes to All" while copying.

  $VBSUnzip=<<<VBSUnzip

    ZipFile = "<xyscripts>\xy.zip"                                                      'name of zip file
    OutputFolder = "$temp\extract"                                                      'temp folder for unzipped files 
    XYFile="<xypath>"									'XYplorer path

    Set objShell = CreateObject( "Shell.Application" )
    Set objSource = objShell.NameSpace(ZipFile).Items()
    Set objTarget = objShell.NameSpace(OutputFolder)
    intOptions = 16
    objTarget.CopyHere objSource, intOptions

    Set objShell = CreateObject( "Shell.Application" )
    Set objSource = objShell.NameSpace(OutputFolder).Items()
    Set objTarget = objShell.NameSpace(XYFile)
    intOptions = 16
    objTarget.MoveHere objSource, intOptions


VBSUnzip;

     writefile("$vbsfile", "$VBSUnzip"); //Write vbs commands to file
     savesettings; //Save all settings
     download ($downloadurl,$downloadfile,o); //download latest XY
   
     substr $drive, <xypath>, 0, 2;
     substr $path, <xypath>, 2; 


//Run: Title > Text > Wait > Run vbs > Delete temp > Start XY
    IF($multiInstance==1){ 
     run "cmd /c title SimpleUpdater && echo Updating from <xyver> to $newver... && ping -n 5 127.0.0.1 >nul && cscript //nologo ""$closepidfile"" && cscript //nologo ""$vbsfile"" && RD /S /Q ""$temp"" && start ""XYplorer"" $drive""$path""\<xyexe>";
     }

    ELSE{
     run "cmd /c title SimpleUpdater && echo Updating from <xyver> to $newver... && ping -n 5 127.0.0.1 >nul && cscript //nologo ""$vbsfile"" && RD /S /Q ""$temp"" && start ""XYplorer"" $drive""$path""\<xyexe>";

    }


     #191; //Exit (without saving XY). Settings already saved above, no worries.
To show that I was a little jobless in last weekend: :wink:
SimpleUpdater.png
SimpleUpdater.png (66.85 KiB) Viewed 4170 times
Last edited by serendipity on 17 Sep 2012 21:05, edited 7 times in total.

LittleBiG
Posts: 1848
Joined: 08 Apr 2011 12:57
Location: Win10x64

Re: SimpleUpdater

Post by LittleBiG »

Amazing script, thanks for it. :appl: However, I had to change wait(500) to 2000 because I always got an error message about non existing output.txt. Additionaly, one improvement I can imagine: listing all changes from the last full version.

klownboy
Posts: 4397
Joined: 28 Feb 2012 19:27
Location: Windows 11, 25H2 Build 26200.7171 at 100% 2560x1440

Re: SimpleUpdater

Post by klownboy »

Hey serendipity, your new version 2 worked like a charm... no error message(s) for me. You may want to mention in your upfront "How it works" section commenting out the savesettings command and changing #192 to #191 if one does not want settings saved. Some people may be like me and save only when I feel I want to save. Nice SimpleUpdater png! Thanks for the time-savings script and making it even more bullet proof.
Ken

serendipity
Posts: 3360
Joined: 07 May 2007 18:14
Location: NJ/NY

Re: SimpleUpdater

Post by serendipity »

LittleBiG wrote:Amazing script, thanks for it. :appl: However, I had to change wait(500) to 2000 because I always got an error message about non existing output.txt. Additionaly, one improvement I can imagine: listing all changes from the last full version.
Thanks for the feedback, i now have a WHILE loop included that will make sure output.txt is available.

serendipity
Posts: 3360
Joined: 07 May 2007 18:14
Location: NJ/NY

Re: SimpleUpdater

Post by serendipity »

klownboy wrote:Hey serendipity, your new version 2 worked like a charm... no error message(s) for me. You may want to mention in your upfront "How it works" section commenting out the savesettings command and changing #192 to #191 if one does not want settings saved. Some people may be like me and save only when I feel I want to save. Nice SimpleUpdater png! Thanks for the time-savings script and making it even more bullet proof.
Ken
OK, put a small note.

serendipity
Posts: 3360
Joined: 07 May 2007 18:14
Location: NJ/NY

Re: SimpleUpdater

Post by serendipity »

admin wrote:
serendipity wrote:Also, can get("instance") enumerate how many open instances?
No, this is unknown.
I made a small vbs script which now says how many instances are open from the current XY.

serendipity
Posts: 3360
Joined: 07 May 2007 18:14
Location: NJ/NY

Re: SimpleUpdater

Post by serendipity »

Marco wrote:@serendipity
Can you write VBS code also for closing every XY and XYcopy window after a delay?
I could include a vbs code now with version 2. The code detects all XY instances from current XY and gives you the option to close them. Note: other XYs from different location like usb etc are not affected.

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

Re: SimpleUpdater

Post by Filehero »

Hi serendipity,

on my notebook with wait(500|2000|3000) I either got the error message LittleBiG has mentioned or a different message telling the vbs-file was not found.



Cheers,
Filehero

serendipity
Posts: 3360
Joined: 07 May 2007 18:14
Location: NJ/NY

Re: SimpleUpdater

Post by serendipity »

Filehero wrote:Hi serendipity,

on my notebook with wait(500|2000|3000) I either got the error message LittleBiG has mentioned or a different message telling the vbs-file was not found.



Cheers,
Filehero
Can you try the one i just uploaded?

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

Re: SimpleUpdater

Post by Filehero »

serendipity wrote:Can you try the one i just uploaded?
Well, my working instance is already up-to-date. But I grabbed one of my old ones, copied over the entire <xydata> folder including the new script version and: No error popups and smooth update! :)

Thanks for this quick fix.


Cheers,
Filehero

serendipity
Posts: 3360
Joined: 07 May 2007 18:14
Location: NJ/NY

Re: SimpleUpdater

Post by serendipity »

Filehero wrote:
serendipity wrote:Can you try the one i just uploaded?
Well, my working instance is already up-to-date. But I grabbed one of my old ones, copied over the entire <xydata> folder including the new script version and: No error popups and smooth update! :)

Thanks for this quick fix.


Cheers,
Filehero
Great, Thanks.

drewkeller
Posts: 33
Joined: 01 Nov 2008 05:29

Re: SimpleUpdater

Post by drewkeller »

Several improvements I can think of
  • Show change logs back to MostRecent($preset_number, $curver)
  • Improve the look of the changelog. Jacky's looked pretty nice. The navy on white with white on green looks.... well, ugly (sorry)
  • The changelog does not need to say "Changelog for the latest beta" for every beta version (lies, I say, all lies).
  • The changelog should use a monospace font since it is formatted with that intention (therefore is more readable monospaced). It does NOT need to be Courier New, if that's what you're trying to get away from. It's not as ugly as Comic Sans, but .... well, I'm an artist, don't get me started on fonts....
  • There actually have been a few times that I did an update and then needed to restore to my previous version. Which Jacky's script made real easy.

Post Reply