Esempio n. 1
0
        protected override Result CommitImpl()
        {
            lock (Locker)
            {
                if (!IsPersistentSaveData)
                {
                    return(Result.Success);
                }

                if (OpenWritableFileCount > 0)
                {
                    // All files must be closed before commiting save data.
                    return(ResultFs.WriteModeFileNotClosed.Log());
                }

                // Get rid of the previous commit by renaming the folder
                Result rc = BaseFs.RenameDirectory(CommittedDirectoryPath, SynchronizingDirectoryPath);
                if (rc.IsFailure())
                {
                    return(rc);
                }

                // If something goes wrong beyond this point, the commit will be
                // completed the next time the savedata is opened

                rc = SynchronizeDirectory(SynchronizingDirectoryPath, WorkingDirectoryPath);
                if (rc.IsFailure())
                {
                    return(rc);
                }

                return(BaseFs.RenameDirectory(SynchronizingDirectoryPath, CommittedDirectoryPath));
            }
        }
Esempio n. 2
0
        protected override Result DoGetTotalSpaceSize(out long totalSpace, U8Span path)
        {
            return(BaseFs.GetTotalSpaceSize(out totalSpace, path));

            // FS does:
            // return ResultFs.UnsupportedOperationReadOnlyFileSystemGetSpace.Log();
        }
        protected override Result DoRenameFile(U8Span oldPath, U8Span newPath)
        {
            FsPath fullCurrentPath;
            FsPath fullNewPath;

            unsafe { _ = &fullCurrentPath; } // workaround for CS0165
            unsafe { _ = &fullNewPath; }     // workaround for CS0165

            Result rc = ResolveFullPath(fullCurrentPath.Str, oldPath);

            if (rc.IsFailure())
            {
                return(rc);
            }

            rc = ResolveFullPath(fullNewPath.Str, newPath);
            if (rc.IsFailure())
            {
                return(rc);
            }

            lock (Locker)
            {
                return(BaseFs.RenameFile(fullCurrentPath, fullNewPath));
            }
        }
Esempio n. 4
0
        protected override Result DoGetFileTimeStampRaw(out FileTimeStampRaw timeStamp, U8Span path)
        {
            return(BaseFs.GetFileTimeStampRaw(out timeStamp, path));

            // FS does:
            // return ResultFs.NotImplemented.Log();
        }
        /// <summary>
        /// Creates the destination directory if needed and copies the source directory to it.
        /// </summary>
        /// <param name="destPath">The path of the destination directory.</param>
        /// <param name="sourcePath">The path of the source directory.</param>
        /// <returns>The <see cref="Result"/> of the operation.</returns>
        private Result SynchronizeDirectory(U8Span destPath, U8Span sourcePath)
        {
            // Delete destination dir and recreate it.
            Result rc = BaseFs.DeleteDirectoryRecursively(destPath);

            // Nintendo returns error unconditionally because SynchronizeDirectory is always called in situations
            // where a PathNotFound error would mean the save directory was in an invalid state.
            // We'll ignore PathNotFound errors to be more user-friendly to users who might accidentally
            // put the save directory in an invalid state.
            if (rc.IsFailure() && !ResultFs.PathNotFound.Includes(rc))
            {
                return(rc);
            }

            rc = BaseFs.CreateDirectory(destPath);
            if (rc.IsFailure())
            {
                return(rc);
            }

            // Get a work buffer to work with.
            using (var buffer = new RentedArray <byte>(IdealWorkBufferSize))
            {
                return(Utility.CopyDirectoryRecursively(BaseFs, destPath, sourcePath, buffer.Span));
            }
        }
Esempio n. 6
0
        protected override Result GetEntryTypeImpl(out DirectoryEntryType entryType, string path)
        {
            string fullPath = GetFullPath(PathTools.Normalize(path));

            lock (Locker)
            {
                return(BaseFs.GetEntryType(out entryType, fullPath));
            }
        }
Esempio n. 7
0
        protected override Result OpenDirectoryImpl(out IDirectory directory, string path, OpenDirectoryMode mode)
        {
            string fullPath = GetFullPath(PathTools.Normalize(path));

            lock (Locker)
            {
                return(BaseFs.OpenDirectory(out directory, fullPath, mode));
            }
        }
