mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Implemented update check
This commit is contained in:
parent
426ebac079
commit
3aa53750f6
@ -325,6 +325,7 @@
|
|||||||
<Compile Include="Utilities\Keyboard\Key.cs" />
|
<Compile Include="Utilities\Keyboard\Key.cs" />
|
||||||
<Compile Include="Utilities\Keyboard\KeyboardRectangle.cs" />
|
<Compile Include="Utilities\Keyboard\KeyboardRectangle.cs" />
|
||||||
<Compile Include="Utilities\ShellLink.cs" />
|
<Compile Include="Utilities\ShellLink.cs" />
|
||||||
|
<Compile Include="Utilities\Updater.cs" />
|
||||||
<Compile Include="ViewModels\Abstract\EffectViewModel.cs" />
|
<Compile Include="ViewModels\Abstract\EffectViewModel.cs" />
|
||||||
<Compile Include="ViewModels\EffectsViewModel.cs" />
|
<Compile Include="ViewModels\EffectsViewModel.cs" />
|
||||||
<Compile Include="Modules\Effects\AudioVisualizer\AudioVisualizerViewModel.cs" />
|
<Compile Include="Modules\Effects\AudioVisualizer\AudioVisualizerViewModel.cs" />
|
||||||
|
|||||||
@ -56,7 +56,7 @@ namespace Artemis.Modules.Games.RocketLeague
|
|||||||
ColorHelpers.ToDrawingColor(Settings.SecondaryColor)
|
ColorHelpers.ToDrawingColor(Settings.SecondaryColor)
|
||||||
}, LinearGradientMode.Horizontal);
|
}, LinearGradientMode.Horizontal);
|
||||||
|
|
||||||
MemoryHelpers.GetPointers();
|
Updater.GetPointers();
|
||||||
_pointer = JsonConvert.DeserializeObject<GamePointersCollectionModel>(Offsets.Default.RocketLeague);
|
_pointer = JsonConvert.DeserializeObject<GamePointersCollectionModel>(Offsets.Default.RocketLeague);
|
||||||
|
|
||||||
var tempProcess = MemoryHelpers.GetProcessIfRunning(ProcessName);
|
var tempProcess = MemoryHelpers.GetProcessIfRunning(ProcessName);
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
using Artemis.Managers;
|
using Artemis.Managers;
|
||||||
using Artemis.Models;
|
using Artemis.Models;
|
||||||
using Artemis.Settings;
|
using Artemis.Settings;
|
||||||
|
using Artemis.Utilities;
|
||||||
using Artemis.Utilities.Memory;
|
using Artemis.Utilities.Memory;
|
||||||
using Caliburn.Micro;
|
using Caliburn.Micro;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
@ -62,7 +63,7 @@ namespace Artemis.Modules.Games.RocketLeague
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
MemoryHelpers.GetPointers();
|
Updater.GetPointers();
|
||||||
var version = JsonConvert
|
var version = JsonConvert
|
||||||
.DeserializeObject<GamePointersCollectionModel>(Offsets.Default.RocketLeague)
|
.DeserializeObject<GamePointersCollectionModel>(Offsets.Default.RocketLeague)
|
||||||
.GameVersion;
|
.GameVersion;
|
||||||
|
|||||||
@ -43,35 +43,5 @@ namespace Artemis.Utilities.Memory
|
|||||||
}
|
}
|
||||||
return address;
|
return address;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GetPointers()
|
|
||||||
{
|
|
||||||
if (!General.Default.EnablePointersUpdate)
|
|
||||||
return;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var jsonClient = new WebClient();
|
|
||||||
// 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());
|
|
||||||
|
|
||||||
// Get a list of pointers
|
|
||||||
var pointers = JsonConvert.DeserializeObject<List<GamePointersCollectionModel>>(json);
|
|
||||||
// Assign each pointer to the settings file
|
|
||||||
var rlPointers = JsonConvert.SerializeObject(pointers.FirstOrDefault(p => p.Game == "RocketLeague"));
|
|
||||||
if (rlPointers != null)
|
|
||||||
{
|
|
||||||
Offsets.Default.RocketLeague = rlPointers;
|
|
||||||
Offsets.Default.Save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception)
|
|
||||||
{
|
|
||||||
// ignored
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
98
Artemis/Artemis/Utilities/Updater.cs
Normal file
98
Artemis/Artemis/Utilities/Updater.cs
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
using Artemis.Models;
|
||||||
|
using Artemis.Settings;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
|
namespace Artemis.Utilities
|
||||||
|
{
|
||||||
|
public static class Updater
|
||||||
|
{
|
||||||
|
public static int CurrentVersion = 100;
|
||||||
|
|
||||||
|
public static void CheckForUpdate()
|
||||||
|
{
|
||||||
|
var newRelease = IsUpdateAvailable();
|
||||||
|
if (newRelease == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var viewUpdate =
|
||||||
|
MessageBox.Show(
|
||||||
|
$"A new version of Artemis is available, version {newRelease["tag_name"].Value<string>()}.\n" +
|
||||||
|
"Do you wish to view the update on GitHub now?\n\n" +
|
||||||
|
"Note: You can disable update notifications in the settings menu", "Artemis - Update available",
|
||||||
|
MessageBoxButtons.YesNo, MessageBoxIcon.Information);
|
||||||
|
if (viewUpdate == DialogResult.Yes)
|
||||||
|
Process.Start(new ProcessStartInfo(newRelease["html_url"].Value<string>()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static JObject IsUpdateAvailable()
|
||||||
|
{
|
||||||
|
if (!General.Default.EnablePointersUpdate)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
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 =
|
||||||
|
jsonClient.DownloadString("https://api.github.com/repos/SpoinkyNL/Artemis/releases/latest?random=" +
|
||||||
|
rand.Next());
|
||||||
|
|
||||||
|
// Get a list of pointers
|
||||||
|
var release = JsonConvert.DeserializeObject<JObject>(json);
|
||||||
|
|
||||||
|
// Parse a version number string to an int
|
||||||
|
var remoteVersion = int.Parse(release["tag_name"].Value<string>().Replace(".", ""));
|
||||||
|
|
||||||
|
return remoteVersion > CurrentVersion ? release : null;
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void GetPointers()
|
||||||
|
{
|
||||||
|
if (!General.Default.EnablePointersUpdate)
|
||||||
|
return;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var jsonClient = new WebClient();
|
||||||
|
|
||||||
|
// 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());
|
||||||
|
|
||||||
|
// Get a list of pointers
|
||||||
|
var pointers = JsonConvert.DeserializeObject<List<GamePointersCollectionModel>>(json);
|
||||||
|
// Assign each pointer to the settings file
|
||||||
|
var rlPointers = JsonConvert.SerializeObject(pointers.FirstOrDefault(p => p.Game == "RocketLeague"));
|
||||||
|
if (rlPointers != null)
|
||||||
|
{
|
||||||
|
Offsets.Default.RocketLeague = rlPointers;
|
||||||
|
Offsets.Default.Save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
// ignored
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,7 +1,13 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Windows;
|
using System.Diagnostics;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Forms;
|
||||||
using Artemis.Events;
|
using Artemis.Events;
|
||||||
|
using Artemis.Utilities;
|
||||||
using Caliburn.Micro;
|
using Caliburn.Micro;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
using Application = System.Windows.Application;
|
||||||
|
using Screen = Caliburn.Micro.Screen;
|
||||||
|
|
||||||
namespace Artemis.ViewModels
|
namespace Artemis.ViewModels
|
||||||
{
|
{
|
||||||
@ -10,6 +16,7 @@ namespace Artemis.ViewModels
|
|||||||
private readonly ShellViewModel _shellViewModel;
|
private readonly ShellViewModel _shellViewModel;
|
||||||
|
|
||||||
private readonly IWindowManager _windowManager;
|
private readonly IWindowManager _windowManager;
|
||||||
|
private bool _checkedForUpdate;
|
||||||
private bool _enabled;
|
private bool _enabled;
|
||||||
private string _toggleText;
|
private string _toggleText;
|
||||||
/*
|
/*
|
||||||
@ -27,6 +34,7 @@ namespace Artemis.ViewModels
|
|||||||
_shellViewModel = shellViewModel;
|
_shellViewModel = shellViewModel;
|
||||||
_shellViewModel.MainManager.Events.Subscribe(this);
|
_shellViewModel.MainManager.Events.Subscribe(this);
|
||||||
_shellViewModel.MainManager.EnableProgram();
|
_shellViewModel.MainManager.EnableProgram();
|
||||||
|
_checkedForUpdate = false;
|
||||||
|
|
||||||
// TODO: Check if show on startup is enabled, if so, show window.
|
// TODO: Check if show on startup is enabled, if so, show window.
|
||||||
}
|
}
|
||||||
@ -85,6 +93,13 @@ namespace Artemis.ViewModels
|
|||||||
if (!CanShowWindow)
|
if (!CanShowWindow)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (!_checkedForUpdate)
|
||||||
|
{
|
||||||
|
_checkedForUpdate = true;
|
||||||
|
var updateTask = new Task(Updater.CheckForUpdate);
|
||||||
|
updateTask.Start();
|
||||||
|
}
|
||||||
|
|
||||||
// manually show the next window view-model
|
// manually show the next window view-model
|
||||||
_windowManager.ShowWindow(_shellViewModel);
|
_windowManager.ShowWindow(_shellViewModel);
|
||||||
|
|
||||||
@ -92,6 +107,7 @@ namespace Artemis.ViewModels
|
|||||||
NotifyOfPropertyChange(() => CanHideWindow);
|
NotifyOfPropertyChange(() => CanHideWindow);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void HideWindow()
|
public void HideWindow()
|
||||||
{
|
{
|
||||||
if (!CanHideWindow)
|
if (!CanHideWindow)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user