22// See the LICENCE file in the repository root for full licence text.
33
44using System ;
5+ using System . Linq ;
56using Android . App ;
67using Android . Content . PM ;
78using Microsoft . Maui . Devices ;
89using osu . Framework . Allocation ;
10+ using osu . Framework . Development ;
911using osu . Framework . Extensions . ObjectExtensions ;
1012using osu . Framework . Platform ;
1113using osu . Game ;
@@ -21,58 +23,30 @@ public partial class OsuGameAndroid : OsuGame
2123 [ Cached ]
2224 private readonly OsuGameActivity gameActivity ;
2325
26+ private readonly PackageInfo packageInfo ;
27+
2428 public override Vector2 ScalingContainerTargetDrawSize => new Vector2 ( 1024 , 1024 * DrawHeight / DrawWidth ) ;
2529
2630 public OsuGameAndroid ( OsuGameActivity activity )
2731 : base ( null )
2832 {
2933 gameActivity = activity ;
34+ packageInfo = Application . Context . ApplicationContext ! . PackageManager ! . GetPackageInfo ( Application . Context . ApplicationContext . PackageName ! , 0 ) . AsNonNull ( ) ;
3035 }
3136
32- public override Version AssemblyVersion
37+ public override string Version
3338 {
3439 get
3540 {
36- var packageInfo = Application . Context . ApplicationContext ! . PackageManager ! . GetPackageInfo ( Application . Context . ApplicationContext . PackageName ! , 0 ) . AsNonNull ( ) ;
37-
38- try
39- {
40- // We store the osu! build number in the "VersionCode" field to better support google play releases.
41- // If we were to use the main build number, it would require a new submission each time (similar to TestFlight).
42- // In order to do this, we should split it up and pad the numbers to still ensure sequential increase over time.
43- //
44- // We also need to be aware that older SDK versions store this as a 32bit int.
45- //
46- // Basic conversion format (as done in Fastfile): 2020.606.0 -> 202006060
47-
48- // https://stackoverflow.com/questions/52977079/android-sdk-28-versioncode-in-packageinfo-has-been-deprecated
49- string versionName ;
50-
51- if ( OperatingSystem . IsAndroidVersionAtLeast ( 28 ) )
52- {
53- versionName = packageInfo . LongVersionCode . ToString ( ) ;
54- // ensure we only read the trailing portion of long (the part we are interested in).
55- versionName = versionName . Substring ( versionName . Length - 9 ) ;
56- }
57- else
58- {
59- #pragma warning disable CS0618 // Type or member is obsolete
60- // this is required else older SDKs will report missing method exception.
61- versionName = packageInfo . VersionCode . ToString ( ) ;
62- #pragma warning restore CS0618 // Type or member is obsolete
63- }
64-
65- // undo play store version garbling (as mentioned above).
66- return new Version ( int . Parse ( versionName . Substring ( 0 , 4 ) ) , int . Parse ( versionName . Substring ( 4 , 4 ) ) , int . Parse ( versionName . Substring ( 8 , 1 ) ) ) ;
67- }
68- catch
69- {
70- }
71-
72- return new Version ( packageInfo . VersionName . AsNonNull ( ) ) ;
41+ if ( ! IsDeployedBuild )
42+ return @"local " + ( DebugUtils . IsDebugBuild ? @"debug" : @"release" ) ;
43+
44+ return packageInfo . VersionName . AsNonNull ( ) ;
7345 }
7446 }
7547
48+ public override Version AssemblyVersion => new Version ( packageInfo . VersionName . AsNonNull ( ) . Split ( '-' ) . First ( ) ) ;
49+
7650 protected override void LoadComplete ( )
7751 {
7852 base . LoadComplete ( ) ;
0 commit comments