vestanpance Posted April 6, 2016 Share Posted April 6, 2016 Hi all, It's rare i post anything as i usually find the answers i want by browsing the forum.. but i can't get this statement right, and i could well be doing it wrong anyway and i was hoping someone could either correct my code or tell me i'm doing things the hard way around.. The function below is launched via a system tray Menu/GUI (using code from "ModernMenu UDF by Holger Kotsch") So i choose Ultimatix from the Menu and it launches the function. To run though the code briefly: It checks to see if Ultimatix.exe is present on the local machine first and if it isn't download it and then open the local file Ultimatix.exe. - It does that just fine. It checks to see if Ultimatix.exe is present and if it is, check to see if the remote file (Ultimatix.exe) has a higher version revision. If it does, download the remote file overwriting the local file and then open the local file Ultimatix.exe. - It does that just fine too. However, if the local file exists AND it's the same revision as the remote file, it doesn't do anything and that's where i'm stuck.. Func Ultimatix() ;Launch Ultimatix Local Const $sFilePath = @MyDocumentsDir & "\AutoIT_Toolbar\Toolbar Items\Apps\Ultimatix.exe" Local $iFileExists = FileExists($sFilePath) If $iFileExists Then Local $LocalFile = FileGetVersion ($sFilePath, "FileVersion") Local $RemoteFile = FileGetVersion("\\1x.2x.1x.8x\htdocs\downloads\software\AutoIT\Ultimatix.exe", "FileVersion") Consolewrite("The file exists" & @CRLF) If $RemoteFile > $LocalFile Then Local $hDownload = InetGet("http://1x.2x.1x.8x/downloads/software/AutoIT/Ultimatix.exe", $sFilePath, $INET_FORCERELOAD, $INET_DOWNLOADBACKGROUND) Do ; Wait for the download to complete by monitoring when the 2nd index value of InetGetInfo returns True. Sleep(250) Until InetGetInfo($hDownload, $INET_DOWNLOADCOMPLETE) InetClose($hDownload) ; Close the handle returned by InetGet. Consolewrite("Remote file is greater than local file" & @CRLF) ShellExecute($sFilePath) Elseif $LocalFile > $RemoteFile Then Consolewrite("local file is greater than remote file" & @CRLF) ShellExecute($sFilePath) EndIf Else Local $hDownload = InetGet("http://1x.2x.1x.8x/downloads/software/AutoIT/Ultimatix.exe", $sFilePath, $INET_FORCERELOAD, $INET_DOWNLOADBACKGROUND) Do ; Wait for the download to complete by monitoring when the 2nd index value of InetGetInfo returns True. Sleep(250) Until InetGetInfo($hDownload, $INET_DOWNLOADCOMPLETE) InetClose($hDownload) ; Close the handle returned by InetGet. ShellExecute($sFilePath) Consolewrite("I downloaded the file" & @CRLF) EndIf EndFunc ;==>Ultimatix Have i tried to over complicate things or have i missed something a little bit obvious? Many thanks in advance. Link to comment Share on other sites More sharing options...
markyrocks Posted April 6, 2016 Share Posted April 6, 2016 (edited) I would personally end all if statements before you enter the do statement. Looks like all the do statements do the same thing anyway (didn't look that closely). Also the until part (I believe ) should be an expression not just a functiion call. Like InetGetInfo ($args.. whatever )<>"" would probably be best to pass InetGetInfo to a variable first like $iNetInfo=InetGetInfo($args....) Then go.. until $iNetInfo<>"" Edited April 6, 2016 by markyrocks Spoiler "I Believe array math to be potentially fatal, I may be dying from array math poisoning" Link to comment Share on other sites More sharing options...
Developers Jos Posted April 6, 2016 Developers Share Posted April 6, 2016 9 minutes ago, vestanpance said: check to see if the remote file (Ultimatix.exe) has a higher version revision Not really as the FileGetVersion() returns a string in the format xx.xx.xx.xx! _VersionCompare() can do what you want. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
MichaelHB Posted April 6, 2016 Share Posted April 6, 2016 If the local file exists AND it's the same version as the remote file, what do you want it do to? Link to comment Share on other sites More sharing options...
vestanpance Posted April 6, 2016 Author Share Posted April 6, 2016 3 minutes ago, MichaelHB said: If the local file exists AND it's the same version as the remote file, what do you want it do to? I want to launch the local version of Ultimatix.exe. Basically i want to do the following. When the function is chosen from the menu: Check to see if Ultimatix.exe is on the local machine. If Ultimatix.exe is NOT on the local machine, download it from the network drive and then launch the local Ultimatix.exe. If Ultimatix.exe IS on the local machine, Is the remote version more up to date? If the remote version of Ultimatix.exe is more up to date - download the newer version overwriting the older version and then execute the local Ultimatix.exe. If the local version of Ultimatix.exe is the same as the remote version (so i haven't create a newer version of Ultimatix.exe and put it on a network drive) then just execute the version you have locally. I hope i'm making sense Link to comment Share on other sites More sharing options...
vestanpance Posted April 6, 2016 Author Share Posted April 6, 2016 14 minutes ago, Jos said: Not really as the FileGetVersion() returns a string in the format xx.xx.xx.xx! _VersionCompare() can do what you want. Jos Hi Jos, thanks for your input.. Always learning, but i don't understand how to use the _VersionCompare for the two files. If i use the code: Local $LocalFile = FileGetVersion ($sFilePath, "FileVersion") Local $RemoteFile = FileGetVersion("\\1x.2x.1x.8x\htdocs\downloads\software\AutoIT\Ultimatix.exe", "FileVersion") ConsoleWrite("The Local File Version is: " & $LocalFile & @CRLF & "The Remote File Version is: " & $RemoteFile & @CRLF) I end up with the following result in the console: The Local File Version is: 2.0.0.3 The Remote File Version is: 2.0.0.2 So for this instance, it doesn't download anything (because the remote file isn't newer) but what i mean is, FileGetVersion is serving it's purpose for me.... even if i am using it in the wrong way.. Link to comment Share on other sites More sharing options...
MichaelHB Posted April 6, 2016 Share Posted April 6, 2016 First i would check Jos suggestion. Then see if this is what you are looking: Func Ultimatix() ;Launch Ultimatix Local Const $sFilePath = @MyDocumentsDir & "\AutoIT_Toolbar\Toolbar Items\Apps\Ultimatix.exe" Local $iFileExists = FileExists($sFilePath) If $iFileExists Then Local $LocalFile = FileGetVersion ($sFilePath, "FileVersion") Local $RemoteFile = FileGetVersion("\\1x.2x.1x.8x\htdocs\downloads\software\AutoIT\Ultimatix.exe", "FileVersion") Consolewrite("The file exists" & @CRLF) If $RemoteFile > $LocalFile Then Local $hDownload = InetGet("http://1x.2x.1x.8x/downloads/software/AutoIT/Ultimatix.exe", $sFilePath, $INET_FORCERELOAD, $INET_DOWNLOADBACKGROUND) Do ; Wait for the download to complete by monitoring when the 2nd index value of InetGetInfo returns True. Sleep(250) Until InetGetInfo($hDownload, $INET_DOWNLOADCOMPLETE) InetClose($hDownload) ; Close the handle returned by InetGet. Consolewrite("Remote file is greater than local file" & @CRLF) ShellExecute($sFilePath) Elseif $LocalFile >= $RemoteFile Then ;******** If Local File is greater or EQUAL RemoteFile just execute it Consolewrite("local file is greater than remote file" & @CRLF) ShellExecute($sFilePath) EndIf Else Local $hDownload = InetGet("http://1x.2x.1x.8x/downloads/software/AutoIT/Ultimatix.exe", $sFilePath, $INET_FORCERELOAD, $INET_DOWNLOADBACKGROUND) Do ; Wait for the download to complete by monitoring when the 2nd index value of InetGetInfo returns True. Sleep(250) Until InetGetInfo($hDownload, $INET_DOWNLOADCOMPLETE) InetClose($hDownload) ; Close the handle returned by InetGet. ShellExecute($sFilePath) Consolewrite("I downloaded the file" & @CRLF) EndIf EndFunc ;==>Ultimatix vestanpance 1 Link to comment Share on other sites More sharing options...
vestanpance Posted April 6, 2016 Author Share Posted April 6, 2016 (edited) Thank you so much MichaelHB, you cracked it... Works a treat... Now to read and understand how you completed the statement, vs how i wrote it. Also be looking at _VersionCompare() as advised by Jos to see how that works. Thanks very much to everyone who had input.. Much appreciated! Daz Edited April 6, 2016 by vestanpance bad spelling :p Link to comment Share on other sites More sharing options...
MichaelHB Posted April 6, 2016 Share Posted April 6, 2016 Glad to help. Link to comment Share on other sites More sharing options...
Developers Jos Posted April 6, 2016 Developers Share Posted April 6, 2016 Still think this if is wrong as indicated: If $RemoteFile > $LocalFile Then 20 minutes ago, vestanpance said: Always learning, but i don't understand how to use the _VersionCompare for the two files. The helpfile is your friend Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
vestanpance Posted April 6, 2016 Author Share Posted April 6, 2016 17 minutes ago, Jos said: Still think this if is wrong as indicated: If $RemoteFile > $LocalFile Then The helpfile is your friend Jos The Helpfile and i are well acquainted which in truth, is why i generally don't need to use the forums. I looked at _VersionCompare() before settling with FileGetVersion because i wasn't getting the results i wanted. I've modified the helpfile example to this. I think i have used it correctly? Local $LocalFile = @MyDocumentsDir & "\AutoIT_Toolbar\Toolbar Items\Apps\Ultimatix.exe" Local $RemoteFile = "\\10.228.167.84\htdocs\downloads\software\AutoIT\Ultimatix.exe" Consolewrite(_VersionCompare($LocalFile, $RemoteFile) & @CRLF) But i always get "1", which according to the helpfile means Version 1 is greater. Even if the remote file Version is greater. However, if i check both .exe files (local and remote) using FileGetVersion, i get the same result for both files? Link to comment Share on other sites More sharing options...
Developers Jos Posted April 6, 2016 Developers Share Posted April 6, 2016 You obviously need to leave the FileGetVersion() for the 2 files in there and only change the If i mentioned! Just put those 2 result variables in the UDF and bob's your uncle. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
mLipok Posted April 6, 2016 Share Posted April 6, 2016 First I would like to use TIDY as was used by @MichaelHB in post #7 Maybe then you can find more wise idea by yourself . Signature beginning:* Please remember: "AutoIt"..... * Wondering who uses AutoIt and what it can be used for ? * Forum Rules ** ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Code * for other useful stuff click the following button: Spoiler Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API * ErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 * My contribution to others projects or UDF based on others projects: * _sql.au3 UDF * POP3.au3 UDF * RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF * SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane * Useful links: * Forum Rules * Forum etiquette * Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * Wiki: * Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX IE Related: * How to use IE.au3 UDF with AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler * IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related: * How to get reference to PDF object embeded in IE * IE on Windows 11 * I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions * EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *I also encourage you to check awesome @trancexx code: * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuff * OnHungApp handler * Avoid "AutoIt Error" message box in unknown errors * HTML editor * winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/ "Homo sum; humani nil a me alienum puto" - Publius Terentius Afer"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming" , be and \\//_. Anticipating Errors : "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty." Signature last update: 2023-04-24 Link to comment Share on other sites More sharing options...
vestanpance Posted April 7, 2016 Author Share Posted April 7, 2016 On 4/6/2016 at 6:20 PM, Jos said: You obviously need to leave the FileGetVersion() for the 2 files in there and only change the If i mentioned! Just put those 2 result variables in the UDF and bob's your uncle. Jos As they say on 'Who wants to be a Millionaire' ; It's only obvious if you know the answer... That said, this evening, i've understood what you meant by your previous comment and i've changed it to: If $iFileExists Then Local $LocalFile = FileGetVersion($sFilePath, "FileVersion") Local $RemoteFile = FileGetVersion("\\10.228.167.84\htdocs\downloads\software\AutoIT\Ultimatix.exe", "FileVersion") Local $UpdateAvailable = _VersionCompare($LocalFile, $RemoteFile) If $UpdateAvailable = -1 Then Local $hDownload = InetGet("http://10.228.167.84/downloads/software/AutoIT/Ultimatix.exe", $sFilePath, $INET_FORCERELOAD, $INET_DOWNLOADBACKGROUND) So i hope i have understood your comments and direction. Thanks to all for your input, patience and for pointing me in the right direction. Link to comment Share on other sites More sharing options...
Developers Jos Posted April 7, 2016 Developers Share Posted April 7, 2016 Just now, vestanpance said: So i hope i have understood your comments and direction. Thanks to all for your input, patience and for pointing me in the right direction. That is indeed what I meant. You're welcome Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now