2019-06-28 11:37:53 +00:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
2019-01-24 08:43:03 +00:00
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
using System;
|
2018-07-06 07:39:27 +00:00
|
|
|
using System.Threading.Tasks;
|
2018-04-13 09:19:50 +00:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Colour;
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2019-03-27 10:29:27 +00:00
|
|
|
using osu.Framework.Graphics.Sprites;
|
2018-04-13 09:19:50 +00:00
|
|
|
using osu.Framework.Logging;
|
|
|
|
using osu.Game;
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Overlays;
|
|
|
|
using osu.Game.Overlays.Notifications;
|
2018-11-20 07:51:59 +00:00
|
|
|
using osuTK;
|
|
|
|
using osuTK.Graphics;
|
2018-04-13 09:19:50 +00:00
|
|
|
using Squirrel;
|
2018-11-19 12:29:29 +00:00
|
|
|
using LogLevel = Splat.LogLevel;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
2018-07-06 07:39:27 +00:00
|
|
|
namespace osu.Desktop.Updater
|
2018-04-13 09:19:50 +00:00
|
|
|
{
|
2019-09-24 09:03:01 +00:00
|
|
|
public class SquirrelUpdateManager : osu.Game.Updater.UpdateManager
|
2018-04-13 09:19:50 +00:00
|
|
|
{
|
|
|
|
private UpdateManager updateManager;
|
|
|
|
private NotificationOverlay notificationOverlay;
|
|
|
|
|
2019-06-28 12:26:31 +00:00
|
|
|
public Task PrepareUpdateAsync() => UpdateManager.RestartAppWhenExited();
|
2018-04-13 09:19:50 +00:00
|
|
|
|
2019-07-29 09:14:06 +00:00
|
|
|
private static readonly Logger logger = Logger.GetLogger("updater");
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(NotificationOverlay notification, OsuGameBase game)
|
|
|
|
{
|
|
|
|
notificationOverlay = notification;
|
|
|
|
|
|
|
|
if (game.IsDeployedBuild)
|
2018-11-19 12:29:29 +00:00
|
|
|
{
|
|
|
|
Splat.Locator.CurrentMutable.Register(() => new SquirrelLogger(), typeof(Splat.ILogger));
|
2018-07-06 07:39:27 +00:00
|
|
|
Schedule(() => Task.Run(() => checkForUpdateAsync()));
|
2018-11-19 12:29:29 +00:00
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private async void checkForUpdateAsync(bool useDeltaPatching = true, UpdateProgressNotification notification = null)
|
|
|
|
{
|
2020-05-05 01:31:11 +00:00
|
|
|
// should we schedule a retry on completion of this check?
|
2019-06-28 11:37:53 +00:00
|
|
|
bool scheduleRecheck = true;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2020-06-03 07:48:44 +00:00
|
|
|
updateManager ??= await UpdateManager.GitHubUpdateManager(@"https://github.com/ppy/osu", @"osulazer", null, null, true);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
var info = await updateManager.CheckForUpdate(!useDeltaPatching);
|
|
|
|
if (info.ReleasesToApply.Count == 0)
|
2020-05-05 01:31:11 +00:00
|
|
|
// no updates available. bail and retry later.
|
2018-04-13 09:19:50 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (notification == null)
|
|
|
|
{
|
|
|
|
notification = new UpdateProgressNotification(this) { State = ProgressNotificationState.Active };
|
|
|
|
Schedule(() => notificationOverlay.Post(notification));
|
|
|
|
}
|
|
|
|
|
|
|
|
notification.Progress = 0;
|
|
|
|
notification.Text = @"Downloading update...";
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
await updateManager.DownloadReleases(info.ReleasesToApply, p => notification.Progress = p / 100f);
|
|
|
|
|
|
|
|
notification.Progress = 0;
|
|
|
|
notification.Text = @"Installing update...";
|
|
|
|
|
|
|
|
await updateManager.ApplyReleases(info, p => notification.Progress = p / 100f);
|
|
|
|
|
|
|
|
notification.State = ProgressNotificationState.Completed;
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
if (useDeltaPatching)
|
|
|
|
{
|
2019-07-29 09:14:06 +00:00
|
|
|
logger.Add(@"delta patching failed; will attempt full download!");
|
2018-04-13 09:19:50 +00:00
|
|
|
|
2020-05-05 01:31:11 +00:00
|
|
|
// could fail if deltas are unavailable for full update path (https://github.com/Squirrel/Squirrel.Windows/issues/959)
|
|
|
|
// try again without deltas.
|
2018-04-13 09:19:50 +00:00
|
|
|
checkForUpdateAsync(false, notification);
|
2019-06-28 11:37:53 +00:00
|
|
|
scheduleRecheck = false;
|
2018-04-13 09:19:50 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-06-28 12:26:31 +00:00
|
|
|
notification.State = ProgressNotificationState.Cancelled;
|
2018-04-13 09:19:50 +00:00
|
|
|
Logger.Error(e, @"update failed!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception)
|
|
|
|
{
|
|
|
|
// we'll ignore this and retry later. can be triggered by no internet connection or thread abortion.
|
|
|
|
}
|
|
|
|
finally
|
|
|
|
{
|
2019-06-28 11:37:53 +00:00
|
|
|
if (scheduleRecheck)
|
2018-04-13 09:19:50 +00:00
|
|
|
{
|
2020-05-05 01:31:11 +00:00
|
|
|
// check again in 30 minutes.
|
2018-04-13 09:19:50 +00:00
|
|
|
Scheduler.AddDelayed(() => checkForUpdateAsync(), 60000 * 30);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
{
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
updateManager?.Dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
private class UpdateProgressNotification : ProgressNotification
|
|
|
|
{
|
|
|
|
private readonly SquirrelUpdateManager updateManager;
|
|
|
|
private OsuGame game;
|
|
|
|
|
|
|
|
public UpdateProgressNotification(SquirrelUpdateManager updateManager)
|
|
|
|
{
|
|
|
|
this.updateManager = updateManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override Notification CreateCompletionNotification()
|
|
|
|
{
|
|
|
|
return new ProgressCompletionNotification
|
|
|
|
{
|
|
|
|
Text = @"Update ready to install. Click to restart!",
|
|
|
|
Activated = () =>
|
|
|
|
{
|
2019-06-28 11:45:25 +00:00
|
|
|
updateManager.PrepareUpdateAsync()
|
2019-07-03 14:06:16 +00:00
|
|
|
.ContinueWith(_ => updateManager.Schedule(() => game.GracefullyExit()));
|
2018-04-13 09:19:50 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(OsuColour colours, OsuGame game)
|
|
|
|
{
|
|
|
|
this.game = game;
|
|
|
|
|
|
|
|
IconContent.AddRange(new Drawable[]
|
|
|
|
{
|
|
|
|
new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Colour = ColourInfo.GradientVertical(colours.YellowDark, colours.Yellow)
|
|
|
|
},
|
|
|
|
new SpriteIcon
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
2019-04-02 10:55:24 +00:00
|
|
|
Icon = FontAwesome.Solid.Upload,
|
2018-04-13 09:19:50 +00:00
|
|
|
Colour = Color4.White,
|
|
|
|
Size = new Vector2(20),
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2018-11-19 12:29:29 +00:00
|
|
|
|
|
|
|
private class SquirrelLogger : Splat.ILogger, IDisposable
|
|
|
|
{
|
|
|
|
public LogLevel Level { get; set; } = LogLevel.Info;
|
|
|
|
|
|
|
|
public void Write(string message, LogLevel logLevel)
|
|
|
|
{
|
|
|
|
if (logLevel < Level)
|
|
|
|
return;
|
|
|
|
|
2019-05-15 05:12:59 +00:00
|
|
|
logger.Add(message);
|
2018-11-19 12:29:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
}
|
|
|
|
}
|