1
0
mirror of https://github.com/ncblakely/GiantsTools synced 2024-11-22 06:05:38 +01:00

Fix version check for launcher.

This commit is contained in:
Nick Blakely 2020-08-11 11:24:04 -07:00
parent 006612a655
commit dcf44ec7d0
4 changed files with 47 additions and 20 deletions

View File

@ -78,6 +78,7 @@
<ItemGroup> <ItemGroup>
<Compile Include="ApplicationNames.cs" /> <Compile Include="ApplicationNames.cs" />
<Compile Include="Updater\ApplicationType.cs" /> <Compile Include="Updater\ApplicationType.cs" />
<Compile Include="VersionHelper.cs" />
<Compile Include="WindowType.cs" /> <Compile Include="WindowType.cs" />
<Compile Include="GameSettings.cs" /> <Compile Include="GameSettings.cs" />
<Compile Include="ImageButton.cs"> <Compile Include="ImageButton.cs">

View File

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
@ -102,26 +103,23 @@ namespace Giants.Launcher
if ((int)GameSettings.Get("NoAutoUpdate") == 0) if ((int)GameSettings.Get("NoAutoUpdate") == 0)
{ {
Version gameVersion = null; Version gameVersion = VersionHelper.GetGameVersion(this.gamePath);
try
{
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(this.gamePath);
gameVersion = new Version(fvi.FileVersion.Replace(',', '.'));
}
finally
{
if (gameVersion == null) if (gameVersion == null)
{ {
string message = string.Format(Resources.AppNotFound, GAME_NAME); string message = string.Format(Resources.AppNotFound, GAME_NAME);
MessageBox.Show(message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show(message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
Application.Exit(); Application.Exit();
} }
}
var appVersions = new Dictionary<ApplicationType, Version>()
{
[ApplicationType.Game] = gameVersion,
[ApplicationType.Launcher] = VersionHelper.GetLauncherVersion()
};
// Check for updates // Check for updates
this.updater = new Updater( this.updater = new Updater(
appVersion: gameVersion, appVersions: appVersions,
updateCompletedCallback: this.LauncherForm_DownloadCompletedCallback, updateCompletedCallback: this.LauncherForm_DownloadCompletedCallback,
updateProgressCallback: this.LauncherForm_DownloadProgressCallback); updateProgressCallback: this.LauncherForm_DownloadProgressCallback);

View File

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.IO; using System.IO;
using System.Net; using System.Net;
@ -10,16 +11,16 @@ namespace Giants.Launcher
{ {
public class Updater public class Updater
{ {
private readonly Version appVersion; private readonly IDictionary<ApplicationType, Version> appVersions;
private readonly AsyncCompletedEventHandler updateCompletedCallback; private readonly AsyncCompletedEventHandler updateCompletedCallback;
private readonly DownloadProgressChangedEventHandler updateProgressCallback; private readonly DownloadProgressChangedEventHandler updateProgressCallback;
public Updater( public Updater(
Version appVersion, IDictionary<ApplicationType, Version> appVersions,
AsyncCompletedEventHandler updateCompletedCallback, AsyncCompletedEventHandler updateCompletedCallback,
DownloadProgressChangedEventHandler updateProgressCallback) DownloadProgressChangedEventHandler updateProgressCallback)
{ {
this.appVersion = appVersion; this.appVersions = appVersions;
this.updateCompletedCallback = updateCompletedCallback; this.updateCompletedCallback = updateCompletedCallback;
this.updateProgressCallback = updateProgressCallback; this.updateProgressCallback = updateProgressCallback;
} }
@ -28,7 +29,7 @@ namespace Giants.Launcher
{ {
try try
{ {
if (this.ToVersion(versionInfo.Version) > this.appVersion) if (this.ToVersion(versionInfo.Version) > this.appVersions[applicationType])
{ {
this.StartApplicationUpdate(applicationType, versionInfo); this.StartApplicationUpdate(applicationType, versionInfo);
} }

View File

@ -0,0 +1,27 @@
namespace Giants.Launcher
{
using System;
using System.Diagnostics;
using System.Windows.Forms;
public static class VersionHelper
{
public static Version GetGameVersion(string gamePath)
{
try
{
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(gamePath);
return new Version(fvi.FileVersion.Replace(',', '.'));
}
catch (Exception)
{
return null;
}
}
public static Version GetLauncherVersion()
{
return new Version(Application.ProductVersion);
}
}
}