2017-02-14 07:13:25 +00: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 05:15:46 +00:00
|
|
|
|
using System;
|
2017-02-14 07:13:25 +00:00
|
|
|
|
using osu.Framework.Allocation;
|
2017-02-12 05:54:56 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
2017-02-21 04:52:30 +00:00
|
|
|
|
using osu.Framework.Graphics.Colour;
|
2017-02-12 05:54:56 +00:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
|
using osu.Game.Overlays;
|
|
|
|
|
using osu.Game.Overlays.Notifications;
|
|
|
|
|
using Squirrel;
|
2017-06-20 05:54:23 +00:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2017-02-13 11:06:51 +00:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
|
using osu.Framework.Graphics.Textures;
|
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using OpenTK;
|
2017-02-15 04:40:13 +00:00
|
|
|
|
using OpenTK.Graphics;
|
2017-02-18 10:46:47 +00:00
|
|
|
|
using System.Net.Http;
|
2017-03-03 09:09:00 +00:00
|
|
|
|
using osu.Framework.Logging;
|
2017-03-06 08:09:48 +00:00
|
|
|
|
using osu.Game;
|
2017-02-12 05:54:56 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Desktop.Overlays
|
|
|
|
|
{
|
|
|
|
|
public class VersionManager : OverlayContainer
|
|
|
|
|
{
|
|
|
|
|
private UpdateManager updateManager;
|
2017-02-21 04:52:52 +00:00
|
|
|
|
private NotificationManager notificationManager;
|
2017-02-12 05:54:56 +00:00
|
|
|
|
|
2017-02-13 10:08:59 +00:00
|
|
|
|
protected override bool HideOnEscape => false;
|
|
|
|
|
|
2017-02-13 11:06:51 +00:00
|
|
|
|
public override bool HandleInput => false;
|
|
|
|
|
|
2017-02-12 05:54:56 +00:00
|
|
|
|
[BackgroundDependencyLoader]
|
2017-03-06 08:09:48 +00:00
|
|
|
|
private void load(NotificationManager notification, OsuColour colours, TextureStore textures, OsuGameBase game)
|
2017-02-12 05:54:56 +00:00
|
|
|
|
{
|
2017-02-27 14:37:38 +00:00
|
|
|
|
notificationManager = notification;
|
2017-02-12 05:54:56 +00:00
|
|
|
|
|
|
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
|
Anchor = Anchor.BottomCentre;
|
|
|
|
|
Origin = Anchor.BottomCentre;
|
2017-02-13 11:06:51 +00:00
|
|
|
|
Alpha = 0;
|
2017-02-12 05:54:56 +00:00
|
|
|
|
|
2017-02-13 11:06:51 +00:00
|
|
|
|
Children = new Drawable[]
|
2017-02-12 05:54:56 +00:00
|
|
|
|
{
|
2017-03-01 18:33:01 +00:00
|
|
|
|
new FillFlowContainer
|
2017-02-13 11:06:51 +00:00
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Both,
|
2017-03-04 10:00:17 +00:00
|
|
|
|
Direction = FillDirection.Vertical,
|
2017-02-13 11:06:51 +00:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2017-03-01 18:33:01 +00:00
|
|
|
|
new FillFlowContainer
|
2017-02-13 11:06:51 +00:00
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Both,
|
2017-03-04 10:00:17 +00:00
|
|
|
|
Direction = FillDirection.Horizontal,
|
2017-03-01 18:33:01 +00:00
|
|
|
|
Spacing = new Vector2(5),
|
2017-02-13 11:06:51 +00:00
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Font = @"Exo2.0-Bold",
|
2017-03-06 08:09:48 +00:00
|
|
|
|
Text = game.Name
|
2017-02-13 11:06:51 +00:00
|
|
|
|
},
|
|
|
|
|
new OsuSpriteText
|
|
|
|
|
{
|
2017-03-06 08:09:48 +00:00
|
|
|
|
Colour = game.IsDebug ? colours.Red : Color4.White,
|
|
|
|
|
Text = game.Version
|
2017-02-13 11:06:51 +00:00
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
TextSize = 12,
|
|
|
|
|
Colour = colours.Yellow,
|
|
|
|
|
Font = @"Venera",
|
2017-03-07 01:59:19 +00:00
|
|
|
|
Text = @"Development Build"
|
2017-02-13 11:06:51 +00:00
|
|
|
|
},
|
|
|
|
|
new Sprite
|
|
|
|
|
{
|
2017-02-26 20:32:43 +00:00
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
2017-02-13 11:06:51 +00:00
|
|
|
|
Texture = textures.Get(@"Menu/dev-build-footer"),
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
2017-02-12 05:54:56 +00:00
|
|
|
|
|
2017-03-06 08:09:48 +00:00
|
|
|
|
if (game.IsDeployedBuild)
|
2017-02-23 21:32:10 +00:00
|
|
|
|
checkForUpdateAsync();
|
2017-02-12 05:54:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
State = Visibility.Visible;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
|
{
|
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
|
updateManager?.Dispose();
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-23 21:32:10 +00:00
|
|
|
|
private async void checkForUpdateAsync(bool useDeltaPatching = true, UpdateProgressNotification notification = null)
|
2017-02-12 05:54:56 +00:00
|
|
|
|
{
|
2017-02-21 05:15:46 +00:00
|
|
|
|
//should we schedule a retry on completion of this check?
|
|
|
|
|
bool scheduleRetry = true;
|
|
|
|
|
|
2017-02-17 18:07:59 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
2017-02-21 04:52:52 +00: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 05:15:46 +00:00
|
|
|
|
if (info.ReleasesToApply.Count == 0)
|
|
|
|
|
//no updates available. bail and retry later.
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (notification == null)
|
2017-02-12 05:54:56 +00:00
|
|
|
|
{
|
2017-02-21 05:15:46 +00:00
|
|
|
|
notification = new UpdateProgressNotification { State = ProgressNotificationState.Active };
|
|
|
|
|
Schedule(() => notificationManager.Post(notification));
|
|
|
|
|
}
|
2017-02-21 04:52:52 +00:00
|
|
|
|
|
2017-02-21 05:15:46 +00:00
|
|
|
|
Schedule(() =>
|
|
|
|
|
{
|
|
|
|
|
notification.Progress = 0;
|
|
|
|
|
notification.Text = @"Downloading update...";
|
|
|
|
|
});
|
2017-02-21 04:52:52 +00:00
|
|
|
|
|
2017-02-21 05:15:46 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
2017-02-21 04:52:52 +00:00
|
|
|
|
await updateManager.DownloadReleases(info.ReleasesToApply, p => Schedule(() => notification.Progress = p / 100f));
|
|
|
|
|
|
2017-02-21 03:58:56 +00:00
|
|
|
|
Schedule(() =>
|
|
|
|
|
{
|
2017-02-21 04:52:52 +00:00
|
|
|
|
notification.Progress = 0;
|
|
|
|
|
notification.Text = @"Installing update...";
|
2017-02-21 03:58:56 +00:00
|
|
|
|
});
|
2017-02-12 05:54:56 +00:00
|
|
|
|
|
2017-02-21 05:15:46 +00:00
|
|
|
|
await updateManager.ApplyReleases(info, p => Schedule(() => notification.Progress = p / 100f));
|
|
|
|
|
|
|
|
|
|
Schedule(() => notification.State = ProgressNotificationState.Completed);
|
|
|
|
|
}
|
2017-03-03 09:09:00 +00:00
|
|
|
|
catch (Exception e)
|
2017-02-21 05:15:46 +00:00
|
|
|
|
{
|
|
|
|
|
if (useDeltaPatching)
|
2017-02-21 04:52:52 +00:00
|
|
|
|
{
|
2017-03-03 09:09:00 +00:00
|
|
|
|
Logger.Error(e, @"delta patching failed!");
|
|
|
|
|
|
2017-02-21 04:52:52 +00: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-23 21:32:10 +00:00
|
|
|
|
checkForUpdateAsync(false, notification);
|
2017-02-21 05:15:46 +00:00
|
|
|
|
scheduleRetry = false;
|
2017-02-21 04:52:52 +00:00
|
|
|
|
}
|
2017-03-03 09:09:00 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Logger.Error(e, @"update failed!");
|
|
|
|
|
}
|
2017-02-21 03:58:56 +00:00
|
|
|
|
}
|
2017-02-12 05:54:56 +00:00
|
|
|
|
}
|
2017-02-21 03:58:56 +00:00
|
|
|
|
catch (HttpRequestException)
|
2017-02-12 05:54:56 +00:00
|
|
|
|
{
|
2017-02-21 05:15:46 +00:00
|
|
|
|
//likely have no internet connection.
|
|
|
|
|
//we'll ignore this and retry later.
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
if (scheduleRetry)
|
|
|
|
|
{
|
|
|
|
|
//check again in 30 minutes.
|
2017-02-23 21:32:10 +00:00
|
|
|
|
Scheduler.AddDelayed(() => checkForUpdateAsync(), 60000 * 30);
|
2017-02-21 05:15:46 +00:00
|
|
|
|
if (notification != null)
|
|
|
|
|
notification.State = ProgressNotificationState.Cancelled;
|
|
|
|
|
}
|
2017-02-12 05:54:56 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void PopIn()
|
|
|
|
|
{
|
2017-02-13 11:06:51 +00:00
|
|
|
|
FadeIn(1000);
|
2017-02-12 05:54:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void PopOut()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-07 01:59:19 +00:00
|
|
|
|
private class UpdateProgressNotification : ProgressNotification
|
2017-02-12 05:54:56 +00:00
|
|
|
|
{
|
2017-04-11 09:40:39 +00:00
|
|
|
|
private OsuGame game;
|
|
|
|
|
|
2017-03-09 06:52:40 +00:00
|
|
|
|
protected override Notification CreateCompletionNotification() => new ProgressCompletionNotification()
|
2017-02-12 05:54:56 +00:00
|
|
|
|
{
|
|
|
|
|
Text = @"Update ready to install. Click to restart!",
|
|
|
|
|
Activated = () =>
|
|
|
|
|
{
|
2017-04-11 09:40:39 +00:00
|
|
|
|
UpdateManager.RestartAppWhenExited();
|
|
|
|
|
game.GracefullyExit();
|
2017-02-12 05:54:56 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
};
|
2017-02-21 04:52:30 +00:00
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2017-04-11 09:40:39 +00:00
|
|
|
|
private void load(OsuColour colours, OsuGame game)
|
2017-02-21 04:52:30 +00:00
|
|
|
|
{
|
2017-04-11 09:40:39 +00:00
|
|
|
|
this.game = game;
|
|
|
|
|
|
2017-02-21 04:52:30 +00:00
|
|
|
|
IconContent.Add(new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
ColourInfo = ColourInfo.GradientVertical(colours.YellowDark, colours.Yellow)
|
|
|
|
|
},
|
|
|
|
|
new TextAwesome
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
2017-03-06 08:09:48 +00:00
|
|
|
|
Origin = Anchor.Centre,
|
2017-02-21 04:52:30 +00:00
|
|
|
|
Icon = FontAwesome.fa_upload,
|
|
|
|
|
Colour = Color4.White,
|
2017-03-20 04:48:06 +00:00
|
|
|
|
TextSize = 20
|
2017-02-21 04:52:30 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2017-02-12 05:54:56 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|