From 7af4abb5431ee8cae5983cc85a0751613bc00065 Mon Sep 17 00:00:00 2001 From: Nick Blakely Date: Sun, 9 Aug 2020 23:24:50 -0700 Subject: [PATCH] Add launcher update script. --- .gitignore | 2 +- GPatch/Launcher/GPatch.ico | Bin 0 -> 2238 bytes GPatch/Launcher/Launcher.nsi | 75 ++++++++++++++++++++++++++++++++ Giants.Launcher/GameSettings.cs | 2 +- Giants.Launcher/OptionsForm.cs | 17 +++----- Giants.Launcher/Updater.cs | 30 ++++++------- 6 files changed, 98 insertions(+), 28 deletions(-) create mode 100644 GPatch/Launcher/GPatch.ico create mode 100644 GPatch/Launcher/Launcher.nsi diff --git a/.gitignore b/.gitignore index ea7a383..f5f9220 100644 --- a/.gitignore +++ b/.gitignore @@ -343,4 +343,4 @@ healthchecksdb #GPatch GPatch/Files -GPatch/Launcher \ No newline at end of file +GPatch/Launcher/*.exe \ No newline at end of file diff --git a/GPatch/Launcher/GPatch.ico b/GPatch/Launcher/GPatch.ico new file mode 100644 index 0000000000000000000000000000000000000000..012e6a834aa076522ce14dc8f9e70ec0d1235b2f GIT binary patch literal 2238 zcmc(gdstOv7KdLj6;nhm!l*c&&=N11*JjAllq9JXyd)|r3Zsyi;;2n#P6~)17+|C+ zCTNHm38JEaSb?Izlnur;4Y`;Q7b7bX;he8^EFKSFfA^i|x7XUgcYSN`v-kHs8;s)QHndF0?}pBS&^Ga=@hLZrB#$yNK`uUbm&A{ zQL9Kb>pd-6trlHtE2>4LTDaGI4{b{`^*=Pz+lQ*%RlRgrU}io${_ z$t%hJv6AAuES!a1{uf`WYVFMmz;S6?dm zo5Wtpqe+*G?$=y2+jA)_&LQ_=4o!8JIGK`7W>ywK*_pJe&(YmE$K|u7<(B3{ublefj%Hug-8qcA_@r3P+Bjs2u8{=Y$i;0DavE*NgVbVJX*tdT_J7S_a zurHcf8}_p4$OpW+WjA|vMG+Md$$O%>&`8E?j=(n}obVlCBqxOu78JsW&|tzsg4q!q zOz3vW1GlryD~K011aLmzpP`HV3EH@Y>iSLicy3~-`v#&C)^p_0di*!8!_{LgqXYbi zjbDS`s@L%l^|V_>K!`7I`}$(!wTQ%YcbUHs+mZ9}8s^5STs~Mr%V4KvUvv6Qewvh8#}3e3kr1}GEHP8?FaOhyvO}^&|RW_{~PJM-Vd_&^n1F~u-|=QTPO2@ z@wcK;uD{NBaNaRna8kW=>Aks5?R}ennE!4(KL1lSGk)KaN$t7wu8V0S$B%bIXaS-)lT8(*G%Ygh-YhQ6u%&zuY0^v=e0+fFBr?}(N8tkruz z=d;Bd{yQ)H!ud{EDQk^e9tV_0V{@H{Jr$*fR5MW~+P}@Uhs;;15S|m@xl`IaWK6jX zPl|t~M%tU2nszLiaG_FvU5B5`uvQkz#-zJJMQ^40)c(Y9rBc3+<8@`$tGBhSL4lij)SXCqMI@Snhrg{I+al`55z;5B`Fk7{MR4xqrky5~&%WDUU{*gyt-Tm+F6wA`C)KC8~%#f3`@?w_mIzJXv zl{S8(l*tDnhFEp=2|Sl~rZA@@R1L0^*Pj}6*w~<;dzVMLKJn}e3Hd#DDHU@Ag1$av zfF-pW*f*-%;Eey5(R6(3fV9l|i1u90a%Zc5m^c+H literal 0 HcmV?d00001 diff --git a/GPatch/Launcher/Launcher.nsi b/GPatch/Launcher/Launcher.nsi new file mode 100644 index 0000000..5c0e3e2 --- /dev/null +++ b/GPatch/Launcher/Launcher.nsi @@ -0,0 +1,75 @@ +SetCompressor /SOLID lzma + +!define PRODUCT_NAME "Giants Launcher" +!define PRODUCT_VERSION "1.0.0.2" + +; MUI 1.67 compatible ------ +!include "MUI.nsh" + +; MUI Settings +!define MUI_ABORTWARNING +!define MUI_ICON "GPatch.ico" + +; Welcome page +;!insertmacro MUI_PAGE_WELCOME +; Directory page +!insertmacro MUI_PAGE_DIRECTORY +; Instfiles page +!insertmacro MUI_PAGE_INSTFILES + +!define MUI_LANGDLL_REGISTRY_ROOT "HKCU" +!define MUI_LANGDLL_REGISTRY_KEY "Software\PlanetMoon\Giants" +!define MUI_LANGDLL_REGISTRY_VALUENAME "SetupLanguage" + +; Language files +!insertmacro MUI_LANGUAGE "English" + +; MUI end ------ + +Name "Giants Launcher Update" +OutFile "LauncherUpdate_1002.exe" +InstallDir "C:\Program Files\Giants" +InstallDirRegKey HKCU "SOFTWARE\PlanetMoon\Giants" "DestDir" +ShowInstDetails hide + +;Request application privileges for Windows Vista +RequestExecutionLevel admin + +Section + SetDetailsView hide + SectionIn RO + SetOverwrite on + + + SetOutPath "$INSTDIR" + File /r "Giants.exe" + + +SectionEnd + +Function .onInit + Processes::KillProcess "Giants.exe" + Processes::FindProcess "Giants.exe" + ${If} $R0 == 1 + MessageBox MB_OK "Please close the Giants launcher before installing this update." + Abort + ${EndIf} + + ClearErrors + FileOpen $R0 "$INSTDIR\Giants.exe" w + ${If} ${Errors} + MessageBox MB_OK "Could not write to Giants.exe. Please ensure the Giants launcher is closed." + Abort + ${Else} + FileClose $R0 + ${EndIf} +FunctionEnd + +Function .onInstFailed + MessageBox MB_OK "Update failed. Please visit www.giantswd.org and download the latest version manually." +FunctionEnd + +Function .onInstSuccess + MessageBox MB_OK "Update complete!" + Exec "$INSTDIR\Giants.exe" +FunctionEnd \ No newline at end of file diff --git a/Giants.Launcher/GameSettings.cs b/Giants.Launcher/GameSettings.cs index 56580ba..69f4ece 100644 --- a/Giants.Launcher/GameSettings.cs +++ b/Giants.Launcher/GameSettings.cs @@ -14,7 +14,7 @@ namespace Giants.Launcher private const string REGISTRY_KEY = @"HKEY_CURRENT_USER\Software\PlanetMoon\Giants"; private const int OPTIONS_VERSION = 3; - private static Dictionary _Settings = new Dictionary(); + private static readonly Dictionary _Settings = new Dictionary(); // List of renderers compatible with the user's system. static public List CompatibleRenderers; diff --git a/Giants.Launcher/OptionsForm.cs b/Giants.Launcher/OptionsForm.cs index e126001..f3c769b 100644 --- a/Giants.Launcher/OptionsForm.cs +++ b/Giants.Launcher/OptionsForm.cs @@ -1,25 +1,20 @@ using System; using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Windows.Forms; using System.IO; +using System.Windows.Forms; namespace Giants.Launcher { - public partial class OptionsForm : Form + public partial class OptionsForm : Form { - string _gamePath = null; + private readonly string gamePath = null; public OptionsForm(string title, string gamePath) { InitializeComponent(); this.Text = title; - _gamePath = gamePath; + this.gamePath = gamePath; } private void OptionsForm_Load(object sender, EventArgs e) @@ -232,12 +227,12 @@ namespace Giants.Launcher private void btnCancel_Click(object sender, EventArgs e) { this.Close(); - GameSettings.Load(_gamePath); + GameSettings.Load(gamePath); } private void btnResetDefaults_Click(object sender, EventArgs e) { - GameSettings.SetDefaults(_gamePath); + GameSettings.SetDefaults(gamePath); SetOptions(); } } diff --git a/Giants.Launcher/Updater.cs b/Giants.Launcher/Updater.cs index 941e35d..679858a 100644 --- a/Giants.Launcher/Updater.cs +++ b/Giants.Launcher/Updater.cs @@ -39,28 +39,28 @@ namespace Giants.Launcher public class Updater { - Uri _updateUri; - Version _appVersion; - AsyncCompletedEventHandler _updateCompletedCallback; - DownloadProgressChangedEventHandler _updateProgressCallback; + private readonly Uri updateUri; + private readonly Version appVersion; + private AsyncCompletedEventHandler updateCompletedCallback; + private DownloadProgressChangedEventHandler updateProgressCallback; public Updater(Uri updateUri, Version appVersion) { - _updateUri = updateUri; - _appVersion = appVersion; + this.updateUri = updateUri; + this.appVersion = appVersion; } public void DownloadUpdateInfo(AsyncCompletedEventHandler downloadCompleteCallback, DownloadProgressChangedEventHandler downloadProgressCallback) { WebClient client = new WebClient(); // Keep track of our progress callbacks - _updateCompletedCallback = downloadCompleteCallback; - _updateProgressCallback = downloadProgressCallback; + updateCompletedCallback = downloadCompleteCallback; + updateProgressCallback = downloadProgressCallback; // Download update info XML client.Proxy = null; client.DownloadDataCompleted += new DownloadDataCompletedEventHandler(DownloadDataCallback); - client.DownloadDataAsync(_updateUri); + client.DownloadDataAsync(updateUri); } private int GetHttpFileSize(Uri uri) @@ -124,8 +124,8 @@ namespace Giants.Launcher Proxy = null }; client.DownloadFileAsync(info.DownloadUri, path, info); - client.DownloadFileCompleted += _updateCompletedCallback; - client.DownloadProgressChanged += _updateProgressCallback; + client.DownloadFileCompleted += updateCompletedCallback; + client.DownloadProgressChanged += updateProgressCallback; } private void StartLauncherUpdate(XElement root) @@ -165,8 +165,8 @@ namespace Giants.Launcher Proxy = null }; client.DownloadFileAsync(info.DownloadUri, path, info); - client.DownloadFileCompleted += _updateCompletedCallback; - client.DownloadProgressChanged += _updateProgressCallback; + client.DownloadFileCompleted += updateCompletedCallback; + client.DownloadProgressChanged += updateProgressCallback; } private void DownloadDataCallback(Object sender, DownloadDataCompletedEventArgs e) @@ -189,8 +189,8 @@ namespace Giants.Launcher StartLauncherUpdate(root); return; } - else if (gameVersion > _appVersion) - StartGameUpdate(root, _appVersion); + else if (gameVersion > appVersion) + StartGameUpdate(root, appVersion); } }