diff --git a/Aaru.Filesystems/GDFX/Dir.cs b/Aaru.Filesystems/GDFX/Dir.cs index 08c09f95c..daef87139 100644 --- a/Aaru.Filesystems/GDFX/Dir.cs +++ b/Aaru.Filesystems/GDFX/Dir.cs @@ -27,10 +27,11 @@ // ****************************************************************************/ using System.Collections.Generic; +using System.Linq; using Aaru.CommonTypes.Enums; using Aaru.CommonTypes.Interfaces; -using Aaru.Helpers; using Aaru.Logging; +using Marshal = Aaru.Helpers.Marshal; namespace Aaru.Filesystems; @@ -41,18 +42,48 @@ public sealed partial class GDFX { node = null; - return ErrorNumber.NotImplemented; + if(!_mounted) return ErrorNumber.AccessDenied; + + string normalizedPath = string.IsNullOrEmpty(path) + ? "/" + : path.StartsWith('/') + ? path + : "/" + path; + + if(!_directoryCache.TryGetValue(normalizedPath, out List entries)) return ErrorNumber.NoSuchFile; + + node = new GdfxDirNode + { + Path = normalizedPath, + Contents = entries.Select(e => e.Name).ToArray(), + Position = 0 + }; + + return ErrorNumber.NoError; } /// - public ErrorNumber CloseDir(IDirNode node) => ErrorNumber.NotImplemented; + public ErrorNumber CloseDir(IDirNode node) + { + if(node is not GdfxDirNode) return ErrorNumber.InvalidArgument; + + return ErrorNumber.NoError; + } /// public ErrorNumber ReadDir(IDirNode node, out string filename) { filename = null; - return ErrorNumber.NotImplemented; + if(!_mounted) return ErrorNumber.AccessDenied; + + if(node is not GdfxDirNode dirNode) return ErrorNumber.InvalidArgument; + + if(dirNode.Position >= dirNode.Contents.Length) return ErrorNumber.NoError; + + filename = dirNode.Contents[dirNode.Position++]; + + return ErrorNumber.NoError; } /// diff --git a/Aaru.Filesystems/GDFX/File.cs b/Aaru.Filesystems/GDFX/File.cs index e9dda7613..7880b6750 100644 --- a/Aaru.Filesystems/GDFX/File.cs +++ b/Aaru.Filesystems/GDFX/File.cs @@ -27,7 +27,6 @@ // ****************************************************************************/ using System; -using System.Collections.Generic; using Aaru.CommonTypes.Enums; using Aaru.CommonTypes.Interfaces; using Aaru.CommonTypes.Structs; @@ -155,30 +154,4 @@ public sealed partial class GDFX return ErrorNumber.NoError; } - - /// Resolves a path string to a directory entry in the cache. - ErrorNumber ResolveEntry(string path, out DecodedEntry entry) - { - entry = null; - - string[] parts = path.Split(['/'], StringSplitOptions.RemoveEmptyEntries); - - if(parts.Length == 0) return ErrorNumber.InvalidArgument; - - string dirPath = parts.Length == 1 ? "/" : "/" + string.Join("/", parts[..^1]); - string fileName = parts[^1]; - - if(!_directoryCache.TryGetValue(dirPath, out List dirEntries)) return ErrorNumber.NoSuchFile; - - foreach(DecodedEntry e in dirEntries) - { - if(!string.Equals(e.Name, fileName, StringComparison.OrdinalIgnoreCase)) continue; - - entry = e; - - return ErrorNumber.NoError; - } - - return ErrorNumber.NoSuchFile; - } } \ No newline at end of file diff --git a/Aaru.Filesystems/GDFX/Helpers.cs b/Aaru.Filesystems/GDFX/Helpers.cs new file mode 100644 index 000000000..3bab9d64a --- /dev/null +++ b/Aaru.Filesystems/GDFX/Helpers.cs @@ -0,0 +1,62 @@ +// /*************************************************************************** +// Aaru Data Preservation Suite +// ---------------------------------------------------------------------------- +// +// Filename : Helpers.cs +// Author(s) : Natalia Portillo +// +// Component : Microsoft Xbox DVD File System plugin. +// +// --[ License ] -------------------------------------------------------------- +// +// This library is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 2.1 of the +// License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, see . +// +// ---------------------------------------------------------------------------- +// Copyright © 2011-2026 Natalia Portillo +// ****************************************************************************/ + +using System; +using System.Collections.Generic; +using Aaru.CommonTypes.Enums; + +namespace Aaru.Filesystems; + +public sealed partial class GDFX +{ + /// Resolves a path string to a directory entry in the cache. + ErrorNumber ResolveEntry(string path, out DecodedEntry entry) + { + entry = null; + + string[] parts = path.Split(['/'], StringSplitOptions.RemoveEmptyEntries); + + if(parts.Length == 0) return ErrorNumber.InvalidArgument; + + string dirPath = parts.Length == 1 ? "/" : "/" + string.Join("/", parts[..^1]); + string fileName = parts[^1]; + + if(!_directoryCache.TryGetValue(dirPath, out List dirEntries)) return ErrorNumber.NoSuchFile; + + foreach(DecodedEntry e in dirEntries) + { + if(!string.Equals(e.Name, fileName, StringComparison.OrdinalIgnoreCase)) continue; + + entry = e; + + return ErrorNumber.NoError; + } + + return ErrorNumber.NoSuchFile; + } +} \ No newline at end of file