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 0000000..012e6a8 Binary files /dev/null and b/GPatch/Launcher/GPatch.ico differ 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); } }