I'll try to keep this short...
I'm sure many of you have seen updaters. Y'know, when someone posts a script, but they don't post the actual script; They post a script that downloads the most recent public copy of that script ( @fady;'s Ivy Chop-O-Matic, for example).
Update.simba solves this crap. Put simply, it does this:
- Retrieves the online copy of the script
- Compares it with the currently running script and if it has changed:
- Overwrites the current script with the newer
- Creates a .bat that:
- Kills the current Simba by PID
- Launches a new Simba and runs the script with:
Code:
AppPath + AppFile() + ' -o ' + ScriptPath + ScriptFile + ' -r'
- Deletes itself
Now you can run a script. If there's an update, it'll automatically download and run the newer script! A bit "hackish", but works mint (from my experiences).
This works with other Simbas, even if you've renamed yours to, say, Simba_Old.exe. See below.
Update.simba provides:
- AppFile() - Similar to ScriptFile, but provides the currently running Simba executable
- TInputPipeStream.ReadAnsiString() - The default is broken and doesn't return correct values
- Update() - Updates your current script from a URL if an update is needed
Want proof? Save and run this!
Simba Code:
program UpdateExample;
{$I Update.simba}
const
VERSION := 1.0;
begin
Update('http://pastebin.com/raw/TdCiPkAr');
WriteLN('Version: ', VERSION);
end.
Thoughts? I'm sure there are better ways but meh, was fun to learn and use TProcess and such. . Tried to make it easy enough to read.