diff --git a/Junctionizer/Model/FolderCollection.cs b/Junctionizer/Model/FolderCollection.cs index 69153b9..d6c6b30 100644 --- a/Junctionizer/Model/FolderCollection.cs +++ b/Junctionizer/Model/FolderCollection.cs @@ -14,7 +14,6 @@ using Junctionizer.Properties; using Microsoft.VisualBasic.FileIO; -using Microsoft.WindowsAPICodePack.Dialogs; using Prism.Commands; using Prism.Mvvm; @@ -112,7 +111,6 @@ public ObservableCollection SelectedItems [NotNull] public IEnumerable AllSelectedGameFolders => SelectedItems.Reverse().Cast().Where(folder => !folder.IsBeingDeleted); - [NotNull] public IEnumerable SelectedFolders => AllSelectedGameFolders.Where(folder => !folder.IsJunction); [NotNull] @@ -194,12 +192,12 @@ private void SetNewLocationImpl(string loc) [AutoLazy.Lazy] public IDelegateListCommand ArchiveSelectedCommand => new DelegateListCommand( () => BothCollectionsInitialized ? SelectedFolders : Enumerable.Empty(), - folder => Archive(folder).Forget()); + folder => ArchiveAsync(folder).Forget()); [AutoLazy.Lazy] public IDelegateListCommand CopySelectedCommand => new DelegateListCommand( () => BothCollectionsInitialized ? SelectedFolders : Enumerable.Empty(), - folder => CorrespondingCollection.CopyFolder(folder)); + folder => CorrespondingCollection.CopyFolderAsync(folder)); [AutoLazy.Lazy] public IDelegateListCommand CreateSelectedJunctionCommand => new DelegateListCommand( @@ -209,7 +207,7 @@ private void SetNewLocationImpl(string loc) [AutoLazy.Lazy] public IDelegateListCommand DeleteSelectedFoldersCommand => new DelegateListCommand( () => SelectedFolders, - selectedFolder => DeleteFolderOrJunction(selectedFolder)); + selectedFolder => DeleteFolderOrJunctionAsync(selectedFolder)); [AutoLazy.Lazy] public IDelegateListCommand DeleteSelectedJunctionsCommand => new DelegateListCommand( @@ -239,9 +237,9 @@ public void SelectUniqueFolders() } [AutoLazy.Lazy] - public DelegateCommand SelectLocationCommand => new DelegateCommand(() => SelectLocation().Forget()); + public DelegateCommand SelectLocationCommand => new DelegateCommand(() => SelectLocationAsync().Forget()); - public async Task SelectLocation() + public async Task SelectLocationAsync() { var directoryInfo = await Dialogs.PromptForDirectory(Resources.SelectLocationCommand_Select_directory_containing_folders, FolderBrowserInitialLocation); if (directoryInfo != null) FolderBrowserInitialLocation = Location = directoryInfo.FullName; @@ -258,7 +256,7 @@ public void RefreshSizes() foreach (var folder in Folders) { - folder.RecalculateSize(); + folder.RecalculateSizeAsync(); } } @@ -268,7 +266,7 @@ private void InitDirectoryWatcher() _directoryWatcher.InternalBufferSize = 40960; _directoryWatcher.Created += (sender, args) => { var newFolder = new GameFolder(args.FullPath); - newFolder.ContinuoslyRecalculateSize().Forget(); + newFolder.ContinuoslyRecalculateSizeAsync().Forget(); Folders.AddAsync(newFolder).Forget(); }; _directoryWatcher.Deleted += (sender, args) => { @@ -295,12 +293,12 @@ public IEnumerable GetFoldersByJunctionTarget([NotNull] DirectoryInf return JunctionTargetsDictionary.TryGetValue(info.FullName, out var enumerable) ? enumerable : Enumerable.Empty(); } - public async Task Archive([NotNull] GameFolder folder) + public async Task ArchiveAsync([NotNull] GameFolder folder) { - var createdFolder = await CorrespondingCollection.CopyFolder(folder); + var createdFolder = await CorrespondingCollection.CopyFolderAsync(folder); if (createdFolder != null) { - var isFolderDeleted = await DeleteFolderOrJunction(folder); + var isFolderDeleted = await DeleteFolderOrJunctionAsync(folder); if (isFolderDeleted) CreateJunctionTo(createdFolder); } } @@ -324,7 +322,7 @@ public void CreateJunctionTo([NotNull] GameFolder junctionTarget) } /// Copies the provided folder to the current directory. Returns the created/overwritten folder only if the copy successfully ran to completion, null otherwise. - public Task CopyFolder([NotNull] GameFolder folderToCopy) + public Task CopyFolderAsync([NotNull] GameFolder folderToCopy) { return Task.Run(() => { string targetDirectory = $@"{Location}\{folderToCopy.Name}"; @@ -347,14 +345,14 @@ public Task CopyFolder([NotNull] GameFolder folderToCopy) else { // Since a new folder isn't being created the file system watcher will not trigger size recalculation, so we do it here - overwrittenFolder.ContinuoslyRecalculateSize().Forget(); + overwrittenFolder.ContinuoslyRecalculateSizeAsync().Forget(); } } FileSystem.CopyDirectory(folderToCopy.DirectoryInfo.FullName, targetDirectory, UIOption.AllDialogs); var createdFolder = GetFolderByName(targetDirectoryInfo.Name); // Send a final recalculation request in case the user had previously paused the operation, or if there was a pause while answering the prompt for replacing vs skipping duplicate files. - createdFolder.RecalculateSize(); + createdFolder.RecalculateSizeAsync(); return createdFolder; } catch (OperationCanceledException e) @@ -362,7 +360,7 @@ public Task CopyFolder([NotNull] GameFolder folderToCopy) Debug.WriteLine(e); // If the user cancels the folder will still be partially copied var createdFolder = GetFolderByName(targetDirectoryInfo.Name); - createdFolder.RecalculateSize(); + createdFolder.RecalculateSizeAsync(); return null; } catch (IOException e) @@ -374,7 +372,7 @@ public Task CopyFolder([NotNull] GameFolder folderToCopy) } /// Returns true on successful delete, false if user cancels operation or there is an error. - public Task DeleteFolderOrJunction([NotNull] GameFolder folderToDelete) + public Task DeleteFolderOrJunctionAsync([NotNull] GameFolder folderToDelete) { folderToDelete.IsBeingDeleted = true; return Task.Run(() => { diff --git a/Junctionizer/Model/GameFolder.cs b/Junctionizer/Model/GameFolder.cs index 7fc3c8d..9dab285 100644 --- a/Junctionizer/Model/GameFolder.cs +++ b/Junctionizer/Model/GameFolder.cs @@ -35,7 +35,7 @@ public GameFolder([NotNull] DirectoryInfo directory) JunctionTarget = JunctionPoint.GetTarget(directory); } - UpdatePropertiesFromSubdirectories().Forget(); + UpdatePropertiesFromSubdirectoriesAsync().Forget(); } [NotNull] @@ -61,7 +61,7 @@ public GameFolder([NotNull] DirectoryInfo directory) public void CancelSubdirectorySearch() => SafeCancelTokenSource(_propertyUpdateTokenSource); - private async Task UpdatePropertiesFromSubdirectories() + private async Task UpdatePropertiesFromSubdirectoriesAsync() { using (var tokenSource = new CancellationTokenSource()) { @@ -123,11 +123,11 @@ private void SearchSubdirectories(CancellationToken cancellationToken) } } - public Task RecalculateSize() => UpdatePropertiesFromSubdirectories(); + public Task RecalculateSizeAsync() => UpdatePropertiesFromSubdirectoriesAsync(); - /// Periodically calls until it is determined that the size is not longer changing. + /// Periodically calls until it is determined that the size is not longer changing. /// - public async Task ContinuoslyRecalculateSize() + public async Task ContinuoslyRecalculateSizeAsync() { IsContinuoslyRecalculating = true; long? oldSize; @@ -137,7 +137,7 @@ public async Task ContinuoslyRecalculateSize() Debug.WriteLine($"{DirectoryInfo.FullName} oldSize {oldSize} Size {Size}"); await Task.Delay(1500); - await UpdatePropertiesFromSubdirectories(); + await UpdatePropertiesFromSubdirectoriesAsync(); } while (Size != oldSize); IsContinuoslyRecalculating = false; diff --git a/Junctionizer/Model/GameFolderPairEnumerable.cs b/Junctionizer/Model/GameFolderPairEnumerable.cs index a5a1b6d..bf5fdf5 100644 --- a/Junctionizer/Model/GameFolderPairEnumerable.cs +++ b/Junctionizer/Model/GameFolderPairEnumerable.cs @@ -174,8 +174,8 @@ private List RemoveItems(IEnumerable folders, bool i private void Delete(GameFolderPair pair) { - if (pair.SourceEntry != null) SourceCollection.DeleteFolderOrJunction(pair.SourceEntry); - if (pair.DestinationEntry != null) DestinationCollection.DeleteFolderOrJunction(pair.DestinationEntry); + if (pair.SourceEntry != null) SourceCollection.DeleteFolderOrJunctionAsync(pair.SourceEntry); + if (pair.DestinationEntry != null) DestinationCollection.DeleteFolderOrJunctionAsync(pair.DestinationEntry); } @@ -188,7 +188,7 @@ private void Delete(GameFolderPair pair) private async Task ArchiveAsync(GameFolderPair pair) { - if (pair.SourceEntry != null) await SourceCollection.Archive(pair.SourceEntry); + if (pair.SourceEntry != null) await SourceCollection.ArchiveAsync(pair.SourceEntry); else if (pair.DestinationEntry?.IsJunction == false) SourceCollection.CreateJunctionTo(pair.DestinationEntry); } @@ -203,8 +203,8 @@ private async Task RestoreAsync(GameFolderPair gameFolderPair) { Debug.Assert(gameFolderPair.DestinationEntry?.IsJunction == false); - var createdFolder = await SourceCollection.CopyFolder(gameFolderPair.DestinationEntry); - if (createdFolder != null) await DestinationCollection.DeleteFolderOrJunction(gameFolderPair.DestinationEntry); + var createdFolder = await SourceCollection.CopyFolderAsync(gameFolderPair.DestinationEntry); + if (createdFolder != null) await DestinationCollection.DeleteFolderOrJunctionAsync(gameFolderPair.DestinationEntry); } @@ -221,12 +221,12 @@ private async Task MirrorAsync(GameFolderPair gameFolderPair) if (gameFolderPair.DestinationEntry?.IsJunction == false) { - await SourceCollection.CopyFolder(gameFolderPair.DestinationEntry); + await SourceCollection.CopyFolderAsync(gameFolderPair.DestinationEntry); } else { Debug.Assert(gameFolderPair.SourceEntry != null); - await DestinationCollection.CopyFolder(gameFolderPair.SourceEntry); + await DestinationCollection.CopyFolderAsync(gameFolderPair.SourceEntry); } } }