Page 1 of 1

Forge Auto-Updater

PostPosted: 10 Dec 2017, 20:27
by Qriist
Hello there, I've created a simple updater that will look for the latest snapshot on snapshots.cardforge and update your copy of Forge if something new comes along.

It will simply launch Forge if you (a) have the latest snapshot or (b) cannot connect to the internet. Though, the very first time you run it, it will go through the whole process as it doesn't have a clue as to what version you actually have.

Once it finds the need to update it will download, test file integrity, and extract all the files to the folder the updater resides. Thusly, set it in your forge folder and create a shortcut to Forge Updater.ahk/exe.

It does have one dependecy, 7za.exe, which it will attempt to automatically download from my personal storage (static links, yay!). If you are leery about this you can download 7za.exe yourself from the 7-zip homepage (it's in the portable package) and place it in the same location as the updater.

Updating Forge is kind of a pain because I never know when there is a new release. Now I don't need to. :)

This was written in AHK and the source code is provided, as is the compiled version.
Enjoy!

Source Code: (minus the actual links it connects to, due to spam filters. It is provided in the zip'd copy.)

Code: Select all
#SingleInstance,ignore
IfNotExist,%A_scriptdir%\7za.exe
{
   SplashTextOn,,,Downloading 7za
   URLDownloadToFile,(SPAM FILTER EDIT!),%a_scriptdir%\7za.exe
}
IfNotExist,%A_scriptdir%\7za.exe
{
   MsgBox,,Forge Updater,7za.exe not found.`nPlease connect to the internet!
   ExitApp
}
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
SplashTextOn,250,25,Forge Updater,Checking latest snapshot
IniRead,LatestSnapshot,%a_scriptdir%\Forge Updater.ini,Forge Updater,Latest Snapshot
FileDelete,%a_scriptdir%\snapshot.html
URLDownloadToFile,(SPAM FILTER EDIT!),%A_ScriptDir%\snapshot.html
IfNotExist,%a_scriptdir%\snapshot.html
   gosub,LaunchForge
FileRead,findsnapshot,%a_scriptdir%\snapshot.html
Loop,parse,findsnapshot,`n
{
   if a_loopfield contains forge-gui-desktop
   {
      StringSplit,snapshot,a_loopfield,`"
      foundsnapshot=%snapshot2%
   }
}
If Snapshot2=%LatestSnapshot%
   gosub,LaunchForge
SplashTextOn,400,25,Forge Updater,Found %snapshot2%
sleep,5000
SplashTextOn,450,25,Forge Updater,Downloading %snapshot2%
URLDownloadToFile,(SPAM FILTER EDIT!),%a_scriptdir%\%foundsnapshot%
SplashTextOn,250,25,Forge Updater,Testing package integrity...
RunWait,%a_scriptdir%\7za.exe t "%a_scriptdir%\%foundsnapshot%",,hide UseErrorLevel
If ErrorLevel != 0
{
   SplashTextOff
   MsgBox,,Forge Updater,Update failed!`nPlease rerun.
   ExitApp
}
FileDelete,%a_scriptdir%\*.jar
SplashTextOn,250,25,Forge Updater,Extracting package...
RunWait,%a_scriptdir%\7za.exe x -aoa "%a_scriptdir%\%foundsnapshot%",,hide
StringTrimRight,foundsnapshot_revised,foundsnapshot,4
RunWait,%a_scriptdir%\7za.exe x -aoa "%a_scriptdir%\%foundsnapshot_revised%",,hide
IniWrite,%foundsnapshot%,%a_scriptdir%\Forge Updater.ini,Forge Updater,Latest Snapshot

LaunchForge:
SplashTextOn,250,25,Forge Updater,Launching Forge...
Run, %a_scriptdir%\Forge.exe
FileDelete,%a_scriptdir%\Snapshot.html
FileDelete,%a_scriptdir%\*forge-gui-desktop.tar*
Sleep,3000
ExitApp
EDIT: Minor change to the package cleanup. Consolidated a few lines.

Re: Forge Auto-Updater

PostPosted: 14 Dec 2017, 06:12
by churrufli
Good idea!

Re: Forge Auto-Updater

PostPosted: 14 Dec 2017, 09:20
by Pux
It works perfectly on my machine. I think it would be a great feature in the base game too.

Re: Forge Auto-Updater

PostPosted: 14 Dec 2017, 10:20
by Qriist
Thank you for the kind words. :)