1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Added new auto-update (WIP)

Added dialog result to MetroDialog
This commit is contained in:
SpoinkyNL 2017-11-28 00:02:34 +01:00
parent e3b39a2649
commit b394c03dbb
12 changed files with 167 additions and 152 deletions

View File

@ -110,12 +110,6 @@
<Component Id="cmp43D899344ED173B0DAFCD84946D02788" Guid="*">
<File Id="fil7FCB3B29476FFB610381CD77013296AD" KeyPath="yes" Source="$(var.HarvestPath)\MahApps.Metro.xml" />
</Component>
<Component Id="cmp43984E66F2A9DD89F93CF7035D8989A0" Guid="*">
<File Id="filD88CABA6D1DF77999CB7D426C4B617A4" KeyPath="yes" Source="$(var.HarvestPath)\Microsoft.Win32.TaskScheduler.dll" />
</Component>
<Component Id="cmp08AF6F09151836641FA7AB5776CEF105" Guid="*">
<File Id="fil95DD99F610362C6190FF14BB3C403053" KeyPath="yes" Source="$(var.HarvestPath)\Microsoft.Win32.TaskScheduler.xml" />
</Component>
<Component Id="cmp2FCEBC7A99564B55654E85ED28E48600" Guid="*">
<File Id="fil4EAD90E131DF96A66C4D6F6426CE480B" KeyPath="yes" Source="$(var.HarvestPath)\MoonSharp.Interpreter.dll" />
</Component>
@ -230,26 +224,6 @@
<Component Id="cmp8E352492AA4EFD741D361DB10D9CDE54" Guid="*">
<File Id="fil4A56C6D02CE99309F98F2DC52BD44FB0" KeyPath="yes" Source="$(var.HarvestPath)\VioletTape.WpfExceptionViewer.dll" />
</Component>
<Directory Id="dir242DC17B8DFC53C13CAF172FC08B730A" Name="de">
<Component Id="cmp899508076A55BF753F74CB0DFA5743E3" Guid="*">
<File Id="filD54B0D32E6618AD0E9082F3C7288DF3B" KeyPath="yes" Source="$(var.HarvestPath)\de\Microsoft.Win32.TaskScheduler.resources.dll" />
</Component>
</Directory>
<Directory Id="dir9AE38F4F5CB5E565E774521E138F44FD" Name="es">
<Component Id="cmp5A7026E0896D194B82895F7742EE8E12" Guid="*">
<File Id="filD9A4BF39D17EB61C5211DDC46DB00008" KeyPath="yes" Source="$(var.HarvestPath)\es\Microsoft.Win32.TaskScheduler.resources.dll" />
</Component>
</Directory>
<Directory Id="dirB55DFDA91FEE7CCCBC65CA7493B75748" Name="fr">
<Component Id="cmpB448414C7B3963A581067103B898A290" Guid="*">
<File Id="filA5C066B28245C75C64533E4E70637BFD" KeyPath="yes" Source="$(var.HarvestPath)\fr\Microsoft.Win32.TaskScheduler.resources.dll" />
</Component>
</Directory>
<Directory Id="dir45DE18DD71F3E8DD6BE4A0E2B48778C8" Name="it">
<Component Id="cmpA2349B128022FD9468B4B0472DF8814A" Guid="*">
<File Id="filA9D742E425F8D28208EA368E72789A62" KeyPath="yes" Source="$(var.HarvestPath)\it\Microsoft.Win32.TaskScheduler.resources.dll" />
</Component>
</Directory>
<Directory Id="dir6D8C24E0E6B175D1F4DFF0EAC196DDF2" Name="lib">
<Component Id="cmp97A41A22042DE905D0A5799554A3C4DB" Guid="*">
<File Id="fil3BC1E3A3EF0D5982FD254F6A5A9D4549" KeyPath="yes" Source="$(var.HarvestPath)\lib\SDKDLL.dll" />
@ -265,11 +239,6 @@
<File Id="fil51DCB5DC79C1956F92047AD679E8AB55" KeyPath="yes" Source="$(var.HarvestPath)\x86\CUESDK_2015.dll" />
</Component>
</Directory>
<Directory Id="dir8C5E37FA87D1897FFB78337F53EB198C" Name="zh-CN">
<Component Id="cmpFA6D9FD1AAA2046A7577475784CE8BCC" Guid="*">
<File Id="fil9AE873A7FEB47AAC64F449F1E25BB97F" KeyPath="yes" Source="$(var.HarvestPath)\zh-CN\Microsoft.Win32.TaskScheduler.resources.dll" />
</Component>
</Directory>
</DirectoryRef>
</Fragment>
<Fragment>
@ -310,8 +279,6 @@
<ComponentRef Id="cmp223D4754378C01052DA8253A843FD297" />
<ComponentRef Id="cmp31541C871E68AFBC70137561BF857C7B" />
<ComponentRef Id="cmp43D899344ED173B0DAFCD84946D02788" />
<ComponentRef Id="cmp43984E66F2A9DD89F93CF7035D8989A0" />
<ComponentRef Id="cmp08AF6F09151836641FA7AB5776CEF105" />
<ComponentRef Id="cmp2FCEBC7A99564B55654E85ED28E48600" />
<ComponentRef Id="cmp10359C02FE64062C8403FF433E774083" />
<ComponentRef Id="cmpF3259CFFC7B5247438581E9B04AB35D8" />
@ -350,14 +317,9 @@
<ComponentRef Id="cmp4C89FD380B87BABF2C2EC0B905FC716A" />
<ComponentRef Id="cmp017BFB3832A5B110A2B3A350E13F2A5C" />
<ComponentRef Id="cmp8E352492AA4EFD741D361DB10D9CDE54" />
<ComponentRef Id="cmp899508076A55BF753F74CB0DFA5743E3" />
<ComponentRef Id="cmp5A7026E0896D194B82895F7742EE8E12" />
<ComponentRef Id="cmpB448414C7B3963A581067103B898A290" />
<ComponentRef Id="cmpA2349B128022FD9468B4B0472DF8814A" />
<ComponentRef Id="cmp97A41A22042DE905D0A5799554A3C4DB" />
<ComponentRef Id="cmpECD409B8EBFA879EA008219F73249A40" />
<ComponentRef Id="cmp0A1EF8C9603FD314A6357DDC62FAABEC" />
<ComponentRef Id="cmpFA6D9FD1AAA2046A7577475784CE8BCC" />
</ComponentGroup>
</Fragment>
</Wix>

