Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

[Func] Self script updater


  • Please log in to reply
69 replies to this topic
Rseding91
  • Members
  • 703 posts
  • Last active: Apr 02 2016 05:05 AM
  • Joined: 07 Jun 2010

It's awesome, but is it possible to make it work without storing any data in any external files like *.ini?
Why can't that kind of info be stored inside of the script's code itself?

The external ini is needed so the script knows if it should download the file or not (is it a newer one?)

Yeah, but why use an external file to store that info?
You could make the script work so:
1. It connects to the server via provided URL and reads the *.ini-file from the server.
2. Runs a comparison of the version stored in the *.ini-file and in the version in the code of the local script (*.ahk or *.exe).
3. If the server has a newer version of the script - download it and replace the existing one with it.

I mean why do you make users have an *.ini file locally? Can't the script read it's own code?
To do what I mean - users would just have to have the script's version stored in the code of the script and separately in the *.ini file (in order to reduce traffic consumption and download only lightweight *.ini at every check, instead of probably heavy *.exe/*.ahk).
That would be nice, since some scripts do work without any external *.ini-files (yeah, I like super-mega portability, when you need to copy only the executable).



That's exactily what it does now?

iDrug
  • Members
  • 389 posts
  • Last active: Oct 11 2015 09:24 PM
  • Joined: 13 Oct 2009
Doesn't it download *.ini?

Rseding91
  • Members
  • 703 posts
  • Last active: Apr 02 2016 05:05 AM
  • Joined: 07 Jun 2010

Doesn't it download *.ini?



Your end script when you call the check for update function downloads the .ini file and looks at it to see what the version number of the file online is. If it's a newer one and it was told to update then it uses the URL in the .ini file and downloads the new version of the script.

If the MD5 key was set in the .ini file it does a MD5 check on the file it just downloaded.

Once downloaded the function will switch over to the new version and delete the .ini and the old version from the computer.

iDrug
  • Members
  • 389 posts
  • Last active: Oct 11 2015 09:24 PM
  • Joined: 13 Oct 2009
Awesome, then it already works as I requested.

gwarble
  • Members
  • 624 posts
  • Last active: Aug 12 2016 07:49 PM
  • Joined: 23 May 2009
Nice script/idea... I use a similar technique, normally on the intranet but just added it to EitherMouse... MD5 is a good addition, but you may want to add an option for an "update message", in case end user has the ability to deny an update they dont want

Also if i can handle the errors more elegantly when the connection fails, a UrlDownloadToMemory() can replace UrlToFile and prevent the file created

Lastly, if the version file Url has to be hardcoded, why not make the download url hardcoded as well, theyll probably change together, no?

Thanks for sharing

Rseding91
  • Members
  • 703 posts
  • Last active: Apr 02 2016 05:05 AM
  • Joined: 07 Jun 2010

Nice script/idea... I use a similar technique, normally on the intranet but just added it to EitherMouse... MD5 is a good addition, but you may want to add an option for an "update message", in case end user has the ability to deny an update they dont want

Also if i can handle the errors more elegantly when the connection fails, a UrlDownloadToMemory() can replace UrlToFile and prevent the file created

Lastly, if the version file Url has to be hardcoded, why not make the download url hardcoded as well, theyll probably change together, no?

Thanks for sharing



It has a "update message" now (paramater 2) and the download URL for the script is more likely to change with versions as some people put versions in the filenames. I'm not sure if UrlDownloadToMemory supports all 4 of the main versions of AHK. If it does I wouldn't be apposed to using it.

gwarble
  • Members
  • 624 posts
  • Last active: Aug 12 2016 07:49 PM
  • Joined: 23 May 2009

It has a "update message" now (paramater 2)

sweet

download URL for the script is more likely to change with versions as some people put versions in the filenames.

duh, thanks

I'm not sure if UrlDownloadToMemory supports all 4 of the main versions of AHK. If it does I wouldn't be apposed to using it.

There are versions for each version i think, but i havent seen a single version for _L and _B, no


