mirror of
https://github.com/aaru-dps/Aaru.git
synced 2026-07-08 18:16:24 +00:00
[GDFX] Implement directory operations
This commit is contained in:
@@ -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<DecodedEntry> entries)) return ErrorNumber.NoSuchFile;
|
||||
|
||||
node = new GdfxDirNode
|
||||
{
|
||||
Path = normalizedPath,
|
||||
Contents = entries.Select(e => e.Name).ToArray(),
|
||||
Position = 0
|
||||
};
|
||||
|
||||
return ErrorNumber.NoError;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public ErrorNumber CloseDir(IDirNode node) => ErrorNumber.NotImplemented;
|
||||
public ErrorNumber CloseDir(IDirNode node)
|
||||
{
|
||||
if(node is not GdfxDirNode) return ErrorNumber.InvalidArgument;
|
||||
|
||||
return ErrorNumber.NoError;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/// <summary>Resolves a path string to a directory entry in the cache.</summary>
|
||||
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<DecodedEntry> 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;
|
||||
}
|
||||
}
|
||||
62
Aaru.Filesystems/GDFX/Helpers.cs
Normal file
62
Aaru.Filesystems/GDFX/Helpers.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
// /***************************************************************************
|
||||
// Aaru Data Preservation Suite
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : Helpers.cs
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// 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 <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// Copyright © 2011-2026 Natalia Portillo
|
||||
// ****************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Aaru.CommonTypes.Enums;
|
||||
|
||||
namespace Aaru.Filesystems;
|
||||
|
||||
public sealed partial class GDFX
|
||||
{
|
||||
/// <summary>Resolves a path string to a directory entry in the cache.</summary>
|
||||
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<DecodedEntry> 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user