2018-01-05 19:21:19 +08:00
|
|
|
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
2017-02-14 15:13:25 +08:00
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
2017-02-21 13:15:46 +08:00
|
|
|
|
using System;
|
2017-08-22 18:41:39 +08:00
|
|
|
|
using System.Diagnostics;
|
2017-02-14 15:13:25 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2017-09-19 12:29:50 +08:00
|
|
|
|
using osu.Framework.Development;
|
2017-02-12 13:54:56 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
2017-02-21 12:52:30 +08:00
|
|
|
|
using osu.Framework.Graphics.Colour;
|
2017-02-12 13:54:56 +08:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2017-06-20 13:54:23 +08:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2017-02-13 19:06:51 +08:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
|
using osu.Framework.Graphics.Textures;
|
2017-09-18 21:32:49 +08:00
|
|
|
|
using osu.Framework.Logging;
|
2017-10-14 01:10:21 +08:00
|
|
|
|
using osu.Game;
|
2017-09-18 21:32:49 +08:00
|
|
|
|
using osu.Game.Configuration;
|
2017-02-13 19:06:51 +08:00
|
|
|
|
using osu.Game.Graphics;
|
2017-09-18 21:32:49 +08:00
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2017-10-14 01:10:21 +08:00
|
|
|
|
using osu.Game.Overlays;
|
2017-09-18 21:32:49 +08:00
|
|
|
|
using osu.Game.Overlays.Notifications;
|
2017-02-13 19:06:51 +08:00
|
|
|
|
using OpenTK;
|
2017-02-15 12:40:13 +08:00
|
|
|
|
using OpenTK.Graphics;
|
2017-09-18 21:32:49 +08:00
|
|
|
|
using Squirrel;
|
2017-02-12 13:54:56 +08:00
|
|
|
|
|
2017-10-14 01:10:21 +08:00
|
|
|
|
namespace osu.Desktop.Overlays
|
2017-02-12 13:54:56 +08:00
|
|
|
|
{
|
|
|
|
|
public class VersionManager : OverlayContainer
|
|
|
|
|
{
|
|
|
|
|
private UpdateManager updateManager;
|
2017-07-28 13:51:49 +08:00
|
|
|
|
private NotificationOverlay notificationOverlay;
|
2017-08-22 18:41:39 +08:00
|
|
|
|
private OsuConfigManager config;
|
|
|
|
|
private OsuGameBase game;
|
2017-02-12 13:54:56 +08:00
|
|
|
|
|
2018-01-08 04:40:00 +08:00
|
|
|
|
public override bool HandleKeyboardInput => false;
|
|
|
|
|
public override bool HandleMouseInput => false;
|
2017-02-13 19:06:51 +08:00
|
|
|
|
|
2017-02-12 13:54:56 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
2017-08-22 18:41:39 +08:00
|
|
|
|
private void load(NotificationOverlay notification, OsuColour colours, TextureStore textures, OsuGameBase game, OsuConfigManager config)
|
2017-02-12 13:54:56 +08:00
|
|
|
|
{
|
2017-07-28 13:51:49 +08:00
|
|
|
|
notificationOverlay = notification;
|
2017-08-22 18:41:39 +08:00
|
|
|
|
this.config = config;
|
|
|
|
|
this.game = game;
|
2017-02-12 13:54:56 +08:00
|
|
|
|
|
|
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
|
Anchor = Anchor.BottomCentre;
|
|
|
|
|
Origin = Anchor.BottomCentre;
|
2017-08-22 18:41:39 +08:00
|
|
|
|
|
2017-02-13 19:06:51 +08:00
|
|
|
|
Alpha = 0;
|
2017-02-12 13:54:56 +08:00
|
|
|
|
|
2017-02-13 19:06:51 +08:00
|
|
|
|
Children = new Drawable[]
|
2017-02-12 13:54:56 +08:00
|
|
|
|
{
|
2017-03-02 02:33:01 +08:00
|
|
|
|
new FillFlowContainer
|
2017-02-13 19:06:51 +08:00
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Both,
|
2017-03-04 18:00:17 +08:00
|
|
|
|
Direction = FillDirection.Vertical,
|
2017-02-13 19:06:51 +08:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2017-03-02 02:33:01 +08:00
|
|
|
|
new FillFlowContainer
|
2017-02-13 19:06:51 +08:00
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Both,
|
2017-03-04 18:00:17 +08:00
|
|
|
|
Direction = FillDirection.Horizontal,
|
2017-03-02 02:33:01 +08:00
|
|
|
|
Spacing = new Vector2(5),
|
2017-02-13 19:06:51 +08:00
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Font = @"Exo2.0-Bold",
|
2017-03-06 16:09:48 +08:00
|
|
|
|
Text = game.Name
|
2017-02-13 19:06:51 +08:00
|
|
|
|
},
|
|
|
|
|
new OsuSpriteText
|
|
|
|
|
{
|
2017-09-19 12:29:50 +08:00
|
|
|
|
Colour = DebugUtils.IsDebug ? colours.Red : Color4.White,
|
2017-03-06 16:09:48 +08:00
|
|
|
|
Text = game.Version
|
2017-02-13 19:06:51 +08:00
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
TextSize = 12,
|
|
|
|
|
Colour = colours.Yellow,
|
|
|
|
|
Font = @"Venera",
|
2017-03-07 09:59:19 +08:00
|
|
|
|
Text = @"Development Build"
|
2017-02-13 19:06:51 +08:00
|
|
|
|
},
|
|
|
|
|
new Sprite
|
|
|
|
|
{
|
2017-02-27 04:32:43 +08:00
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
2017-02-13 19:06:51 +08:00
|
|
|
|
Texture = textures.Get(@"Menu/dev-build-footer"),
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
2017-02-12 13:54:56 +08:00
|
|
|
|
|
2017-03-06 16:09:48 +08:00
|
|
|
|
if (game.IsDeployedBuild)
|
2017-02-24 05:32:10 +08:00
|
|
|
|
checkForUpdateAsync();
|
2017-02-12 13:54:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-22 18:41:39 +08:00
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
|
|
var version = game.Version;
|
|
|
|
|
var lastVersion = config.Get<string>(OsuSetting.Version);
|
2017-08-22 21:48:50 +08:00
|
|
|
|
if (game.IsDeployedBuild && version != lastVersion)
|
2017-08-22 18:41:39 +08:00
|
|
|
|
{
|
|
|
|
|
config.Set(OsuSetting.Version, version);
|
|
|
|
|
|
|
|
|
|
// only show a notification if we've previously saved a version to the config file (ie. not the first run).
|
|
|
|
|
if (!string.IsNullOrEmpty(lastVersion))
|
2017-12-25 17:52:09 +08:00
|
|
|
|
notificationOverlay.Post(new UpdateCompleteNotification(version));
|
2017-08-22 18:41:39 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class UpdateCompleteNotification : SimpleNotification
|
|
|
|
|
{
|
|
|
|
|
public UpdateCompleteNotification(string version)
|
|
|
|
|
{
|
|
|
|
|
Text = $"You are now running osu!lazer {version}.\nClick to see what's new!";
|
|
|
|
|
Icon = FontAwesome.fa_check_square;
|
|
|
|
|
Activated = delegate
|
|
|
|
|
{
|
|
|
|
|
Process.Start($"https://github.com/ppy/osu/releases/tag/v{version}");
|
|
|
|
|
return true;
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
|
{
|
|
|
|
|
IconBackgound.Colour = colours.BlueDark;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-12 13:54:56 +08:00
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
|
{
|
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
|
updateManager?.Dispose();
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-24 05:32:10 +08:00
|
|
|
|
private async void checkForUpdateAsync(bool useDeltaPatching = true, UpdateProgressNotification notification = null)
|
2017-02-12 13:54:56 +08:00
|
|
|
|
{
|
2017-02-21 13:15:46 +08:00
|
|
|
|
//should we schedule a retry on completion of this check?
|
|
|
|
|
bool scheduleRetry = true;
|
|
|
|
|
|
2017-02-18 02:07:59 +08:00
|
|
|
|
try
|
|
|
|
|
{
|
2017-02-21 12:52:52 +08:00
|
|
|
|
if (updateManager == null) updateManager = await UpdateManager.GitHubUpdateManager(@"https://github.com/ppy/osu", @"osulazer", null, null, true);
|
|
|
|
|
|
|
|
|
|
var info = await updateManager.CheckForUpdate(!useDeltaPatching);
|
2017-02-21 13:15:46 +08:00
|
|
|
|
if (info.ReleasesToApply.Count == 0)
|
|
|
|
|
//no updates available. bail and retry later.
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (notification == null)
|
2017-02-12 13:54:56 +08:00
|
|
|
|
{
|
2017-02-21 13:15:46 +08:00
|
|
|
|
notification = new UpdateProgressNotification { State = ProgressNotificationState.Active };
|
2017-07-28 13:51:49 +08:00
|
|
|
|
Schedule(() => notificationOverlay.Post(notification));
|
2017-02-21 13:15:46 +08:00
|
|
|
|
}
|
2017-02-21 12:52:52 +08:00
|
|
|
|
|
2017-02-21 13:15:46 +08:00
|
|
|
|
Schedule(() =>
|
|
|
|
|
{
|
|
|
|
|
notification.Progress = 0;
|
|
|
|
|
notification.Text = @"Downloading update...";
|
|
|
|
|
});
|
2017-02-21 12:52:52 +08:00
|
|
|
|
|
2017-02-21 13:15:46 +08:00
|
|
|
|
try
|
|
|
|
|
{
|
2017-02-21 12:52:52 +08:00
|
|
|
|
await updateManager.DownloadReleases(info.ReleasesToApply, p => Schedule(() => notification.Progress = p / 100f));
|
|
|
|
|
|
2017-02-21 11:58:56 +08:00
|
|
|
|
Schedule(() =>
|
|
|
|
|
{
|
2017-02-21 12:52:52 +08:00
|
|
|
|
notification.Progress = 0;
|
|
|
|
|
notification.Text = @"Installing update...";
|
2017-02-21 11:58:56 +08:00
|
|
|
|
});
|
2017-02-12 13:54:56 +08:00
|
|
|
|
|
2017-02-21 13:15:46 +08:00
|
|
|
|
await updateManager.ApplyReleases(info, p => Schedule(() => notification.Progress = p / 100f));
|
|
|
|
|
|
|
|
|
|
Schedule(() => notification.State = ProgressNotificationState.Completed);
|
|
|
|
|
}
|
2017-03-03 17:09:00 +08:00
|
|
|
|
catch (Exception e)
|
2017-02-21 13:15:46 +08:00
|
|
|
|
{
|
|
|
|
|
if (useDeltaPatching)
|
2017-02-21 12:52:52 +08:00
|
|
|
|
{
|
2017-03-03 17:09:00 +08:00
|
|
|
|
Logger.Error(e, @"delta patching failed!");
|
|
|
|
|
|
2017-02-21 12:52:52 +08:00
|
|
|
|
//could fail if deltas are unavailable for full update path (https://github.com/Squirrel/Squirrel.Windows/issues/959)
|
|
|
|
|
//try again without deltas.
|
2017-02-24 05:32:10 +08:00
|
|
|
|
checkForUpdateAsync(false, notification);
|
2017-02-21 13:15:46 +08:00
|
|
|
|
scheduleRetry = false;
|
2017-02-21 12:52:52 +08:00
|
|
|
|
}
|
2017-03-03 17:09:00 +08:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Logger.Error(e, @"update failed!");
|
|
|
|
|
}
|
2017-02-21 11:58:56 +08:00
|
|
|
|
}
|
2017-02-12 13:54:56 +08:00
|
|
|
|
}
|
2017-11-21 13:42:49 +08:00
|
|
|
|
catch (Exception)
|
2017-02-12 13:54:56 +08:00
|
|
|
|
{
|
2017-11-21 13:42:49 +08:00
|
|
|
|
// we'll ignore this and retry later. can be triggered by no internet connection or thread abortion.
|
2017-02-21 13:15:46 +08:00
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
if (scheduleRetry)
|
|
|
|
|
{
|
|
|
|
|
//check again in 30 minutes.
|
2017-02-24 05:32:10 +08:00
|
|
|
|
Scheduler.AddDelayed(() => checkForUpdateAsync(), 60000 * 30);
|
2017-02-21 13:15:46 +08:00
|
|
|
|
if (notification != null)
|
|
|
|
|
notification.State = ProgressNotificationState.Cancelled;
|
|
|
|
|
}
|
2017-02-12 13:54:56 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void PopIn()
|
|
|
|
|
{
|
2017-07-15 00:18:12 +08:00
|
|
|
|
this.FadeIn(1000);
|
2017-02-12 13:54:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void PopOut()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-07 09:59:19 +08:00
|
|
|
|
private class UpdateProgressNotification : ProgressNotification
|
2017-02-12 13:54:56 +08:00
|
|
|
|
{
|
2017-04-11 17:40:39 +08:00
|
|
|
|
private OsuGame game;
|
|
|
|
|
|
2017-07-13 14:02:45 +08:00
|
|
|
|
protected override Notification CreateCompletionNotification() => new ProgressCompletionNotification
|
2017-02-12 13:54:56 +08:00
|
|
|
|
{
|
|
|
|
|
Text = @"Update ready to install. Click to restart!",
|
|
|
|
|
Activated = () =>
|
|
|
|
|
{
|
2017-11-14 17:05:07 +08:00
|
|
|
|
// Squirrel returns execution to us after the update process is started, so it's safe to use Wait() here
|
|
|
|
|
UpdateManager.RestartAppWhenExited().Wait();
|
2017-04-11 17:40:39 +08:00
|
|
|
|
game.GracefullyExit();
|
2017-02-12 13:54:56 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
};
|
2017-02-21 12:52:30 +08:00
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2017-04-11 17:40:39 +08:00
|
|
|
|
private void load(OsuColour colours, OsuGame game)
|
2017-02-21 12:52:30 +08:00
|
|
|
|
{
|
2017-04-11 17:40:39 +08:00
|
|
|
|
this.game = game;
|
|
|
|
|
|
2017-07-11 21:58:06 +08:00
|
|
|
|
IconContent.AddRange(new Drawable[]
|
2017-02-21 12:52:30 +08:00
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2017-07-23 13:30:50 +08:00
|
|
|
|
Colour = ColourInfo.GradientVertical(colours.YellowDark, colours.Yellow)
|
2017-02-21 12:52:30 +08:00
|
|
|
|
},
|
2017-08-03 13:36:21 +08:00
|
|
|
|
new SpriteIcon
|
2017-02-21 12:52:30 +08:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
2017-03-06 16:09:48 +08:00
|
|
|
|
Origin = Anchor.Centre,
|
2017-02-21 12:52:30 +08:00
|
|
|
|
Icon = FontAwesome.fa_upload,
|
|
|
|
|
Colour = Color4.White,
|
2017-08-03 13:36:21 +08:00
|
|
|
|
Size = new Vector2(20),
|
2017-02-21 12:52:30 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2017-02-12 13:54:56 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|