private int CreateParentDirectoryRecursive(ref PathParser parser, ref SaveEntryKey key)
        {
            int prevIndex = 0;

            while (!parser.IsFinished())
            {
                int index = DirectoryTable.GetIndexFromKey(ref key).Index;

                if (index < 0)
                {
                    var newEntry = new TableEntry <SaveFindPosition>();
                    index = DirectoryTable.Add(ref key, ref newEntry);

                    if (prevIndex > 0)
                    {
                        LinkDirectoryToParent(prevIndex, index);
                    }
                }

                prevIndex  = index;
                key.Parent = index;
                parser.TryGetNext(out key.Name);
            }

            return(prevIndex);
        }
        private bool FindPathRecursive(ReadOnlySpan <byte> path, out SaveEntryKey key)
        {
            var parser = new PathParser(path);

            key = new SaveEntryKey(parser.GetCurrent(), 0);

            while (!parser.IsFinished())
            {
                key.Parent = DirectoryTable.GetIndexFromKey(ref key).Index;

                if (key.Parent < 0)
                {
                    return(false);
                }

                parser.TryGetNext(out key.Name);
            }

            return(true);
        }
        private void CreateDirectoryRecursive(ReadOnlySpan <byte> path)
        {
            var parser = new PathParser(path);
            var key    = new SaveEntryKey(parser.GetCurrent(), 0);

            int parentIndex = CreateParentDirectoryRecursive(ref parser, ref key);

            int index = DirectoryTable.GetIndexFromKey(ref key).Index;
            TableEntry <SaveFindPosition> dirEntry = default;

            // Directory already exists. Do nothing.
            if (index >= 0)
            {
                return;
            }

            index = DirectoryTable.Add(ref key, ref dirEntry);

            LinkDirectoryToParent(parentIndex, index);
        }
        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);
        }
Exemple #5
0
 public (int Index, int PreviousIndex) GetIndexFromKey(ref SaveEntryKey key)
 {
     Span <byte>     entryBytes = stackalloc byte[_sizeOfEntry];
     Span <byte>     name       = entryBytes.Slice(4, MaxNameLength);
     ref SaveFsEntry entry      = ref GetEntryFromBytes(entryBytes);