Edit: param 2 is not what i meant... I meant a custom update message, written to the ini file, that is passed to the script when a check for update is done (which the script can then pass to the user as more info about the update

Crossfire
  • Guests
  • Last active:
  • Joined: --
Hey man nice script you have here. One thing though. When it downloads the new file and runs it. My Load function which loads information from a .ini file doesnt work. It works when i exit the app then reload it. Is there a way to fix this? When it first runs the app again does it run it in a different location then where it saves it? That could be the problem.

skyline7349
  • Members
  • 14 posts
  • Last active: Jun 05 2012 10:21 PM
  • Joined: 05 Jun 2012
Great script really helpful. Thank you!

Rseding91
  • Members
  • 703 posts
  • Last active: Apr 02 2016 05:05 AM
  • Joined: 07 Jun 2010

Hey man nice script you have here. One thing though. When it downloads the new file and runs it. My Load function which loads information from a .ini file doesnt work. It works when i exit the app then reload it. Is there a way to fix this? When it first runs the app again does it run it in a different location then where it saves it? That could be the problem.



You're probably using the working directory instead of specifying full paths.

Do this: Iniread,blabla,%A_ScriptDir%\My ini.ini
Not this: Iniread,blabla,My ini.ini

realre
  • Members
  • 38 posts
  • Last active: Aug 24 2016 01:14 PM
  • Joined: 10 Jul 2011
still alive there? what if i upload the files without extension .exe in any hosting. can you suggest some change in your script to make it work? many hosting file do not allow us to host an exe files and that make this auto update should be in ahk for me.

Rseding91
  • Members
  • 703 posts
  • Last active: Apr 02 2016 05:05 AM
  • Joined: 07 Jun 2010

still alive there? what if i upload the files without extension .exe in any hosting. can you suggest some change in your script to make it work? many hosting file do not allow us to host an exe files and that make this auto update should be in ahk for me.




Autohotkey.net allows .exe file types. The script will also work with .ahk file types though.

realre
  • Members
  • 38 posts
  • Last active: Aug 24 2016 01:14 PM
  • Joined: 10 Jul 2011

still alive there? what if i upload the files without extension .exe in any hosting. can you suggest some change in your script to make it work? many hosting file do not allow us to host an exe files and that make this auto update should be in ahk for me.




Autohotkey.net allows .exe file types. The script will also work with .ahk file types though.


thanks Rseding91 for the info...

zoraxe
  • Members
  • 25 posts
  • Last active: Dec 14 2012 10:29 AM
  • Joined: 17 Aug 2012
Rseding91, today I used your script. Thank you!

I did a few changes to tweak it for my needs.
I have a few suggestions, I hope you don't mind:
1. For some reason the Shell.Run task didn't wait for TaskKill to complete, before trying to update the exe file.
I added a Sleep task for 1 sec. to solve this (in the VBScript).

2. You are using TaskKill /F ... What happens is when /F is used the tray icon is left visible until you hover with a mouse over it, which is kind of annoying when updating the application and now you see two icons. There is a way to resolve this:
Just use TaskKill without the "/F". This will still cause the old application to close at most times while the tray icon is removed as well.
Just to be safe you can leave another TaskKill task running with the /F after it, in case "requesting nicely" didn't take effect.

3. You pop a message box when update is complete from the VBScript task. Personally I'm not very fond of message boxes, when traytip can be used (no need to bother the user with another click). What I do is run the updated exe with "/update" command-line parameter. At the start of the script I check for the existence of "/update" parameter. If it exists, I turn on a TrayTip for 5 seconds: "Script successfully updated to version ..."

Thank you,
ZoRAXE

Rseding91
  • Members
  • 703 posts
  • Last active: Apr 02 2016 05:05 AM
  • Joined: 07 Jun 2010

1. For some reason the Shell.Run task didn't wait for TaskKill to complete, before trying to update the exe file.
I added a Sleep task for 1 sec. to solve this (in the VBScript).


Can you post the code you have? I know there was a problem with the older versions of the updater where that would happen almost every time.


3. You pop a message box when update is complete from the VBScript task. Personally I'm not very fond of message boxes, when traytip can be used (no need to bother the user with another click). What I do is run the updated exe with "/update" command-line parameter. At the start of the script I check for the existence of "/update" parameter. If it exists, I turn on a TrayTip for 5 seconds: "Script successfully updated to version ..."


You seem to have missed parameter 2:

parameter 2: _SuppressMsgBox = 0
About: If set to 1, the function will skip asking if the user wants to update and simply attempt to update (if there is a newer version available).
If set to 2, the function will skip the "Update finished" message after the update finishes.
If set to 3, the function will skip both of the messages.