Esempio n. 8
0
        protected override Result DeleteFileImpl(string path)
        {
            string fullPath = GetFullPath(PathTools.Normalize(path));

            lock (Locker)
            {
                return(BaseFs.DeleteFile(fullPath));
            }
        }
Esempio n. 9
0
        protected override Result CleanDirectoryRecursivelyImpl(string path)
        {
            string fullPath = GetFullPath(PathTools.Normalize(path));

            lock (Locker)
            {
                return(BaseFs.CleanDirectoryRecursively(fullPath));
            }
        }
Esempio n. 10
0
        protected override Result CreateDirectoryImpl(string path)
        {
            string fullPath = GetFullPath(PathTools.Normalize(path));

            lock (Locker)
            {
                return(BaseFs.CreateDirectory(fullPath));
            }
        }
Esempio n. 11
0
        public void DeleteFile(string path)
        {
            string fullPath = GetFullPath(PathTools.Normalize(path));

            lock (Locker)
            {
                BaseFs.DeleteFile(fullPath);
            }
        }
Esempio n. 12
0
        public DirectoryEntryType GetEntryType(string path)
        {
            string fullPath = GetFullPath(PathTools.Normalize(path));

            lock (Locker)
            {
                return(BaseFs.GetEntryType(fullPath));
            }
        }
Esempio n. 13
0
        public void CleanDirectoryRecursively(string path)
        {
            string fullPath = GetFullPath(PathTools.Normalize(path));

            lock (Locker)
            {
                BaseFs.CleanDirectoryRecursively(fullPath);
            }
        }
Esempio n. 14
0
        public void CreateDirectory(string path)
        {
            string fullPath = GetFullPath(PathTools.Normalize(path));

            lock (Locker)
            {
                BaseFs.CreateDirectory(fullPath);
            }
        }
Esempio n. 15
0
        public void CreateFile(string path, long size, CreateFileOptions options)
        {
            string fullPath = GetFullPath(PathTools.Normalize(path));

            lock (Locker)
            {
                BaseFs.CreateFile(fullPath, size, options);
            }
        }
Esempio n. 16
0
        public bool FileExists(string path)
        {
            string fullPath = GetFullPath(PathTools.Normalize(path));

            lock (Locker)
            {
                return(BaseFs.FileExists(fullPath));
            }
        }
Esempio n. 17
0
        public IDirectory OpenDirectory(string path, OpenDirectoryMode mode)
        {
            string fullPath = GetFullPath(PathTools.Normalize(path));

            lock (Locker)
            {
                return(BaseFs.OpenDirectory(fullPath, mode));
            }
        }
Esempio n. 18
0
        protected override Result CreateFileImpl(string path, long size, CreateFileOptions options)
        {
            string fullPath = GetFullPath(PathTools.Normalize(path));

            lock (Locker)
            {
                return(BaseFs.CreateFile(fullPath, size, options));
            }
        }
Esempio n. 19
0
        public void RenameFile(string srcPath, string dstPath)
        {
            string fullSrcPath = GetFullPath(PathTools.Normalize(srcPath));
            string fullDstPath = GetFullPath(PathTools.Normalize(dstPath));

            lock (Locker)
            {
                BaseFs.RenameFile(fullSrcPath, fullDstPath);
            }
        }
Esempio n. 20
0
        protected override Result RenameFileImpl(string oldPath, string newPath)
        {
            string fullOldPath = GetFullPath(PathTools.Normalize(oldPath));
            string fullNewPath = GetFullPath(PathTools.Normalize(newPath));

            lock (Locker)
            {
                return(BaseFs.RenameFile(fullOldPath, fullNewPath));
            }
        }
Esempio n. 21
0
        public void Commit()
        {
            if (OpenWritableFileCount > 0)
            {
                throw new InvalidOperationException("All files must be closed before commiting save data.");
            }

            SynchronizeDirectory(SyncDir, WorkingDir);

            BaseFs.DeleteDirectoryRecursively(CommittedDir);

            BaseFs.RenameDirectory(SyncDir, CommittedDir);
        }
