public async Task <ReturnResult> RestoreItemsFromTrashAsync(IEnumerable <IStorageItemWithPath> source, IEnumerable <string> destination, bool registerHistory) { source = await source.ToListAsync(); destination = await destination.ToListAsync(); var returnStatus = ReturnResult.InProgress; var errorCode = new Progress <FileSystemStatusCode>(); errorCode.ProgressChanged += (s, e) => returnStatus = returnStatus < ReturnResult.Failed ? e.ToStatus() : returnStatus; var sw = new Stopwatch(); sw.Start(); IStorageHistory history = await filesystemOperations.RestoreItemsFromTrashAsync((IList <IStorageItemWithPath>) source, (IList <string>) destination, null, errorCode, cancellationToken); await Task.Yield(); if (registerHistory && source.Any((item) => !string.IsNullOrWhiteSpace(item.Path))) { App.HistoryWrapper.AddHistory(history); } int itemsMoved = history?.Source.Count() ?? 0; sw.Stop(); return(returnStatus); }
public async Task <IStorageHistory> MoveAsync(IStorageItemWithPath source, string destination, IProgress <float> progress, IProgress <FilesystemErrorCode> errorCode, CancellationToken cancellationToken) { if (source.Path == destination) { progress?.Report(100.0f); errorCode?.Report(FilesystemErrorCode.ERROR_SUCCESS); return(null); } IStorageHistory history = await CopyAsync(source, destination, progress, errorCode, cancellationToken); if (history == null) { // If copy was not performed we don't continue to delete to prevent data loss return(null); } if (string.IsNullOrWhiteSpace(source.Path)) { // Can't move (only copy) files from MTP devices because: // StorageItems returned in DataPackageView are read-only // The item.Path property will be empty and there's no way of retrieving a new StorageItem with R/W access errorCode?.Report(FilesystemErrorCode.ERROR_SUCCESS | FilesystemErrorCode.ERROR_INPROGRESS); } await DeleteAsync(source, progress, errorCode, true, cancellationToken); progress?.Report(100.0f); return(new StorageHistory(FileOperationType.Move, history.Source, history.Destination)); }
public void RemoveHistory(IStorageHistory history) { if (history != null) { this.storageHistory?.Remove(history); this.storageHistoryIndex--; } }
public void AddHistory(IStorageHistory history) { if (history != null) { this.storageHistory?.Add(history); if (this.storageHistory?.Count > 1) { this.storageHistoryIndex++; } } }
public void AddHistory(IStorageHistory history) { if (history != null) { this.storageHistoryIndex++; this.storageHistory.Insert(this.storageHistoryIndex, history); // If a history item is added also remove all the redo operations after it for (var idx = this.storageHistory.Count - 1; idx > this.storageHistoryIndex; idx--) { this.storageHistory.RemoveAt(idx); } } }
public async Task <ReturnResult> RenameAsync(PathWithType source, string newName, NameCollisionOption collision, bool registerHistory) { FilesystemErrorCode returnCode = FilesystemErrorCode.ERROR_INPROGRESS; Progress <FilesystemErrorCode> errorCode = new Progress <FilesystemErrorCode>(); errorCode.ProgressChanged += (s, e) => returnCode = e; IStorageHistory history = await filesystemOperations.RenameAsync(source, newName, collision, errorCode, cancellationToken); if (registerHistory && !string.IsNullOrWhiteSpace(source.Path)) { App.HistoryWrapper.AddHistory(history); } return(returnCode.ToStatus()); }
public void RemoveHistory(IStorageHistory history, bool decreaseIndex) { if (history != null) { // If a history item is invalid also remove all the redo operations after it for (var idx = this.storageHistory.Count - 1; idx > this.storageHistoryIndex; idx--) { this.storageHistory.RemoveAt(idx); } if (decreaseIndex) { this.storageHistoryIndex--; } this.storageHistory.Remove(history); } }
public async Task <ReturnResult> CreateAsync(IStorageItemWithPath source, bool registerHistory) { FilesystemErrorCode returnCode = FilesystemErrorCode.ERROR_INPROGRESS; Progress <FilesystemErrorCode> errorCode = new Progress <FilesystemErrorCode>(); errorCode.ProgressChanged += (s, e) => returnCode = e; IStorageHistory history = await filesystemOperations.CreateAsync(source, errorCode, cancellationToken); if (registerHistory && !string.IsNullOrWhiteSpace(source.Path)) { App.HistoryWrapper.AddHistory(history); } return(returnCode.ToStatus()); }
public async Task <ReturnResult> RestoreFromTrashAsync(IStorageItemWithPath source, string destination, bool registerHistory) { var returnCode = FileSystemStatusCode.InProgress; var errorCode = new Progress <FileSystemStatusCode>(); errorCode.ProgressChanged += (s, e) => returnCode = e; IStorageHistory history = await filesystemOperations.RestoreFromTrashAsync(source, destination, null, errorCode, cancellationToken); if (registerHistory && !string.IsNullOrWhiteSpace(source.Path)) { App.HistoryWrapper.AddHistory(history); } return(returnCode.ToStatus()); }
public async Task <ReturnResult> MoveItemAsync(PathWithType source, string destination, bool registerHistory) { PostedStatusBanner banner = associatedInstance.BottomStatusStripControl.OngoingTasksControl.PostBanner( string.Empty, associatedInstance.FilesystemViewModel.WorkingDirectory, 0, ReturnResult.InProgress, FileOperationType.Move); ReturnResult returnStatus = ReturnResult.InProgress; banner.ErrorCode.ProgressChanged += (s, e) => returnStatus = e.ToStatus(); Stopwatch sw = new Stopwatch(); sw.Start(); associatedInstance.ContentPage.ClearSelection(); IStorageHistory history = await filesystemOperations.MoveAsync(source, destination, banner.Progress, banner.ErrorCode, cancellationToken); if (registerHistory && !string.IsNullOrWhiteSpace(source.Path)) { App.HistoryWrapper.AddHistory(history); } banner.Remove(); sw.Stop(); if (sw.Elapsed.TotalSeconds >= 10) { associatedInstance.BottomStatusStripControl.OngoingTasksControl.PostBanner( "Move Complete", "The operation has completed.", 0, ReturnResult.Success, FileOperationType.Move); } return(returnStatus); }
public async Task <ReturnResult> DeleteItemsAsync(IEnumerable <IStorageItemWithPath> source, bool showDialog, bool permanently, bool registerHistory) { source = await source.ToListAsync(); var returnStatus = ReturnResult.InProgress; var deleteFromRecycleBin = source.Select(item => item.Path).Any(path => recycleBinHelpers.IsPathUnderRecycleBin(path)); var canBeSentToBin = !deleteFromRecycleBin && await recycleBinHelpers.HasRecycleBin(source.FirstOrDefault()?.Path); if (((!permanently && !canBeSentToBin) || UserSettingsService.PreferencesSettingsService.ShowConfirmDeleteDialog) && showDialog) // Check if the setting to show a confirmation dialog is on { List <FilesystemItemsOperationItemModel> incomingItems = new List <FilesystemItemsOperationItemModel>(); foreach (var src in source) { if (recycleBinHelpers.IsPathUnderRecycleBin(src.Path)) { var binItems = associatedInstance.FilesystemViewModel.FilesAndFolders; var matchingItem = binItems.FirstOrDefault(x => x.ItemPath == src.Path); // Get original file name incomingItems.Add(new FilesystemItemsOperationItemModel(FilesystemOperationType.Delete, src.Path, null, matchingItem?.ItemName)); } else { incomingItems.Add(new FilesystemItemsOperationItemModel(FilesystemOperationType.Delete, src.Path, null)); } } var dialog = FilesystemOperationDialogViewModel.GetDialog(new FilesystemItemsOperationDataModel( FilesystemOperationType.Delete, false, canBeSentToBin ? permanently : true, canBeSentToBin, incomingItems, new List <FilesystemItemsOperationItemModel>())); if (await dialog.TryShowAsync() != DialogResult.Primary) { return(ReturnResult.Cancelled); // Return if the result isn't delete } // Delete selected items if the result is Yes permanently = dialog.ViewModel.PermanentlyDelete; } // post the status banner var banner = PostBannerHelpers.PostBanner_Delete(source, returnStatus, permanently, false, 0); banner.ErrorCode.ProgressChanged += (s, e) => returnStatus = e.ToStatus(); var token = banner.CancellationToken; var sw = new Stopwatch(); sw.Start(); IStorageHistory history = await filesystemOperations.DeleteItemsAsync((IList <IStorageItemWithPath>) source, banner.Progress, banner.ErrorCode, permanently, token); ((IProgress <float>)banner.Progress).Report(100.0f); await Task.Yield(); if (!permanently && registerHistory) { App.HistoryWrapper.AddHistory(history); } var itemsDeleted = history?.Source.Count() ?? 0; source.ForEach(x => App.JumpList.RemoveFolder(x.Path)); // Remove items from jump list banner.Remove(); sw.Stop(); PostBannerHelpers.PostBanner_Delete(source, returnStatus, permanently, token.IsCancellationRequested, itemsDeleted); return(returnStatus); }
public async Task <ReturnResult> DeleteItemAsync(IStorageItem source, bool showDialog, bool permanently, bool registerHistory) { try { PostedStatusBanner banner; bool deleteFromRecycleBin = recycleBinHelpers.IsPathUnderRecycleBin(source.Path); if (deleteFromRecycleBin) { permanently = true; } if (permanently) { banner = associatedInstance.StatusCenterActions.PostBanner(string.Empty, associatedInstance.FilesystemViewModel.WorkingDirectory, 0, ReturnResult.InProgress, FileOperationType.Delete); } else { banner = associatedInstance.StatusCenterActions.PostBanner(string.Empty, associatedInstance.FilesystemViewModel.WorkingDirectory, 0, ReturnResult.InProgress, FileOperationType.Recycle); } var returnStatus = ReturnResult.InProgress; banner.ErrorCode.ProgressChanged += (s, e) => returnStatus = e.ToStatus(); if (App.AppSettings.ShowConfirmDeleteDialog && showDialog) // Check if the setting to show a confirmation dialog is on { List <FilesystemItemsOperationItemModel> incomingItems = new List <FilesystemItemsOperationItemModel> { new FilesystemItemsOperationItemModel(FilesystemOperationType.Delete, source.Path, null) }; FilesystemOperationDialog dialog = FilesystemOperationDialogViewModel.GetDialog(new FilesystemItemsOperationDataModel( FilesystemOperationType.Delete, false, !deleteFromRecycleBin ? permanently : deleteFromRecycleBin, !deleteFromRecycleBin, incomingItems, new List <FilesystemItemsOperationItemModel>())); ContentDialogResult result = await dialog.ShowAsync(); if (result != ContentDialogResult.Primary) { banner.Remove(); return(ReturnResult.Cancelled); // Return if the result isn't delete } // Delete selected item if the result is Yes permanently = dialog.ViewModel.PermanentlyDelete; } var sw = new Stopwatch(); sw.Start(); IStorageHistory history = await filesystemOperations.DeleteAsync(source, banner.Progress, banner.ErrorCode, permanently, cancellationToken); ((IProgress <float>)banner.Progress).Report(100.0f); if (!permanently && registerHistory) { App.HistoryWrapper.AddHistory(history); } banner.Remove(); sw.Stop(); PostBannerHelpers.PostBanner_Delete(returnStatus, permanently ? FileOperationType.Delete : FileOperationType.Recycle, sw, associatedInstance); return(returnStatus); } catch (System.Exception ex) { NLog.LogManager.GetCurrentClassLogger().Warn($"Delete item operation failed:\n{ex}"); return(ReturnResult.Failed); } }
private bool IsHistoryNull(IStorageHistory history) // history.Destination is null with CreateNew => IsHistoryNull(history.Source) || (history.Destination is not null && IsHistoryNull(history.Destination));
public async Task <ReturnResult> DeleteItemsAsync(IEnumerable <IStorageItemWithPath> source, bool showDialog, bool permanently, bool registerHistory) { source = await source.ToListAsync(); var returnStatus = ReturnResult.InProgress; var deleteFromRecycleBin = source.Select(item => item.Path).Any(path => recycleBinHelpers.IsPathUnderRecycleBin(path)); var canBeSentToBin = !deleteFromRecycleBin && await recycleBinHelpers.HasRecycleBin(source.FirstOrDefault()?.Path); if (((!permanently && !canBeSentToBin) || UserSettingsService.PreferencesSettingsService.ShowConfirmDeleteDialog) && showDialog) // Check if the setting to show a confirmation dialog is on { var incomingItems = new List <BaseFileSystemDialogItemViewModel>(); List <ShellFileItem> binItems = null; foreach (var src in source) { if (recycleBinHelpers.IsPathUnderRecycleBin(src.Path)) { binItems ??= await recycleBinHelpers.EnumerateRecycleBin(); if (!binItems.IsEmpty()) // Might still be null because we're deserializing the list from Json { var matchingItem = binItems.FirstOrDefault(x => x.RecyclePath == src.Path); // Get original file name incomingItems.Add(new FileSystemDialogDefaultItemViewModel() { SourcePath = src.Path, DisplayName = matchingItem?.FileName ?? src.Name }); } } else { incomingItems.Add(new FileSystemDialogDefaultItemViewModel() { SourcePath = src.Path }); } } var dialogViewModel = FileSystemDialogViewModel.GetDialogViewModel( new() { IsInDeleteMode = true }, (canBeSentToBin ? permanently : true, canBeSentToBin), FilesystemOperationType.Delete, incomingItems, new()); var dialogService = Ioc.Default.GetRequiredService <IDialogService>(); if (await dialogService.ShowDialogAsync(dialogViewModel) != DialogResult.Primary) { return(ReturnResult.Cancelled); // Return if the result isn't delete } // Delete selected items if the result is Yes permanently = dialogViewModel.DeletePermanently; } // post the status banner var banner = PostBannerHelpers.PostBanner_Delete(source, returnStatus, permanently, false, 0); banner.ErrorCode.ProgressChanged += (s, e) => returnStatus = returnStatus < ReturnResult.Failed ? e.ToStatus() : returnStatus; var token = banner.CancellationToken; var sw = new Stopwatch(); sw.Start(); IStorageHistory history = await filesystemOperations.DeleteItemsAsync((IList <IStorageItemWithPath>) source, banner.Progress, banner.ErrorCode, permanently, token); ((IProgress <float>)banner.Progress).Report(100.0f); await Task.Yield(); if (!permanently && registerHistory) { App.HistoryWrapper.AddHistory(history); } var itemsDeleted = history?.Source.Count() ?? 0; source.ForEach(x => App.JumpList.RemoveFolder(x.Path)); // Remove items from jump list banner.Remove(); sw.Stop(); PostBannerHelpers.PostBanner_Delete(source, returnStatus, permanently, token.IsCancellationRequested, itemsDeleted); return(returnStatus); }
public async Task <ReturnResult> DeleteItemAsync(IStorageItem source, bool showDialog, bool permanently, bool registerHistory) { PostedStatusBanner banner; bool deleteFromRecycleBin = recycleBinHelpers.IsPathUnderRecycleBin(source.Path); if (deleteFromRecycleBin) { permanently = true; } if (permanently) { banner = associatedInstance.StatusCenterActions.PostBanner(string.Empty, associatedInstance.FilesystemViewModel.WorkingDirectory, 0, ReturnResult.InProgress, FileOperationType.Delete); } else { banner = associatedInstance.StatusCenterActions.PostBanner(string.Empty, associatedInstance.FilesystemViewModel.WorkingDirectory, 0, ReturnResult.InProgress, FileOperationType.Recycle); } var returnStatus = ReturnResult.InProgress; banner.ErrorCode.ProgressChanged += (s, e) => returnStatus = e.ToStatus(); if (App.AppSettings.ShowConfirmDeleteDialog && showDialog) // Check if the setting to show a confirmation dialog is on { ConfirmDeleteDialog dialog = new ConfirmDeleteDialog( deleteFromRecycleBin, permanently, associatedInstance.SlimContentPage.SelectedItems.Count); if (UIHelpers.IsAnyContentDialogOpen()) { // Can show only one dialog at a time banner.Remove(); return(ReturnResult.Cancelled); } await dialog.ShowAsync(); if (dialog.Result != DialogResult.Delete) // Delete selected item if the result is Yes { banner.Remove(); return(ReturnResult.Cancelled); // Return if the result isn't delete } permanently = dialog.PermanentlyDelete; } var sw = new Stopwatch(); sw.Start(); IStorageHistory history = await filesystemOperations.DeleteAsync(source, banner.Progress, banner.ErrorCode, permanently, cancellationToken); ((IProgress <float>)banner.Progress).Report(100.0f); if (!permanently && registerHistory) { App.HistoryWrapper.AddHistory(history); } banner.Remove(); sw.Stop(); PostBannerHelpers.PostBanner_Delete(returnStatus, permanently ? FileOperationType.Delete : FileOperationType.Recycle, sw, associatedInstance); return(returnStatus); }
public void Modify(IStorageHistory newHistory) { OperationType = newHistory.OperationType; Source = newHistory.Source; Destination = newHistory.Destination; }
public async Task <ReturnResult> Redo(IStorageHistory history) { ReturnResult returnStatus = ReturnResult.InProgress; Progress <FileSystemStatusCode> errorCode = new Progress <FileSystemStatusCode>(); errorCode.ProgressChanged += (s, e) => { returnStatus = e.ToStatus(); }; switch (history.OperationType) { case FileOperationType.CreateNew: // CreateNew PASS { if (IsHistoryNull(history)) { break; } for (int i = 0; i < history.Source.Count(); i++) { await filesystemOperations.CreateAsync(history.Source.ElementAt(i), errorCode, cancellationToken); } break; } case FileOperationType.Rename: // Rename PASS { if (IsHistoryNull(history)) { break; } NameCollisionOption collision = NameCollisionOption.GenerateUniqueName; for (int i = 0; i < history.Source.Count(); i++) { await filesystemOperations.RenameAsync( history.Source.ElementAt(i), Path.GetFileName(history.Destination.ElementAt(i).Path), collision, errorCode, cancellationToken); } break; } case FileOperationType.Copy: // Copy PASS { if (IsHistoryNull(history)) { break; } return(await filesystemHelpers.CopyItemsAsync(history.Source, history.Destination.Select((item) => item.Path), false, false)); } case FileOperationType.Move: // Move PASS { if (IsHistoryNull(history)) { break; } return(await filesystemHelpers.MoveItemsAsync(history.Source, history.Destination.Select((item) => item.Path), false, false)); } case FileOperationType.Extract: // Extract PASS { returnStatus = ReturnResult.Success; Debugger.Break(); break; } case FileOperationType.Recycle: // Recycle PASS { if (IsHistoryNull(history.Destination)) { break; } List <IStorageHistory> rawStorageHistory = new List <IStorageHistory>(); for (int i = 0; i < history.Source.Count(); i++) { rawStorageHistory.Add(await filesystemOperations.DeleteAsync( history.Source.ElementAt(i), null, errorCode, false, cancellationToken)); } if (rawStorageHistory.TrueForAll((item) => item != null)) { IStorageHistory newHistory = new StorageHistory( FileOperationType.Recycle, rawStorageHistory.SelectMany((item) => item?.Source).ToList(), rawStorageHistory.SelectMany((item) => item?.Destination).ToList()); // We need to change the recycled item paths (since IDs are different) - for Undo() to work App.HistoryWrapper.ModifyCurrentHistory(newHistory); } else { App.HistoryWrapper.RemoveHistory(history, true); } break; } case FileOperationType.Restore: // Restore PASS { if (IsHistoryNull(history)) { break; } for (int i = 0; i < history.Destination.Count(); i++) { await filesystemHelpers.RestoreFromTrashAsync(history.Source.ElementAt(i), history.Destination.ElementAt(i).Path, false); } break; } case FileOperationType.Delete: // Delete PASS { returnStatus = ReturnResult.Success; break; } } return(returnStatus); }
// history.Destination is null with CreateNew private bool IsHistoryNull(IStorageHistory history) => !(history.Source.ToList().TrueForAll((item) => item != null && !string.IsNullOrWhiteSpace(item.Path)) && (history.Destination == null || history.Destination.ToList().TrueForAll((item) => item != null && !string.IsNullOrWhiteSpace(item.Path))));
public void ModifyCurrentHistory(IStorageHistory newHistory) { this.storageHistory[this.storageHistoryIndex].Modify(newHistory); }
public async Task <ReturnResult> Redo(IStorageHistory history) { ReturnResult returnStatus = ReturnResult.InProgress; Progress <FileSystemStatusCode> errorCode = new(); errorCode.ProgressChanged += (s, e) => { returnStatus = e.ToStatus(); }; switch (history.OperationType) { case FileOperationType.CreateNew: if (IsHistoryNull(history)) { foreach (var source in history.Source) { await operations.CreateAsync(source, errorCode, cancellationToken); } } break; case FileOperationType.CreateLink: if (!IsHistoryNull(history)) { await operations.CreateShortcutItemsAsync(history.Source, await history.Destination.Select(item => item.Path).ToListAsync(), null, errorCode, cancellationToken); } break; case FileOperationType.Rename: if (!IsHistoryNull(history)) { NameCollisionOption collision = NameCollisionOption.GenerateUniqueName; for (int i = 0; i < history.Source.Count; i++) { string name = Path.GetFileName(history.Destination[i].Path); await operations.RenameAsync(history.Source[i], name, collision, errorCode, cancellationToken); } } break; case FileOperationType.Copy: if (!IsHistoryNull(history)) { return(await helpers.CopyItemsAsync(history.Source, history.Destination.Select(item => item.Path), false, false)); } break; case FileOperationType.Move: if (!IsHistoryNull(history)) { return(await helpers.MoveItemsAsync(history.Source, history.Destination.Select(item => item.Path), false, false)); } break; case FileOperationType.Extract: returnStatus = ReturnResult.Success; Debugger.Break(); break; case FileOperationType.Recycle: // Recycle PASS if (!IsHistoryNull(history.Destination)) { var newHistory = await operations.DeleteItemsAsync(history.Source, null, errorCode, false, cancellationToken); if (newHistory is null) { App.HistoryWrapper.RemoveHistory(history, true); } else { // We need to change the recycled item paths (since IDs are different) - for Undo() to work App.HistoryWrapper.ModifyCurrentHistory(newHistory); } } break; case FileOperationType.Restore: if (!IsHistoryNull(history)) { await helpers.RestoreItemsFromTrashAsync(history.Source, history.Destination.Select(item => item.Path), false); } break; case FileOperationType.Delete: returnStatus = ReturnResult.Success; break; } return(returnStatus); }
public async Task <ReturnResult> DeleteItemAsync(IStorageItem source, bool showDialog, bool permanently, bool registerHistory) { PostedStatusBanner banner; bool deleteFromRecycleBin = await recycleBinHelpers.IsRecycleBinItem(source); if (deleteFromRecycleBin) { permanently = true; } if (permanently) { banner = associatedInstance.BottomStatusStripControl.OngoingTasksControl.PostBanner(string.Empty, associatedInstance.FilesystemViewModel.WorkingDirectory, 0, ReturnResult.InProgress, FileOperationType.Delete); } else { banner = associatedInstance.BottomStatusStripControl.OngoingTasksControl.PostBanner(string.Empty, associatedInstance.FilesystemViewModel.WorkingDirectory, 0, ReturnResult.InProgress, FileOperationType.Recycle); } ReturnResult returnStatus = ReturnResult.InProgress; banner.ErrorCode.ProgressChanged += (s, e) => returnStatus = e.ToStatus(); if (App.AppSettings.ShowConfirmDeleteDialog && showDialog) // Check if the setting to show a confirmation dialog is on { ConfirmDeleteDialog dialog = new ConfirmDeleteDialog( deleteFromRecycleBin, permanently, associatedInstance.ContentPage.SelectedItemsPropertiesViewModel); await dialog.ShowAsync(); if (dialog.Result != DialogResult.Delete) // Delete selected item if the result is Yes { return(ReturnResult.Cancelled); // Return if the result isn't delete } permanently = dialog.PermanentlyDelete; } Stopwatch sw = new Stopwatch(); sw.Start(); IStorageHistory history = await filesystemOperations.DeleteAsync(source, banner.Progress, banner.ErrorCode, permanently, cancellationToken); if (!permanently && registerHistory) { App.HistoryWrapper.AddHistory(history); } banner.Remove(); sw.Stop(); PostBannerHelpers.PostBanner_Delete(returnStatus, permanently ? FileOperationType.Delete : FileOperationType.Recycle, sw, associatedInstance); return(returnStatus); }
public async Task <ReturnResult> Undo(IStorageHistory history) { ReturnResult returnStatus = ReturnResult.InProgress; Progress <FileSystemStatusCode> errorCode = new Progress <FileSystemStatusCode>(); errorCode.ProgressChanged += (s, e) => returnStatus = e.ToStatus(); switch (history.OperationType) { case FileOperationType.CreateNew: // CreateNew PASS { // Opposite: Delete created items if (IsHistoryNull(history.Source)) { break; } return(await filesystemHelpers.DeleteItemsAsync(history.Source, false, true, false)); } case FileOperationType.CreateLink: // CreateLink PASS { // Opposite: Delete created items if (IsHistoryNull(history.Destination)) { break; } return(await filesystemHelpers.DeleteItemsAsync(history.Destination, false, true, false)); } case FileOperationType.Rename: // Rename PASS { // Opposite: Restore original item names if (IsHistoryNull(history)) { break; } NameCollisionOption collision = NameCollisionOption.GenerateUniqueName; for (int i = 0; i < history.Destination.Count(); i++) { await filesystemOperations.RenameAsync( history.Destination.ElementAt(i), Path.GetFileName(history.Source.ElementAt(i).Path), collision, errorCode, cancellationToken); } break; } case FileOperationType.Copy: // Copy PASS { // Opposite: Delete copied items if (IsHistoryNull(history.Destination)) { break; } return(await filesystemHelpers.DeleteItemsAsync(history.Destination, false, true, false)); } case FileOperationType.Move: // Move PASS { // Opposite: Move the items to original directory if (IsHistoryNull(history)) { break; } return(await filesystemHelpers.MoveItemsAsync(history.Destination, history.Source.Select((item) => item.Path), false, false)); } case FileOperationType.Extract: // Extract PASS { // Opposite: No opposite for archive extraction returnStatus = ReturnResult.Success; Debugger.Break(); break; } case FileOperationType.Recycle: // Recycle PASS { // Opposite: Restore recycled items if (IsHistoryNull(history)) { break; } for (int i = 0; i < history.Destination.Count(); i++) { returnStatus = await filesystemHelpers.RestoreFromTrashAsync( history.Destination.ElementAt(i), history.Source.ElementAt(i).Path, false); } if (returnStatus == ReturnResult.IntegrityCheckFailed) // Not found, corrupted { App.HistoryWrapper.RemoveHistory(history, false); } break; } case FileOperationType.Restore: // Restore PASS { // Opposite: Move restored items to Recycle Bin if (IsHistoryNull(history.Destination)) { break; } var newHistory = await filesystemOperations.DeleteItemsAsync(history.Destination, null, errorCode, false, cancellationToken); if (newHistory != null) { // We need to change the recycled item paths (since IDs are different) - for Redo() to work App.HistoryWrapper.ModifyCurrentHistory(newHistory); } else { App.HistoryWrapper.RemoveHistory(history, false); } break; } case FileOperationType.Delete: // Delete PASS { // Opposite: No opposite for pernament deletion returnStatus = ReturnResult.Success; break; } } return(returnStatus); }
public void Modify(IStorageHistory newHistory) => (OperationType, Source, Destination) = (newHistory.OperationType, newHistory.Source, newHistory.Destination);