Exemplo n.º 1
0
        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 = StringUtils.NullTerminatedUtf8ToString(nameBytes);

            return(true);
        }
Exemplo n.º 2
0
        private Result ReadImpl(out long entriesRead, ref SaveFindPosition position, Span <DirectoryEntry> entryBuffer)
        {
            HierarchicalSaveFileTable tab = ParentFileSystem.FileTable;

            int i = 0;

            if (Mode.HasFlag(OpenDirectoryMode.Directory))
            {
                while ((entryBuffer.IsEmpty || i < entryBuffer.Length) && tab.FindNextDirectory(ref position, out string name))
                {
                    if (!entryBuffer.IsEmpty)
                    {
                        ref DirectoryEntry entry    = ref entryBuffer[i];
                        Span <byte>        nameUtf8 = Encoding.UTF8.GetBytes(name);

                        StringUtils.Copy(entry.Name, nameUtf8);
                        entry.Name[64] = 0;

                        entry.Type = DirectoryEntryType.Directory;
                        entry.Size = 0;
                    }

                    i++;
                }
            }
Exemplo n.º 3
0
        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 = StringUtils.NullTerminatedUtf8ToString(nameBytes);

            return(true);
        }
Exemplo n.º 4
0
 public SaveDataDirectory(SaveDataFileSystemCore fs, SaveFindPosition position, OpenDirectoryMode mode)
 {
     ParentFileSystem = fs;
     InitialPosition  = position;
     _currentPosition = position;
     Mode             = mode;
 }
Exemplo n.º 5
0
        public bool TryOpenDirectory(U8Span path, out SaveFindPosition position)
        {
            if (!FindPathRecursive(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);
        }
Exemplo n.º 6
0
        public bool TryOpenDirectory(U8Span path, out SaveFindPosition position)
        {
            UnsafeHelpers.SkipParamInit(out position);

            if (!FindPathRecursive(path, out SaveEntryKey key))
            {
                return(false);
            }

            if (DirectoryTable.TryGetValue(ref key, out TableEntry <SaveFindPosition> entry))
            {
                position = entry.Value;
                return(true);
            }

            return(false);
        }
Exemplo n.º 7
0
        public Result GetEntryCount(out long entryCount)
        {
            SaveFindPosition position = InitialPosition;

            return(ReadImpl(out entryCount, ref position, Span <DirectoryEntry> .Empty));
        }
Exemplo n.º 8
0
        protected override Result DoGetEntryCount(out long entryCount)
        {
            SaveFindPosition position = InitialPosition;

            return(ReadImpl(out entryCount, ref position, Span <DirectoryEntry> .Empty));
        }