Skip to content

Commit

Permalink
Add automatic updater for v2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Zachary Canann committed Jan 11, 2023
1 parent 433cd81 commit bb83b6b
Show file tree
Hide file tree
Showing 14 changed files with 327 additions and 41 deletions.
13 changes: 3 additions & 10 deletions GES.Engine.Memory/GES.Engine.Memory.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<LangVersion>latest</LangVersion>
<Version>3.0.1</Version>
<Version>2.0.0</Version>
<Description>FFCC GES Tool</Description>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>
Expand All @@ -13,13 +13,6 @@
<Folder Include="Properties\" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="StyleCop.MSBuild" Version="6.2.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\GES.Engine.Processes\GES.Engine.Processes.csproj" />
<ProjectReference Include="..\GES.Engine.Utils\GES.Engine.Common.csproj" />
Expand All @@ -28,8 +21,8 @@
<PropertyGroup>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
<AssemblyVersion>3.0.1</AssemblyVersion>
<FileVersion>3.0.1</FileVersion>
<AssemblyVersion>2.0.0</AssemblyVersion>
<FileVersion>2.0.0</FileVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand Down
11 changes: 4 additions & 7 deletions GES.Engine.Processes/GES.Engine.Processes.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<LangVersion>latest</LangVersion>
<Version>3.0.1</Version>
<AssemblyVersion>3.0.1</AssemblyVersion>
<FileVersion>3.0.1</FileVersion>
<Version>2.0.0</Version>
<AssemblyVersion>2.0.0</AssemblyVersion>
<FileVersion>2.0.0</FileVersion>
<UserSecretsId>ff02c859-7e0c-466a-8d97-eac2f037b653</UserSecretsId>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="StyleCop.MSBuild" Version="6.2.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="System.Drawing.Common" Version="7.0.0" />
</ItemGroup>

Expand Down
10 changes: 3 additions & 7 deletions GES.Engine.Scanning/GES.Engine.Scanning.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<LangVersion>latest</LangVersion>
<Version>3.0.1</Version>
<Version>2.0.0</Version>
<Description>GES engine component for performant memory scanning. GES achieves fast memory scanning (often faster than Cheat Engine) by leveraging multi-threaded parallelism along with single core parallelism via SIMD instructions.

Scanners are JIT compiled into SSE, AVX, or AVX-512 instructions via RyuJIT through the System.Numerics.Vectors library.</Description>
Expand All @@ -21,15 +21,11 @@ Scanners are JIT compiled into SSE, AVX, or AVX-512 instructions via RyuJIT thro
<PropertyGroup>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
<AssemblyVersion>3.0.1</AssemblyVersion>
<FileVersion>3.0.1</FileVersion>
<AssemblyVersion>2.0.0</AssemblyVersion>
<FileVersion>2.0.0</FileVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="StyleCop.MSBuild" Version="6.2.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="System.Memory" Version="4.5.5" />
<PackageReference Include="System.Numerics.Vectors" Version="4.5.0" />
</ItemGroup>
Expand Down
10 changes: 3 additions & 7 deletions GES.Engine.Utils/GES.Engine.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<LangVersion>latest</LangVersion>
<Version>3.0.1</Version>
<AssemblyVersion>3.0.1</AssemblyVersion>
<FileVersion>3.0.1</FileVersion>
<Version>2.0.0</Version>
<AssemblyVersion>2.0.0</AssemblyVersion>
<FileVersion>2.0.0</FileVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand All @@ -18,10 +18,6 @@

<ItemGroup>
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="StyleCop.MSBuild" Version="6.2.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="System.Configuration.ConfigurationManager" Version="7.0.0" />
<PackageReference Include="System.Numerics.Vectors" Version="4.5.0" />
</ItemGroup>
Expand Down
10 changes: 3 additions & 7 deletions GES.Engine/GES.Engine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<Copyright></Copyright>
<PackageTags></PackageTags>
<NeutralLanguage />
<Version>3.0.1</Version>
<Version>2.0.0</Version>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
</PropertyGroup>

Expand All @@ -30,8 +30,8 @@
<PropertyGroup>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
<AssemblyVersion>3.0.1</AssemblyVersion>
<FileVersion>3.0.1</FileVersion>
<AssemblyVersion>2.0.0</AssemblyVersion>
<FileVersion>2.0.0</FileVersion>
</PropertyGroup>

<ItemGroup>
Expand All @@ -54,10 +54,6 @@

<ItemGroup>
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="StyleCop.MSBuild" Version="6.2.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
Expand Down
3 changes: 3 additions & 0 deletions GES/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
<setting name="SelectedLanguage" serializeAs="String">
<value />
</setting>
<setting name="AutomaticUpdates" serializeAs="String">
<value>True</value>
</setting>
</GES.Properties.Settings>
</userSettings>
</configuration>
4 changes: 2 additions & 2 deletions GES/GES.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
<NoWarn>$(NoWarn);NU1605</NoWarn>
<SignAssembly>false</SignAssembly>
<ApplicationManifest>Application.manifest</ApplicationManifest>
<AssemblyVersion>3.0.1</AssemblyVersion>
<FileVersion>3.0.1</FileVersion>
<AssemblyVersion>2.0.0</AssemblyVersion>
<FileVersion>2.0.0</FileVersion>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
</PropertyGroup>

Expand Down
12 changes: 12 additions & 0 deletions GES/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions GES/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@
<Setting Name="SelectedLanguage" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="AutomaticUpdates" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
</Settings>
</SettingsFile>
13 changes: 13 additions & 0 deletions GES/Properties/SqualrSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@

