From b0d33b29f294894224b3a47982ce86d602bf4dff Mon Sep 17 00:00:00 2001 From: SpoinkyNL Date: Thu, 18 Aug 2016 10:52:58 +0200 Subject: [PATCH] Implemented Squirrel installer Cleaned up old project files --- Artemis/Artemis/App.config | 2 +- Artemis/Artemis/Artemis.csproj | 50 +++++- Artemis/Artemis/ArtemisBootstrapper.cs | 24 +-- .../Corsair/CorsairKeyboards.cs | 5 - Artemis/Artemis/Managers/MainManager.cs | 13 +- Artemis/Artemis/Properties/AssemblyInfo.cs | 5 +- Artemis/Artemis/Settings/General.Designer.cs | 6 +- Artemis/Artemis/Settings/General.settings | 6 +- Artemis/Artemis/Settings/GeneralSettings.cs | 12 +- .../Artemis/Utilities/Memory/MemoryHelpers.cs | 19 ++- Artemis/Artemis/Utilities/Updater.cs | 80 +++------ .../Flyouts/FlyoutSettingsViewModel.cs | 3 + .../Artemis/ViewModels/SystemTrayViewModel.cs | 28 +++- .../Views/Flyouts/FlyoutSettingsView.xaml | 6 +- Artemis/Artemis/packages.config | 4 + Artemis/ArtemisTests/ArtemisTests.csproj | 89 ---------- .../ArtemisTests/Properties/AssemblyInfo.cs | 36 ----- Artemis/UT2Artemis/UT2Artemis.vcxproj | 153 ------------------ Artemis/UT2Artemis/UT2Artemis.vcxproj.filters | 17 -- 19 files changed, 136 insertions(+), 422 deletions(-) delete mode 100644 Artemis/ArtemisTests/ArtemisTests.csproj delete mode 100644 Artemis/ArtemisTests/Properties/AssemblyInfo.cs delete mode 100644 Artemis/UT2Artemis/UT2Artemis.vcxproj delete mode 100644 Artemis/UT2Artemis/UT2Artemis.vcxproj.filters diff --git a/Artemis/Artemis/App.config b/Artemis/Artemis/App.config index af9997c3f..32bf9909e 100644 --- a/Artemis/Artemis/App.config +++ b/Artemis/Artemis/App.config @@ -276,7 +276,7 @@ True - + True diff --git a/Artemis/Artemis/Artemis.csproj b/Artemis/Artemis/Artemis.csproj index 707d8f05a..322673b1b 100644 --- a/Artemis/Artemis/Artemis.csproj +++ b/Artemis/Artemis/Artemis.csproj @@ -39,8 +39,8 @@ https://github.com/SpoinkyNL/Artemis/wiki/Frequently-Asked-Questions-%28FAQ%29 Artemis Artemis - 0 - 1.2.3.0 + 1 + 1.2.3.1 false true true @@ -149,6 +149,18 @@ ..\packages\CUE.NET.1.0.3\lib\net45\CUE.NET.dll True + + ..\packages\DeltaCompressionDotNet.1.0.0\lib\net45\DeltaCompressionDotNet.dll + True + + + ..\packages\DeltaCompressionDotNet.1.0.0\lib\net45\DeltaCompressionDotNet.MsDelta.dll + True + + + ..\packages\DeltaCompressionDotNet.1.0.0\lib\net45\DeltaCompressionDotNet.PatchApi.dll + True + ..\packages\DynamicExpresso.Core.1.3.1.0\lib\net40\DynamicExpresso.Core.dll True @@ -161,6 +173,10 @@ ..\packages\Hardcodet.NotifyIcon.Wpf.1.0.8\lib\net451\Hardcodet.Wpf.TaskbarNotification.dll True + + ..\packages\squirrel.windows.1.4.4\lib\Net45\ICSharpCode.SharpZipLib.dll + True + ..\packages\log4net.2.0.5\lib\net45-full\log4net.dll True @@ -172,6 +188,22 @@ False + + ..\packages\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.dll + True + + + ..\packages\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.Mdb.dll + True + + + ..\packages\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.Pdb.dll + True + + + ..\packages\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.Rocks.dll + True + ..\packages\NAudio.1.7.3\lib\net35\NAudio.dll True @@ -200,14 +232,22 @@ ..\packages\NLog.4.3.7\lib\net45\NLog.dll True - - False - D:\Downloads\Chome Downloads\Process.NET-master\Process.NET-master\src\Process.NET\bin\Release\Process.NET.dll + + ..\packages\squirrel.windows.1.4.4\lib\Net45\NuGet.Squirrel.dll + True + + + ..\packages\Splat.1.6.2\lib\Net45\Splat.dll + True ..\packages\SpotifyAPI-NET.2.11.0\lib\SpotifyAPI.dll True + + ..\packages\squirrel.windows.1.4.4\lib\Net45\Squirrel.dll + True + diff --git a/Artemis/Artemis/ArtemisBootstrapper.cs b/Artemis/Artemis/ArtemisBootstrapper.cs index 2b67e8842..d49c0808d 100644 --- a/Artemis/Artemis/ArtemisBootstrapper.cs +++ b/Artemis/Artemis/ArtemisBootstrapper.cs @@ -1,9 +1,9 @@ using System; using System.Collections.Generic; -using System.Threading; +using System.Reflection; using System.Windows; using System.Windows.Controls; -using System.Windows.Forms; +using System.Windows.Input; using Artemis.InjectionModules; using Artemis.Settings; using Artemis.Utilities; @@ -12,9 +12,7 @@ using Artemis.ViewModels; using Caliburn.Micro; using Newtonsoft.Json; using Ninject; -using Application = System.Windows.Application; -using MessageBox = System.Windows.Forms.MessageBox; -using MouseEventArgs = System.Windows.Input.MouseEventArgs; +using Ninject.Extensions.Logging; namespace Artemis { @@ -27,13 +25,10 @@ namespace Artemis // Start logging before anything else Logging.SetupLogging(General.Default.LogLevel); - CheckDuplicateInstances(); Initialize(); BindSpecialValues(); } - public Mutex Mutex { get; set; } - private void BindSpecialValues() { MessageBinder.SpecialValues.Add("$scaledmousex", ctx => @@ -95,7 +90,6 @@ namespace Artemis protected override void OnExit(object sender, EventArgs e) { _kernel.Dispose(); -// Enviroment.Exit(0); base.OnExit(sender, e); } @@ -121,17 +115,5 @@ namespace Artemis { DisplayRootViewFor(); } - - private void CheckDuplicateInstances() - { - bool aIsNewInstance; - Mutex = new Mutex(true, "ArtemisMutex", out aIsNewInstance); - if (aIsNewInstance) - return; - - MessageBox.Show("An instance of Artemis is already running (check your system tray).", - "Artemis (╯°□°)╯︵ ┻━┻", MessageBoxButtons.OK, MessageBoxIcon.Warning); - Application.Current.Shutdown(); - } } } \ No newline at end of file diff --git a/Artemis/Artemis/DeviceProviders/Corsair/CorsairKeyboards.cs b/Artemis/Artemis/DeviceProviders/Corsair/CorsairKeyboards.cs index e25074c60..a77d286b7 100644 --- a/Artemis/Artemis/DeviceProviders/Corsair/CorsairKeyboards.cs +++ b/Artemis/Artemis/DeviceProviders/Corsair/CorsairKeyboards.cs @@ -78,11 +78,6 @@ namespace Artemis.DeviceProviders.Corsair break; } -// Height = 7; -// Width = 18; -// Slug = "corsair-k65-rgb"; -// PreviewSettings = new PreviewSettings(610, 240, new Thickness(0, -30, 0, 0), Resources.k65); - Logger.Debug("Corsair SDK reported device as: {0}", _keyboard.DeviceInfo.Model); _keyboard.Brush = _keyboardBrush ?? (_keyboardBrush = new ImageBrush()); } diff --git a/Artemis/Artemis/Managers/MainManager.cs b/Artemis/Artemis/Managers/MainManager.cs index 09d10be9d..ffbf5b547 100644 --- a/Artemis/Artemis/Managers/MainManager.cs +++ b/Artemis/Artemis/Managers/MainManager.cs @@ -1,14 +1,20 @@ using System; +using System.Diagnostics; using System.Linq; +using System.Reflection; +using System.Threading.Tasks; using System.Timers; using Artemis.Events; using Artemis.Models; +using Artemis.Settings; +using Artemis.Utilities; using Artemis.Utilities.DataReaders; using Artemis.Utilities.GameState; using Artemis.ViewModels; using Caliburn.Micro; using Ninject; using Ninject.Extensions.Logging; +using Squirrel; namespace Artemis.Managers { @@ -48,7 +54,12 @@ namespace Artemis.Managers // Start the named pipe PipeServer.Start("artemis"); + // Start the update task + var updateTask = new Task(Updater.UpdateApp); + updateTask.Start(); + Logger.Info("Intialized MainManager"); + Logger.Info($"Artemis version {Assembly.GetExecutingAssembly().GetName().Version} is ready!"); } [Inject] @@ -109,7 +120,7 @@ namespace Artemis.Managers if (!ProgramEnabled) return; - var runningProcesses = System.Diagnostics.Process.GetProcesses(); + var runningProcesses = Process.GetProcesses(); // If the currently active effect is a disabled game, get rid of it. if (EffectManager.ActiveEffect != null) diff --git a/Artemis/Artemis/Properties/AssemblyInfo.cs b/Artemis/Artemis/Properties/AssemblyInfo.cs index f6e912e89..6af1ea75a 100644 --- a/Artemis/Artemis/Properties/AssemblyInfo.cs +++ b/Artemis/Artemis/Properties/AssemblyInfo.cs @@ -52,5 +52,6 @@ using System.Windows; // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file +[assembly: AssemblyVersion("1.3.0.0")] +[assembly: AssemblyFileVersion("1.3.0.0")] +[assembly: AssemblyMetadata("SquirrelAwareVersion", "1")] \ No newline at end of file diff --git a/Artemis/Artemis/Settings/General.Designer.cs b/Artemis/Artemis/Settings/General.Designer.cs index b639e7962..0d56558a5 100644 --- a/Artemis/Artemis/Settings/General.Designer.cs +++ b/Artemis/Artemis/Settings/General.Designer.cs @@ -110,12 +110,12 @@ namespace Artemis.Settings { [global::System.Configuration.UserScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Configuration.DefaultSettingValueAttribute("True")] - public bool CheckForUpdates { + public bool AutoUpdate { get { - return ((bool)(this["CheckForUpdates"])); + return ((bool)(this["AutoUpdate"])); } set { - this["CheckForUpdates"] = value; + this["AutoUpdate"] = value; } } diff --git a/Artemis/Artemis/Settings/General.settings b/Artemis/Artemis/Settings/General.settings index 326ce89c3..9eef70257 100644 --- a/Artemis/Artemis/Settings/General.settings +++ b/Artemis/Artemis/Settings/General.settings @@ -1,7 +1,5 @@  - - + @@ -25,7 +23,7 @@ True - + True diff --git a/Artemis/Artemis/Settings/GeneralSettings.cs b/Artemis/Artemis/Settings/GeneralSettings.cs index 573f4e20c..f66788f39 100644 --- a/Artemis/Artemis/Settings/GeneralSettings.cs +++ b/Artemis/Artemis/Settings/GeneralSettings.cs @@ -46,13 +46,13 @@ namespace Artemis.Settings } } - public bool CheckForUpdates + public bool AutoUpdate { - get { return General.Default.CheckForUpdates; } + get { return General.Default.AutoUpdate; } set { - if (General.Default.CheckForUpdates == value) return; - General.Default.CheckForUpdates = value; + if (General.Default.AutoUpdate == value) return; + General.Default.AutoUpdate = value; } } @@ -91,7 +91,7 @@ namespace Artemis.Settings // TODO: Restart Gamestate server with new port } - private void ApplyAutorun() + public void ApplyAutorun() { var startupFolder = Environment.GetFolderPath(Environment.SpecialFolder.Startup); if (Autorun) @@ -144,7 +144,7 @@ namespace Artemis.Settings GamestatePort = 51364; EnablePointersUpdate = true; Autorun = true; - CheckForUpdates = true; + AutoUpdate = true; ShowOnStartup = true; Theme = "Light"; LogLevel = "Info"; diff --git a/Artemis/Artemis/Utilities/Memory/MemoryHelpers.cs b/Artemis/Artemis/Utilities/Memory/MemoryHelpers.cs index 7987498d9..1f0f8ccbc 100644 --- a/Artemis/Artemis/Utilities/Memory/MemoryHelpers.cs +++ b/Artemis/Artemis/Utilities/Memory/MemoryHelpers.cs @@ -1,6 +1,5 @@ using System; using System.Runtime.InteropServices; -using Process.NET.Memory; namespace Artemis.Utilities.Memory { @@ -38,14 +37,14 @@ namespace Artemis.Utilities.Memory return address; } - public static T ReadMultilevelPointer(this IMemory memory, IntPtr address, params int[] offsets) - where T : struct - { - for (var i = 0; i < offsets.Length - 1; i++) - { - address = memory.Read(address + offsets[i]); - } - return memory.Read(address + offsets[offsets.Length - 1]); - } +// public static T ReadMultilevelPointer(this IMemory memory, IntPtr address, params int[] offsets) +// where T : struct +// { +// for (var i = 0; i < offsets.Length - 1; i++) +// { +// address = memory.Read(address + offsets[i]); +// } +// return memory.Read(address + offsets[offsets.Length - 1]); +// } } } \ No newline at end of file diff --git a/Artemis/Artemis/Utilities/Updater.cs b/Artemis/Artemis/Utilities/Updater.cs index adb673416..3086ff820 100644 --- a/Artemis/Artemis/Utilities/Updater.cs +++ b/Artemis/Artemis/Utilities/Updater.cs @@ -1,80 +1,45 @@ using System; using System.Collections.Generic; -using System.Diagnostics; using System.Linq; using System.Net; -using System.Threading.Tasks; -using Artemis.Services; using Artemis.Settings; using Artemis.Utilities.Memory; using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -using NLog; +using Squirrel; namespace Artemis.Utilities { public static class Updater { - public static int CurrentVersion = 1230; - private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - - public static async Task CheckForUpdate(MetroDialogService dialogService) + public static async void UpdateApp() { - Logger.Info("Checking for updates - Current version: 1.2.3.0"); - if (!General.Default.CheckForUpdates) - return null; + // Only update if the user allows it + if (!General.Default.AutoUpdate) + return; - var newRelease = IsUpdateAvailable(); - if (newRelease == null) + using (var mgr = new UpdateManager("http://artemis-rgb.com/auto-update")) { - Logger.Info("No update found."); - return null; + // Replace / remove the autorun shortcut + SquirrelAwareApp.HandleEvents(onAppUpdate: v => AppUpdate(mgr), onAppUninstall: v => AppUninstall(mgr)); + + await mgr.UpdateApp(); } - - Logger.Info("Found new version - {0}.", newRelease["tag_name"].Value()); - var viewUpdate = await - dialogService.ShowQuestionMessageBox("ApplyProperties available", - $"A new version of Artemis is available, version {newRelease["tag_name"].Value()}.\n" + - "Do you wish to view the update on GitHub now?\n\n" + - "Note: You can disable update notifications in the settings menu"); - - if (viewUpdate.Value) - System.Diagnostics.Process.Start(new ProcessStartInfo(newRelease["html_url"].Value())); - - return null; } - public static JObject IsUpdateAvailable() + private static void AppUpdate(IUpdateManager mgr) { - if (!General.Default.EnablePointersUpdate) - return null; + var settings = new GeneralSettings(); - try - { - var jsonClient = new WebClient(); + settings.ApplyAutorun(); + mgr.CreateShortcutForThisExe(); + } - // 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;)"); + private static void AppUninstall(IUpdateManager mgr) + { + var settings = new GeneralSettings {Autorun = false}; - // Random number to get around cache issues - var rand = new Random(DateTime.Now.Millisecond); - var json = - jsonClient.DownloadString("https://api.github.com/repos/SpoinkyNL/Artemis/releases/latest?random=" + - rand.Next()); - - // Get a list of pointers - var release = JsonConvert.DeserializeObject(json); - - // Parse a version number string to an int - var remoteVersion = int.Parse(release["tag_name"].Value().Replace(".", "")); - - return remoteVersion > CurrentVersion ? release : null; - } - catch (Exception) - { - return null; - } + settings.ApplyAutorun(); + mgr.RemoveShortcutForThisExe(); } public static void GetPointers() @@ -88,9 +53,8 @@ namespace Artemis.Utilities // Random number to get around cache issues var rand = new Random(DateTime.Now.Millisecond); - var json = - jsonClient.DownloadString( - "https://raw.githubusercontent.com/SpoinkyNL/Artemis/master/pointers.json?random=" + rand.Next()); + var json = jsonClient.DownloadString( + "https://raw.githubusercontent.com/SpoinkyNL/Artemis/master/pointers.json?random=" + rand.Next()); // Get a list of pointers var pointers = JsonConvert.DeserializeObject>(json); diff --git a/Artemis/Artemis/ViewModels/Flyouts/FlyoutSettingsViewModel.cs b/Artemis/Artemis/ViewModels/Flyouts/FlyoutSettingsViewModel.cs index 8cbb254c8..94ae3beea 100644 --- a/Artemis/Artemis/ViewModels/Flyouts/FlyoutSettingsViewModel.cs +++ b/Artemis/Artemis/ViewModels/Flyouts/FlyoutSettingsViewModel.cs @@ -2,6 +2,7 @@ using System.ComponentModel; using System.Diagnostics; using System.Dynamic; using System.Linq; +using System.Reflection; using Artemis.Events; using Artemis.Managers; using Artemis.Settings; @@ -84,6 +85,8 @@ namespace Artemis.ViewModels.Flyouts "Corsair Dark" }; + public string VersionText => "Artemis " + Assembly.GetExecutingAssembly().GetName().Version; + public BindableCollection LogLevels { get; set; } public string SelectedTheme diff --git a/Artemis/Artemis/ViewModels/SystemTrayViewModel.cs b/Artemis/Artemis/ViewModels/SystemTrayViewModel.cs index 2d1ff3388..98ce10671 100644 --- a/Artemis/Artemis/ViewModels/SystemTrayViewModel.cs +++ b/Artemis/Artemis/ViewModels/SystemTrayViewModel.cs @@ -1,11 +1,11 @@ using System; +using System.Threading; using System.Threading.Tasks; using System.Windows; using Artemis.Events; using Artemis.Managers; using Artemis.Services; using Artemis.Settings; -using Artemis.Utilities; using Caliburn.Micro; namespace Artemis.ViewModels @@ -15,9 +15,9 @@ namespace Artemis.ViewModels private readonly ShellViewModel _shellViewModel; private readonly IWindowManager _windowManager; private string _activeIcon; - private bool _checkedForUpdate; private bool _enabled; private string _toggleText; + private bool _checked; public SystemTrayViewModel(IWindowManager windowManager, IEventAggregator events, MetroDialogService dialogService, ShellViewModel shellViewModel, @@ -25,7 +25,6 @@ namespace Artemis.ViewModels { _windowManager = windowManager; _shellViewModel = shellViewModel; - _checkedForUpdate = false; DialogService = dialogService; MainManager = mainManager; @@ -81,6 +80,8 @@ namespace Artemis.ViewModels } } + public Mutex Mutex { get; set; } + public void Handle(ToggleEnabled message) { Enabled = message.Enabled; @@ -113,13 +114,24 @@ namespace Artemis.ViewModels NotifyOfPropertyChange(() => CanShowWindow); NotifyOfPropertyChange(() => CanHideWindow); - if (_checkedForUpdate) + ShowKeyboardDialog(); + CheckDuplicateInstances(); + } + + private void CheckDuplicateInstances() + { + if (_checked) + return; + _checked = true; + + bool aIsNewInstance; + Mutex = new Mutex(true, "ArtemisMutex", out aIsNewInstance); + if (aIsNewInstance) return; - _checkedForUpdate = true; - - ShowKeyboardDialog(); - Updater.CheckForUpdate(DialogService); + DialogService.ShowMessageBox("Multiple instances found", + "It looks like there are multiple running instances of Artemis. " + + "This can cause issues. If so, please make sure Artemis isn't already running"); } private async void ShowKeyboardDialog() diff --git a/Artemis/Artemis/Views/Flyouts/FlyoutSettingsView.xaml b/Artemis/Artemis/Views/Flyouts/FlyoutSettingsView.xaml index 9d98bfff7..34b66d7a6 100644 --- a/Artemis/Artemis/Views/Flyouts/FlyoutSettingsView.xaml +++ b/Artemis/Artemis/Views/Flyouts/FlyoutSettingsView.xaml @@ -72,10 +72,10 @@