1010using osu . Framework . Allocation ;
1111using osu . Framework . Bindables ;
1212using osu . Framework . Development ;
13- using osu . Framework . Extensions . ObjectExtensions ;
1413using osu . Framework . Platform ;
1514using osu . Game ;
1615using osu . Game . Configuration ;
@@ -27,7 +26,7 @@ public partial class OsuGameAndroid : OsuGame
2726 [ Cached ]
2827 private readonly OsuGameActivity gameActivity ;
2928
30- private readonly PackageInfo packageInfo ;
29+ private readonly PackageInfo ? packageInfo ;
3130
3231 public override Vector2 ScalingContainerTargetDrawSize => new Vector2 ( 1024 , 1024 * DrawHeight / DrawWidth ) ;
3332
@@ -43,7 +42,16 @@ public OsuGameAndroid(OsuGameActivity activity)
4342 : base ( null )
4443 {
4544 gameActivity = activity ;
46- packageInfo = Application . Context . ApplicationContext ! . PackageManager ! . GetPackageInfo ( Application . Context . ApplicationContext . PackageName ! , 0 ) . AsNonNull ( ) ;
45+
46+ try
47+ {
48+ packageInfo = Application . Context . ApplicationContext ! . PackageManager ! . GetPackageInfo ( Application . Context . ApplicationContext . PackageName ! , 0 ) ;
49+ }
50+ catch ( Exception e )
51+ {
52+ Debug . WriteLine ( $ "[osu!] Failed to retrieve package info: { e . Message } ") ;
53+ packageInfo = null ;
54+ }
4755 }
4856
4957 public override string Version
@@ -53,11 +61,29 @@ public override string Version
5361 if ( ! IsDeployedBuild )
5462 return @"local " + ( DebugUtils . IsDebugBuild ? @"debug" : @"release" ) ;
5563
56- return packageInfo . VersionName . AsNonNull ( ) ;
64+ return packageInfo ? . VersionName ?? @"unknown" ;
5765 }
5866 }
5967
60- public override Version AssemblyVersion => new Version ( packageInfo . VersionName . AsNonNull ( ) . Split ( '-' ) . First ( ) ) ;
68+ public override Version AssemblyVersion
69+ {
70+ get
71+ {
72+ try
73+ {
74+ string ? versionName = packageInfo ? . VersionName ;
75+
76+ if ( ! string . IsNullOrEmpty ( versionName ) )
77+ return new Version ( versionName . Split ( '-' ) . First ( ) ) ;
78+ }
79+ catch ( Exception e )
80+ {
81+ Debug . WriteLine ( $ "[osu!] Failed to parse assembly version: { e . Message } ") ;
82+ }
83+
84+ return new Version ( @"0.0.0" ) ;
85+ }
86+ }
6187
6288 [ BackgroundDependencyLoader ]
6389 private void load ( OsuConfigManager config )
@@ -247,24 +273,31 @@ private void updateOrientation()
247273 {
248274 gameActivity . RunOnUiThread ( ( ) =>
249275 {
250- if ( ScreenStack . CurrentScreen is not IOsuScreen currentScreen )
251- return ;
276+ try
277+ {
278+ if ( ScreenStack . CurrentScreen is not IOsuScreen currentScreen )
279+ return ;
252280
253- var orientation = MobileUtils . GetOrientation ( this , currentScreen , gameActivity . IsTablet ) ;
281+ var orientation = MobileUtils . GetOrientation ( this , currentScreen , gameActivity . IsTablet ) ;
254282
255- switch ( orientation )
256- {
257- case MobileUtils . Orientation . Locked :
258- gameActivity . RequestedOrientation = ScreenOrientation . Locked ;
259- break ;
283+ switch ( orientation )
284+ {
285+ case MobileUtils . Orientation . Locked :
286+ gameActivity . RequestedOrientation = ScreenOrientation . Locked ;
287+ break ;
260288
261- case MobileUtils . Orientation . Portrait :
262- gameActivity . RequestedOrientation = ScreenOrientation . Portrait ;
263- break ;
289+ case MobileUtils . Orientation . Portrait :
290+ gameActivity . RequestedOrientation = ScreenOrientation . Portrait ;
291+ break ;
264292
265- case MobileUtils . Orientation . Default :
266- gameActivity . RequestedOrientation = gameActivity . DefaultOrientation ;
267- break ;
293+ case MobileUtils . Orientation . Default :
294+ gameActivity . RequestedOrientation = gameActivity . DefaultOrientation ;
295+ break ;
296+ }
297+ }
298+ catch ( Exception e )
299+ {
300+ Debug . WriteLine ( $ "[osu!] Failed to update orientation: { e . Message } ") ;
268301 }
269302 } ) ;
270303 }
0 commit comments