From 045edb6ab77e436996b6526352b7ef230595d201 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Sun, 12 Feb 2017 14:54:56 +0900 Subject: [PATCH] Add very simple in-game update checker/display. --- osu.Desktop/OsuGameDesktop.cs | 8 +++ osu.Desktop/Overlays/VersionManager.cs | 93 ++++++++++++++++++++++++++ 2 files changed, 101 insertions(+) create mode 100644 osu.Desktop/Overlays/VersionManager.cs diff --git a/osu.Desktop/OsuGameDesktop.cs b/osu.Desktop/OsuGameDesktop.cs index 5edeffd448..61c2180595 100644 --- a/osu.Desktop/OsuGameDesktop.cs +++ b/osu.Desktop/OsuGameDesktop.cs @@ -11,6 +11,7 @@ using osu.Framework.Platform; using osu.Framework.Desktop.Platform; using osu.Game.Database; +using osu.Desktop.Overlays; namespace osu.Desktop { @@ -22,6 +23,13 @@ public OsuGameDesktop(string[] args = null) } + protected override void LoadComplete() + { + base.LoadComplete(); + + (new VersionManager()).Preload(this, Add); + } + public override void SetHost(BasicGameHost host) { base.SetHost(host); diff --git a/osu.Desktop/Overlays/VersionManager.cs b/osu.Desktop/Overlays/VersionManager.cs new file mode 100644 index 0000000000..a3648e1f12 --- /dev/null +++ b/osu.Desktop/Overlays/VersionManager.cs @@ -0,0 +1,93 @@ +using osu.Framework.Allocation; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Game.Graphics.Sprites; +using osu.Game.Overlays; +using osu.Game.Overlays.Notifications; +using Squirrel; +using System.Reflection; + +namespace osu.Desktop.Overlays +{ + public class VersionManager : OverlayContainer + { + private UpdateManager updateManager; + private NotificationManager notification; + + [BackgroundDependencyLoader] + private void load(NotificationManager notification) + { + this.notification = notification; + + AutoSizeAxes = Axes.Both; + Anchor = Anchor.BottomCentre; + Origin = Anchor.BottomCentre; + + var asm = Assembly.GetEntryAssembly().GetName(); + Add(new OsuSpriteText + { + Text = $@"osu!lazer v{asm.Version}" + }); + + updateChecker(); + } + + protected override void LoadComplete() + { + base.LoadComplete(); + State = Visibility.Visible; + } + + protected override void Dispose(bool isDisposing) + { + base.Dispose(isDisposing); + updateManager?.Dispose(); + } + + private async void updateChecker() + { + updateManager = await UpdateManager.GitHubUpdateManager(@"https://github.com/ppy/osu", @"osulazer", null, null, true); + var info = await updateManager.CheckForUpdate(); + if (info.ReleasesToApply.Count > 0) + { + ProgressNotification n = new UpdateProgressNotification + { + Text = @"Downloading update..." + }; + Schedule(() => notification.Post(n)); + Schedule(() => n.State = ProgressNotificationState.Active); + await updateManager.DownloadReleases(info.ReleasesToApply, (int p) => Schedule(() => n.Progress = p / 100f)); + Schedule(() => n.Text = @"Installing update..."); + await updateManager.ApplyReleases(info, (int p) => Schedule(() => n.Progress = p / 100f)); + Schedule(() => n.State = ProgressNotificationState.Completed); + + } + else + { + //check again every 30 minutes. + Scheduler.AddDelayed(updateChecker, 60000 * 30); + } + } + + protected override void PopIn() + { + } + + protected override void PopOut() + { + } + + class UpdateProgressNotification : ProgressNotification + { + protected override Notification CreateCompletionNotification() => new ProgressCompletionNotification(this) + { + Text = @"Update ready to install. Click to restart!", + Activated = () => + { + UpdateManager.RestartApp(); + return true; + } + }; + } + } +}