public static class GESSettings
{
public static Boolean AutomaticUpdates
{
get
{
return Properties.Settings.Default.AutomaticUpdates;
}

set
{
Properties.Settings.Default.AutomaticUpdates = value;
}
}

public static String SelectedLanguage
{
get
Expand Down
4 changes: 3 additions & 1 deletion GES/Source/Main/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using GES.Source.EquipmentViewer;
using GES.Source.InventoryViewer;
using GES.Source.Output;
using GES.Source.Updater;
using System;
using System.Collections.Generic;
using System.Diagnostics;
Expand All @@ -33,7 +34,6 @@ public enum EDetectedVersion
public const String LanguageEN = "English (英語)";
public const String LanguageJPN = "日本語 (Japanese)";

private String selectedVersion;
private String selectedLanguage;

/// <summary>
Expand All @@ -52,6 +52,8 @@ private MainViewModel() : base()
Logger.Subscribe(OutputViewModel.GetInstance());
Logger.Log(LogLevel.Info, "FFCC GES Tools started");

ApplicationUpdater.UpdateApp();

this.LanguageList = new List<String>
{
LanguageEN,
Expand Down
165 changes: 165 additions & 0 deletions GES/Source/Updater/ApplicationUpdater.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
namespace GES.Source.Updater
{
using GES.Engine.Common;
using GES.Engine.Common.Logging;
using GES.Source.Tasks;
using Squirrel;
using Squirrel.Sources;
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;

/// <summary>
/// Class for automatically downloading and applying application updates.
/// </summary>
static class ApplicationUpdater
{
/// <summary>
/// The url for the Github repository from which updates are fetched.
/// </summary>
private static readonly String GithubRepositoryUrl = "https://github.com/zcanann/FFCC-GES-Viewer";

/// <summary>
/// Fetches and applies updates from the Github repository. The application is not restarted. Refer to https://github.com/clowd/Clowd.Squirrel for details.
/// </summary>
public static void UpdateApp()
{
if (!GESSettings.AutomaticUpdates)
{
Logger.Log(LogLevel.Info, "Automatic updates disabled. GES will not check for updates this session.");
return;
}

SquirrelAwareApp.HandleEvents(
onInitialInstall: ApplicationUpdater.OnAppInstall,
onAppUninstall: ApplicationUpdater.OnAppUninstall,
onEveryRun: ApplicationUpdater.OnAppRun);

if (!ApplicationUpdater.IsSquirrelInstalled())
{
Logger.Log(LogLevel.Warn, "Updater not found. Automatic updates will not be available.");
return;
}

Task.Run(async () =>
{
try
{
using (UpdateManager manager = new UpdateManager(new GithubSource(ApplicationUpdater.GithubRepositoryUrl, String.Empty, false)))
{
UpdateInfo updates = await manager.CheckForUpdate();

TrackableTask<Boolean> checkForUpdatesTask = TrackableTask<Boolean>
.Create("Checking for Updates", out UpdateProgress updateProgress, out CancellationToken cancellationToken)
.With(Task<Boolean>.Run(
() =>
{
try
{
manager.CheckForUpdate(false, (progress) => updateProgress(progress)).Wait();
}
catch (Exception ex)
{
Logger.Log(LogLevel.Error, "Error checking for application updates.", ex);
return false;
}

return true;
},
cancellationToken));

TaskTrackerViewModel.GetInstance().TrackTask(checkForUpdatesTask);

if (!checkForUpdatesTask.Result)
{
return;
}

ReleaseEntry lastVersion = updates?.ReleasesToApply?.OrderBy(x => x.Version).LastOrDefault();

if (lastVersion == null)
{
Logger.Log(LogLevel.Info, "GES is up to date.");
return;
}

Logger.Log(LogLevel.Info, "New version of GES found. Downloading files in background...");

TrackableTask<Boolean> updateTask = TrackableTask<Boolean>
.Create("Updating", out updateProgress, out cancellationToken)
.With(Task<Boolean>.Run(
() =>
{
try
{
manager.UpdateApp((progress) => updateProgress(progress)).Wait();
}
catch (Exception ex)
{
Logger.Log(LogLevel.Error, "Error applying updates.", ex);
return false;
}

return true;
},
cancellationToken));

TaskTrackerViewModel.GetInstance().TrackTask(updateTask);

if (!updateTask.Result)
{
return;
}

Logger.Log(LogLevel.Info, "New GES version downloaded. Restart the application to apply updates.");
}
}
catch (Exception ex)
{
Logger.Log(LogLevel.Error, "Error updating GES.", ex);
}
});
}

/// <summary>
/// Determines if the current application was installed via Squirrel.
/// </summary>
/// <returns>A value indicating if the current application was installed via Squirrel.</returns>
private static Boolean IsSquirrelInstalled()
{
try
{
Assembly assembly = Assembly.GetEntryAssembly();
String updateDotExe = Path.Combine(new DirectoryInfo(Path.GetDirectoryName(assembly.Location)).Parent.FullName, "Update.exe");
Boolean isInstalled = File.Exists(updateDotExe);

return isInstalled;
}
catch (Exception ex)
{
Logger.Log(LogLevel.Error, "Error determining if GES was installed by the installer.", ex);
return false;
}
}

private static void OnAppInstall(SemanticVersion version, IAppTools tools)
{
tools.CreateShortcutForThisExe(ShortcutLocation.StartMenu | ShortcutLocation.Desktop);
}

private static void OnAppUninstall(SemanticVersion version, IAppTools tools)
{
tools.RemoveShortcutForThisExe(ShortcutLocation.StartMenu | ShortcutLocation.Desktop);
}

private static void OnAppRun(SemanticVersion version, IAppTools tools, Boolean firstRun)
{
tools.SetProcessAppUserModelId();
}
}
//// End class
}
//// End namespace
Loading

0 comments on commit bb83b6b

Please sign in to comment.