View File

@ -1,9 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">
<Product Id="*" Name="Artemis" Language="1033" Version="1.12.0.0"
Manufacturer="SpoinkyNL" UpgradeCode="ebc7bc50-0473-4729-8de8-32ddb99bb986">
<Product Id="*" Name="Artemis" Language="1033" Version="1.12.0.0" Manufacturer="SpoinkyNL" UpgradeCode="ebc7bc50-0473-4729-8de8-32ddb99bb986">
<Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />
<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
<MediaTemplate EmbedCab="yes" />
@ -27,10 +26,7 @@
<Property Id="WIXUI_EXITDIALOGOPTIONALCHECKBOXTEXT" Value="Launch Artemis" />
<UIRef Id="WixUI_InstallDir" />
<Publish Dialog="ExitDialog"
Control="Finish"
Event="DoAction"
Value="LaunchApplication">
<Publish Dialog="ExitDialog" Control="Finish" Event="DoAction" Value="LaunchApplication">
WIXUI_EXITDIALOGOPTIONALCHECKBOX = 1 and NOT Installed
</Publish>
@ -41,9 +37,8 @@
</Product>
<Fragment>
<CustomAction Id="TaskDelete" Return="ignore" Execute="deferred" Directory="TARGETDIR" Impersonate="no"
ExeCommand="SCHTASKS.EXE /DELETE /TN &quot;Artemis autorun&quot; /F" />
<CustomAction Id="CloseApp" Return="ignore" Execute="deferred" Directory="TARGETDIR" Impersonate="no" ExeCommand="TASKKILL.EXE /F /IM Artemis.exe" />
<CustomAction Id="TaskDelete" Return="ignore" Execute="deferred" Directory="TARGETDIR" Impersonate="no" ExeCommand="SCHTASKS.EXE /DELETE /TN Artemis /F" />
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFiles64Folder">
<Directory Id="INSTALLFOLDER" Name="Artemis" />
@ -51,10 +46,8 @@
<Directory Id="ProgramMenuFolder">
<Directory Id="ProgramMenuSubfolder" Name="Artemis">
<Component Id="ApplicationShortcuts" Guid="b7465bd9-c8d7-4999-9695-8bbfd9306986">
<Shortcut Id="ApplicationShortcut1" Name="Artemis" Description="Artemis"
Target="[INSTALLFOLDER]Artemis.exe" WorkingDirectory="INSTALLFOLDER" />
<RegistryValue Root="HKCU" Key="Software\SpoinkyNL\Artemis" Name="installed" Type="integer" Value="1"
KeyPath="yes" />
<Shortcut Id="ApplicationShortcut1" Name="Artemis" Description="Artemis" Target="[INSTALLFOLDER]Artemis.exe" WorkingDirectory="INSTALLFOLDER" />
<RegistryValue Root="HKCU" Key="Software\SpoinkyNL\Artemis" Name="installed" Type="integer" Value="1" KeyPath="yes" />
<RemoveFolder Id="ProgramMenuSubfolder" On="uninstall" />
</Component>
</Directory>
@ -66,6 +59,8 @@
<CustomAction Id="LaunchApplication" BinaryKey="WixCA" DllEntry="WixShellExec" Impersonate="yes" />
<InstallExecuteSequence>
<!-- Always close any running instances of Artemis -->
<Custom Action="CloseApp" After="InstallInitialize" />
<!--Remove task on Uninstall or Upgrade-->
<Custom Action='TaskDelete' Before="InstallFinalize">REMOVE="ALL"</Custom>
</InstallExecuteSequence>

