[WIP] Added initial Autoupdater.NET config

Have created the basic setup using the JSON
version of the Autoupdater.NET config shown
on the Autoupdater.NET website at:
https://github.com/ravibpatel/AutoUpdater.NET

JSON file to be stored on the update website:
{
   "version":"0.2.0.0",
   "url":"http://displaymagician.com/downloads/DisplayMagicianSetup.zip",
   "changelog":"https://github.com/terrymacdonald/DisplayMagician/releases",
   "mandatory":{
      "value":false,
      "minVersion": "0.1.0.0",
      "mode":1
   },
   "checksum":{
      "value":"E5F59E50FC91A9E52634FFCB11F32BD37FE0E2F1",
      "hashingAlgorithm":"SHA1"
   }
}
This commit is contained in:
Terry MacDonald 2020-12-12 22:35:13 +13:00
parent 05bb163312
commit c662681860
4 changed files with 102 additions and 3 deletions

View File

@ -214,6 +214,9 @@
<PackageReference Include="AudioSwitcher.AudioApi.CoreAudio"> <PackageReference Include="AudioSwitcher.AudioApi.CoreAudio">
<Version>4.0.0-alpha5</Version> <Version>4.0.0-alpha5</Version>
</PackageReference> </PackageReference>
<PackageReference Include="Autoupdater.NET.Official">
<Version>1.6.4</Version>
</PackageReference>
<PackageReference Include="CircularProgressBar"> <PackageReference Include="CircularProgressBar">
<Version>2.8.0.16</Version> <Version>2.8.0.16</Version>
</PackageReference> </PackageReference>

View File

@ -13,6 +13,9 @@ using System.Reflection;
using DisplayMagician.Shared; using DisplayMagician.Shared;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.IO; using System.IO;
using AutoUpdaterDotNET;
using Newtonsoft.Json;
using System.Net;
namespace DisplayMagician.UIForms namespace DisplayMagician.UIForms
{ {
@ -121,6 +124,9 @@ namespace DisplayMagician.UIForms
// Start loading the Steam Games just after the Main form opens // Start loading the Steam Games just after the Main form opens
//SteamGame.GetAllInstalledGames(); //SteamGame.GetAllInstalledGames();
EnableShortcutButtonIfProfiles(); EnableShortcutButtonIfProfiles();
AutoUpdater.CheckForUpdateEvent += AutoUpdaterOnCheckForUpdateEvent;
AutoUpdater.Start("http://rbsoft.org/updates/AutoUpdaterTest.json");
} }
private void EnableShortcutButtonIfProfiles() private void EnableShortcutButtonIfProfiles()
@ -277,7 +283,97 @@ namespace DisplayMagician.UIForms
private void MainForm_Activated(object sender, EventArgs e) 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);
}
}
} }
} }
} }

View File

@ -270,7 +270,7 @@
this.ShowIcon = false; this.ShowIcon = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "DisplayMagician - Setup Game Shortcuts"; 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.Load += new System.EventHandler(this.ShortcutLibraryForm_Load);
this.cms_shortcuts.ResumeLayout(false); this.cms_shortcuts.ResumeLayout(false);
this.ResumeLayout(false); this.ResumeLayout(false);

View File

@ -279,7 +279,7 @@ namespace DisplayMagician.UIForms
private void ShortcutLibraryForm_Activated(object sender, EventArgs e) private void ShortcutLibraryForm_Activated(object sender, EventArgs e)
{ {
//RemoveWarningIfShortcuts(); RemoveWarningIfShortcuts();
} }
private void tsmi_save_to_desktop_Click(object sender, EventArgs e) private void tsmi_save_to_desktop_Click(object sender, EventArgs e)