1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-13 03:57:24 +08:00
osu-lazer/osu.Desktop/Overlays/VersionManager.cs

174 lines
6.0 KiB
C#
Raw Normal View History

2017-02-14 15:13:25 +08:00
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Diagnostics;
2017-02-14 15:13:25 +08:00
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;
2017-02-13 19:06:51 +08:00
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures;
using osu.Game.Graphics;
using OpenTK;
using OpenTK.Graphics;
2017-02-18 02:07:59 +08:00
using System;
namespace osu.Desktop.Overlays
{
public class VersionManager : OverlayContainer
{
private UpdateManager updateManager;
private NotificationManager notification;
protected override bool HideOnEscape => false;
2017-02-13 19:06:51 +08:00
public override bool HandleInput => false;
[BackgroundDependencyLoader]
2017-02-13 19:06:51 +08:00
private void load(NotificationManager notification, OsuColour colours, TextureStore textures)
{
this.notification = notification;
AutoSizeAxes = Axes.Both;
Anchor = Anchor.BottomCentre;
Origin = Anchor.BottomCentre;
2017-02-13 19:06:51 +08:00
Alpha = 0;
bool isDebug = false;
Debug.Assert(isDebug = true);
var asm = Assembly.GetEntryAssembly().GetName();
string version;
if (asm.Version.Major == 0)
{
version = @"local " + (isDebug ? @"debug" : @"release");
}
else
version = $@"{asm.Version.Major}.{asm.Version.Minor}.{asm.Version.Build}";
2017-02-13 19:06:51 +08:00
Children = new Drawable[]
{
2017-02-13 19:06:51 +08:00
new FlowContainer
{
AutoSizeAxes = Axes.Both,
Direction = FlowDirections.Vertical,
Children = new Drawable[]
{
new FlowContainer
{
AutoSizeAxes = Axes.Both,
Direction = FlowDirections.Horizontal,
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Spacing = new Vector2(5),
Children = new Drawable[]
{
new OsuSpriteText
{
Font = @"Exo2.0-Bold",
Text = $@"osu!lazer"
},
new OsuSpriteText
{
Colour = isDebug ? colours.Red : Color4.White,
Text = version
2017-02-13 19:06:51 +08:00
},
}
},
new OsuSpriteText
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
TextSize = 12,
Colour = colours.Yellow,
Font = @"Venera",
Text = $@"Development Build"
},
new Sprite
{
Texture = textures.Get(@"Menu/dev-build-footer"),
},
}
}
};
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()
{
2017-02-18 02:07:59 +08:00
try
{
updateManager = await UpdateManager.GitHubUpdateManager(@"https://github.com/ppy/osu", @"osulazer", null, null, true);
2017-02-18 02:07:59 +08:00
if (!updateManager.IsInstalledApp)
return;
2017-02-18 02:07:59 +08:00
var info = await updateManager.CheckForUpdate();
if (info.ReleasesToApply.Count > 0)
{
2017-02-18 02:07:59 +08:00
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);
2017-02-18 02:07:59 +08:00
}
else
{
//check again every 30 minutes.
Scheduler.AddDelayed(updateChecker, 60000 * 30);
}
}
2017-02-18 02:07:59 +08:00
catch(Exception e)
{
//check again every 30 minutes.
Scheduler.AddDelayed(updateChecker, 60000 * 30);
}
}
protected override void PopIn()
{
2017-02-13 19:06:51 +08:00
FadeIn(1000);
}
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;
}
};
}
}
}