View File

@ -762,6 +762,7 @@
<Compile Include="Properties\AssemblyInfo.cs">
<SubType>Code</SubType>
</Compile>
<Resource Include="Resources\Keyboards\masterkeys-pro-m.png" />
<None Include="Modules\Games\WoW\Resources\Addon source\Artemis.toc" />
<None Include="Modules\Games\WoW\Resources\Addon source\Core.lua" />
<None Include="Modules\Games\WoW\Resources\Addon source\Libs\AceAddon-3.0\AceAddon-3.0.lua" />

View File

@ -43,11 +43,15 @@
HorizontalAlignment="Right"
Orientation="Horizontal">
<Button x:Name="PART_AffirmativeButton"
Height="35"
MinWidth="80"
Margin="0 0 5 0"
Content="Alrighty, let's go!"
Style="{DynamicResource AccentedDialogSquareButton}" Click="PART_AffirmativeButton_Click" />
Height="35"
MinWidth="80"
Margin="0 0 5 0"
Content="{Binding AffirmativeButtonText, RelativeSource={RelativeSource AncestorType=dialogs1:MarkdownDialog, Mode=FindAncestor}, UpdateSourceTrigger=PropertyChanged}" />
<Button x:Name="PART_NegativeButton"
Height="35"
MinWidth="80"
Margin="5 0 5 0"
Content="{Binding NegativeButtonText, RelativeSource={RelativeSource AncestorType=dialogs1:MarkdownDialog, Mode=FindAncestor}, UpdateSourceTrigger=PropertyChanged}" />
</StackPanel>
</Grid>
</dialogs:CustomDialog>

View File

@ -11,33 +11,44 @@ namespace Artemis.Dialogs
/// </summary>
public partial class MarkdownDialog : CustomDialog
{
public MetroWindow ParentWindow { get; set; }
public static readonly DependencyProperty MarkdownProperty = DependencyProperty.Register("Markdown", typeof(string), typeof(MarkdownDialog), new PropertyMetadata(default(string)));
public static readonly DependencyProperty AffirmativeButtonTextProperty = DependencyProperty.Register("AffirmativeButtonText", typeof(string), typeof(MarkdownDialog), new PropertyMetadata("OK"));
public static readonly DependencyProperty NegativeButtonTextProperty = DependencyProperty.Register("NegativeButtonText", typeof(string), typeof(MarkdownDialog), new PropertyMetadata("Cancel"));
public static readonly DependencyProperty MarkdownProperty = DependencyProperty.Register("Markdown",
typeof(string), typeof(MarkdownDialog), new PropertyMetadata(default(string)));
public MarkdownDialog(MetroWindow parentWindow)
public MarkdownDialog(MetroWindow parentWindow, MetroDialogSettings settings = null) : base(parentWindow, settings)
{
ParentWindow = parentWindow;
InitializeComponent();
Tcs = new TaskCompletionSource<MessageDialogResult>();
CommandBindings.Add(new CommandBinding(NavigationCommands.GoToPage, (sender, e) => System.Diagnostics.Process.Start((string) e.Parameter)));
PART_AffirmativeButton.Click += (sender, args) => ParentWindow.HideMetroDialogAsync(this);
PART_NegativeButton.Click += (sender, args) => ParentWindow.HideMetroDialogAsync(this);
CommandBindings.Add(new CommandBinding(NavigationCommands.GoToPage,
(sender, e) => System.Diagnostics.Process.Start((string) e.Parameter)));
if (settings == null)
return;
AffirmativeButtonText = settings.AffirmativeButtonText;
NegativeButtonText = settings.NegativeButtonText;
}
public TaskCompletionSource<MessageDialogResult> Tcs { get; set; }
public MetroWindow ParentWindow { get; set; }
public string Markdown
{
get { return (string) GetValue(MarkdownProperty); }
set { SetValue(MarkdownProperty, value); }
get => (string) GetValue(MarkdownProperty);
set => SetValue(MarkdownProperty, value);
}
private void PART_AffirmativeButton_Click(object sender, RoutedEventArgs e)
public string AffirmativeButtonText
{
ParentWindow.HideMetroDialogAsync(this);
get => (string) GetValue(AffirmativeButtonTextProperty);
set => SetValue(AffirmativeButtonTextProperty, value);
}
public string NegativeButtonText
{
get => (string) GetValue(NegativeButtonTextProperty);
set => SetValue(NegativeButtonTextProperty, value);
}
}
}
}

