diff --git a/Giants.Launcher/Giants.Launcher.csproj b/Giants.Launcher/Giants.Launcher.csproj index 04fde0b..7eb73b7 100644 --- a/Giants.Launcher/Giants.Launcher.csproj +++ b/Giants.Launcher/Giants.Launcher.csproj @@ -78,6 +78,7 @@ + diff --git a/Giants.Launcher/LauncherForm.cs b/Giants.Launcher/LauncherForm.cs index 135b872..acf891a 100644 --- a/Giants.Launcher/LauncherForm.cs +++ b/Giants.Launcher/LauncherForm.cs @@ -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() { - 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 gameVersionInfo = this.GetVersionInfo(ApplicationNames.Giants); Task launcherVersionInfo = this.GetVersionInfo(ApplicationNames.GiantsLauncher); diff --git a/Giants.Launcher/Updater/Updater.cs b/Giants.Launcher/Updater/Updater.cs index aa548ad..1e9bc26 100644 --- a/Giants.Launcher/Updater/Updater.cs +++ b/Giants.Launcher/Updater/Updater.cs @@ -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 appVersions; private readonly AsyncCompletedEventHandler updateCompletedCallback; private readonly DownloadProgressChangedEventHandler updateProgressCallback; public Updater( - Version appVersion, + IDictionary 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); } diff --git a/Giants.Launcher/VersionHelper.cs b/Giants.Launcher/VersionHelper.cs new file mode 100644 index 0000000..5dd5654 --- /dev/null +++ b/Giants.Launcher/VersionHelper.cs @@ -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); + } + } +}