2019-03-17 22:39:07 +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.
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using Android.App;
|
2020-06-16 19:16:04 +08:00
|
|
|
|
using Android.OS;
|
2019-03-17 22:39:07 +08:00
|
|
|
|
using osu.Game;
|
2019-09-24 17:12:04 +08:00
|
|
|
|
using osu.Game.Updater;
|
2019-03-17 22:39:07 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Android
|
|
|
|
|
{
|
|
|
|
|
public class OsuGameAndroid : OsuGame
|
|
|
|
|
{
|
2019-09-24 16:45:45 +08:00
|
|
|
|
public override Version AssemblyVersion
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2019-09-24 17:12:04 +08:00
|
|
|
|
var packageInfo = Application.Context.ApplicationContext.PackageManager.GetPackageInfo(Application.Context.ApplicationContext.PackageName, 0);
|
2019-09-24 16:45:45 +08:00
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2020-06-16 19:16:04 +08:00
|
|
|
|
// We store the osu! build number in the "VersionCode" field to better support google play releases.
|
|
|
|
|
// If we were to use the main build number, it would require a new submission each time (similar to TestFlight).
|
|
|
|
|
// In order to do this, we should split it up and pad the numbers to still ensure sequential increase over time.
|
|
|
|
|
//
|
|
|
|
|
// We also need to be aware that older SDK versions store this as a 32bit int.
|
|
|
|
|
//
|
|
|
|
|
// Basic conversion format (as done in Fastfile): 2020.606.0 -> 202006060
|
|
|
|
|
|
|
|
|
|
// https://stackoverflow.com/questions/52977079/android-sdk-28-versioncode-in-packageinfo-has-been-deprecated
|
|
|
|
|
string versionName = string.Empty;
|
|
|
|
|
|
|
|
|
|
if (Build.VERSION.SdkInt >= BuildVersionCodes.P)
|
|
|
|
|
{
|
|
|
|
|
versionName = packageInfo.LongVersionCode.ToString();
|
2020-06-16 19:20:46 +08:00
|
|
|
|
// ensure we only read the trailing portion of long (the part we are interested in).
|
2020-06-16 19:16:04 +08:00
|
|
|
|
versionName = versionName.Substring(versionName.Length - 9);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
#pragma warning disable CS0618 // Type or member is obsolete
|
|
|
|
|
// this is required else older SDKs will report missing method exception.
|
|
|
|
|
versionName = packageInfo.VersionCode.ToString();
|
|
|
|
|
#pragma warning restore CS0618 // Type or member is obsolete
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// undo play store version garbling (as mentioned above).
|
2019-09-24 16:45:45 +08:00
|
|
|
|
return new Version(int.Parse(versionName.Substring(0, 4)), int.Parse(versionName.Substring(4, 4)), int.Parse(versionName.Substring(8, 1)));
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-24 17:12:04 +08:00
|
|
|
|
return new Version(packageInfo.VersionName);
|
2019-09-24 16:45:45 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-09-24 17:12:04 +08:00
|
|
|
|
|
2020-03-05 12:34:04 +08:00
|
|
|
|
protected override UpdateManager CreateUpdateManager() => new SimpleUpdateManager();
|
2019-03-17 22:39:07 +08:00
|
|
|
|
}
|
2019-09-24 16:45:45 +08:00
|
|
|
|
}
|