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 void CreateFile(string path, long size, CreateFileOptions options) { path = PathTools.Normalize(path); if (size == 0) { var emptyFileEntry = new SaveFileInfo { StartBlock = int.MinValue, Length = size }; FileTable.AddFile(path, ref emptyFileEntry); return; } int blockCount = (int)Util.DivideByRoundUp(size, AllocationTable.Header.BlockSize); int startBlock = AllocationTable.Allocate(blockCount); if (startBlock == -1) { ThrowHelper.ThrowResult(ResultFs.AllocationTableInsufficientFreeBlocks, "Not enough available space to create file."); } var fileEntry = new SaveFileInfo { StartBlock = startBlock, Length = size }; FileTable.AddFile(path, ref fileEntry); }
public void AddFile(string path, ref SaveFileInfo fileInfo) { path = PathTools.Normalize(path); ReadOnlySpan <byte> pathBytes = Util.GetUtf8Bytes(path); if (path == "/") { throw new ArgumentException("Path cannot be empty"); } CreateFileRecursive(pathBytes, ref fileInfo); }
public bool TryOpenFile(string path, out SaveFileInfo fileInfo) { FindPathRecursive(Util.GetUtf8Bytes(path), out SaveEntryKey key); if (FileTable.TryGetValue(ref key, out FileSaveEntry value)) { fileInfo = value.Info; return(true); } fileInfo = default; return(false); }
private void CreateFileRecursive(ReadOnlySpan <byte> path, ref SaveFileInfo fileInfo) { var parser = new PathParser(path); var key = new SaveEntryKey(parser.GetCurrent(), 0); int parentIndex = CreateParentDirectoryRecursive(ref parser, ref key); int index = FileTable.GetIndexFromKey(ref key).Index; TableEntry <SaveFileInfo> fileEntry = default; // File already exists. Update file info. if (index >= 0) { FileTable.GetValue(index, out fileEntry); fileEntry.Value = fileInfo; FileTable.SetValue(index, ref fileEntry); return; } fileEntry.Value = fileInfo; index = FileTable.Add(ref key, ref fileEntry); LinkFileToParent(parentIndex, index); }