From ee007a5b42c80c2536ba653e4b3023db69cf8ba5 Mon Sep 17 00:00:00 2001 From: AL <26797547+Al12rs@users.noreply.github.com> Date: Mon, 14 Aug 2023 11:51:09 +0200 Subject: [PATCH] Removed GamePath from Paths library --- src/NexusMods.Paths/GamePath.cs | 92 -------------------- tests/NexusMods.Paths.Tests/GamePathTests.cs | 69 --------------- 2 files changed, 161 deletions(-) delete mode 100644 src/NexusMods.Paths/GamePath.cs delete mode 100644 tests/NexusMods.Paths.Tests/GamePathTests.cs diff --git a/src/NexusMods.Paths/GamePath.cs b/src/NexusMods.Paths/GamePath.cs deleted file mode 100644 index 1f570c0..0000000 --- a/src/NexusMods.Paths/GamePath.cs +++ /dev/null @@ -1,92 +0,0 @@ -using System; -using NexusMods.Paths.Extensions; - -namespace NexusMods.Paths; - -/// -/// Stores the path for an individual game. -/// -public readonly struct GamePath : IPath, IEquatable -{ - /// - /// The path to this instance. - /// - public RelativePath Path { get; } = RelativePath.Empty; - - /// - /// Type of folder stored in this instance. - /// - public GameFolderType Type { get; } - - /// - public Extension Extension => Path.Extension; - - /// - public RelativePath FileName => Path.FileName; - - /// - /// Type of folder contained in this path. - /// The path to the item. - public GamePath(GameFolderType type, RelativePath path) - { - Type = type; - Path = path; - } - - /// - /// Type of folder contained in this path. - /// The path to the item. - public GamePath(GameFolderType type, string path) : this(type, path.ToRelativePath()) { } - - /// - public bool Equals(GamePath other) => Type == other.Type && Path == other.Path; - - /// - public static bool operator ==(GamePath a, GamePath b) => a.Type == b.Type && a.Path == b.Path; - - /// - public static bool operator !=(GamePath a, GamePath b) => a.Type != b.Type || a.Path != b.Path; - - /// - public override bool Equals(object? obj) => obj is GamePath other && Equals(other); - - /// - public override int GetHashCode() => Path.GetHashCode() ^ (int)Type; - - /// - public override string ToString() => "{" + Type + "}/" + Path; - - /// - /// Joins the current absolute path with a relative path. - /// - /// - /// The absolute path to combine with current relative path. - /// - public AbsolutePath Combine(AbsolutePath folderPath) => folderPath.Combine(Path); -} - -/// -/// The base folder for the GamePath, more values can easily be added here as needed -/// -public enum GameFolderType : byte -{ - /// - /// Stores the path for the game. - /// - Game = 0, - - /// - /// Path used to store the save data of a game. - /// - Saves, - - /// - /// Path used to store player settings/preferences. - /// - Preferences, - - /// - /// Stores other application data [sometimes including save data]. - /// - AppData -} diff --git a/tests/NexusMods.Paths.Tests/GamePathTests.cs b/tests/NexusMods.Paths.Tests/GamePathTests.cs deleted file mode 100644 index cdd3c96..0000000 --- a/tests/NexusMods.Paths.Tests/GamePathTests.cs +++ /dev/null @@ -1,69 +0,0 @@ -using NexusMods.Paths.Extensions; -using NexusMods.Paths.Utilities; - -namespace NexusMods.Paths.Tests; - -public class GamePathTests -{ - private readonly InMemoryFileSystem _fileSystem; - - public GamePathTests() - { - _fileSystem = new InMemoryFileSystem(); - } - - [Fact] - public void CanComparePaths() - { - var pathA = new GamePath(GameFolderType.Game, "foo/bar.zip"); - var pathB = new GamePath(GameFolderType.Game, "Foo/bar.zip"); - var pathC = new GamePath(GameFolderType.Preferences, "foo/bar.zip"); - var pathD = new GamePath(GameFolderType.Game, "foo/bar.pex"); - - Assert.Equal(pathA, pathB); - Assert.NotEqual(pathA, pathC); - Assert.NotEqual(pathA, pathD); - - Assert.True(pathA == pathB); - Assert.False(pathA == pathC); - Assert.True(pathA != pathC); - } - - [Fact] - public void CanTreatLikeIPath() - { - var pathA = new GamePath(GameFolderType.Game, "foo/bar.zip"); - var ipath = (IPath)pathA; - - Assert.Equal(KnownExtensions.Zip, ipath.Extension); - Assert.Equal("bar.zip".ToRelativePath(), ipath.FileName); - } - - [Fact] - public void CanGetHashCode() - { - var pathA = new GamePath(GameFolderType.Game, "foo/bar.zip"); - var pathB = new GamePath(GameFolderType.Game, "foo/ba.zip"); - - Assert.Equal(pathA.GetHashCode(), pathA.GetHashCode()); - Assert.NotEqual(pathA.GetHashCode(), pathB.GetHashCode()); - } - - [Fact] - public void CanConvertToString() - { - var pathA = new GamePath(GameFolderType.Game, "foo/bar.zip"); - var pathB = new GamePath(GameFolderType.Saves, "foo/ba.zip"); - Assert.Equal("{Game}/foo/bar.zip", pathA.ToString()); - Assert.Equal("{Saves}/foo/ba.zip", pathB.ToString()); - } - - [Fact] - public void CanGetPathRelativeTo() - { - var baseFolder = _fileSystem.GetKnownPath(KnownPath.CurrentDirectory); - var pathA = new GamePath(GameFolderType.Game, "foo/bar"); - Assert.Equal(baseFolder.Combine("foo/bar"), pathA.Combine(baseFolder)); - } - -}