diff --git a/CodeAnalysis/BannedSymbols.txt b/CodeAnalysis/BannedSymbols.txt index fac1bc0b8..a0a86a2fe 100644 --- a/CodeAnalysis/BannedSymbols.txt +++ b/CodeAnalysis/BannedSymbols.txt @@ -12,4 +12,4 @@ M:System.Char.ToLower(System.Char);char.ToLower() changes behaviour depending on M:System.Char.ToUpper(System.Char);char.ToUpper() changes behaviour depending on CultureInfo.CurrentCulture. Use char.ToUpperInvariant() instead. If wanting culture-sensitive behaviour, explicitly provide CultureInfo.CurrentCulture. M:System.String.ToLower();string.ToLower() changes behaviour depending on CultureInfo.CurrentCulture. Use string.ToLowerInvariant() instead. If wanting culture-sensitive behaviour, explicitly provide CultureInfo.CurrentCulture or use LocalisableString. M:System.String.ToUpper();string.ToUpper() changes behaviour depending on CultureInfo.CurrentCulture. Use string.ToUpperInvariant() instead. If wanting culture-sensitive behaviour, explicitly provide CultureInfo.CurrentCulture or use LocalisableString. -M:System.Reflection.Assembly.GetEntryAssembly();Use osu.Framework.Development.DebugUtils.GetEntryAssembly() instead +M:System.Reflection.Assembly.GetEntryAssembly();Use osu.Framework.RuntimeInfo.EntryAssembly instead diff --git a/osu.Framework.Android/AndroidGameActivity.cs b/osu.Framework.Android/AndroidGameActivity.cs index bc8883cac..57130be1e 100644 --- a/osu.Framework.Android/AndroidGameActivity.cs +++ b/osu.Framework.Android/AndroidGameActivity.cs @@ -11,7 +11,7 @@ using Android.Views; using ManagedBass; using osu.Framework.Bindables; using osu.Framework.Extensions.ObjectExtensions; -using DebugUtils = osu.Framework.Development.DebugUtils; +using Debug = System.Diagnostics.Debug; namespace osu.Framework.Android { @@ -65,7 +65,8 @@ namespace osu.Framework.Android protected override void OnCreate(Bundle? savedInstanceState) { - DebugUtils.EntryAssembly = GetType().Assembly; + Debug.Assert(RuntimeInfo.EntryAssembly.IsNull(), "RuntimeInfo.EntryAssembly should be null on Android and therefore needs to be manually updated."); + RuntimeInfo.EntryAssembly = GetType().Assembly; // The default current directory on android is '/'. // On some devices '/' maps to the app data directory. On others it maps to the root of the internal storage. diff --git a/osu.Framework.Tests/Visual/Platform/TestSceneDebugUtils.cs b/osu.Framework.Tests/Visual/Platform/TestSceneDebugUtils.cs index f80c2fda0..ca971286e 100644 --- a/osu.Framework.Tests/Visual/Platform/TestSceneDebugUtils.cs +++ b/osu.Framework.Tests/Visual/Platform/TestSceneDebugUtils.cs @@ -41,7 +41,7 @@ namespace osu.Framework.Tests.Visual.Platform textFlow.Clear(); log(DebugUtils.IsNUnitRunning); log(DebugUtils.IsDebugBuild); - log(DebugUtils.GetEntryAssembly()); + log(RuntimeInfo.EntryAssembly); #pragma warning disable RS0030 log(Assembly.GetEntryAssembly()); #pragma warning restore RS0030 @@ -69,7 +69,7 @@ namespace osu.Framework.Tests.Visual.Platform [Test] public void TestEntryAssembly() { - AddAssert("check GetEntryAssembly()", () => DebugUtils.GetEntryAssembly().FullName, () => Does.StartWith("osu.Framework.Tests")); + AddAssert("check RuntimeInfo.EntryAssembly", () => RuntimeInfo.EntryAssembly.FullName, () => Does.StartWith("osu.Framework.Tests")); } /// diff --git a/osu.Framework/Development/DebugUtils.cs b/osu.Framework/Development/DebugUtils.cs index 2118be48e..a84fd239d 100644 --- a/osu.Framework/Development/DebugUtils.cs +++ b/osu.Framework/Development/DebugUtils.cs @@ -17,7 +17,9 @@ namespace osu.Framework.Development private static readonly Lazy is_nunit_running = new Lazy(() => { - var entry = EntryAssembly; +#pragma warning disable RS0030 + var entry = Assembly.GetEntryAssembly(); +#pragma warning restore RS0030 string? assemblyName = entry?.GetName().Name; @@ -35,6 +37,8 @@ namespace osu.Framework.Development } ); + internal static Assembly NUnitTestAssembly => nunit_test_assembly.Value; + private static readonly Lazy nunit_test_assembly = new Lazy(() => { Debug.Assert(IsNUnitRunning); @@ -44,20 +48,10 @@ namespace osu.Framework.Development } ); -#pragma warning disable RS0030 - /// - /// The entry assembly. - /// - /// - /// Usually obtained via , but can be set by a different mechanism on platforms that don't support that. - /// - internal static Assembly? EntryAssembly { private get; set; } = Assembly.GetEntryAssembly(); -#pragma warning restore RS0030 - public static bool IsDebugBuild => is_debug_build.Value; private static readonly Lazy is_debug_build = new Lazy(() => - isDebugAssembly(typeof(DebugUtils).Assembly) || isDebugAssembly(GetEntryAssembly()) + isDebugAssembly(typeof(DebugUtils).Assembly) || isDebugAssembly(RuntimeInfo.EntryAssembly) ); /// @@ -68,21 +62,5 @@ namespace osu.Framework.Development // https://stackoverflow.com/a/2186634 private static bool isDebugAssembly(Assembly? assembly) => assembly?.GetCustomAttributes(false).OfType().Any(da => da.IsJITTrackingEnabled) ?? false; - - /// - /// Gets the entry assembly. - /// When running under NUnit, the assembly of the current test will be returned instead. - /// - /// The entry assembly. - public static Assembly GetEntryAssembly() - { - if (IsNUnitRunning) - return nunit_test_assembly.Value; - - // can only be null when running under nunit, and that case is covered above. - Debug.Assert(EntryAssembly != null); - - return EntryAssembly; - } } } diff --git a/osu.Framework/Graphics/Video/VideoDecoder.cs b/osu.Framework/Graphics/Video/VideoDecoder.cs index 06731ec1b..bce42922e 100644 --- a/osu.Framework/Graphics/Video/VideoDecoder.cs +++ b/osu.Framework/Graphics/Video/VideoDecoder.cs @@ -18,9 +18,7 @@ using System.Threading.Tasks; using JetBrains.Annotations; using osu.Framework.Allocation; using osu.Framework.Bindables; -using osu.Framework.Development; using osu.Framework.Extensions.EnumExtensions; -using osu.Framework.Extensions.ObjectExtensions; using osu.Framework.Graphics.Rendering; using osu.Framework.Logging; using osu.Framework.Platform; @@ -830,7 +828,7 @@ namespace osu.Framework.Graphics.Video throw new ArgumentOutOfRangeException(nameof(RuntimeInfo.OS), RuntimeInfo.OS, null); } - return NativeLibrary.Load(libraryName, DebugUtils.GetEntryAssembly().AsNonNull(), DllImportSearchPath.UseDllDirectoryForDependencies | DllImportSearchPath.SafeDirectories); + return NativeLibrary.Load(libraryName, RuntimeInfo.EntryAssembly, DllImportSearchPath.UseDllDirectoryForDependencies | DllImportSearchPath.SafeDirectories); }; return new FFmpegFuncs diff --git a/osu.Framework/Platform/GameHost.cs b/osu.Framework/Platform/GameHost.cs index a08625278..e7abfaa47 100644 --- a/osu.Framework/Platform/GameHost.cs +++ b/osu.Framework/Platform/GameHost.cs @@ -713,10 +713,8 @@ namespace osu.Framework.Platform Trace.Listeners.Clear(); Trace.Listeners.Add(new ThrowingTraceListener()); - var assembly = DebugUtils.GetEntryAssembly(); - Logger.GameIdentifier = Name; - Logger.VersionIdentifier = assembly.GetName().Version?.ToString() ?? Logger.VersionIdentifier; + Logger.VersionIdentifier = RuntimeInfo.EntryAssembly.GetName().Version?.ToString() ?? Logger.VersionIdentifier; Dependencies.CacheAs(this); Dependencies.CacheAs(Storage = game.CreateStorage(this, GetDefaultGameStorage())); diff --git a/osu.Framework/RuntimeInfo.cs b/osu.Framework/RuntimeInfo.cs index 96ba36aeb..ed1b83364 100644 --- a/osu.Framework/RuntimeInfo.cs +++ b/osu.Framework/RuntimeInfo.cs @@ -4,6 +4,8 @@ using System; using System.Diagnostics; using System.Reflection; +using osu.Framework.Development; +using osu.Framework.Extensions.ObjectExtensions; namespace osu.Framework { @@ -25,6 +27,17 @@ namespace osu.Framework return assembly.Location; } + /// + /// Gets the entry assembly. + /// When running under NUnit, the assembly of the current test will be returned instead. + /// + /// The entry assembly. + public static Assembly EntryAssembly { get; internal set; } = DebugUtils.IsNUnitRunning + ? DebugUtils.NUnitTestAssembly +#pragma warning disable RS0030 + : Assembly.GetEntryAssembly().AsNonNull(); +#pragma warning restore RS0030 + public static Platform OS { get; } public static bool IsUnix => OS != Platform.Windows;