1) Optimized script for speed with conditional loops instead of wait(). If vbs file or output file takes longer than 10 seconds (which is unlikely) script will throw an error.
2) Update window colors could always be changed, just made them easier by assigning variables in User defined parameters section
3) Moved user defined parameter below variable $newver. Now you can change the variable $downloadfile from xy.zip to $newver.zip to keep copies of old betas.
4) Changed "Changelog for the latest beta" to simply "Change Log".
5) Stylesheet had verdana as font, changed to arial.
Code: Select all
//SimpleUpdater v3
/*
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 3
1) Optimized script for speed with conditional loops instead of wait(). If vbs file or output file takes longer than 10 seconds (which is unlikely) script will throw an error.
2) Update window colors could always be changed, just made them easier by assigning variables in User defined parameters section
3) Moved user defined parameter below variable $newver. Now you can change the variable $downloadfile from xy.zip to $newver.zip to keep copies of old betas.
4) Changed "Changelog for the latest beta" to simply "Change Log".
5) Stylesheet had verdana as font, changed to arial.
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.
Version 1
1) Script now uses VBS script to unzip files to XY instead of unzip.exe. So no third party tools needed anymore.
*/
//Declare global variables
global $downloadurl,$downloadpath,$downloadfile,$newver,$temp,$vbsfile, $closepids, $closepidfile,$multiInstance;
//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";
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//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)
$updatebuttonbg="#00CC00"; //Update button background color
$updatebuttontext="#FFF"; //Update button text color
$windowbg="#FFF"; //Window background color
$bodytext="#000066"; //Text color for beta logs
$Officialcolor="Green"; //Text color for official release
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//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){
Status "Checking for other XY instances", "FF0000", "progress";
$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
Status "pidfile.vbs created", "FF0000", "progress";
//Loop to make sure pidfile is indeed available, else break in 10 seconds
$count=0;
WHILE(exists($pidfile)!=1){
wait (500);
Status "Waiting for pidfile.vbs", "FF0000", "progress";
$count++;
IF($count>20){
break;
}
}
run """$pidfile""";
//Loop to make sure outpid file is indeed available, else break in 10 seconds
$count=0;
WHILE(exists($outpid)!=1){
wait (500);
Status "Waiting for output.txt", "FF0000", "progress";
$count++;
IF($count>20){
break;
}
}
$readpid= readfile("$outpid");
wait (500);
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!=""){
Status "WARNING!! Cannot update while XYcopy is running!", "FF0000", "alert";
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=$Officialcolor>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</b><br>$betatext";
}
$count++;
}
//Update window interface
$Updatewindow=<<<Updatewindow
<style type="text/css" rel="stylesheet">
#mysubmit { background-color: $updatebuttonbg; border:0.01cm solid black; cursor= hand; font-size: 110%; font-family:Arial; color: $updatebuttontext;
height:30px;
font-weight: bold;}
#body { background-color: $windowbg; border:medium none; font-size: 75%; font-family:Arial,Helvetica;height:25px; color: $bodytext }
</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.