From 5b764e487e31fcea54c2ea2438d61fe0447e21b6 Mon Sep 17 00:00:00 2001 From: Alex Barney Date: Mon, 20 May 2019 15:04:11 -0500 Subject: [PATCH] Remove old SaveFsEntry file --- src/LibHac/Fs/Save/SaveFsEntries.cs | 37 ---------- src/LibHac/Fs/Save/SaveFsEntry.cs | 105 ++++++---------------------- 2 files changed, 22 insertions(+), 120 deletions(-) delete mode 100644 src/LibHac/Fs/Save/SaveFsEntries.cs diff --git a/src/LibHac/Fs/Save/SaveFsEntries.cs b/src/LibHac/Fs/Save/SaveFsEntries.cs deleted file mode 100644 index 1a4c14a7..00000000 --- a/src/LibHac/Fs/Save/SaveFsEntries.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System; -using System.Runtime.InteropServices; - -namespace LibHac.Fs.Save -{ - internal ref struct SaveEntryKey - { - public ReadOnlySpan Name; - public int Parent; - - public SaveEntryKey(ReadOnlySpan name, int parent) - { - Name = name; - Parent = parent; - } - } - - [StructLayout(LayoutKind.Sequential, Pack = 1, Size = 0x14)] - public struct SaveFileInfo - { - public int StartBlock; - public long Length; - public long Reserved; - } - - /// - /// Represents the current position when enumerating a directory's contents. - /// - [StructLayout(LayoutKind.Sequential, Pack = 1, Size = 0x14)] - public struct SaveFindPosition - { - /// The ID of the next directory to be enumerated. - public int NextDirectory; - /// The ID of the next file to be enumerated. - public int NextFile; - } -} diff --git a/src/LibHac/Fs/Save/SaveFsEntry.cs b/src/LibHac/Fs/Save/SaveFsEntry.cs index 085b3897..1a4c14a7 100644 --- a/src/LibHac/Fs/Save/SaveFsEntry.cs +++ b/src/LibHac/Fs/Save/SaveFsEntry.cs @@ -1,98 +1,37 @@ -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Text; +using System; +using System.Runtime.InteropServices; namespace LibHac.Fs.Save { - [DebuggerDisplay("{" + nameof(FullPath) + "}")] - public abstract class SaveFsEntry + internal ref struct SaveEntryKey { - public int ParentDirIndex { get; protected set; } - public string Name { get; protected set; } + public ReadOnlySpan Name; + public int Parent; - public string FullPath { get; private set; } - public SaveDirectoryEntry ParentDir { get; internal set; } - - internal static void ResolveFilenames(IEnumerable entries) + public SaveEntryKey(ReadOnlySpan name, int parent) { - var list = new List(); - var sb = new StringBuilder(); - string delimiter = "/"; - foreach (SaveFsEntry file in entries) - { - list.Add(file.Name); - SaveDirectoryEntry dir = file.ParentDir; - while (dir != null) - { - list.Add(delimiter); - list.Add(dir.Name); - dir = dir.ParentDir; - } - - for (int i = list.Count - 1; i >= 0; i--) - { - sb.Append(list[i]); - } - - file.FullPath = sb.Length == 0 ? delimiter : sb.ToString(); - list.Clear(); - sb.Clear(); - } + Name = name; + Parent = parent; } } - public class SaveFileEntry : SaveFsEntry + [StructLayout(LayoutKind.Sequential, Pack = 1, Size = 0x14)] + public struct SaveFileInfo { - public int NextSiblingIndex { get; } - public int BlockIndex { get; } - public long FileSize { get; } - public long Field54 { get; } - public int NextInChainIndex { get; } - - public SaveFileEntry NextSibling { get; internal set; } - public SaveFileEntry NextInChain { get; internal set; } - - public SaveFileEntry(BinaryReader reader) - { - long start = reader.BaseStream.Position; - ParentDirIndex = reader.ReadInt32(); - Name = reader.ReadUtf8Z(0x40); - reader.BaseStream.Position = start + 0x44; - - NextSiblingIndex = reader.ReadInt32(); - BlockIndex = reader.ReadInt32(); - FileSize = reader.ReadInt64(); - Field54 = reader.ReadInt64(); - NextInChainIndex = reader.ReadInt32(); - } + public int StartBlock; + public long Length; + public long Reserved; } - public class SaveDirectoryEntry : SaveFsEntry + /// + /// Represents the current position when enumerating a directory's contents. + /// + [StructLayout(LayoutKind.Sequential, Pack = 1, Size = 0x14)] + public struct SaveFindPosition { - public int NextSiblingIndex { get; } - public int FirstChildIndex { get; } - public long FirstFileIndex { get; } - public long Field54 { get; } - public int NextInChainIndex { get; } - - public SaveDirectoryEntry NextSibling { get; internal set; } - public SaveDirectoryEntry FirstChild { get; internal set; } - public SaveFileEntry FirstFile { get; internal set; } - public SaveDirectoryEntry NextInChain { get; internal set; } - - public SaveDirectoryEntry(BinaryReader reader) - { - long start = reader.BaseStream.Position; - ParentDirIndex = reader.ReadInt32(); - Name = reader.ReadUtf8Z(0x40); - reader.BaseStream.Position = start + 0x44; - - NextSiblingIndex = reader.ReadInt32(); - FirstChildIndex = reader.ReadInt32(); - FirstFileIndex = reader.ReadInt64(); - Field54 = reader.ReadInt64(); - NextInChainIndex = reader.ReadInt32(); - } + /// The ID of the next directory to be enumerated. + public int NextDirectory; + /// The ID of the next file to be enumerated. + public int NextFile; } }