View File

@ -53,6 +53,6 @@ using System.Windows;
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.11.0.0")]
[assembly: AssemblyFileVersion("1.11.0.0")]
[assembly: AssemblyVersion("1.12.0.0")]
[assembly: AssemblyFileVersion("1.12.0.0")]
[assembly: InternalsVisibleTo("Artemis.Explorables")]

View File

@ -75,17 +75,17 @@ namespace Artemis.Properties {
///&lt;Task version=&quot;1.4&quot; xmlns=&quot;http://schemas.microsoft.com/windows/2004/02/mit/task&quot;&gt;
/// &lt;RegistrationInfo&gt;
/// &lt;Date&gt;2017-11-12T17:45:45.4993602&lt;/Date&gt;
/// &lt;Author&gt;SpoinkyNL&lt;/Author&gt;
/// &lt;Author&gt;{{author}}&lt;/Author&gt;
/// &lt;Description&gt;Task to run Artemis on PC startup without showing a UAC dialog&lt;/Description&gt;
/// &lt;URI&gt;\Artemis autorun&lt;/URI&gt;
/// &lt;URI&gt;\Artemis&lt;/URI&gt;
/// &lt;/RegistrationInfo&gt;
/// &lt;Triggers&gt;
/// &lt;LogonTrigger&gt;
/// &lt;Enabled&gt;true&lt;/Enabled&gt;
/// &lt;Delay&gt;PT30S&lt;/Delay&gt;
/// &lt;/LogonTrigger&gt;
/// &lt;/Triggers&gt;
/// &lt;Set [rest of string was truncated]&quot;;.
/// &lt;/Triggers&gt;
/// &lt;Principals&gt; [rest of string was truncated]&quot;;.
/// </summary>
internal static string Artemis_autorun {
get {
@ -372,6 +372,26 @@ namespace Artemis.Properties {
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap masterkeys_pro_m {
get {
object obj = ResourceManager.GetObject("masterkeys_pro_m", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap masterkeys_pro_m1 {
get {
object obj = ResourceManager.GetObject("masterkeys_pro_m1", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>

View File

@ -232,4 +232,7 @@
<data name="Artemis_autorun" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Artemis autorun.xml;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-16</value>
</data>
<data name="masterkeys_pro_m1" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Keyboards\masterkeys-pro-m.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>

View File

@ -36,12 +36,7 @@ namespace Artemis.Services
public MetroWindow GetActiveWindow()
{
MetroWindow window = null;
Execute.OnUIThread(() =>
{
window = Application.Current.Windows.OfType<MetroWindow>()
.FirstOrDefault(w => w.IsActive && w.IsVisible);
});
Execute.OnUIThread(() => window = Application.Current.Windows.OfType<MetroWindow>().FirstOrDefault(w => w.IsActive && w.IsVisible));
return window;
}
@ -54,21 +49,24 @@ namespace Artemis.Services
Execute.OnUIThread(() => GetActiveWindow().ShowMessageAsync(title, message));
}
public void ShowMarkdownDialog(string title, string markdown)
public async Task<bool?> ShowMarkdownDialog(string title, string markdown, MetroDialogSettings settings = null)
{
var result = false;
var window = GetActiveWindow();
if (window == null)
return;
return null;
window.Dispatcher.Invoke(() =>
var dialog = new MarkdownDialog(window, settings)
{
var dialog = new MarkdownDialog(window)
{
Markdown = markdown,
Title = title
};
return window.ShowMetroDialogAsync(dialog);
});
Markdown = markdown,
Title = title
};
dialog.PART_AffirmativeButton.Click += (sender, args) => result = true;
await Execute.OnUIThreadAsync(() => GetActiveWindow().ShowMetroDialogAsync(dialog));
await dialog.WaitUntilUnloadedAsync();
return result;
}
public override async Task<bool?> ShowQuestionMessageBox(string title, string message)
@ -79,8 +77,7 @@ namespace Artemis.Services
var metroDialogSettings = new MetroDialogSettings {AffirmativeButtonText = "Yes", NegativeButtonText = "No"};
var result = await window.Dispatcher.Invoke(() =>
window.ShowMessageAsync(title, message, MessageDialogStyle.AffirmativeAndNegative,
metroDialogSettings));
window.ShowMessageAsync(title, message, MessageDialogStyle.AffirmativeAndNegative, metroDialogSettings));
switch (result)
{
@ -136,11 +133,10 @@ namespace Artemis.Services
return res != null && res.Value;
}
public Task<ProgressDialogController> ShowProgressDialog(string title, string message, bool isCancelable = false,
MetroDialogSettings settings = null)
public Task<ProgressDialogController> ShowProgressDialog(string title, string message, bool isCancelable = false, MetroDialogSettings settings = null)
{
var window = GetActiveWindow();
return window?.Dispatcher.Invoke(() => window.ShowProgressAsync(title, message, isCancelable, settings));
}
}
}
}

View File

@ -76,8 +76,6 @@ namespace Artemis.Settings
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)]
public ActiveWindowDetectionType ActiveWindowDetection { get; set; }
public Version LastRanVersion { get; set; }
public void Save()
{
SettingsProvider.Save(this);

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Reflection;
@ -8,6 +9,7 @@ using Artemis.DAL;
using Artemis.Services;
using Artemis.Settings;
using Artemis.Utilities.Memory;
using MahApps.Metro.Controls.Dialogs;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using NLog;
@ -17,76 +19,99 @@ namespace Artemis.Utilities
public static class Updater
{
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
/// <summary>
/// Checks to see if the program has updated and shows a dialog if so.
/// Checks to see if a new version is available on GitHub asks the user to see changes and download
/// </summary>
/// <param name="dialogService">The dialog service to use for progress and result dialogs</param>
/// <returns></returns>
public static async void CheckChangelog(MetroDialogService dialogService)
public static async void CheckForUpdate(MetroDialogService dialogService)
{
var settings = SettingsProvider.Load<GeneralSettings>();
var currentVersion = Assembly.GetExecutingAssembly().GetName().Version;
if (settings.LastRanVersion != null && currentVersion > settings.LastRanVersion)
{
Logger.Info("Updated from {0} to {1}, showing changelog.", settings.LastRanVersion, currentVersion);
// Ask the user whether he/she wants to see what's new
var showChanges = await dialogService.ShowQuestionMessageBox("New version installed",
$"Artemis has recently updated from version {settings.LastRanVersion} to {currentVersion}. \n" +
"Would you like to see what's new?");
// If user wants to see changelog, show it to them
if (showChanges != null && showChanges.Value)
await ShowChanges(dialogService, currentVersion);
}
settings.LastRanVersion = currentVersion;
settings.Save();
}
/// <summary>
/// Fetches all releases from GitHub, looks up the current release and shows the changelog
/// </summary>
/// <param name="dialogService">The dialog service to use for progress and result dialogs</param>
/// <param name="version">The version to fetch the changelog for</param>
/// <returns></returns>
private static async Task ShowChanges(MetroDialogService dialogService, Version version)
{
var progressDialog = await dialogService.ShowProgressDialog("Changelog", "Fetching release data from GitHub..");
progressDialog.SetIndeterminate();
if (!settings.AutoUpdate)
return;
// Check GitHub for a new version
var jsonClient = new WebClient();
// GitHub trips if we don't add a user agent
jsonClient.Headers.Add("user-agent",
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
jsonClient.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
// Random number to get around cache issues
var rand = new Random(DateTime.Now.Millisecond);
var json = await jsonClient.DownloadStringTaskAsync(
"https://api.github.com/repos/SpoinkyNL/Artemis/releases?random=" + rand.Next());
var json = await jsonClient.DownloadStringTaskAsync("https://api.github.com/repos/SpoinkyNL/Artemis/releases/latest?random=" + rand.Next());
// Get a list of releases
var releases = JsonConvert.DeserializeObject<JArray>(json);
var release = releases.FirstOrDefault(r => r["tag_name"].Value<string>() == version.ToString());
try
var release = JObject.Parse(json);
var releaseVersion = Version.Parse(release["tag_name"].Value<string>());
var currentVersion = Assembly.GetExecutingAssembly().GetName().Version;
// if (releaseVersion > currentVersion)
await ShowChanges(dialogService, release);
}
/// <summary>
/// Shows the changes for the given release and offers to download it
/// </summary>
/// <param name="dialogService">The dialog service to use for progress and result dialogs</param>
/// <param name="release">The release to show and offer the download for</param>
/// <returns></returns>
private static async Task ShowChanges(MetroDialogService dialogService, JObject release)
{
var settings = new MetroDialogSettings
{
await progressDialog.CloseAsync();
}
catch (InvalidOperationException)
AffirmativeButtonText = "Download & install",
NegativeButtonText = "Ask again later"
};
var update = await dialogService.ShowMarkdownDialog(release["name"].Value<string>(), release["body"].Value<string>(), settings);
if (update == null || (bool) !update)
return;
// Show a process dialog
var dialog = await dialogService.ShowProgressDialog("Applying update", "The new update is being downloaded right now...");
// Download the release file, it's the one starting with "artemis-setup"
// var releaseFile = release["assets"].Children().FirstOrDefault(c => c["name"].Value<string>().StartsWith("artemis-setup"));
var releaseFile = release["assets"].Children().FirstOrDefault(c => c["name"].Value<string>().StartsWith("Artemis-1.9.0.1-delta"));
// If there's no matching release it means whoever published the new version fucked up, can't do much about that
if (releaseFile == null)
{
// Occurs when main window is closed before finished
dialogService.ShowMessageBox("Applying update failed", "Couldn't find the update file. Please install the latest version manually, sorry!");
return;
}
if (release != null)
dialogService.ShowMarkdownDialog(release["name"].Value<string>(), release["body"].Value<string>());
else
var downloadClient = new WebClient();
downloadClient.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
var download = downloadClient.DownloadDataTaskAsync(releaseFile["browser_download_url"].Value<string>());
downloadClient.DownloadProgressChanged += (sender, args) =>
{
dialogService.ShowMessageBox("Couldn't fetch release",
"Sorry, Artemis was unable to fetch the release data off of GitHub.\n" +
"If you'd like, you can always find out the latest changes on the GitHub page accessible from the options menu");
}
dialog.SetMessage("The new update is being downloaded right now...\n\n" +
$"Progress: {ConvertBytesToMegabytes(args.BytesReceived)} MB/{ConvertBytesToMegabytes(args.TotalBytesToReceive)} MB");
dialog.SetProgress(args.ProgressPercentage / 100.0);
};
var setupBytes = await download;
dialog.SetMessage("Installing the new update...");
dialog.SetIndeterminate();
// Ensure the update folder exists
var updateFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\Artemis\\updates";
if (!Directory.Exists(updateFolder))
Directory.CreateDirectory(updateFolder);
// Store the bytes
File.WriteAllBytes(updateFolder + "\\" + releaseFile["name"].Value<string>(), setupBytes);
// Create a bat file that'll take care of the installation (Artemis gets shut down during install) the bat file will
// carry forth our legacy (read that in an heroic tone)
//ECHO OFF
//CLS
//"C:\Repos\Artemis\Artemis\Artemis.Installer\bin\Release\Artemis.msi" / passive
//cd "C:\Program Files\Artemis"
//start Artemis.exe
}
private static object ConvertBytesToMegabytes(long bytes)
{
return Math.Round((bytes / 1024f) / 1024f, 2);
}
/// <summary>

View File

@ -142,7 +142,7 @@ namespace Artemis.ViewModels
// Show certain dialogs if needed
CheckKeyboardState();
CheckDuplicateInstances();
Updater.CheckChangelog(MetroDialogService);
Updater.CheckForUpdate(MetroDialogService);
// Run this on the UI thread to avoid having to use dispatchers in VMs
Execute.OnUIThread(ActivateViews);