From 3739ffad03a135a40fb8f7cc364f29fcc2095913 Mon Sep 17 00:00:00 2001 From: SpoinkyNL Date: Tue, 23 Aug 2016 21:40:09 +0200 Subject: [PATCH] Added changelog display Implemented audio visualization layer sensitivity and fade speed --- Artemis/Artemis/App.xaml.cs | 8 -- Artemis/Artemis/Artemis.csproj | 1 - Artemis/Artemis/ArtemisBootstrapper.cs | 10 +- .../Types/Audio/AudioPropertiesView.xaml | 22 ++-- .../Profiles/Layers/Types/Audio/AudioType.cs | 29 ++++- Artemis/Artemis/Properties/AssemblyInfo.cs | 5 +- Artemis/Artemis/Settings/GeneralSettings.cs | 21 ++-- Artemis/Artemis/Utilities/ShellLink.cs | 46 -------- Artemis/Artemis/Utilities/Updater.cs | 111 ++++++++++++++---- .../Artemis/ViewModels/SystemTrayViewModel.cs | 10 +- 10 files changed, 148 insertions(+), 115 deletions(-) delete mode 100644 Artemis/Artemis/Utilities/ShellLink.cs diff --git a/Artemis/Artemis/App.xaml.cs b/Artemis/Artemis/App.xaml.cs index 31558776a..f6b42a8e5 100644 --- a/Artemis/Artemis/App.xaml.cs +++ b/Artemis/Artemis/App.xaml.cs @@ -13,14 +13,6 @@ namespace Artemis { public App() { - //using (var mgr = UpdateManager.GitHubUpdateManager("https://github.com/SpoinkyNL/Artemis")) - //using (var mgr = new UpdateManager("C:\\Users\\Robert\\Desktop\\Artemis builds\\squirrel_test")) - //{ - // SquirrelAwareApp.HandleEvents( - // onInitialInstall: v => mgr.CreateShortcutForThisExe(), - // onAppUpdate: v => Updater.AppUpdate(mgr), - // onAppUninstall: v => Updater.AppUninstall(mgr)); - //} InitializeComponent(); } diff --git a/Artemis/Artemis/Artemis.csproj b/Artemis/Artemis/Artemis.csproj index 7294ccc2d..428dacda1 100644 --- a/Artemis/Artemis/Artemis.csproj +++ b/Artemis/Artemis/Artemis.csproj @@ -525,7 +525,6 @@ - diff --git a/Artemis/Artemis/ArtemisBootstrapper.cs b/Artemis/Artemis/ArtemisBootstrapper.cs index 26b781a71..07e5ad234 100644 --- a/Artemis/Artemis/ArtemisBootstrapper.cs +++ b/Artemis/Artemis/ArtemisBootstrapper.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Security.Principal; using System.Windows; using System.Windows.Controls; using System.Windows.Input; @@ -13,7 +12,6 @@ using Artemis.ViewModels; using Caliburn.Micro; using Newtonsoft.Json; using Ninject; -using LogManager = NLog.LogManager; namespace Artemis { @@ -39,14 +37,14 @@ namespace Artemis var e = ctx.EventArgs as MouseEventArgs; // If there is an image control, get the scaled position - if (img != null && e != null) + if ((img != null) && (e != null)) { var position = e.GetPosition(img); return (int) (img.Source.Width*(position.X/img.ActualWidth)); } // If there is another type of of IInputControl get the non-scaled position - or do some processing to get a scaled position, whatever needs to happen - if (e != null && input != null) + if ((e != null) && (input != null)) return e.GetPosition(input).X; // Return 0 if no processing could be done @@ -59,14 +57,14 @@ namespace Artemis var e = ctx.EventArgs as MouseEventArgs; // If there is an image control, get the scaled position - if (img != null && e != null) + if ((img != null) && (e != null)) { var position = e.GetPosition(img); return (int) (img.Source.Width*(position.Y/img.ActualWidth)); } // If there is another type of of IInputControl get the non-scaled position - or do some processing to get a scaled position, whatever needs to happen - if (e != null && input != null) + if ((e != null) && (input != null)) return e.GetPosition(input).Y; // Return 0 if no processing could be done diff --git a/Artemis/Artemis/Profiles/Layers/Types/Audio/AudioPropertiesView.xaml b/Artemis/Artemis/Profiles/Layers/Types/Audio/AudioPropertiesView.xaml index 4d6484b53..37d65e0fd 100644 --- a/Artemis/Artemis/Profiles/Layers/Types/Audio/AudioPropertiesView.xaml +++ b/Artemis/Artemis/Profiles/Layers/Types/Audio/AudioPropertiesView.xaml @@ -22,21 +22,21 @@ - - + + Value="{Binding Path=LayerModel.Properties.Sensitivity, Mode=TwoWay}" Margin="10,12,10,2" Height="24" + TickPlacement="BottomRight" TickFrequency="1" Minimum="1" Maximum="10" SmallChange="1" + IsSnapToTickEnabled="True" /> - - + + Value="{Binding Path=LayerModel.Properties.FadeSpeed, Mode=TwoWay}" Margin="10,12,10,2" + Height="24" TickPlacement="BottomRight" TickFrequency="1" Minimum="1" Maximum="3" SmallChange="1" + IsSnapToTickEnabled="True" /> @@ -50,7 +50,7 @@ - = audioLayer.Properties.Height) audioLayer.Properties.Height = newHeight; @@ -98,6 +120,9 @@ namespace Artemis.Profiles.Layers.Types.Audio if (audioLayer.Properties.Height < 0) audioLayer.Properties.Height = 0; + audioLayer.Properties.Brush = layerModel.Properties.Brush; + audioLayer.Properties.Contain = false; + audioLayer.Update(null, false, true); index++; } @@ -167,10 +192,8 @@ namespace Artemis.Profiles.Layers.Types.Audio if (b1 <= b0) b1 = b0 + 1; for (; b0 < b1; b0++) - { if (peak < e.Result[1 + b0].X) peak = e.Result[1 + b0].X; - } var y = (int) (Math.Sqrt(peak)*3*255 - 4); if (y > 255) y = 255; diff --git a/Artemis/Artemis/Properties/AssemblyInfo.cs b/Artemis/Artemis/Properties/AssemblyInfo.cs index 44852e01a..fa2275276 100644 --- a/Artemis/Artemis/Properties/AssemblyInfo.cs +++ b/Artemis/Artemis/Properties/AssemblyInfo.cs @@ -52,6 +52,5 @@ using System.Windows; // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.3.0.2")] -[assembly: AssemblyFileVersion("1.3.0.2")] -//[assembly: AssemblyMetadata("SquirrelAwareVersion", "1")] \ No newline at end of file +[assembly: AssemblyVersion("1.3.0.0")] +[assembly: AssemblyFileVersion("1.3.0.0")] \ No newline at end of file diff --git a/Artemis/Artemis/Settings/GeneralSettings.cs b/Artemis/Artemis/Settings/GeneralSettings.cs index 41a8738c3..91f212998 100644 --- a/Artemis/Artemis/Settings/GeneralSettings.cs +++ b/Artemis/Artemis/Settings/GeneralSettings.cs @@ -1,14 +1,12 @@ using System; using System.ComponentModel; -using System.IO; -using System.Reflection; -using System.Runtime.InteropServices.ComTypes; using System.Windows; using Artemis.DAL; using Artemis.Utilities; using Caliburn.Micro; using MahApps.Metro; using Newtonsoft.Json; +using Squirrel; namespace Artemis.Settings { @@ -17,6 +15,7 @@ namespace Artemis.Settings public GeneralSettings() { ThemeManager.AddAccent("CorsairYellow", new Uri("pack://application:,,,/Styles/Accents/CorsairYellow.xaml")); + ApplyAutorun(); } [DefaultValue("WindowsProfile")] @@ -59,6 +58,8 @@ namespace Artemis.Settings [JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)] public string LogLevel { get; set; } + public Version LastRanVersion { get; set; } + public void Save() { SettingsProvider.Save(this); @@ -86,17 +87,13 @@ namespace Artemis.Settings public void ApplyAutorun() { - var startupFolder = Environment.GetFolderPath(Environment.SpecialFolder.Startup); - if (Autorun) + using (var mgr = new UpdateManager("")) { - var link = (IShellLink) new ShellLink(); - link.SetPath(Assembly.GetExecutingAssembly().Location); - var file = (IPersistFile) link; - - file.Save(startupFolder + @"\Artemis.lnk", false); + if (Autorun) + mgr.CreateShortcutsForExecutable("Artemis.exe", ShortcutLocation.Startup, false); + else + mgr.RemoveShortcutsForExecutable("Artemis.exe", ShortcutLocation.Startup); } - else if (File.Exists(startupFolder + @"\Artemis.lnk")) - File.Delete(startupFolder + @"\Artemis.lnk"); } public void ApplyTheme() diff --git a/Artemis/Artemis/Utilities/ShellLink.cs b/Artemis/Artemis/Utilities/ShellLink.cs deleted file mode 100644 index fa0632d02..000000000 --- a/Artemis/Artemis/Utilities/ShellLink.cs +++ /dev/null @@ -1,46 +0,0 @@ -using System; -using System.Runtime.InteropServices; -using System.Text; - -namespace Artemis.Utilities -{ - /// - /// Creates a shortcut (.lnk) file. - /// Source: http://stackoverflow.com/a/14632782/5015269 - /// - [ComImport] - [Guid("00021401-0000-0000-C000-000000000046")] - internal class ShellLink - { - } - - [ComImport] - [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] - [Guid("000214F9-0000-0000-C000-000000000046")] - internal interface IShellLink - { - void GetPath([Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszFile, int cchMaxPath, out IntPtr pfd, - int fFlags); - - void GetIDList(out IntPtr ppidl); - void SetIDList(IntPtr pidl); - void GetDescription([Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszName, int cchMaxName); - void SetDescription([MarshalAs(UnmanagedType.LPWStr)] string pszName); - void GetWorkingDirectory([Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszDir, int cchMaxPath); - void SetWorkingDirectory([MarshalAs(UnmanagedType.LPWStr)] string pszDir); - void GetArguments([Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszArgs, int cchMaxPath); - void SetArguments([MarshalAs(UnmanagedType.LPWStr)] string pszArgs); - void GetHotkey(out short pwHotkey); - void SetHotkey(short wHotkey); - void GetShowCmd(out int piShowCmd); - void SetShowCmd(int iShowCmd); - - void GetIconLocation([Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszIconPath, int cchIconPath, - out int piIcon); - - void SetIconLocation([MarshalAs(UnmanagedType.LPWStr)] string pszIconPath, int iIcon); - void SetRelativePath([MarshalAs(UnmanagedType.LPWStr)] string pszPathRel, int dwReserved); - void Resolve(IntPtr hwnd, int fFlags); - void SetPath([MarshalAs(UnmanagedType.LPWStr)] string pszFile); - } -} \ No newline at end of file diff --git a/Artemis/Artemis/Utilities/Updater.cs b/Artemis/Artemis/Utilities/Updater.cs index 974560de5..01f63e870 100644 --- a/Artemis/Artemis/Utilities/Updater.cs +++ b/Artemis/Artemis/Utilities/Updater.cs @@ -2,10 +2,14 @@ using System.Collections.Generic; using System.Linq; using System.Net; +using System.Reflection; +using System.Threading.Tasks; using Artemis.DAL; +using Artemis.Services; using Artemis.Settings; using Artemis.Utilities.Memory; using Newtonsoft.Json; +using Newtonsoft.Json.Linq; using NLog; using Squirrel; @@ -13,45 +17,108 @@ namespace Artemis.Utilities { public static class Updater { - private static readonly Logger _logger = LogManager.GetCurrentClassLogger(); + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + /// + /// Uses Squirrel to update the application through GitHub + /// public static async void UpdateApp() { // Only update if the user allows it - if (!SettingsProvider.Load().AutoUpdate) + if (SettingsProvider.Load().AutoUpdate) return; - _logger.Info("Checking for updates..."); - // TODO: Remove prerelease before releasing - //using (var mgr = UpdateManager.GitHubUpdateManager("https://github.com/SpoinkyNL/Artemis", null, null, null, true)) - //{ - // await mgr.Result.UpdateApp(); - //} - - using (var mgr = new UpdateManager("C:\\Users\\Robert\\Desktop\\Artemis builds\\squirrel_test")) + Logger.Info("Checking for updates..."); + // Pre-release + using (var mgr = UpdateManager.GitHubUpdateManager("https://github.com/SpoinkyNL/Artemis", null, null, null, true)) + // Release + // using (var mgr = UpdateManager.GitHubUpdateManager("https://github.com/SpoinkyNL/Artemis")) { - await mgr.UpdateApp(); + try + { + await mgr.Result.UpdateApp(); + mgr.Result.Dispose(); + } + catch (Exception e) + { + Logger.Error(e, "Update check failed"); + } } } - public static void AppUpdate(IUpdateManager mgr) + /// + /// Checks to see if the program has updated and shows a dialog if so. + /// + /// The dialog service to use for progress and result dialogs + /// + public static async Task CheckChangelog(MetroDialogService dialogService) { - _logger.Info("Running AppUpdate"); - var settings = new GeneralSettings(); - settings.ApplyAutorun(); - mgr.CreateShortcutForThisExe(); + var settings = SettingsProvider.Load(); + 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(); } - public static void AppUninstall(IUpdateManager mgr) + /// + /// Fetches all releases from GitHub, looks up the current release and shows the changelog + /// + /// The dialog service to use for progress and result dialogs + /// The version to fetch the changelog for + /// + private static async Task ShowChanges(MetroDialogService dialogService, Version version) { - _logger.Info("Running AppUninstall"); - // Use GeneralSettings to get rid of the autorun shortcut - var fakeSettings = new GeneralSettings {Autorun = false}; - fakeSettings.ApplyAutorun(); + var progressDialog = await dialogService.ShowProgressDialog("Changelog", "Fetching release data from GitHub.."); + progressDialog.SetIndeterminate(); - mgr.RemoveShortcutForThisExe(); + 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;)"); + + // 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()); + + // Get a list of releases + var releases = JsonConvert.DeserializeObject(json); + var release = releases.FirstOrDefault(r => r["tag_name"].Value() == version.ToString()); + try + { + await progressDialog.CloseAsync(); + } + catch (InvalidOperationException) + { + // Occurs when main window is closed before finished + } + + if (release != null) + dialogService.ShowMessageBox(release["name"].Value(), release["body"].Value()); + else + 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"); } + /// + /// Queries GitHub for the latest pointers file + /// public static void GetPointers() { if (!SettingsProvider.Load().EnablePointersUpdate) diff --git a/Artemis/Artemis/ViewModels/SystemTrayViewModel.cs b/Artemis/Artemis/ViewModels/SystemTrayViewModel.cs index 4e1ac238c..368ccaf46 100644 --- a/Artemis/Artemis/ViewModels/SystemTrayViewModel.cs +++ b/Artemis/Artemis/ViewModels/SystemTrayViewModel.cs @@ -7,6 +7,7 @@ using Artemis.Events; using Artemis.Managers; using Artemis.Services; using Artemis.Settings; +using Artemis.Utilities; using Caliburn.Micro; namespace Artemis.ViewModels @@ -114,10 +115,13 @@ namespace Artemis.ViewModels NotifyOfPropertyChange(() => CanShowWindow); NotifyOfPropertyChange(() => CanHideWindow); - - ShowKeyboardDialog(); + SettingsProvider.Load().ApplyTheme(); + + // Show certain dialogs if needed + CheckKeyboardState(); CheckDuplicateInstances(); + Updater.CheckChangelog(DialogService); } private void CheckDuplicateInstances() @@ -137,7 +141,7 @@ namespace Artemis.ViewModels "If so, please make sure Artemis isn't already running"); } - private async void ShowKeyboardDialog() + private async void CheckKeyboardState() { while (!_shellViewModel.IsActive) await Task.Delay(200);