Skip to content

Commit

Permalink
Implement Squirrel updater
Browse files Browse the repository at this point in the history
  • Loading branch information
VolcanicArts committed Jun 18, 2022
1 parent 86c6820 commit 222c8f5
Show file tree
Hide file tree
Showing 8 changed files with 388 additions and 22 deletions.
34 changes: 16 additions & 18 deletions VRCOSC.Desktop/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using osu.Framework;
using osu.Framework.Platform;
using Squirrel;
using VRCOSC.Game;

namespace VRCOSC.Desktop;

Expand All @@ -16,28 +15,27 @@ public static void Main()
initSquirrel();

using GameHost host = Host.GetSuitableDesktopHost(@"VRCOSC");
using osu.Framework.Game game = new VRCOSCGame();
using osu.Framework.Game game = new VRCOSCGameDesktop();
host.Run(game);
}

[SupportedOSPlatform("windows")]
private static void initSquirrel()
{
SquirrelAwareApp.HandleEvents(onInitialInstall: OnAppInstall, onAppUninstall: OnAppUninstall, onEveryRun: OnAppRun);
}

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

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

private static void OnAppRun(SemanticVersion version, IAppTools tools, bool firstRun)
{
tools.SetProcessAppUserModelId();
SquirrelAwareApp.HandleEvents(onInitialInstall: (_, tools) =>
{
tools.CreateShortcutForThisExe();
tools.CreateUninstallerRegistryEntry();
}, onAppUpdate: (_, tools) =>
{
tools.CreateUninstallerRegistryEntry();
}, onAppUninstall: (_, tools) =>
{
tools.RemoveShortcutForThisExe();
tools.RemoveUninstallerRegistryEntry();
}, onEveryRun: (_, tools, _) =>
{
tools.SetProcessAppUserModelId();
});
}
}
72 changes: 72 additions & 0 deletions VRCOSC.Desktop/Updater/SquirrelUpdateManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Copyright (c) VolcanicArts. Licensed under the GPL-3.0 License.
// See the LICENSE file in the repository root for full license text.

using System;
using System.Threading.Tasks;
using osu.Framework.Allocation;
using osu.Framework.Logging;
using osu.Framework.Platform;
using Squirrel;
using VRCOSC.Game.Graphics.Updater;

namespace VRCOSC.Desktop.Updater;

public class SquirrelUpdateManager : VRCOSCUpdateManager
{
private GithubUpdateManager updateManager;
private UpdateInfo updateInfo;

[Resolved]
private GameHost host { get; set; }

public override async Task CheckForUpdate(bool useDelta)
{
try
{
Logger.Log("Attempting to find update...");
updateManager ??= new GithubUpdateManager(@"https://github.com/VolcanicArts/VRCOSC");

if (!updateManager.IsInstalledApp)
{
Logger.Log("Cannot update. Not installed app");
return;
}

Logger.Log("Checking for update...");
updateInfo = await updateManager.CheckForUpdate(!useDelta).ConfigureAwait(false);

if (updateInfo.ReleasesToApply.Count == 0) return;

Logger.Log("Found updates to apply!");

Show();

ResetProgress();
UpdateText("Downloading...");
await updateManager.DownloadReleases(updateInfo.ReleasesToApply, progress => UpdateProgress(progress / 100f)).ConfigureAwait(false);

ResetProgress();
UpdateText("Installing...");
await updateManager.ApplyReleases(updateInfo, progress => UpdateProgress(progress / 100f)).ConfigureAwait(false);

CompleteUpdate(true);
}
catch (Exception)
{
//delta update may have failed due to the installed version being too outdated. Retry without trying for delta
if (useDelta)
{
await CheckForUpdate(false).ConfigureAwait(false);
return;
}

CompleteUpdate(false);
throw;
}
}

public override void RequestRestart()
{
UpdateManager.RestartAppWhenExited().ContinueWith(_ => host.Exit()).ConfigureAwait(false);
}
}
16 changes: 16 additions & 0 deletions VRCOSC.Desktop/VRCOSCGameDesktop.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c) VolcanicArts. Licensed under the GPL-3.0 License.
// See the LICENSE file in the repository root for full license text.

using VRCOSC.Desktop.Updater;
using VRCOSC.Game;
using VRCOSC.Game.Graphics.Updater;

namespace VRCOSC.Desktop;

public class VRCOSCGameDesktop : VRCOSCGame
{
public override VRCOSCUpdateManager CreateUpdateManager()
{
return new SquirrelUpdateManager();
}
}
3 changes: 2 additions & 1 deletion VRCOSC.Desktop/app.manifest
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<asmv1:assembly xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3"
manifestVersion="1.0"
xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity version="1.0.0.0" name="osu!"/>
<assemblyIdentity version="1.0.0.0" name="VRCOSC"/>
<SquirrelAwareVersion xmlns="urn:schema-squirrel-com:asm.v1">1</SquirrelAwareVersion>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
Expand Down
43 changes: 43 additions & 0 deletions VRCOSC.Game/Graphics/Updater/UpdateBar.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright (c) VolcanicArts. Licensed under the GPL-3.0 License.
// See the LICENSE file in the repository root for full license text.

using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;

namespace VRCOSC.Game.Graphics.Updater;

public class UpdateBar : Container
{
public Bindable<float> Progress = new();

[BackgroundDependencyLoader]
private void load()
{
Box progressBar;

Children = new Drawable[]
{
new Box
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
Colour = VRCOSCColour.Gray3
},
progressBar = new Box
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
RelativeSizeAxes = Axes.Both,
RelativePositionAxes = Axes.X,
Colour = VRCOSCColour.Green,
X = -1
}
};

Progress.ValueChanged += (percentage) => progressBar.MoveToX(-1 + percentage.NewValue);
}
}
Loading

0 comments on commit 222c8f5

Please sign in to comment.