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>
<Compile Include="ApplicationNames.cs" />
<Compile Include="Updater\ApplicationType.cs" />
<Compile Include="VersionHelper.cs" />
<Compile Include="WindowType.cs" />
<Compile Include="GameSettings.cs" />
<Compile Include="ImageButton.cs">

View File

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

View File

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