diff --git a/src/AET.SteamAbstraction/AET.SteamAbstraction.Test/LinuxSteamWrapperTest.cs b/src/AET.SteamAbstraction/AET.SteamAbstraction.Test/LinuxSteamWrapperTest.cs index 39000c1..95fe716 100644 --- a/src/AET.SteamAbstraction/AET.SteamAbstraction.Test/LinuxSteamWrapperTest.cs +++ b/src/AET.SteamAbstraction/AET.SteamAbstraction.Test/LinuxSteamWrapperTest.cs @@ -1,6 +1,7 @@ using System; using System.IO.Abstractions; using AET.SteamAbstraction.Games; +using AET.SteamAbstraction.Registry; using AET.SteamAbstraction.Utilities; using Microsoft.Extensions.DependencyInjection; using Moq; diff --git a/src/AET.SteamAbstraction/AET.SteamAbstraction.Test/SteamLibraryFinderTest.cs b/src/AET.SteamAbstraction/AET.SteamAbstraction.Test/SteamLibraryFinderTest.cs index 7a1f02b..ecbbd55 100644 --- a/src/AET.SteamAbstraction/AET.SteamAbstraction.Test/SteamLibraryFinderTest.cs +++ b/src/AET.SteamAbstraction/AET.SteamAbstraction.Test/SteamLibraryFinderTest.cs @@ -2,6 +2,7 @@ using System.IO.Abstractions; using System.Linq; using AET.SteamAbstraction.Library; +using AET.SteamAbstraction.Registry; using Microsoft.Extensions.DependencyInjection; using Moq; using Testably.Abstractions.Testing; diff --git a/src/AET.SteamAbstraction/AET.SteamAbstraction.Test/SteamRegistryFactoryTest.cs b/src/AET.SteamAbstraction/AET.SteamAbstraction.Test/SteamRegistryFactoryTest.cs index 2e57e57..838e2af 100644 --- a/src/AET.SteamAbstraction/AET.SteamAbstraction.Test/SteamRegistryFactoryTest.cs +++ b/src/AET.SteamAbstraction/AET.SteamAbstraction.Test/SteamRegistryFactoryTest.cs @@ -1,6 +1,7 @@ using System; using System.IO.Abstractions; using System.Runtime.InteropServices; +using AET.SteamAbstraction.Registry; using AET.SteamAbstraction.Utilities; using AnakinRaW.CommonUtilities.Registry; using Microsoft.Extensions.DependencyInjection; diff --git a/src/AET.SteamAbstraction/AET.SteamAbstraction.Test/SteamWrapperFactoryTest.cs b/src/AET.SteamAbstraction/AET.SteamAbstraction.Test/SteamWrapperFactoryTest.cs index 0f0fd1b..b7d94de 100644 --- a/src/AET.SteamAbstraction/AET.SteamAbstraction.Test/SteamWrapperFactoryTest.cs +++ b/src/AET.SteamAbstraction/AET.SteamAbstraction.Test/SteamWrapperFactoryTest.cs @@ -1,5 +1,6 @@ using System; using System.IO.Abstractions; +using AET.SteamAbstraction.Registry; using AET.SteamAbstraction.Utilities; using Microsoft.Extensions.DependencyInjection; using Moq; diff --git a/src/AET.SteamAbstraction/AET.SteamAbstraction.Test/SteamWrapperTest.cs b/src/AET.SteamAbstraction/AET.SteamAbstraction.Test/SteamWrapperTest.cs index 8c90324..24029e1 100644 --- a/src/AET.SteamAbstraction/AET.SteamAbstraction.Test/SteamWrapperTest.cs +++ b/src/AET.SteamAbstraction/AET.SteamAbstraction.Test/SteamWrapperTest.cs @@ -6,6 +6,7 @@ using System.Threading.Tasks; using AET.SteamAbstraction.Games; using AET.SteamAbstraction.Library; +using AET.SteamAbstraction.Registry; using AET.SteamAbstraction.Utilities; using Microsoft.Extensions.DependencyInjection; using Moq; diff --git a/src/AET.SteamAbstraction/AET.SteamAbstraction.Test/WindowsSteamWrapperTest.cs b/src/AET.SteamAbstraction/AET.SteamAbstraction.Test/WindowsSteamWrapperTest.cs index 81cc13d..f4591c3 100644 --- a/src/AET.SteamAbstraction/AET.SteamAbstraction.Test/WindowsSteamWrapperTest.cs +++ b/src/AET.SteamAbstraction/AET.SteamAbstraction.Test/WindowsSteamWrapperTest.cs @@ -2,6 +2,7 @@ using System.Diagnostics; using System.IO.Abstractions; using AET.SteamAbstraction.Games; +using AET.SteamAbstraction.Registry; using AET.SteamAbstraction.Utilities; using Microsoft.Extensions.DependencyInjection; using Moq; diff --git a/src/AET.SteamAbstraction/AET.SteamAbstraction/Games/ISteamGameLocationFinder.cs b/src/AET.SteamAbstraction/AET.SteamAbstraction/Games/ISteamGameLocationFinder.cs index 1b8073d..a4af74f 100644 --- a/src/AET.SteamAbstraction/AET.SteamAbstraction/Games/ISteamGameLocationFinder.cs +++ b/src/AET.SteamAbstraction/AET.SteamAbstraction/Games/ISteamGameLocationFinder.cs @@ -1,8 +1,6 @@ -using System; +namespace AET.SteamAbstraction.Games; -namespace AET.SteamAbstraction.Games; - -internal interface ISteamGameFinder : IDisposable +internal interface ISteamGameFinder { SteamAppManifest? FindGame(uint gameId); } \ No newline at end of file diff --git a/src/AET.SteamAbstraction/AET.SteamAbstraction/Games/SteamGameFinder.cs b/src/AET.SteamAbstraction/AET.SteamAbstraction/Games/SteamGameFinder.cs index 6e3b865..d352d7b 100644 --- a/src/AET.SteamAbstraction/AET.SteamAbstraction/Games/SteamGameFinder.cs +++ b/src/AET.SteamAbstraction/AET.SteamAbstraction/Games/SteamGameFinder.cs @@ -1,12 +1,11 @@ using System; using System.Linq; using AET.SteamAbstraction.Library; -using AnakinRaW.CommonUtilities; using Microsoft.Extensions.DependencyInjection; namespace AET.SteamAbstraction.Games; -internal class SteamGameFinder : DisposableObject, ISteamGameFinder +internal class SteamGameFinder : ISteamGameFinder { private readonly ISteamLibraryFinder _libraryFinder; @@ -26,10 +25,4 @@ public SteamGameFinder(IServiceProvider serviceProvider) .FirstOrDefault(matching => matching is not null); return game; } - - protected override void DisposeManagedResources() - { - base.DisposeManagedResources(); - _libraryFinder.Dispose(); - } } \ No newline at end of file diff --git a/src/AET.SteamAbstraction/AET.SteamAbstraction/Library/ISteamLibraryFinder.cs b/src/AET.SteamAbstraction/AET.SteamAbstraction/Library/ISteamLibraryFinder.cs index 0bdd74c..db84389 100644 --- a/src/AET.SteamAbstraction/AET.SteamAbstraction/Library/ISteamLibraryFinder.cs +++ b/src/AET.SteamAbstraction/AET.SteamAbstraction/Library/ISteamLibraryFinder.cs @@ -1,9 +1,8 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; namespace AET.SteamAbstraction.Library; -internal interface ISteamLibraryFinder : IDisposable +internal interface ISteamLibraryFinder { IEnumerable FindLibraries(); } \ No newline at end of file diff --git a/src/AET.SteamAbstraction/AET.SteamAbstraction/Library/SteamLibrary.cs b/src/AET.SteamAbstraction/AET.SteamAbstraction/Library/SteamLibrary.cs index 1acfbad..6fd1280 100644 --- a/src/AET.SteamAbstraction/AET.SteamAbstraction/Library/SteamLibrary.cs +++ b/src/AET.SteamAbstraction/AET.SteamAbstraction/Library/SteamLibrary.cs @@ -16,9 +16,9 @@ internal class SteamLibrary : ISteamLibrary private readonly Dictionary _locationsNames = new() { - { KnownLibraryLocations.SteamApps, new[] { "steamapps" } }, - { KnownLibraryLocations.Common, new[] { "steamapps", "common" } }, - { KnownLibraryLocations.Workshops, new[] { "steamapps", "workshop" } } + { KnownLibraryLocations.SteamApps, ["steamapps"] }, + { KnownLibraryLocations.Common, ["steamapps", "common"] }, + { KnownLibraryLocations.Workshops, ["steamapps", "workshop"] } }; private readonly string _normalizedLocation; diff --git a/src/AET.SteamAbstraction/AET.SteamAbstraction/Library/SteamLibraryFinder.cs b/src/AET.SteamAbstraction/AET.SteamAbstraction/Library/SteamLibraryFinder.cs index a25c954..4b8d858 100644 --- a/src/AET.SteamAbstraction/AET.SteamAbstraction/Library/SteamLibraryFinder.cs +++ b/src/AET.SteamAbstraction/AET.SteamAbstraction/Library/SteamLibraryFinder.cs @@ -1,15 +1,15 @@ using System; using System.Collections.Generic; using System.IO.Abstractions; -using AnakinRaW.CommonUtilities; +using AET.SteamAbstraction.Registry; using Microsoft.Extensions.DependencyInjection; namespace AET.SteamAbstraction.Library; -internal class SteamLibraryFinder(IServiceProvider serviceProvider) : DisposableObject, ISteamLibraryFinder +internal class SteamLibraryFinder(IServiceProvider serviceProvider) : ISteamLibraryFinder { private readonly IServiceProvider _serviceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider)); - private readonly ISteamRegistry _registry = serviceProvider.GetRequiredService().CreateRegistry(); + private readonly ISteamRegistryFactory _registryFactory = serviceProvider.GetRequiredService(); private readonly IFileSystem _fileSystem = serviceProvider.GetRequiredService(); private readonly ISteamVdfReader _configReader = serviceProvider.GetRequiredService(); @@ -41,7 +41,8 @@ private bool TryCreateLibraryFromLocation(IDirectoryInfo libraryLocation, out St private IFileInfo? GetLibraryLocationsFile() { - var steamInstallLocation = _registry.InstallationDirectory; + using var registry = _registryFactory.CreateRegistry(); + var steamInstallLocation = registry.InstallationDirectory; if (steamInstallLocation is null) throw new SteamException("Unable to find an installation of Steam."); @@ -56,10 +57,4 @@ private bool TryCreateLibraryFromLocation(IDirectoryInfo libraryLocation, out St return libraryLocationsFile.Exists ? libraryLocationsFile : null; } - - protected override void DisposeManagedResources() - { - base.DisposeManagedResources(); - _registry.Dispose(); - } } \ No newline at end of file diff --git a/src/AET.SteamAbstraction/AET.SteamAbstraction/Linux/LinuxSteamRegistry.cs b/src/AET.SteamAbstraction/AET.SteamAbstraction/Linux/LinuxSteamRegistry.cs index 089c8ea..25be9bc 100644 --- a/src/AET.SteamAbstraction/AET.SteamAbstraction/Linux/LinuxSteamRegistry.cs +++ b/src/AET.SteamAbstraction/AET.SteamAbstraction/Linux/LinuxSteamRegistry.cs @@ -1,5 +1,6 @@ using System; using System.IO.Abstractions; +using AET.SteamAbstraction.Registry; using AnakinRaW.CommonUtilities; namespace AET.SteamAbstraction; diff --git a/src/AET.SteamAbstraction/AET.SteamAbstraction/Linux/LinuxSteamWrapper.cs b/src/AET.SteamAbstraction/AET.SteamAbstraction/Linux/LinuxSteamWrapper.cs index a749317..b4986ac 100644 --- a/src/AET.SteamAbstraction/AET.SteamAbstraction/Linux/LinuxSteamWrapper.cs +++ b/src/AET.SteamAbstraction/AET.SteamAbstraction/Linux/LinuxSteamWrapper.cs @@ -1,6 +1,7 @@ using System; using System.Threading; using System.Threading.Tasks; +using AET.SteamAbstraction.Registry; namespace AET.SteamAbstraction; diff --git a/src/AET.SteamAbstraction/AET.SteamAbstraction/NativeMethods/WindowHandleInfo.cs b/src/AET.SteamAbstraction/AET.SteamAbstraction/NativeMethods/WindowHandleInfo.cs index 15ba5e4..a28fec7 100644 --- a/src/AET.SteamAbstraction/AET.SteamAbstraction/NativeMethods/WindowHandleInfo.cs +++ b/src/AET.SteamAbstraction/AET.SteamAbstraction/NativeMethods/WindowHandleInfo.cs @@ -8,7 +8,7 @@ internal class WindowHandleInfo(IntPtr handle) { public List GetAllChildHandles() { - List childHandles = new(); + List childHandles = []; var gcChildHandlesList = GCHandle.Alloc(childHandles); var pointerChildHandlesList = GCHandle.ToIntPtr(gcChildHandlesList); diff --git a/src/AET.SteamAbstraction/AET.SteamAbstraction/ISteamRegistry.cs b/src/AET.SteamAbstraction/AET.SteamAbstraction/Registry/ISteamRegistry.cs similarity index 65% rename from src/AET.SteamAbstraction/AET.SteamAbstraction/ISteamRegistry.cs rename to src/AET.SteamAbstraction/AET.SteamAbstraction/Registry/ISteamRegistry.cs index 3dd2bf8..889dc68 100644 --- a/src/AET.SteamAbstraction/AET.SteamAbstraction/ISteamRegistry.cs +++ b/src/AET.SteamAbstraction/AET.SteamAbstraction/Registry/ISteamRegistry.cs @@ -1,9 +1,7 @@ using System; -using System.Collections.Generic; using System.IO.Abstractions; -using AnakinRaW.CommonUtilities.Registry; -namespace AET.SteamAbstraction; +namespace AET.SteamAbstraction.Registry; /// /// Registry representation for the Steam Client. @@ -24,13 +22,4 @@ internal interface ISteamRegistry : IDisposable /// The installation directory of the Steam client /// IDirectoryInfo? InstallationDirectory { get; } -} - -internal interface IWindowsSteamRegistry : ISteamRegistry -{ - IRegistryKey? ActiveProcessKey { get; } - - int? ProcessId { get; } - - ISet? InstalledApps { get; } } \ No newline at end of file diff --git a/src/AET.SteamAbstraction/AET.SteamAbstraction/ISteamRegistryFactory.cs b/src/AET.SteamAbstraction/AET.SteamAbstraction/Registry/ISteamRegistryFactory.cs similarity index 65% rename from src/AET.SteamAbstraction/AET.SteamAbstraction/ISteamRegistryFactory.cs rename to src/AET.SteamAbstraction/AET.SteamAbstraction/Registry/ISteamRegistryFactory.cs index c2cbccc..1126b43 100644 --- a/src/AET.SteamAbstraction/AET.SteamAbstraction/ISteamRegistryFactory.cs +++ b/src/AET.SteamAbstraction/AET.SteamAbstraction/Registry/ISteamRegistryFactory.cs @@ -1,4 +1,4 @@ -namespace AET.SteamAbstraction; +namespace AET.SteamAbstraction.Registry; internal interface ISteamRegistryFactory { diff --git a/src/AET.SteamAbstraction/AET.SteamAbstraction/Registry/IWindowsSteamRegistry.cs b/src/AET.SteamAbstraction/AET.SteamAbstraction/Registry/IWindowsSteamRegistry.cs new file mode 100644 index 0000000..698d601 --- /dev/null +++ b/src/AET.SteamAbstraction/AET.SteamAbstraction/Registry/IWindowsSteamRegistry.cs @@ -0,0 +1,13 @@ +using System.Collections.Generic; +using AnakinRaW.CommonUtilities.Registry; + +namespace AET.SteamAbstraction.Registry; + +internal interface IWindowsSteamRegistry : ISteamRegistry +{ + IRegistryKey? ActiveProcessKey { get; } + + int? ProcessId { get; } + + ISet? InstalledApps { get; } +} \ No newline at end of file diff --git a/src/AET.SteamAbstraction/AET.SteamAbstraction/SteamRegistryFactory.cs b/src/AET.SteamAbstraction/AET.SteamAbstraction/Registry/SteamRegistryFactory.cs similarity index 93% rename from src/AET.SteamAbstraction/AET.SteamAbstraction/SteamRegistryFactory.cs rename to src/AET.SteamAbstraction/AET.SteamAbstraction/Registry/SteamRegistryFactory.cs index ef05e23..0ba99ae 100644 --- a/src/AET.SteamAbstraction/AET.SteamAbstraction/SteamRegistryFactory.cs +++ b/src/AET.SteamAbstraction/AET.SteamAbstraction/Registry/SteamRegistryFactory.cs @@ -1,7 +1,7 @@ using System; using System.Runtime.InteropServices; -namespace AET.SteamAbstraction; +namespace AET.SteamAbstraction.Registry; internal class SteamRegistryFactory(IServiceProvider serviceProvider) : ISteamRegistryFactory { diff --git a/src/AET.SteamAbstraction/AET.SteamAbstraction/SteamAbstractionLayer.cs b/src/AET.SteamAbstraction/AET.SteamAbstraction/SteamAbstractionLayer.cs index 196b8c7..c381b1b 100644 --- a/src/AET.SteamAbstraction/AET.SteamAbstraction/SteamAbstractionLayer.cs +++ b/src/AET.SteamAbstraction/AET.SteamAbstraction/SteamAbstractionLayer.cs @@ -1,5 +1,6 @@ using AET.SteamAbstraction.Games; using AET.SteamAbstraction.Library; +using AET.SteamAbstraction.Registry; using AET.SteamAbstraction.Utilities; using Microsoft.Extensions.DependencyInjection; @@ -8,7 +9,7 @@ namespace AET.SteamAbstraction; /// /// Provides initialization routines for this library. /// -public class SteamAbstractionLayer +public static class SteamAbstractionLayer { /// /// Adds services provided by this library to the given diff --git a/src/AET.SteamAbstraction/AET.SteamAbstraction/SteamException.cs b/src/AET.SteamAbstraction/AET.SteamAbstraction/SteamException.cs index 09c6011..b85a9f7 100644 --- a/src/AET.SteamAbstraction/AET.SteamAbstraction/SteamException.cs +++ b/src/AET.SteamAbstraction/AET.SteamAbstraction/SteamException.cs @@ -21,13 +21,4 @@ public SteamException(string message) : base(message) public SteamException(string message, Exception exception) : base(message, exception) { } -} - - -/// -/// -/// -public sealed class SteamNotFoundException : SteamException -{ - } \ No newline at end of file diff --git a/src/AET.SteamAbstraction/AET.SteamAbstraction/SteamNotFoundException.cs b/src/AET.SteamAbstraction/AET.SteamAbstraction/SteamNotFoundException.cs new file mode 100644 index 0000000..de9f792 --- /dev/null +++ b/src/AET.SteamAbstraction/AET.SteamAbstraction/SteamNotFoundException.cs @@ -0,0 +1,6 @@ +namespace AET.SteamAbstraction; + +/// +/// Exception which gets thrown if an installation of Steam was not found. +/// +public sealed class SteamNotFoundException : SteamException; \ No newline at end of file diff --git a/src/AET.SteamAbstraction/AET.SteamAbstraction/SteamWrapper.cs b/src/AET.SteamAbstraction/AET.SteamAbstraction/SteamWrapper.cs index fcf50d6..3fb78fb 100644 --- a/src/AET.SteamAbstraction/AET.SteamAbstraction/SteamWrapper.cs +++ b/src/AET.SteamAbstraction/AET.SteamAbstraction/SteamWrapper.cs @@ -6,6 +6,7 @@ using System.Threading; using System.Threading.Tasks; using AET.SteamAbstraction.Games; +using AET.SteamAbstraction.Registry; using AnakinRaW.CommonUtilities; using Microsoft.Extensions.DependencyInjection; @@ -63,7 +64,7 @@ public bool IsUserLoggedIn public virtual bool IsGameInstalled(uint gameId, [NotNullWhen(true)] out SteamAppManifest? game) { ThrowIfSteamNotInstalled(); - using var gameFinder = ServiceProvider.GetRequiredService(); + var gameFinder = ServiceProvider.GetRequiredService(); game = gameFinder.FindGame(gameId); return game is not null; } diff --git a/src/AET.SteamAbstraction/AET.SteamAbstraction/SteamWrapperFactory.cs b/src/AET.SteamAbstraction/AET.SteamAbstraction/SteamWrapperFactory.cs index fec3061..5dd65eb 100644 --- a/src/AET.SteamAbstraction/AET.SteamAbstraction/SteamWrapperFactory.cs +++ b/src/AET.SteamAbstraction/AET.SteamAbstraction/SteamWrapperFactory.cs @@ -1,5 +1,6 @@ using System; using System.Runtime.InteropServices; +using AET.SteamAbstraction.Registry; using Microsoft.Extensions.DependencyInjection; namespace AET.SteamAbstraction; diff --git a/src/AET.SteamAbstraction/AET.SteamAbstraction/Windows/WindowsSteamRegistry.cs b/src/AET.SteamAbstraction/AET.SteamAbstraction/Windows/WindowsSteamRegistry.cs index 45678e7..089c59d 100644 --- a/src/AET.SteamAbstraction/AET.SteamAbstraction/Windows/WindowsSteamRegistry.cs +++ b/src/AET.SteamAbstraction/AET.SteamAbstraction/Windows/WindowsSteamRegistry.cs @@ -3,6 +3,7 @@ using System.IO.Abstractions; using System; using System.Linq; +using AET.SteamAbstraction.Registry; using AnakinRaW.CommonUtilities; using Microsoft.Extensions.DependencyInjection; diff --git a/src/AET.SteamAbstraction/AET.SteamAbstraction/Windows/WindowsSteamWrapper.cs b/src/AET.SteamAbstraction/AET.SteamAbstraction/Windows/WindowsSteamWrapper.cs index 90c740e..8469fa3 100644 --- a/src/AET.SteamAbstraction/AET.SteamAbstraction/Windows/WindowsSteamWrapper.cs +++ b/src/AET.SteamAbstraction/AET.SteamAbstraction/Windows/WindowsSteamWrapper.cs @@ -7,6 +7,7 @@ using System.Threading.Tasks; using AET.SteamAbstraction.Games; using AET.SteamAbstraction.NativeMethods; +using AET.SteamAbstraction.Registry; using AET.SteamAbstraction.Utilities; using AnakinRaW.CommonUtilities.Registry.Windows; using Microsoft.Extensions.DependencyInjection;