protected override Result DoRenameDirectory(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.RenameDirectory(fullCurrentPath, fullNewPath));
            }
        }
Example #2
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));
            }
        }
        public void RenameDirectory(string srcPath, string dstPath)
        {
            string fullSrcPath = GetFullPath(PathTools.Normalize(srcPath));
            string fullDstPath = GetFullPath(PathTools.Normalize(dstPath));

            lock (Locker)
            {
                BaseFs.RenameDirectory(fullSrcPath, fullDstPath);
            }
        }
Example #4
0
        protected override Result RenameDirectoryImpl(string oldPath, string newPath)
        {
            string fullOldPath = GetFullPath(PathTools.Normalize(oldPath));
            string fullNewPath = GetFullPath(PathTools.Normalize(newPath));

            lock (Locker)
            {
                return(BaseFs.RenameDirectory(fullOldPath, fullNewPath));
            }
        }
        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);
        }
        protected override Result DoRenameDirectory(U8Span oldPath, U8Span newPath)
        {
            Unsafe.SkipInit(out FsPath fullCurrentPath);
            Unsafe.SkipInit(out FsPath fullNewPath);

            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.RenameDirectory(fullCurrentPath, fullNewPath));
            }
        }
        private Result Initialize(bool isPersistentSaveData, bool canCommitProvisionally)
        {
            IsPersistentSaveData   = isPersistentSaveData;
            CanCommitProvisionally = canCommitProvisionally;

            // Ensure the working directory exists
            Result rc = BaseFs.GetEntryType(out _, WorkingDirectoryPath);

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

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

                if (!IsPersistentSaveData)
                {
                    return(Result.Success);
                }

                rc = BaseFs.CreateDirectory(CommittedDirectoryPath);

                // Nintendo returns on all failures, but we'll keep going if committed already exists
                // to avoid confusing people manually creating savedata in emulators
                if (rc.IsFailure() && !ResultFs.PathAlreadyExists.Includes(rc))
                {
                    return(rc);
                }
            }

            // Only the working directory is needed for temporary savedata
            if (!IsPersistentSaveData)
            {
                return(Result.Success);
            }

            rc = BaseFs.GetEntryType(out _, CommittedDirectoryPath);

            if (rc.IsSuccess())
            {
                return(SynchronizeDirectory(WorkingDirectoryPath, CommittedDirectoryPath));
            }

            if (!ResultFs.PathNotFound.Includes(rc))
            {
                return(rc);
            }

            // If a previous commit failed, the committed dir may be missing.
            // Finish that commit by copying the working dir to the committed dir

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

            return(BaseFs.RenameDirectory(SynchronizingDirectoryPath, CommittedDirectoryPath));
        }