2019-01-24 16:43:03 +08:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-07-06 15:39:42 +08:00
|
|
|
|
|
2020-10-16 11:58:34 +08:00
|
|
|
|
using System;
|
2021-07-20 00:05:36 +08:00
|
|
|
|
using System.Linq;
|
2018-07-06 15:39:42 +08:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using osu.Framework;
|
|
|
|
|
using osu.Framework.Allocation;
|
2019-03-27 18:29:27 +08:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2018-07-06 15:39:42 +08:00
|
|
|
|
using osu.Framework.Platform;
|
2020-01-17 18:21:27 +08:00
|
|
|
|
using osu.Game.Online.API;
|
2018-07-06 15:39:42 +08:00
|
|
|
|
using osu.Game.Overlays.Notifications;
|
|
|
|
|
|
2019-09-24 17:03:01 +08:00
|
|
|
|
namespace osu.Game.Updater
|
2018-07-06 15:39:42 +08:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// An update manager that shows notifications if a newer release is detected.
|
|
|
|
|
/// Installation is left up to the user.
|
|
|
|
|
/// </summary>
|
2019-09-24 17:03:01 +08:00
|
|
|
|
public class SimpleUpdateManager : UpdateManager
|
2018-07-06 15:39:42 +08:00
|
|
|
|
{
|
|
|
|
|
private string version;
|
2020-02-14 21:14:00 +08:00
|
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
|
private GameHost host { get; set; }
|
2018-07-06 15:39:42 +08:00
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2020-02-14 21:14:00 +08:00
|
|
|
|
private void load(OsuGameBase game)
|
2018-07-06 15:39:42 +08:00
|
|
|
|
{
|
|
|
|
|
version = game.Version;
|
2020-05-08 08:48:27 +08:00
|
|
|
|
}
|
2020-05-07 14:07:22 +08:00
|
|
|
|
|
2020-10-06 12:00:02 +08:00
|
|
|
|
protected override async Task<bool> PerformUpdateCheck()
|
2018-07-06 15:39:42 +08:00
|
|
|
|
{
|
2018-12-06 13:59:17 +08:00
|
|
|
|
try
|
|
|
|
|
{
|
2020-01-17 18:21:27 +08:00
|
|
|
|
var releases = new OsuJsonWebRequest<GitHubRelease>("https://api.github.com/repos/ppy/osu/releases/latest");
|
2018-07-06 15:39:42 +08:00
|
|
|
|
|
2021-03-08 11:57:16 +08:00
|
|
|
|
await releases.PerformAsync().ConfigureAwait(false);
|
2018-07-06 15:39:42 +08:00
|
|
|
|
|
2018-12-06 13:59:17 +08:00
|
|
|
|
var latest = releases.ResponseObject;
|
|
|
|
|
|
2021-07-20 00:05:36 +08:00
|
|
|
|
// avoid any discrepancies due to build suffixes for now.
|
|
|
|
|
// eventually we will want to support release streams and consider these.
|
|
|
|
|
version = version.Split('-').First();
|
2021-10-27 12:04:41 +08:00
|
|
|
|
string latestTagName = latest.TagName.Split('-').First();
|
2021-07-20 00:05:36 +08:00
|
|
|
|
|
|
|
|
|
if (latestTagName != version)
|
2018-07-06 15:39:42 +08:00
|
|
|
|
{
|
2019-09-24 17:03:01 +08:00
|
|
|
|
Notifications.Post(new SimpleNotification
|
2018-07-06 15:39:42 +08:00
|
|
|
|
{
|
2021-07-20 00:05:36 +08:00
|
|
|
|
Text = $"A newer release of osu! has been found ({version} → {latestTagName}).\n\n"
|
2018-12-06 13:59:17 +08:00
|
|
|
|
+ "Click here to download the new version, which can be installed over the top of your existing installation",
|
2019-04-02 18:55:24 +08:00
|
|
|
|
Icon = FontAwesome.Solid.Upload,
|
2018-12-06 13:59:17 +08:00
|
|
|
|
Activated = () =>
|
|
|
|
|
{
|
|
|
|
|
host.OpenUrlExternally(getBestUrl(latest));
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
});
|
2020-10-06 12:00:02 +08:00
|
|
|
|
|
|
|
|
|
return true;
|
2018-12-06 13:59:17 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
// we shouldn't crash on a web failure. or any failure for the matter.
|
2020-10-06 12:00:02 +08:00
|
|
|
|
return true;
|
2018-07-06 15:39:42 +08:00
|
|
|
|
}
|
2020-10-06 12:00:02 +08:00
|
|
|
|
|
|
|
|
|
return false;
|
2018-07-06 15:39:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string getBestUrl(GitHubRelease release)
|
|
|
|
|
{
|
|
|
|
|
GitHubAsset bestAsset = null;
|
|
|
|
|
|
|
|
|
|
switch (RuntimeInfo.OS)
|
|
|
|
|
{
|
|
|
|
|
case RuntimeInfo.Platform.Windows:
|
2020-10-16 11:58:34 +08:00
|
|
|
|
bestAsset = release.Assets?.Find(f => f.Name.EndsWith(".exe", StringComparison.Ordinal));
|
2018-07-06 15:39:42 +08:00
|
|
|
|
break;
|
2019-04-01 11:44:46 +08:00
|
|
|
|
|
2021-03-09 13:27:20 +08:00
|
|
|
|
case RuntimeInfo.Platform.macOS:
|
2020-10-16 11:58:34 +08:00
|
|
|
|
bestAsset = release.Assets?.Find(f => f.Name.EndsWith(".app.zip", StringComparison.Ordinal));
|
2018-07-06 15:39:42 +08:00
|
|
|
|
break;
|
2019-09-24 17:03:01 +08:00
|
|
|
|
|
2020-02-21 18:16:08 +08:00
|
|
|
|
case RuntimeInfo.Platform.Linux:
|
2020-10-16 11:58:34 +08:00
|
|
|
|
bestAsset = release.Assets?.Find(f => f.Name.EndsWith(".AppImage", StringComparison.Ordinal));
|
2020-02-21 18:16:08 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2020-10-06 12:09:42 +08:00
|
|
|
|
case RuntimeInfo.Platform.iOS:
|
|
|
|
|
// iOS releases are available via testflight. this link seems to work well enough for now.
|
|
|
|
|
// see https://stackoverflow.com/a/32960501
|
|
|
|
|
return "itms-beta://beta.itunes.apple.com/v1/app/1447765923";
|
|
|
|
|
|
2019-09-24 17:03:01 +08:00
|
|
|
|
case RuntimeInfo.Platform.Android:
|
2019-09-24 17:34:54 +08:00
|
|
|
|
// on our testing device this causes the download to magically disappear.
|
|
|
|
|
//bestAsset = release.Assets?.Find(f => f.Name.EndsWith(".apk"));
|
2019-09-24 17:03:01 +08:00
|
|
|
|
break;
|
2018-07-06 15:39:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return bestAsset?.BrowserDownloadUrl ?? release.HtmlUrl;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|