diff --git a/Files/Files.csproj b/Files/Files.csproj index e4fdd9cac6f4..07661e23f7fc 100644 --- a/Files/Files.csproj +++ b/Files/Files.csproj @@ -29,6 +29,7 @@ x86|x64|arm|arm64 0 Resources\MiddleClickScrolling-CursorType.res + 9.0 true @@ -40,7 +41,6 @@ false prompt true - 9.0 true false true @@ -56,7 +56,6 @@ prompt true true - 9.0 true @@ -69,7 +68,6 @@ false prompt true - 9.0 true true @@ -84,7 +82,6 @@ prompt true true - 9.0 true @@ -98,7 +95,6 @@ prompt true true - 9.0 true true @@ -113,7 +109,6 @@ prompt true true - 9.0 true @@ -126,7 +121,6 @@ false prompt true - 9.0 true true @@ -141,7 +135,6 @@ prompt true true - 9.0 true @@ -423,9 +416,6 @@ - - - diff --git a/Files/Filesystem/Drives.cs b/Files/Filesystem/Drives.cs index e149bcf336bb..69efe00fbfa9 100644 --- a/Files/Filesystem/Drives.cs +++ b/Files/Filesystem/Drives.cs @@ -384,7 +384,7 @@ private DriveType GetDriveType(DriveInfo drive) return type; } - public static async Task GetRootFromPathAsync(string devicePath) + public static async Task GetRootFromPathAsync(string devicePath) { if (!Path.IsPathRooted(devicePath)) { @@ -419,13 +419,13 @@ public static async Task GetRootFromPathAsync(string devi } if (matchingDrive != null) { - return new StorageFolderWithPath(matchingDrive, rootPath); + return matchingDrive; } } else if (devicePath.StartsWith("\\\\")) // Network share { rootPath = rootPath.LastIndexOf("\\") > 1 ? rootPath.Substring(0, rootPath.LastIndexOf("\\")) : rootPath; // Remove share name - return new StorageFolderWithPath(await StorageFolder.GetFolderFromPathAsync(rootPath), rootPath); + return await StorageFolder.GetFolderFromPathAsync(rootPath); } // It's ok to return null here, on normal drives StorageFolder.GetFolderFromPathAsync works return null; diff --git a/Files/Filesystem/FilesystemOperations/FilesystemOperations.cs b/Files/Filesystem/FilesystemOperations/FilesystemOperations.cs index 29f9c59958ae..d5c9e6c4b28c 100644 --- a/Files/Filesystem/FilesystemOperations/FilesystemOperations.cs +++ b/Files/Filesystem/FilesystemOperations/FilesystemOperations.cs @@ -50,14 +50,14 @@ public FilesystemOperations(IShellPage associatedInstance) #region IFilesystemOperations - public async Task<(IStorageHistory, IStorageItem)> CreateAsync(IStorageItemWithPath source, IProgress errorCode, CancellationToken cancellationToken) + public async Task<(IStorageHistory, IStorageItem)> CreateAsync(IStorageItem source, IProgress errorCode, CancellationToken cancellationToken) { IStorageItem item = null; try { - switch (source.ItemType) + switch (source) { - case FilesystemItemType.File: + case IStorageFile: { var newEntryInfo = await RegistryHelper.GetNewContextMenuEntryForType(Path.GetExtension(source.Path)); if (newEntryInfo == null) @@ -73,7 +73,7 @@ public FilesystemOperations(IShellPage associatedInstance) break; } - case FilesystemItemType.Directory: + case IStorageFolder: { StorageFolder folder = await associatedInstance.FilesystemViewModel.GetFolderFromPathAsync(Path.GetDirectoryName(source.Path)); item = await folder.CreateFolderAsync(Path.GetFileName(source.Path)); @@ -81,12 +81,6 @@ public FilesystemOperations(IShellPage associatedInstance) break; } - case FilesystemItemType.Symlink: - { - Debugger.Break(); - throw new NotImplementedException(); - } - default: Debugger.Break(); break; @@ -108,21 +102,6 @@ public async Task CopyAsync(IStorageItem source, IProgress progress, IProgress errorCode, CancellationToken cancellationToken) - { - return await CopyAsync(source.FromStorageItem(), - destination, - collision, - progress, - errorCode, - cancellationToken); - } - - public async Task CopyAsync(IStorageItemWithPath source, - string destination, - NameCollisionOption collision, - IProgress progress, - IProgress errorCode, - CancellationToken cancellationToken) { if (destination.StartsWith(App.AppSettings.RecycleBinPath)) { @@ -139,7 +118,7 @@ await DialogDisplayHelper.ShowDialogAsync( IStorageItem copiedItem = null; //long itemSize = await FilesystemHelpers.GetItemSize(await source.ToStorageItem(associatedInstance)); - if (source.ItemType == FilesystemItemType.Directory) + if (source is IStorageFolder) { if (!string.IsNullOrWhiteSpace(source.Path) && Path.GetDirectoryName(destination).IsSubPathOf(source.Path)) // We check if user tried to copy anything above the source.ItemPath @@ -216,7 +195,7 @@ await DialogDisplayHelper.ShowDialogAsync( } } } - else if (source.ItemType == FilesystemItemType.File) + else if (source is IStorageFile) { var fsResult = (FilesystemResult)await Task.Run(() => NativeFileOperationsHelper.CopyFileFromApp(source.Path, destination, true)); @@ -291,9 +270,7 @@ await Windows.ApplicationModel.Core.CoreApplication.MainView.DispatcherQueue.Enq return null; // Cannot undo overwrite operation } - var pathWithType = copiedItem.FromStorageItem(destination, source.ItemType); - - return new StorageHistory(FileOperationType.Copy, source, pathWithType); + return new StorageHistory(FileOperationType.Copy, source, copiedItem); } public async Task MoveAsync(IStorageItem source, @@ -302,21 +279,6 @@ public async Task MoveAsync(IStorageItem source, IProgress progress, IProgress errorCode, CancellationToken cancellationToken) - { - return await MoveAsync(source.FromStorageItem(), - destination, - collision, - progress, - errorCode, - cancellationToken); - } - - public async Task MoveAsync(IStorageItemWithPath source, - string destination, - NameCollisionOption collision, - IProgress progress, - IProgress errorCode, - CancellationToken cancellationToken) { if (source.Path == destination) { @@ -348,7 +310,7 @@ await DialogDisplayHelper.ShowDialogAsync( IStorageItem movedItem = null; //long itemSize = await FilesystemHelpers.GetItemSize(await source.ToStorageItem(associatedInstance)); - if (source.ItemType == FilesystemItemType.Directory) + if (source is IStorageFolder) { if (!string.IsNullOrWhiteSpace(source.Path) && Path.GetDirectoryName(destination).IsSubPathOf(source.Path)) // We check if user tried to move anything above the source.ItemPath @@ -427,7 +389,7 @@ await DialogDisplayHelper.ShowDialogAsync( errorCode?.Report(fsResult.ErrorCode); } } - else if (source.ItemType == FilesystemItemType.File) + else if (source is IStorageFile) { var fsResult = (FilesystemResult)await Task.Run(() => NativeFileOperationsHelper.MoveFileFromApp(source.Path, destination)); @@ -496,9 +458,7 @@ await Windows.ApplicationModel.Core.CoreApplication.MainView.DispatcherQueue.Enq return null; // Cannot undo overwrite operation } - var pathWithType = movedItem.FromStorageItem(destination, source.ItemType); - - return new StorageHistory(FileOperationType.Move, source, pathWithType); + return new StorageHistory(FileOperationType.Move, source, movedItem); } public async Task DeleteAsync(IStorageItem source, @@ -506,19 +466,6 @@ public async Task DeleteAsync(IStorageItem source, IProgress errorCode, bool permanently, CancellationToken cancellationToken) - { - return await DeleteAsync(source.FromStorageItem(), - progress, - errorCode, - permanently, - cancellationToken); - } - - public async Task DeleteAsync(IStorageItemWithPath source, - IProgress progress, - IProgress errorCode, - bool permanently, - CancellationToken cancellationToken) { bool deleteFromRecycleBin = recycleBinHelpers.IsPathUnderRecycleBin(source.Path); @@ -533,12 +480,12 @@ public async Task DeleteAsync(IStorageItemWithPath source, } if (!fsResult) { - if (source.ItemType == FilesystemItemType.File) + if (source is IStorageFile) { fsResult = await associatedInstance.FilesystemViewModel.GetFileFromPathAsync(source.Path) .OnSuccess((t) => t.DeleteAsync(permanently ? StorageDeleteOption.PermanentDelete : StorageDeleteOption.Default).AsTask()); } - else if (source.ItemType == FilesystemItemType.Directory) + else if (source is IStorageFolder) { fsResult = await associatedInstance.FilesystemViewModel.GetFolderFromPathAsync(source.Path) .OnSuccess((t) => t.DeleteAsync(permanently ? StorageDeleteOption.PermanentDelete : StorageDeleteOption.Default).AsTask()); @@ -631,15 +578,6 @@ public async Task RenameAsync(IStorageItem source, NameCollisionOption collision, IProgress errorCode, CancellationToken cancellationToken) - { - return await RenameAsync(StorageItemHelpers.FromStorageItem(source), newName, collision, errorCode, cancellationToken); - } - - public async Task RenameAsync(IStorageItemWithPath source, - string newName, - NameCollisionOption collision, - IProgress errorCode, - CancellationToken cancellationToken) { if (Path.GetFileName(source.Path) == newName && collision == NameCollisionOption.FailIfExists) { @@ -668,7 +606,7 @@ public async Task RenameAsync(IStorageItemWithPath source, if (renamed) { errorCode?.Report(FileSystemStatusCode.Success); - return new StorageHistory(FileOperationType.Rename, source, renamed.Result.FromStorageItem()); + return new StorageHistory(FileOperationType.Rename, source.CreateEnumerable(), renamed.Result.FromStorageItem()); } else if (renamed == FileSystemStatusCode.Unauthorized) { @@ -747,7 +685,7 @@ public async Task RenameAsync(IStorageItemWithPath source, return null; } - public async Task RestoreFromTrashAsync(IStorageItemWithPath source, + public async Task RestoreFromTrashAsync(IStorageItem source, string destination, IProgress progress, IProgress errorCode, @@ -760,7 +698,7 @@ public async Task RestoreFromTrashAsync(IStorageItemWithPath so if (!fsResult) { - if (source.ItemType == FilesystemItemType.Directory) + if (source is IStorageFolder) { FilesystemResult sourceFolder = await associatedInstance.FilesystemViewModel.GetFolderFromPathAsync(source.Path); FilesystemResult destinationFolder = await associatedInstance.FilesystemViewModel.GetFolderFromPathAsync(Path.GetDirectoryName(destination)); @@ -953,12 +891,7 @@ public async Task CopyItemsAsync(IEnumerable MoveItemsAsync(IEnumerable source, IEnumerable destination, IEnumerable collisions, IProgress progress, IProgress errorCode, CancellationToken cancellationToken) - { - return await MoveItemsAsync(source.Select((item) => item.FromStorageItem()).ToList(), destination, collisions, progress, errorCode, cancellationToken); - } - - public async Task MoveItemsAsync(IEnumerable source, IEnumerable destination, IEnumerable collisions, IProgress progress, IProgress errorCode, CancellationToken token) + public async Task MoveItemsAsync(IEnumerable source, IEnumerable destination, IEnumerable collisions, IProgress progress, IProgress errorCode, CancellationToken token) { var rawStorageHistory = new List(); @@ -993,12 +926,7 @@ public async Task MoveItemsAsync(IEnumerable DeleteItemsAsync(IEnumerable source, IProgress progress, IProgress errorCode, bool permanently, CancellationToken cancellationToken) - { - return await DeleteItemsAsync(source.Select((item) => item.FromStorageItem()), progress, errorCode, permanently, cancellationToken); - } - - public async Task DeleteItemsAsync(IEnumerable source, IProgress progress, IProgress errorCode, bool permanently, CancellationToken token) + public async Task DeleteItemsAsync(IEnumerable source, IProgress progress, IProgress errorCode, bool permanently, CancellationToken token) { bool originalPermanently = permanently; var rawStorageHistory = new List(); diff --git a/Files/Filesystem/FilesystemOperations/IFilesystemOperations.cs b/Files/Filesystem/FilesystemOperations/IFilesystemOperations.cs index c41a99c54bc9..9b0d3441ce97 100644 --- a/Files/Filesystem/FilesystemOperations/IFilesystemOperations.cs +++ b/Files/Filesystem/FilesystemOperations/IFilesystemOperations.cs @@ -30,7 +30,7 @@ public interface IFilesystemOperations : IDisposable ///
/// Destination: null /// - Task<(IStorageHistory, IStorageItem)> CreateAsync(IStorageItemWithPath source, IProgress errorCode, CancellationToken cancellationToken); + Task<(IStorageHistory, IStorageItem)> CreateAsync(IStorageItem source, IProgress errorCode, CancellationToken cancellationToken); /// /// Copies to fullPath @@ -54,28 +54,6 @@ Task CopyAsync(IStorageItem source, IProgress errorCode, CancellationToken cancellationToken); - /// - /// Copies to fullPath - /// - /// The source item to be copied - /// The destination fullPath - /// The item naming collision - /// Progress of the operation - /// Status of the operation - /// Can be cancelled with - /// where: - ///
- /// Source: The item fullPath (as ) - ///
- /// Destination: The item fullPath (as ) the was copied - ///
- Task CopyAsync(IStorageItemWithPath source, - string destination, - NameCollisionOption collision, - IProgress progress, - IProgress errorCode, - CancellationToken cancellationToken); - /// /// Copies to fullPath /// @@ -86,16 +64,6 @@ Task CopyItemsAsync(IEnumerable source, IProgress errorCode, CancellationToken cancellationToken); - /// - /// Copies to fullPath - /// - Task CopyItemsAsync(IEnumerable source, - IEnumerable destination, - IEnumerable collisions, - IProgress progress, - IProgress errorCode, - CancellationToken cancellationToken); - /// /// Moves to fullPath /// @@ -118,28 +86,6 @@ Task MoveAsync(IStorageItem source, IProgress errorCode, CancellationToken cancellationToken); - /// - /// Moves to fullPath - /// - /// The source item to be moved - /// The destination fullPath - /// The item naming collision - /// Progress of the operation - /// Status of the operation - /// Can be cancelled with - /// where: - ///
- /// Source: The source item fullPath (as ) - ///
- /// Destination: The item fullPath (as ) the was moved - ///
- Task MoveAsync(IStorageItemWithPath source, - string destination, - NameCollisionOption collision, - IProgress progress, - IProgress errorCode, - CancellationToken cancellationToken); - /// /// Moves to fullPath /// @@ -150,16 +96,6 @@ Task MoveItemsAsync(IEnumerable source, IProgress errorCode, CancellationToken cancellationToken); - /// - /// Moves to fullPath - /// - Task MoveItemsAsync(IEnumerable source, - IEnumerable destination, - IEnumerable collisions, - IProgress progress, - IProgress errorCode, - CancellationToken cancellationToken); - /// /// Deletes /// @@ -184,31 +120,6 @@ Task DeleteAsync(IStorageItem source, bool permanently, CancellationToken cancellationToken); - /// - /// Deletes - /// - /// The source to delete - /// Type of the item - /// Progress of the operation - /// Status of the operation - /// Determines whether is be deleted permanently - /// Can be cancelled with - /// where: - ///
- /// Source: The deleted item fullPath (as ) - ///
- /// Destination: - ///
- /// Returns null if was true - ///
- /// If was false, returns path to recycled item - ///
- Task DeleteAsync(IStorageItemWithPath source, - IProgress progress, - IProgress errorCode, - bool permanently, - CancellationToken cancellationToken); - /// /// Deletes provided /// @@ -218,15 +129,6 @@ Task DeleteItemsAsync(IEnumerable source, bool permanently, CancellationToken cancellationToken); - /// - /// Deletes provided - /// - Task DeleteItemsAsync(IEnumerable source, - IProgress progress, - IProgress errorCode, - bool permanently, - CancellationToken cancellationToken); - /// /// Renames with /// @@ -247,26 +149,6 @@ Task RenameAsync(IStorageItem source, IProgress errorCode, CancellationToken cancellationToken); - /// - /// Renames fullPath with - /// - /// The item to rename - /// Desired new name - /// Determines what to do if item already exists - /// Status of the operation - /// Can be cancelled with - /// where: - ///
- /// Source: The original item fullPath (as ) - ///
- /// Destination: The renamed item fullPath (as ) - ///
- Task RenameAsync(IStorageItemWithPath source, - string newName, - NameCollisionOption collision, - IProgress errorCode, - CancellationToken cancellationToken); - /// /// Restores from the RecycleBin to fullPath /// @@ -281,7 +163,7 @@ Task RenameAsync(IStorageItemWithPath source, ///
/// Destination: The item fullPath (as ) the has been restored /// - Task RestoreFromTrashAsync(IStorageItemWithPath source, + Task RestoreFromTrashAsync(IStorageItem source, string destination, IProgress progress, IProgress errorCode, diff --git a/Files/Filesystem/StorageEnumerators/UniversalStorageEnumerator.cs b/Files/Filesystem/StorageEnumerators/UniversalStorageEnumerator.cs index 04729aa8378e..9e3e817a618d 100644 --- a/Files/Filesystem/StorageEnumerators/UniversalStorageEnumerator.cs +++ b/Files/Filesystem/StorageEnumerators/UniversalStorageEnumerator.cs @@ -19,7 +19,7 @@ public static class UniversalStorageEnumerator { public static async Task> ListEntries( StorageFolder rootFolder, - StorageFolderWithPath currentStorageFolder, + IStorageFolder currentStorageFolder, string returnformat, Type sourcePageType, CancellationToken cancellationToken, @@ -138,7 +138,7 @@ ex is UnauthorizedAccessException return tempList; } - private static async Task AddFolderAsync(StorageFolder folder, StorageFolderWithPath currentStorageFolder, string dateReturnFormat, CancellationToken cancellationToken) + private static async Task AddFolderAsync(StorageFolder folder, IStorageFolder currentStorageFolder, string dateReturnFormat, CancellationToken cancellationToken) { var basicProperties = await folder.GetBasicPropertiesAsync(); if (!cancellationToken.IsCancellationRequested) @@ -166,7 +166,7 @@ private static async Task AddFolderAsync(StorageFolder folder, Stora private static async Task AddFileAsync( StorageFile file, - StorageFolderWithPath currentStorageFolder, + IStorageFolder currentStorageFolder, string dateReturnFormat, bool suppressThumbnailLoading, Type sourcePageType, diff --git a/Files/Filesystem/StorageFileHelpers/FilesystemResult.cs b/Files/Filesystem/StorageFileHelpers/FilesystemResult.cs index 7ff6a0151fac..d9cc2e0c434c 100644 --- a/Files/Filesystem/StorageFileHelpers/FilesystemResult.cs +++ b/Files/Filesystem/StorageFileHelpers/FilesystemResult.cs @@ -70,7 +70,7 @@ public static FileSystemStatusCode GetErrorCode(Exception ex, Type T = null) } else if (ex is ArgumentException) // Item was invalid { - return (T == typeof(StorageFolder) || T == typeof(StorageFolderWithPath)) ? + return (T == typeof(IStorageFolder) || T.GetInterface("IStorageFolder") is not null) ? FileSystemStatusCode.NotAFolder : FileSystemStatusCode.NotAFile; } else if ((uint)ex.HResult == 0x800700B7) diff --git a/Files/Filesystem/StorageFileHelpers/IStorageItemWithPath.cs b/Files/Filesystem/StorageFileHelpers/IStorageItemWithPath.cs deleted file mode 100644 index 46e508639700..000000000000 --- a/Files/Filesystem/StorageFileHelpers/IStorageItemWithPath.cs +++ /dev/null @@ -1,12 +0,0 @@ -using Windows.Storage; - -namespace Files.Filesystem -{ - public interface IStorageItemWithPath // TODO: Maybe use here : IStorageItem instead of declaring a variable, - // and keep the Path property for it to override IStorageItem.Path ? - { - public string Path { get; set; } - public IStorageItem Item { get; set; } - public FilesystemItemType ItemType { get; } - } -} \ No newline at end of file diff --git a/Files/Filesystem/StorageFileHelpers/StorageFileExtensions.cs b/Files/Filesystem/StorageFileHelpers/StorageFileExtensions.cs index b975ecffc706..59892dd17771 100644 --- a/Files/Filesystem/StorageFileHelpers/StorageFileExtensions.cs +++ b/Files/Filesystem/StorageFileHelpers/StorageFileExtensions.cs @@ -92,7 +92,7 @@ public static List GetDirectoryPathComponents(string value) return pathBoxItems; } - public async static Task DangerousGetFolderWithPathFromPathAsync(string value, StorageFolderWithPath rootFolder = null, StorageFolderWithPath parentFolder = null) + public async static Task DangerousGetFolderWithPathFromPathAsync(string value, IStorageFolder rootFolder = null, IStorageFolder parentFolder = null) { if (rootFolder != null) { @@ -104,26 +104,22 @@ public async static Task DangerousGetFolderWithPathFromPa } else if (parentFolder != null && value.IsSubPathOf(parentFolder.Path)) { - var folder = parentFolder.Folder; + var folder = parentFolder; var prevComponents = GetDirectoryPathComponents(parentFolder.Path); - var path = parentFolder.Path; foreach (var component in currComponents.ExceptBy(prevComponents, c => c.Path)) { folder = await folder.GetFolderAsync(component.Title); - path = Path.Combine(path, folder.Name); } - return new StorageFolderWithPath(folder, path); + return folder; } else if (value.IsSubPathOf(rootFolder.Path)) { - var folder = rootFolder.Folder; - var path = rootFolder.Path; + var folder = rootFolder; foreach (var component in currComponents.Skip(1)) { folder = await folder.GetFolderAsync(component.Title); - path = Path.Combine(path, folder.Name); } - return new StorageFolderWithPath(folder, path); + return folder; } } @@ -131,24 +127,24 @@ public async static Task DangerousGetFolderWithPathFromPa { // Relative path var fullPath = Path.GetFullPath(Path.Combine(parentFolder.Path, value)); - return new StorageFolderWithPath(await StorageFolder.GetFolderFromPathAsync(fullPath)); + return await StorageFolder.GetFolderFromPathAsync(fullPath); } else { - return new StorageFolderWithPath(await StorageFolder.GetFolderFromPathAsync(value)); + return await StorageFolder.GetFolderFromPathAsync(value); } } - public async static Task DangerousGetFolderFromPathAsync(string value, - StorageFolderWithPath rootFolder = null, - StorageFolderWithPath parentFolder = null) + public async static Task DangerousGetFolderFromPathAsync(string value, + IStorageFolder rootFolder = null, + IStorageFolder parentFolder = null) { - return (await DangerousGetFolderWithPathFromPathAsync(value, rootFolder, parentFolder)).Folder; + return await DangerousGetFolderWithPathFromPathAsync(value, rootFolder, parentFolder); } - public async static Task DangerousGetFileWithPathFromPathAsync(string value, - StorageFolderWithPath rootFolder = null, - StorageFolderWithPath parentFolder = null) + public async static Task DangerousGetFileWithPathFromPathAsync(string value, + IStorageFolder rootFolder = null, + IStorageFolder parentFolder = null) { if (rootFolder != null) { @@ -156,30 +152,24 @@ public async static Task DangerousGetFileWithPathFromPathAs if (parentFolder != null && value.IsSubPathOf(parentFolder.Path)) { - var folder = parentFolder.Folder; + var folder = parentFolder; var prevComponents = GetDirectoryPathComponents(parentFolder.Path); - var path = parentFolder.Path; foreach (var component in currComponents.ExceptBy(prevComponents, c => c.Path).SkipLast(1)) { folder = await folder.GetFolderAsync(component.Title); - path = Path.Combine(path, folder.Name); } var file = await folder.GetFileAsync(currComponents.Last().Title); - path = Path.Combine(path, file.Name); - return new StorageFileWithPath(file, path); + return file; } else if (value.IsSubPathOf(rootFolder.Path)) { - var folder = rootFolder.Folder; - var path = rootFolder.Path; + var folder = rootFolder; foreach (var component in currComponents.Skip(1).SkipLast(1)) { folder = await folder.GetFolderAsync(component.Title); - path = Path.Combine(path, folder.Name); } var file = await folder.GetFileAsync(currComponents.Last().Title); - path = Path.Combine(path, file.Name); - return new StorageFileWithPath(file, path); + return file; } } @@ -187,40 +177,28 @@ public async static Task DangerousGetFileWithPathFromPathAs { // Relative path var fullPath = Path.GetFullPath(Path.Combine(parentFolder.Path, value)); - return new StorageFileWithPath(await StorageFile.GetFileFromPathAsync(fullPath)); + return await StorageFile.GetFileFromPathAsync(fullPath); } else { - return new StorageFileWithPath(await StorageFile.GetFileFromPathAsync(value)); + return await StorageFile.GetFileFromPathAsync(value); } } - public async static Task DangerousGetFileFromPathAsync(string value, - StorageFolderWithPath rootFolder = null, - StorageFolderWithPath parentFolder = null) + public async static Task DangerousGetFileFromPathAsync(string value, + IStorageFolder rootFolder = null, + IStorageFolder parentFolder = null) { - return (await DangerousGetFileWithPathFromPathAsync(value, rootFolder, parentFolder)).File; + return await DangerousGetFileWithPathFromPathAsync(value, rootFolder, parentFolder); } - public async static Task> GetFoldersWithPathAsync(this StorageFolderWithPath parentFolder, uint maxNumberOfItems = uint.MaxValue) - { - return (await parentFolder.Folder.GetFoldersAsync(CommonFolderQuery.DefaultQuery, 0, maxNumberOfItems)) - .Select(x => new StorageFolderWithPath(x, Path.Combine(parentFolder.Path, x.Name))).ToList(); - } - - public async static Task> GetFilesWithPathAsync(this StorageFolderWithPath parentFolder, uint maxNumberOfItems = uint.MaxValue) - { - return (await parentFolder.Folder.GetFilesAsync(CommonFileQuery.DefaultQuery, 0, maxNumberOfItems)) - .Select(x => new StorageFileWithPath(x, Path.Combine(parentFolder.Path, x.Name))).ToList(); - } - - public async static Task> GetFoldersWithPathAsync(this StorageFolderWithPath parentFolder, string nameFilter, uint maxNumberOfItems = uint.MaxValue) + public async static Task> GetFoldersWithPathAsync(this StorageFolder parentFolder, string nameFilter, uint maxNumberOfItems = uint.MaxValue) { var queryOptions = new QueryOptions(); queryOptions.ApplicationSearchFilter = $"System.FileName:{nameFilter}*"; - StorageFolderQueryResult queryResult = parentFolder.Folder.CreateFolderQueryWithOptions(queryOptions); + StorageFolderQueryResult queryResult = parentFolder.CreateFolderQueryWithOptions(queryOptions); - return (await queryResult.GetFoldersAsync(0, maxNumberOfItems)).Select(x => new StorageFolderWithPath(x, Path.Combine(parentFolder.Path, x.Name))).ToList(); + return (await queryResult.GetFoldersAsync(0, maxNumberOfItems)).ToList(); } public static string GetPathWithoutEnvironmentVariable(string path) diff --git a/Files/Filesystem/StorageFileHelpers/StorageFileWithPath.cs b/Files/Filesystem/StorageFileHelpers/StorageFileWithPath.cs deleted file mode 100644 index f5397dc1efb3..000000000000 --- a/Files/Filesystem/StorageFileHelpers/StorageFileWithPath.cs +++ /dev/null @@ -1,35 +0,0 @@ -using Windows.Storage; - -namespace Files.Filesystem -{ - public class StorageFileWithPath : IStorageItemWithPath - { - public StorageFile File - { - get - { - return (StorageFile)Item; - } - set - { - Item = value; - } - } - - public string Path { get; set; } - public IStorageItem Item { get; set; } - public FilesystemItemType ItemType => FilesystemItemType.File; - - public StorageFileWithPath(StorageFile file) - { - File = file; - Path = File.Path; - } - - public StorageFileWithPath(StorageFile file, string path) - { - File = file; - Path = path; - } - } -} \ No newline at end of file diff --git a/Files/Filesystem/StorageFileHelpers/StorageFolderWithPath.cs b/Files/Filesystem/StorageFileHelpers/StorageFolderWithPath.cs deleted file mode 100644 index 63174d5fe842..000000000000 --- a/Files/Filesystem/StorageFileHelpers/StorageFolderWithPath.cs +++ /dev/null @@ -1,35 +0,0 @@ -using Windows.Storage; - -namespace Files.Filesystem -{ - public class StorageFolderWithPath : IStorageItemWithPath - { - public StorageFolder Folder - { - get - { - return (StorageFolder)Item; - } - set - { - Item = value; - } - } - - public string Path { get; set; } - public IStorageItem Item { get; set; } - public FilesystemItemType ItemType => FilesystemItemType.Directory; - - public StorageFolderWithPath(StorageFolder folder) - { - Folder = folder; - Path = folder.Path; - } - - public StorageFolderWithPath(StorageFolder folder, string path) - { - Folder = folder; - Path = path; - } - } -} \ No newline at end of file diff --git a/Files/Filesystem/StorageHistory/IStorageHistory.cs b/Files/Filesystem/StorageHistory/IStorageHistory.cs index 5ccbb1bd8246..4aea5426d331 100644 --- a/Files/Filesystem/StorageHistory/IStorageHistory.cs +++ b/Files/Filesystem/StorageHistory/IStorageHistory.cs @@ -1,6 +1,7 @@ using Files.Enums; using System; using System.Collections.Generic; +using Windows.Storage; namespace Files.Filesystem.FilesystemHistory { @@ -19,7 +20,7 @@ public interface IStorageHistory : IDisposable ///
/// May contain more that one item ///
- IEnumerable Source { get; } + IEnumerable Source { get; } /// /// Destination file/folder @@ -29,15 +30,15 @@ public interface IStorageHistory : IDisposable ///
/// May contain more that one item ///
- IEnumerable Destination { get; } + IEnumerable Destination { get; } #region Modify void Modify(IStorageHistory newHistory); - void Modify(FileOperationType operationType, IEnumerable source, IEnumerable destination); + void Modify(FileOperationType operationType, IEnumerable source, IEnumerable destination); - void Modify(FileOperationType operationType, IStorageItemWithPath source, IStorageItemWithPath destination); + void Modify(FileOperationType operationType, IStorageItem source, IStorageItem destination); #endregion Modify } diff --git a/Files/Filesystem/StorageHistory/StorageHistory.cs b/Files/Filesystem/StorageHistory/StorageHistory.cs index 458687d2050c..1b99205ba183 100644 --- a/Files/Filesystem/StorageHistory/StorageHistory.cs +++ b/Files/Filesystem/StorageHistory/StorageHistory.cs @@ -1,6 +1,7 @@ using Files.Enums; using Files.Extensions; using System.Collections.Generic; +using Windows.Storage; namespace Files.Filesystem.FilesystemHistory { @@ -10,22 +11,22 @@ public class StorageHistory : IStorageHistory public FileOperationType OperationType { get; private set; } - public IEnumerable Source { get; private set; } + public IEnumerable Source { get; private set; } - public IEnumerable Destination { get; private set; } + public IEnumerable Destination { get; private set; } #endregion Public Properties #region Constructor - public StorageHistory(FileOperationType operationType, IEnumerable source, IEnumerable destination) + public StorageHistory(FileOperationType operationType, IEnumerable source, IEnumerable destination) { OperationType = operationType; Source = source; Destination = destination; } - public StorageHistory(FileOperationType operationType, IStorageItemWithPath source, IStorageItemWithPath destination) + public StorageHistory(FileOperationType operationType, IStorageItem source, IStorageItem destination) { OperationType = operationType; Source = source.CreateEnumerable(); @@ -43,14 +44,14 @@ public void Modify(IStorageHistory newHistory) Destination = newHistory.Destination; } - public void Modify(FileOperationType operationType, IEnumerable source, IEnumerable destination) + public void Modify(FileOperationType operationType, IEnumerable source, IEnumerable destination) { OperationType = operationType; Source = source; Destination = destination; } - public void Modify(FileOperationType operationType, IStorageItemWithPath source, IStorageItemWithPath destination) + public void Modify(FileOperationType operationType, IStorageItem source, IStorageItem destination) { OperationType = operationType; Source = source.CreateEnumerable(); diff --git a/Files/Helpers/StorageItemHelpers.cs b/Files/Helpers/StorageItemHelpers.cs index d263fac42a89..998d43de600b 100644 --- a/Files/Helpers/StorageItemHelpers.cs +++ b/Files/Helpers/StorageItemHelpers.cs @@ -108,27 +108,13 @@ public static async Task GetFileSize(this IStorageFile file) return (long)properties.Size; } - public static async Task> ToStorageItemResult(this IStorageItemWithPath item, IShellPage associatedInstance = null) + public static async Task> ToStorageItemResult(this IStorageItem item, IShellPage associatedInstance = null) { - var returnedItem = new FilesystemResult(null, FileSystemStatusCode.Generic); - if (!string.IsNullOrEmpty(item.Path)) - { - returnedItem = (item.ItemType == FilesystemItemType.File) ? - ToType(associatedInstance != null ? - await associatedInstance.FilesystemViewModel.GetFileFromPathAsync(item.Path) : - await FilesystemTasks.Wrap(() => StorageFileExtensions.DangerousGetFileFromPathAsync(item.Path))) : - ToType(associatedInstance != null ? - await associatedInstance.FilesystemViewModel.GetFolderFromPathAsync(item.Path) : - await FilesystemTasks.Wrap(() => StorageFileExtensions.DangerousGetFolderFromPathAsync(item.Path))); - } - if (returnedItem.Result == null && item.Item != null) - { - returnedItem = new FilesystemResult(item.Item, FileSystemStatusCode.Success); - } + var returnedItem = new FilesystemResult(item, FileSystemStatusCode.Success); return returnedItem; } - public static IStorageItemWithPath FromPathAndType(string customPath, FilesystemItemType? itemType) + public static IStorageItem FromPathAndType(string customPath, FilesystemItemType? itemType) { return (itemType == FilesystemItemType.File) ? (IStorageItemWithPath)new StorageFileWithPath(null, customPath) : diff --git a/Files/Interacts/BaseLayoutCommandImplementationModel.cs b/Files/Interacts/BaseLayoutCommandImplementationModel.cs index 092b656b2aae..f8c2708a933b 100644 --- a/Files/Interacts/BaseLayoutCommandImplementationModel.cs +++ b/Files/Interacts/BaseLayoutCommandImplementationModel.cs @@ -227,7 +227,7 @@ public virtual async void OpenFileLocation(RoutedEventArgs e) // Check if destination path exists string folderPath = Path.GetDirectoryName(item.TargetPath); - FilesystemResult destFolder = await associatedInstance.FilesystemViewModel.GetFolderWithPathFromPathAsync(folderPath); + FilesystemResult destFolder = await associatedInstance.FilesystemViewModel.GetFolderWithPathFromPathAsync(folderPath); if (destFolder) { diff --git a/Files/ViewModels/ItemViewModel.cs b/Files/ViewModels/ItemViewModel.cs index f992b8983a15..1f2f7e121a33 100644 --- a/Files/ViewModels/ItemViewModel.cs +++ b/Files/ViewModels/ItemViewModel.cs @@ -86,8 +86,8 @@ public string WorkingDirectory get; private set; } - private StorageFolderWithPath currentStorageFolder; - private StorageFolderWithPath workingRoot; + private IStorageFolder currentStorageFolder; + private IStorageFolder workingRoot; public delegate void WorkingDirectoryModifiedEventHandler(object sender, WorkingDirectoryModifiedEventArgs e); @@ -151,12 +151,12 @@ public async Task> GetFileFromPathAsync(string val return await FilesystemTasks.Wrap(() => StorageFileExtensions.DangerousGetFileFromPathAsync(value, workingRoot, currentStorageFolder)); } - public async Task> GetFolderWithPathFromPathAsync(string value) + public async Task> GetFolderWithPathFromPathAsync(string value) { return await FilesystemTasks.Wrap(() => StorageFileExtensions.DangerousGetFolderWithPathFromPathAsync(value, workingRoot, currentStorageFolder)); } - public async Task> GetFileWithPathFromPathAsync(string value) + public async Task> GetFileWithPathFromPathAsync(string value) { return await FilesystemTasks.Wrap(() => StorageFileExtensions.DangerousGetFileWithPathFromPathAsync(value, workingRoot, currentStorageFolder)); } @@ -1459,7 +1459,7 @@ await DialogDisplayHelper.ShowDialogAsync( } } - private async Task EnumFromStorageFolderAsync(string path, ListedItem currentFolder, StorageFolder rootFolder, StorageFolderWithPath currentStorageFolder, Type sourcePageType, CancellationToken cancellationToken) + private async Task EnumFromStorageFolderAsync(string path, ListedItem currentFolder, StorageFolder rootFolder, IStorageFolder currentStorageFolder, Type sourcePageType, CancellationToken cancellationToken) { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); diff --git a/Files/ViewModels/MainPageViewModel.cs b/Files/ViewModels/MainPageViewModel.cs index 518fc5e2a3a5..6a15f99d8e41 100644 --- a/Files/ViewModels/MainPageViewModel.cs +++ b/Files/ViewModels/MainPageViewModel.cs @@ -336,13 +336,13 @@ public static async Task UpdateTabInfo(TabItem tabItem, object navigationArg) fontIconSource.Glyph = "\xE8B7"; // Folder icon tabLocationHeader = currentPath.TrimEnd(System.IO.Path.DirectorySeparatorChar, System.IO.Path.AltDirectorySeparatorChar).Split('\\', StringSplitOptions.RemoveEmptyEntries).Last(); - FilesystemResult rootItem = await FilesystemTasks.Wrap(() => DrivesManager.GetRootFromPathAsync(currentPath)); + FilesystemResult rootItem = await FilesystemTasks.Wrap(() => DrivesManager.GetRootFromPathAsync(currentPath)); if (rootItem) { - StorageFolder currentFolder = await FilesystemTasks.Wrap(() => StorageFileExtensions.DangerousGetFolderFromPathAsync(currentPath, rootItem)); - if (currentFolder != null && !string.IsNullOrEmpty(currentFolder.DisplayName)) + IStorageFolder currentFolder = (await FilesystemTasks.Wrap(() => StorageFileExtensions.DangerousGetFolderFromPathAsync(currentPath, rootItem.Result))).Result; + if (currentFolder is StorageFolder folder && !string.IsNullOrEmpty(folder.DisplayName)) { - tabLocationHeader = currentFolder.DisplayName; + tabLocationHeader = folder.DisplayName; } } } diff --git a/Files/ViewModels/NavToolbarViewModel.cs b/Files/ViewModels/NavToolbarViewModel.cs index 6f105336c005..99aa9ea63001 100644 --- a/Files/ViewModels/NavToolbarViewModel.cs +++ b/Files/ViewModels/NavToolbarViewModel.cs @@ -518,12 +518,12 @@ public void Dispose() public async Task SetPathBoxDropDownFlyoutAsync(MenuFlyout flyout, PathBoxItem pathItem, IShellPage shellPage) { var nextPathItemTitle = PathComponents[PathComponents.IndexOf(pathItem) + 1].Title; - IList childFolders = null; + IList childFolders = null; - StorageFolderWithPath folder = await shellPage.FilesystemViewModel.GetFolderWithPathFromPathAsync(pathItem.Path); - if (folder != null) + IStorageFolder folder = (await shellPage.FilesystemViewModel.GetFolderWithPathFromPathAsync(pathItem.Path)).Result; + if (folder is StorageFolder storageFolder) { - childFolders = (await FilesystemTasks.Wrap(() => folder.GetFoldersWithPathAsync(string.Empty))).Result; + childFolders = (await FilesystemTasks.Wrap(() => storageFolder.GetFoldersWithPathAsync(string.Empty))).Result.Cast().ToList(); } flyout.Items?.Clear(); @@ -549,7 +549,7 @@ public async Task SetPathBoxDropDownFlyoutAsync(MenuFlyout flyout, PathBoxItem p foreach (var childFolder in childFolders) { - var isPathItemFocused = childFolder.Item.Name == nextPathItemTitle; + var isPathItemFocused = childFolder.Name == nextPathItemTitle; var flyoutItem = new MenuFlyoutItem { @@ -558,7 +558,7 @@ public async Task SetPathBoxDropDownFlyoutAsync(MenuFlyout flyout, PathBoxItem p Glyph = "\uED25", FontWeight = isPathItemFocused ? boldFontWeight : normalFontWeight }, - Text = childFolder.Item.Name, + Text = childFolder.Name, FontSize = 12, FontWeight = isPathItemFocused ? boldFontWeight : normalFontWeight }; @@ -607,7 +607,7 @@ public async Task CheckPathInput(string currentInput, string currentSelectedPath var item = await FilesystemTasks.Wrap(() => DrivesManager.GetRootFromPathAsync(currentInput)); - var resFolder = await FilesystemTasks.Wrap(() => StorageFileExtensions.DangerousGetFolderWithPathFromPathAsync(currentInput, item)); + var resFolder = await FilesystemTasks.Wrap(() => StorageFileExtensions.DangerousGetFolderWithPathFromPathAsync(currentInput, item.Result)); if (resFolder || FolderHelpers.CheckFolderAccessWithWin32(currentInput)) { var pathToNavigate = resFolder.Result?.Path ?? currentInput; @@ -615,7 +615,7 @@ public async Task CheckPathInput(string currentInput, string currentSelectedPath } else // Not a folder or inaccessible { - var resFile = await FilesystemTasks.Wrap(() => StorageFileExtensions.DangerousGetFileWithPathFromPathAsync(currentInput, item)); + var resFile = await FilesystemTasks.Wrap(() => StorageFileExtensions.DangerousGetFileWithPathFromPathAsync(currentInput, item.Result)); if (resFile) { var pathToInvoke = resFile.Result.Path; @@ -681,27 +681,31 @@ public async void SetAddressBarSuggestions(AutoSuggestBox sender, IShellPage she var expandedPath = StorageFileExtensions.GetPathWithoutEnvironmentVariable(sender.Text); var folderPath = Path.GetDirectoryName(expandedPath) ?? expandedPath; var folder = await shellpage.FilesystemViewModel.GetFolderWithPathFromPathAsync(folderPath); - var currPath = await folder.Result.GetFoldersWithPathAsync(Path.GetFileName(expandedPath), (uint)maxSuggestions); + if (folder.Result is not StorageFolder storageFolder) + { + return; + } + var currPath = await storageFolder.GetFoldersWithPathAsync(Path.GetFileName(expandedPath), (uint)maxSuggestions); if (currPath.Count() >= maxSuggestions) { suggestions = currPath.Select(x => new ListedItem(null) { ItemPath = x.Path, - ItemName = x.Folder.DisplayName + ItemName = x.DisplayName }).ToList(); } else if (currPath.Any()) { - var subPath = await currPath.First().GetFoldersWithPathAsync((uint)(maxSuggestions - currPath.Count())); + var subPath = await currPath.First().GetFoldersWithPathAsync("", (uint)(maxSuggestions - currPath.Count())); suggestions = currPath.Select(x => new ListedItem(null) { ItemPath = x.Path, - ItemName = x.Folder.DisplayName + ItemName = x.DisplayName }).Concat( subPath.Select(x => new ListedItem(null) { ItemPath = x.Path, - ItemName = Path.Combine(currPath.First().Folder.DisplayName, x.Folder.DisplayName) + ItemName = Path.Combine(currPath.First().DisplayName, x.DisplayName) })).ToList(); } else