Esempio n. 22
0
        private void SynchronizeDirectory(string dest, string src)
        {
            if (BaseFs.DirectoryExists(dest))
            {
                BaseFs.DeleteDirectoryRecursively(dest);
            }

            BaseFs.CreateDirectory(dest);

            IDirectory sourceDir = BaseFs.OpenDirectory(src, OpenDirectoryMode.All);
            IDirectory destDir   = BaseFs.OpenDirectory(dest, OpenDirectoryMode.All);

            sourceDir.CopyDirectory(destDir);
        }
        protected override Result DoCreateFile(U8Span path, long size, CreateFileOptions options)
        {
            Unsafe.SkipInit(out FsPath fullPath);

            Result rc = ResolveFullPath(fullPath.Str, path);

            if (rc.IsFailure())
            {
                return(rc);
            }

            lock (Locker)
            {
                return(BaseFs.CreateFile(fullPath, size, options));
            }
        }
        protected override Result DoDeleteFile(U8Span path)
        {
            Unsafe.SkipInit(out FsPath fullPath);

            Result rc = ResolveFullPath(fullPath.Str, path);

            if (rc.IsFailure())
            {
                return(rc);
            }

            lock (Locker)
            {
                return(BaseFs.DeleteFile(fullPath));
            }
        }
        protected override Result DoCleanDirectoryRecursively(U8Span path)
        {
            Unsafe.SkipInit(out FsPath fullPath);

            Result rc = ResolveFullPath(fullPath.Str, path);

            if (rc.IsFailure())
            {
                return(rc);
            }

            lock (Locker)
            {
                return(BaseFs.CleanDirectoryRecursively(fullPath));
            }
        }
Esempio n. 26
0
        public IFile OpenFile(string path, OpenMode mode)
        {
            string fullPath = GetFullPath(PathTools.Normalize(path));

            lock (Locker)
            {
                IFile baseFile = BaseFs.OpenFile(fullPath, mode);
                var   file     = new DirectorySaveDataFile(this, baseFile);

                if (mode.HasFlag(OpenMode.Write))
                {
                    OpenWritableFileCount++;
                }

                return(file);
            }
        }
        protected override Result DoOpenDirectory(out IDirectory directory, U8Span path, OpenDirectoryMode mode)
        {
            Unsafe.SkipInit(out FsPath fullPath);

            Result rc = ResolveFullPath(fullPath.Str, path);

            if (rc.IsFailure())
            {
                UnsafeHelpers.SkipParamInit(out directory);
                return(rc);
            }

            lock (Locker)
            {
                return(BaseFs.OpenDirectory(out directory, fullPath, mode));
            }
        }
        protected override Result DoGetEntryType(out DirectoryEntryType entryType, U8Span path)
        {
            Unsafe.SkipInit(out FsPath fullPath);

            Result rc = ResolveFullPath(fullPath.Str, path);

            if (rc.IsFailure())
            {
                UnsafeHelpers.SkipParamInit(out entryType);
                return(rc);
            }

            lock (Locker)
            {
                return(BaseFs.GetEntryType(out entryType, fullPath));
            }
        }
Esempio n. 29
0
        private Result SynchronizeDirectory(string dest, string src)
        {
            Result rc = BaseFs.DeleteDirectoryRecursively(dest);

            if (rc.IsFailure() && rc != ResultFs.PathNotFound)
            {
                return(rc);
            }

            rc = BaseFs.CreateDirectory(dest);
            if (rc.IsFailure())
            {
                return(rc);
            }

            return(BaseFs.CopyDirectory(BaseFs, src, dest));
        }
        protected override Result DoDeleteFile(U8Span path)
        {
            FsPath fullPath;

            unsafe { _ = &fullPath; } // workaround for CS0165

            Result rc = ResolveFullPath(fullPath.Str, path);

            if (rc.IsFailure())
            {
                return(rc);
            }

            lock (Locker)
            {
                return(BaseFs.DeleteFile(fullPath));
            }
        }