/// <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)); } }
public void CreateDirectory(string path) { string fullPath = GetFullPath(PathTools.Normalize(path)); lock (Locker) { BaseFs.CreateDirectory(fullPath); } }
protected override Result CreateDirectoryImpl(string path) { string fullPath = GetFullPath(PathTools.Normalize(path)); lock (Locker) { return(BaseFs.CreateDirectory(fullPath)); } }
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 DoCreateDirectory(U8Span path) { Unsafe.SkipInit(out FsPath fullPath); Result rc = ResolveFullPath(fullPath.Str, path); if (rc.IsFailure()) { return(rc); } lock (Locker) { return(BaseFs.CreateDirectory(fullPath)); } }
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 DoCreateDirectory(U8Span path) { FsPath fullPath; unsafe { _ = &fullPath; } // workaround for CS0165 Result rc = ResolveFullPath(fullPath.Str, path); if (rc.IsFailure()) { return(rc); } lock (Locker) { return(BaseFs.CreateDirectory(fullPath)); } }
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)); }