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
|
|
|
|
|
|
2017-02-21 13:15:46 +08:00
|
|
|
|
using System;
|
2017-02-15 12:40:13 +08:00
|
|
|
|
using System.Diagnostics;
|
2017-02-14 15:13:25 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
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;
|
|
|
|
|
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;
|
2017-02-15 12:40:13 +08:00
|
|
|
|
using OpenTK.Graphics;
|
2017-02-18 18:46:47 +08:00
|
|
|
|
using System.Net.Http;
|
2017-02-12 13:54:56 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Desktop.Overlays
|
|
|
|
|
{
|
|
|
|
|
public class VersionManager : OverlayContainer
|
|
|
|
|
{
|
|
|
|
|
private UpdateManager updateManager;
|
2017-02-21 12:52:52 +08:00
|
|
|
|
private NotificationManager notificationManager;
|
2017-02-12 13:54:56 +08:00
|
|
|
|
|
2017-02-17 17:59:30 +08:00
|
|
|
|
AssemblyName assembly = Assembly.GetEntryAssembly().GetName();
|
|
|
|
|
|
2017-02-17 19:07:11 +08:00
|
|
|
|
public bool IsDeployedBuild => assembly.Version.Major > 0;
|
2017-02-17 17:59:30 +08:00
|
|
|
|
|
2017-02-13 18:08:59 +08:00
|
|
|
|
protected override bool HideOnEscape => false;
|
|
|
|
|
|
2017-02-13 19:06:51 +08:00
|
|
|
|
public override bool HandleInput => false;
|
|
|
|
|
|
2017-02-12 13:54:56 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
2017-02-13 19:06:51 +08:00
|
|
|
|
private void load(NotificationManager notification, OsuColour colours, TextureStore textures)
|
2017-02-12 13:54:56 +08:00
|
|
|
|
{
|
2017-02-27 22:37:38 +08:00
|
|
|
|
notificationManager = notification;
|
2017-02-12 13:54:56 +08:00
|
|
|
|
|
|
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
|
Anchor = Anchor.BottomCentre;
|
|
|
|
|
Origin = Anchor.BottomCentre;
|
2017-02-13 19:06:51 +08:00
|
|
|
|
Alpha = 0;
|
2017-02-12 13:54:56 +08:00
|
|
|
|
|
2017-02-15 12:40:13 +08:00
|
|
|
|
bool isDebug = false;
|
|
|
|
|
Debug.Assert(isDebug = true);
|
|
|
|
|
|
|
|
|
|
string version;
|
2017-02-17 19:07:11 +08:00
|
|
|
|
if (!IsDeployedBuild)
|
2017-02-15 12:40:13 +08:00
|
|
|
|
{
|
|
|
|
|
version = @"local " + (isDebug ? @"debug" : @"release");
|
|
|
|
|
}
|
|
|
|
|
else
|
2017-02-17 17:59:30 +08:00
|
|
|
|
version = $@"{assembly.Version.Major}.{assembly.Version.Minor}.{assembly.Version.Build}";
|
2017-02-15 12:40:13 +08:00
|
|
|
|
|
2017-02-13 19:06:51 +08:00
|
|
|
|
Children = new Drawable[]
|
2017-02-12 13:54:56 +08:00
|
|
|
|
{
|
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
|
|
|
|
|
{
|
2017-02-15 12:40:13 +08:00
|
|
|
|
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"),
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
2017-02-12 13:54:56 +08:00
|
|
|
|
|
2017-02-22 23:41:04 +08:00
|
|
|
|
if (IsDeployedBuild)
|
2017-02-24 05:32:10 +08:00
|
|
|
|
checkForUpdateAsync();
|
2017-02-12 13:54:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
State = Visibility.Visible;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 };
|
|
|
|
|
Schedule(() => notificationManager.Post(notification));
|
|
|
|
|
}
|
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);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
|
|
|
|
if (useDeltaPatching)
|
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-02-21 11:58:56 +08:00
|
|
|
|
}
|
2017-02-12 13:54:56 +08:00
|
|
|
|
}
|
2017-02-21 11:58:56 +08:00
|
|
|
|
catch (HttpRequestException)
|
2017-02-12 13:54:56 +08:00
|
|
|
|
{
|
2017-02-21 13:15:46 +08:00
|
|
|
|
//likely have no internet connection.
|
|
|
|
|
//we'll ignore this and retry later.
|
|
|
|
|
}
|
|
|
|
|
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-02-13 19:06:51 +08:00
|
|
|
|
FadeIn(1000);
|
2017-02-12 13:54:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
};
|
2017-02-21 12:52:30 +08:00
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
|
{
|
|
|
|
|
IconContent.Add(new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
ColourInfo = ColourInfo.GradientVertical(colours.YellowDark, colours.Yellow)
|
|
|
|
|
},
|
|
|
|
|
new TextAwesome
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Icon = FontAwesome.fa_upload,
|
|
|
|
|
Colour = Color4.White,
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2017-02-12 13:54:56 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|