diff --git a/DisplayMagician/DisplayMagician.csproj b/DisplayMagician/DisplayMagician.csproj index 87166b5..52bdbb9 100644 --- a/DisplayMagician/DisplayMagician.csproj +++ b/DisplayMagician/DisplayMagician.csproj @@ -214,6 +214,9 @@ 4.0.0-alpha5 + + 1.6.4 + 2.8.0.16 diff --git a/DisplayMagician/UIForms/MainForm.cs b/DisplayMagician/UIForms/MainForm.cs index c8aaa74..b2b1ba1 100644 --- a/DisplayMagician/UIForms/MainForm.cs +++ b/DisplayMagician/UIForms/MainForm.cs @@ -13,6 +13,9 @@ using System.Reflection; using DisplayMagician.Shared; using System.Runtime.InteropServices; using System.IO; +using AutoUpdaterDotNET; +using Newtonsoft.Json; +using System.Net; namespace DisplayMagician.UIForms { @@ -121,6 +124,9 @@ namespace DisplayMagician.UIForms // Start loading the Steam Games just after the Main form opens //SteamGame.GetAllInstalledGames(); EnableShortcutButtonIfProfiles(); + + AutoUpdater.CheckForUpdateEvent += AutoUpdaterOnCheckForUpdateEvent; + AutoUpdater.Start("http://rbsoft.org/updates/AutoUpdaterTest.json"); } private void EnableShortcutButtonIfProfiles() @@ -277,7 +283,97 @@ namespace DisplayMagician.UIForms private void MainForm_Activated(object sender, EventArgs e) { - //EnableShortcutButtonIfProfiles(); + EnableShortcutButtonIfProfiles(); + } + + private void AutoUpdaterOnParseUpdateInfoEvent(ParseUpdateInfoEventArgs args) + { + dynamic json = JsonConvert.DeserializeObject(args.RemoteData); + args.UpdateInfo = new UpdateInfoEventArgs + { + CurrentVersion = json.version, + ChangelogURL = json.changelog, + DownloadURL = json.url, + Mandatory = new Mandatory + { + Value = json.mandatory.value, + UpdateMode = json.mandatory.mode, + MinimumVersion = json.mandatory.minVersion + }, + CheckSum = new CheckSum + { + Value = json.checksum.value, + HashingAlgorithm = json.checksum.hashingAlgorithm + } + }; + } + + private void AutoUpdaterOnCheckForUpdateEvent(UpdateInfoEventArgs args) + { + if (args.Error == null) + { + if (args.IsUpdateAvailable) + { + DialogResult dialogResult; + if (args.Mandatory.Value) + { + dialogResult = + MessageBox.Show( + $@"There is new version {args.CurrentVersion} available. You are using version {args.InstalledVersion}. This is required update. Press Ok to begin updating the application.", @"Update Available", + MessageBoxButtons.OK, + MessageBoxIcon.Information); + } + else + { + dialogResult = + MessageBox.Show( + $@"There is new version {args.CurrentVersion} available. You are using version { + args.InstalledVersion + }. Do you want to update the application now?", @"Update Available", + MessageBoxButtons.YesNo, + MessageBoxIcon.Information); + } + + // Uncomment the following line if you want to show standard update dialog instead. + // AutoUpdater.ShowUpdateForm(args); + + if (dialogResult.Equals(DialogResult.Yes) || dialogResult.Equals(DialogResult.OK)) + { + try + { + if (AutoUpdater.DownloadUpdate(args)) + { + Application.Exit(); + } + } + catch (Exception exception) + { + MessageBox.Show(exception.Message, exception.GetType().ToString(), MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + else + { + MessageBox.Show(@"There is no update available please try again later.", @"No update available", + MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + else + { + if (args.Error is WebException) + { + MessageBox.Show( + @"There is a problem reaching update server. Please check your internet connection and try again later.", + @"Update Check Failed", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + else + { + MessageBox.Show(args.Error.Message, + args.Error.GetType().ToString(), MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } } } } diff --git a/DisplayMagician/UIForms/ShortcutLibraryForm.Designer.cs b/DisplayMagician/UIForms/ShortcutLibraryForm.Designer.cs index 5d2dbde..0c12e20 100644 --- a/DisplayMagician/UIForms/ShortcutLibraryForm.Designer.cs +++ b/DisplayMagician/UIForms/ShortcutLibraryForm.Designer.cs @@ -270,7 +270,7 @@ this.ShowIcon = false; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.Text = "DisplayMagician - Setup Game Shortcuts"; - //this.Activated += new System.EventHandler(this.ShortcutLibraryForm_Activated); + this.Activated += new System.EventHandler(this.ShortcutLibraryForm_Activated); this.Load += new System.EventHandler(this.ShortcutLibraryForm_Load); this.cms_shortcuts.ResumeLayout(false); this.ResumeLayout(false); diff --git a/DisplayMagician/UIForms/ShortcutLibraryForm.cs b/DisplayMagician/UIForms/ShortcutLibraryForm.cs index fe8f900..bdafa9b 100644 --- a/DisplayMagician/UIForms/ShortcutLibraryForm.cs +++ b/DisplayMagician/UIForms/ShortcutLibraryForm.cs @@ -279,7 +279,7 @@ namespace DisplayMagician.UIForms private void ShortcutLibraryForm_Activated(object sender, EventArgs e) { - //RemoveWarningIfShortcuts(); + RemoveWarningIfShortcuts(); } private void tsmi_save_to_desktop_Click(object sender, EventArgs e)