1
0
mirror of https://github.com/ncblakely/GiantsTools synced 2024-11-23 22:55:37 +01:00

Add launcher update script.

This commit is contained in:
Nick Blakely 2020-08-09 23:24:50 -07:00
parent 95f608e8f2
commit 7af4abb543
6 changed files with 98 additions and 28 deletions

2
.gitignore vendored
View File

@ -343,4 +343,4 @@ healthchecksdb
#GPatch
GPatch/Files
GPatch/Launcher
GPatch/Launcher/*.exe

BIN
GPatch/Launcher/GPatch.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

View File

@ -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

View File

@ -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<string, object> _Settings = new Dictionary<string, object>();
private static readonly Dictionary<string, object> _Settings = new Dictionary<string, object>();
// List of renderers compatible with the user's system.
static public List<RendererInterop.Capabilities> CompatibleRenderers;

View File

@ -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
{
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();
}
}

View File

@ -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);
}
}