public int GetEntryCount() { int count = 0; SaveFindPosition position = InitialPosition; HierarchicalSaveFileTable tab = ParentFileSystem.FileTable; if (Mode.HasFlag(OpenDirectoryMode.Directories)) { while (tab.FindNextDirectory(ref position, out string _)) { count++; } } if (Mode.HasFlag(OpenDirectoryMode.Files)) { while (tab.FindNextFile(ref position, out SaveFileInfo _, out string _)) { count++; } } return(count); }
public SaveDataDirectory(SaveDataFileSystemCore fs, string path, SaveFindPosition position, OpenDirectoryMode mode) { ParentFileSystem = fs; InitialPosition = position; FullPath = path; Mode = mode; }
public bool FindNextDirectory(ref SaveFindPosition position, out string name) { if (position.NextDirectory == 0) { name = default; return(false); } Span <byte> nameBytes = stackalloc byte[DirectoryTable.MaxNameLength]; bool success = DirectoryTable.TryGetValue(position.NextDirectory, out TableEntry <SaveFindPosition> entry, ref nameBytes); // todo error message if (!success) { name = default; return(false); } position.NextDirectory = entry.NextSibling; name = Util.GetUtf8StringNullTerminated(nameBytes); return(true); }
public bool FindNextFile(ref SaveFindPosition position, out SaveFileInfo info, out string name) { if (position.NextFile == 0) { info = default; name = default; return(false); } Span <byte> nameBytes = stackalloc byte[FileTable.MaxNameLength]; bool success = FileTable.TryGetValue(position.NextFile, out TableEntry <SaveFileInfo> entry, ref nameBytes); // todo error message if (!success) { info = default; name = default; return(false); } position.NextFile = entry.NextSibling; info = entry.Value; name = Util.GetUtf8StringNullTerminated(nameBytes); return(true); }
public bool TryOpenDirectory(string path, out SaveFindPosition position) { if (!FindPathRecursive(Util.GetUtf8Bytes(path), out SaveEntryKey key)) { position = default; return(false); } if (DirectoryTable.TryGetValue(ref key, out TableEntry <SaveFindPosition> entry)) { position = entry.Value; return(true); } position = default; return(false); }
public IEnumerable <DirectoryEntry> Read() { SaveFindPosition position = InitialPosition; HierarchicalSaveFileTable tab = ParentFileSystem.FileTable; if (Mode.HasFlag(OpenDirectoryMode.Directories)) { while (tab.FindNextDirectory(ref position, out string name)) { yield return(new DirectoryEntry(name, PathTools.Combine(FullPath, name), DirectoryEntryType.Directory, 0)); } } if (Mode.HasFlag(OpenDirectoryMode.Files)) { while (tab.FindNextFile(ref position, out SaveFileInfo info, out string name)) { yield return(new DirectoryEntry(name, PathTools.Combine(FullPath, name), DirectoryEntryType.File, info.Length)); } } }