From 35109059fa8d77cdbd616035c74b2d05d9c05c81 Mon Sep 17 00:00:00 2001 From: Steve Date: Mon, 3 May 2021 21:46:45 +0800 Subject: [PATCH] refactor completed without tests --- .../StorageItems/PlaceholderFile.cs | 35 +++++++++++++++++++ .../StorageItems/PlaceholderFolder.cs | 31 ++++++++++++++++ Files/Helpers/StorageItemHelpers.cs | 12 ++++++- Files/Helpers/UIFilesystemHelpers.cs | 9 ++--- Files/Helpers/WallpaperHelpers.cs | 2 +- .../BaseLayoutCommandImplementationModel.cs | 23 +++--------- Files/ViewModels/MainPageViewModel.cs | 2 +- Files/ViewModels/Pages/YourHomeViewModel.cs | 2 +- Files/ViewModels/Previews/BasePreviewModel.cs | 10 +++--- .../Previews/HtmlPreviewViewModel.cs | 5 ++- .../Previews/ImagePreviewViewModel.cs | 29 ++++++++------- .../Previews/MarkdownPreviewViewModel.cs | 9 +++-- .../Previews/MediaPreviewViewModel.cs | 7 +++- .../Previews/PDFPreviewViewModel.cs | 8 ++++- .../Previews/RichTextPreviewViewModel.cs | 7 +++- .../Previews/TextPreviewViewModel.cs | 12 +++++-- Files/ViewModels/Properties/FileProperties.cs | 2 +- Files/Views/ColumnShellPage.xaml.cs | 33 ++++++++--------- Files/Views/ModernShellPage.xaml.cs | 33 ++++++++--------- Files/Views/Pages/PropertiesGeneral.xaml.cs | 3 +- Files/Views/WidgetsPage.xaml.cs | 3 +- 21 files changed, 183 insertions(+), 94 deletions(-) create mode 100644 Files/Filesystem/StorageItems/PlaceholderFile.cs create mode 100644 Files/Filesystem/StorageItems/PlaceholderFolder.cs diff --git a/Files/Filesystem/StorageItems/PlaceholderFile.cs b/Files/Filesystem/StorageItems/PlaceholderFile.cs new file mode 100644 index 0000000000000..704acff80d3c2 --- /dev/null +++ b/Files/Filesystem/StorageItems/PlaceholderFile.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Windows.Foundation; +using Windows.Storage; +using Windows.Storage.FileProperties; + +namespace Files.Filesystem.StorageItems +{ + class PlaceholderFile : IStorageItem + { + public IAsyncAction RenameAsync(string desiredName) => throw new NotSupportedException(); + public IAsyncAction RenameAsync(string desiredName, NameCollisionOption option) => throw new NotSupportedException(); + public IAsyncAction DeleteAsync() => throw new NotSupportedException(); + public IAsyncAction DeleteAsync(StorageDeleteOption option) => throw new NotSupportedException(); + public IAsyncOperation GetBasicPropertiesAsync() => throw new NotSupportedException(); + public bool IsOfType(StorageItemTypes type) => type == StorageItemTypes.File; + + public FileAttributes Attributes => throw new NotSupportedException(); + + public DateTimeOffset DateCreated => throw new NotSupportedException(); + + public string Name { get; } + + public string Path { get; } + + public PlaceholderFile(string path) + { + Path = path; + Name = System.IO.Path.GetFileName(path); + } + } +} diff --git a/Files/Filesystem/StorageItems/PlaceholderFolder.cs b/Files/Filesystem/StorageItems/PlaceholderFolder.cs new file mode 100644 index 0000000000000..e8d698fc36346 --- /dev/null +++ b/Files/Filesystem/StorageItems/PlaceholderFolder.cs @@ -0,0 +1,31 @@ +using System; +using Windows.Foundation; +using Windows.Storage; +using Windows.Storage.FileProperties; + +namespace Files.Filesystem.StorageItems +{ + class PlaceholderFolder : IStorageItem + { + public IAsyncAction RenameAsync(string desiredName) => throw new NotSupportedException(); + public IAsyncAction RenameAsync(string desiredName, NameCollisionOption option) => throw new NotSupportedException(); + public IAsyncAction DeleteAsync() => throw new NotSupportedException(); + public IAsyncAction DeleteAsync(StorageDeleteOption option) => throw new NotSupportedException(); + public IAsyncOperation GetBasicPropertiesAsync() => throw new NotSupportedException(); + public bool IsOfType(StorageItemTypes type) => type == StorageItemTypes.File; + + public FileAttributes Attributes => throw new NotSupportedException(); + + public DateTimeOffset DateCreated => throw new NotSupportedException(); + + public string Name { get; } + + public string Path { get; } + + public PlaceholderFolder(string path) + { + Path = path; + Name = System.IO.Path.GetFileName(path); + } + } +} diff --git a/Files/Helpers/StorageItemHelpers.cs b/Files/Helpers/StorageItemHelpers.cs index 42de84a76ecd7..3f08575ecd844 100644 --- a/Files/Helpers/StorageItemHelpers.cs +++ b/Files/Helpers/StorageItemHelpers.cs @@ -37,7 +37,17 @@ public static async Task PathToStorageItemAsync(string path, Type return new RecycleBinFolder(path); } - throw new InvalidOperationException(); + if (type == typeof(PlaceholderFile)) + { + return new PlaceholderFile(path); + } + + if (type == typeof(PlaceholderFolder)) + { + return new PlaceholderFolder(path); + } + + throw new NotSupportedException("Not supported IStorageItem implementation."); } public static async Task PathToStorageItemAsync(string path) where T : IStorageItem diff --git a/Files/Helpers/UIFilesystemHelpers.cs b/Files/Helpers/UIFilesystemHelpers.cs index 8b2e3938d6887..babd64bf129c1 100644 --- a/Files/Helpers/UIFilesystemHelpers.cs +++ b/Files/Helpers/UIFilesystemHelpers.cs @@ -2,6 +2,7 @@ using Files.Dialogs; using Files.Enums; using Files.Filesystem; +using Files.Filesystem.StorageItems; using Files.Interacts; using Microsoft.Toolkit.Uwp; using System; @@ -186,7 +187,7 @@ public static async Task RenameFileItemAsync(ListedItem item, string oldNa ReturnResult renamed = ReturnResult.InProgress; if (item.PrimaryItemAttribute == StorageItemTypes.Folder) { - renamed = await associatedInstance.FilesystemHelpers.RenameAsync(StorageItemHelpers.FromPathAndType(item.ItemPath, FilesystemItemType.Directory), + renamed = await associatedInstance.FilesystemHelpers.RenameAsync(item.StorageItem, newName, NameCollisionOption.FailIfExists, true); } else @@ -196,7 +197,7 @@ public static async Task RenameFileItemAsync(ListedItem item, string oldNa newName += item.FileExtension; } - renamed = await associatedInstance.FilesystemHelpers.RenameAsync(StorageItemHelpers.FromPathAndType(item.ItemPath, FilesystemItemType.File), + renamed = await associatedInstance.FilesystemHelpers.RenameAsync(item.StorageItem, newName, NameCollisionOption.FailIfExists, true); } @@ -238,7 +239,7 @@ public static async void CreateFileFromDialogResultType(AddItemType itemType, Sh created = await FilesystemTasks.Wrap(async () => { return await associatedInstance.FilesystemHelpers.CreateAsync( - StorageItemHelpers.FromPathAndType(System.IO.Path.Combine(folderRes.Result.Path, userInput), FilesystemItemType.Directory), + await StorageItemHelpers.PathToStorageItemAsync(System.IO.Path.Combine(folderRes.Result.Path, userInput)), true); }); break; @@ -248,7 +249,7 @@ public static async void CreateFileFromDialogResultType(AddItemType itemType, Sh created = await FilesystemTasks.Wrap(async () => { return await associatedInstance.FilesystemHelpers.CreateAsync( - StorageItemHelpers.FromPathAndType(System.IO.Path.Combine(folderRes.Result.Path, userInput + itemInfo?.Extension), FilesystemItemType.File), + await StorageItemHelpers.PathToStorageItemAsync(System.IO.Path.Combine(folderRes.Result.Path, userInput + itemInfo?.Extension)), true); }); break; diff --git a/Files/Helpers/WallpaperHelpers.cs b/Files/Helpers/WallpaperHelpers.cs index 32798539b4043..7ddd4f23f5030 100644 --- a/Files/Helpers/WallpaperHelpers.cs +++ b/Files/Helpers/WallpaperHelpers.cs @@ -13,7 +13,7 @@ public static async void SetAsBackground(WallpaperType type, string filePath, IS if (UserProfilePersonalizationSettings.IsSupported()) { // Get the path of the selected file - StorageFile sourceFile = await StorageItemHelpers.ToStorageItem(filePath, associatedInstance); + StorageFile sourceFile = await StorageItemHelpers.PathToStorageItemAsync(filePath); if (sourceFile == null) { return; diff --git a/Files/Interacts/BaseLayoutCommandImplementationModel.cs b/Files/Interacts/BaseLayoutCommandImplementationModel.cs index 7b126f4972c77..0060be96cb948 100644 --- a/Files/Interacts/BaseLayoutCommandImplementationModel.cs +++ b/Files/Interacts/BaseLayoutCommandImplementationModel.cs @@ -180,10 +180,7 @@ public virtual async void RestoreItem(RoutedEventArgs e) { if (listedItem is RecycleBinItem binItem) { - FilesystemItemType itemType = binItem.PrimaryItemAttribute == StorageItemTypes.Folder ? FilesystemItemType.Directory : FilesystemItemType.File; - await FilesystemHelpers.RestoreFromTrashAsync(StorageItemHelpers.FromPathAndType( - (listedItem as RecycleBinItem).ItemPath, - itemType), (listedItem as RecycleBinItem).ItemOriginalPath, true); + await FilesystemHelpers.RestoreFromTrashAsync(listedItem.StorageItem, (listedItem as RecycleBinItem).ItemOriginalPath, true); } } } @@ -192,9 +189,7 @@ await FilesystemHelpers.RestoreFromTrashAsync(StorageItemHelpers.FromPathAndType public virtual async void DeleteItem(RoutedEventArgs e) { await FilesystemHelpers.DeleteItemsAsync( - SlimContentPage.SelectedItems.Select((item) => StorageItemHelpers.FromPathAndType( - item.ItemPath, - item.PrimaryItemAttribute == StorageItemTypes.File ? FilesystemItemType.File : FilesystemItemType.Directory)).ToList(), + SlimContentPage.SelectedItems.Select((item) => item.StorageItem).ToList(), true, false, true); } @@ -219,7 +214,7 @@ public virtual async void OpenFileLocation(RoutedEventArgs e) // Check if destination path exists string folderPath = System.IO.Path.GetDirectoryName(item.TargetPath); - FilesystemResult destFolder = await associatedInstance.FilesystemViewModel.GetFolderWithPathFromPathAsync(folderPath); + FilesystemResult destFolder = await associatedInstance.FilesystemViewModel.GetFolderWithPathFromPathAsync(folderPath); if (destFolder) { @@ -352,19 +347,9 @@ async void Manager_DataRequested(DataTransferManager sender, DataRequestedEventA return; } } - else if (item.PrimaryItemAttribute == StorageItemTypes.Folder) - { - if (await StorageItemHelpers.ToStorageItem(item.ItemPath, associatedInstance) is StorageFolder folder) - { - items.Add(folder); - } - } else { - if (await StorageItemHelpers.ToStorageItem(item.ItemPath, associatedInstance) is StorageFile file) - { - items.Add(file); - } + items.Add(item.StorageItem); } } diff --git a/Files/ViewModels/MainPageViewModel.cs b/Files/ViewModels/MainPageViewModel.cs index 472bbafdf07a0..7dddcb1561bd5 100644 --- a/Files/ViewModels/MainPageViewModel.cs +++ b/Files/ViewModels/MainPageViewModel.cs @@ -320,7 +320,7 @@ 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)); diff --git a/Files/ViewModels/Pages/YourHomeViewModel.cs b/Files/ViewModels/Pages/YourHomeViewModel.cs index f1c4ae5a57a40..7f4d5042809c4 100644 --- a/Files/ViewModels/Pages/YourHomeViewModel.cs +++ b/Files/ViewModels/Pages/YourHomeViewModel.cs @@ -70,7 +70,7 @@ private void BundlesViewModel_OpenPathInNewPaneEvent(object sender, string e) private async void BundlesViewModel_OpenPathEvent(object sender, BundlesOpenPathEventArgs e) { - await NavigationHelpers.OpenPath(e.path, associatedInstance, e.itemType, e.openSilent, e.openViaApplicationPicker, e.selectItems); + await NavigationHelpers.OpenPath(e.item, associatedInstance, false /* TODO: ? */, e.openSilent, e.openViaApplicationPicker, e.selectItems); } #region IDisposable diff --git a/Files/ViewModels/Previews/BasePreviewModel.cs b/Files/ViewModels/Previews/BasePreviewModel.cs index 3c80201f24c0e..f7be009b99c80 100644 --- a/Files/ViewModels/Previews/BasePreviewModel.cs +++ b/Files/ViewModels/Previews/BasePreviewModel.cs @@ -54,9 +54,9 @@ public async virtual Task> LoadPreviewAndDetails() { Item.FileImage = await IconData.ToBitmapAsync(); } - else + else if (Item.StorageItem is StorageFile file) { - using var icon = await Item.ItemFile.GetThumbnailAsync(ThumbnailMode.SingleItem, 400); + using var icon = await file.GetThumbnailAsync(ThumbnailMode.SingleItem, 400); Item.FileImage ??= new Windows.UI.Xaml.Media.Imaging.BitmapImage(); await Item.FileImage.SetSourceAsync(icon); } @@ -66,12 +66,12 @@ public async virtual Task> LoadPreviewAndDetails() private async Task> GetSystemFileProperties() { - if (Item.IsShortcutItem) + if (Item.IsShortcutItem || Item.StorageItem is not StorageFile file) { return null; } - var list = await FileProperty.RetrieveAndInitializePropertiesAsync(Item.ItemFile, Constants.ResourceFilePaths.PreviewPaneDetailsPropertiesJsonPath); + var list = await FileProperty.RetrieveAndInitializePropertiesAsync(file, Constants.ResourceFilePaths.PreviewPaneDetailsPropertiesJsonPath); list.Find(x => x.ID == "address").Value = await FileProperties.GetAddressFromCoordinatesAsync((double?)list.Find(x => x.Property == "System.GPS.LatitudeDecimal").Value, (double?)list.Find(x => x.Property == "System.GPS.LongitudeDecimal").Value); @@ -86,7 +86,7 @@ private async Task> GetSystemFileProperties() public virtual async Task LoadAsync() { var detailsFull = new List(); - Item.ItemFile ??= await StorageFile.GetFileFromPathAsync(Item.ItemPath); + Item.StorageItem ??= await StorageFile.GetFileFromPathAsync(Item.ItemPath); DetailsFromPreview = await LoadPreviewAndDetails(); RaiseLoadedEvent(); var props = await GetSystemFileProperties(); diff --git a/Files/ViewModels/Previews/HtmlPreviewViewModel.cs b/Files/ViewModels/Previews/HtmlPreviewViewModel.cs index 24465fcbc530b..411f6df657dab 100644 --- a/Files/ViewModels/Previews/HtmlPreviewViewModel.cs +++ b/Files/ViewModels/Previews/HtmlPreviewViewModel.cs @@ -30,7 +30,10 @@ public string TextValue public async override Task> LoadPreviewAndDetails() { - TextValue = await FileIO.ReadTextAsync(Item.ItemFile); + if (Item.StorageItem is StorageFile file) + { + TextValue = await FileIO.ReadTextAsync(file); + } return new List(); } } diff --git a/Files/ViewModels/Previews/ImagePreviewViewModel.cs b/Files/ViewModels/Previews/ImagePreviewViewModel.cs index a2cf9ff60067f..ed5872bc910ad 100644 --- a/Files/ViewModels/Previews/ImagePreviewViewModel.cs +++ b/Files/ViewModels/Previews/ImagePreviewViewModel.cs @@ -31,20 +31,23 @@ public ImageSource ImageSource public override async Task> LoadPreviewAndDetails() { - FileRandomAccessStream stream = (FileRandomAccessStream)await Item.ItemFile.OpenAsync(FileAccessMode.Read); - - // svg files require a different type of source - if (!Item.ItemPath.EndsWith(".svg")) - { - var bitmap = new BitmapImage(); - ImageSource = bitmap; - await bitmap.SetSourceAsync(stream); - } - else + if (Item.StorageItem is StorageFile file) { - var bitmap = new SvgImageSource(); - ImageSource = bitmap; - await bitmap.SetSourceAsync(stream); + FileRandomAccessStream stream = (FileRandomAccessStream)await file.OpenAsync(FileAccessMode.Read); + + // svg files require a different type of source + if (!Item.ItemPath.EndsWith(".svg")) + { + var bitmap = new BitmapImage(); + ImageSource = bitmap; + await bitmap.SetSourceAsync(stream); + } + else + { + var bitmap = new SvgImageSource(); + ImageSource = bitmap; + await bitmap.SetSourceAsync(stream); + } } return new List(); diff --git a/Files/ViewModels/Previews/MarkdownPreviewViewModel.cs b/Files/ViewModels/Previews/MarkdownPreviewViewModel.cs index d60c7dcef5030..181387b0636f7 100644 --- a/Files/ViewModels/Previews/MarkdownPreviewViewModel.cs +++ b/Files/ViewModels/Previews/MarkdownPreviewViewModel.cs @@ -28,9 +28,12 @@ public string TextValue public override async Task> LoadPreviewAndDetails() { - var text = await FileIO.ReadTextAsync(Item.ItemFile); - var displayText = text.Length < Constants.PreviewPane.TextCharacterLimit ? text : text.Remove(Constants.PreviewPane.TextCharacterLimit); - TextValue = displayText; + if (Item.StorageItem is StorageFile file) + { + var text = await FileIO.ReadTextAsync(file); + var displayText = text.Length < Constants.PreviewPane.TextCharacterLimit ? text : text.Remove(Constants.PreviewPane.TextCharacterLimit); + TextValue = displayText; + } return new List(); } diff --git a/Files/ViewModels/Previews/MediaPreviewViewModel.cs b/Files/ViewModels/Previews/MediaPreviewViewModel.cs index e1d209ce5e71b..45024c47a62a8 100644 --- a/Files/ViewModels/Previews/MediaPreviewViewModel.cs +++ b/Files/ViewModels/Previews/MediaPreviewViewModel.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Threading.Tasks; using Windows.Media.Core; +using Windows.Storage; using Windows.UI.Xaml; namespace Files.ViewModels.Previews @@ -30,7 +31,11 @@ public MediaSource Source public override Task> LoadPreviewAndDetails() { - Source = MediaSource.CreateFromStorageFile(Item.ItemFile); + if (Item.StorageItem is StorageFile file) + { + Source = MediaSource.CreateFromStorageFile(file); + } + return Task.FromResult(new List()); } diff --git a/Files/ViewModels/Previews/PDFPreviewViewModel.cs b/Files/ViewModels/Previews/PDFPreviewViewModel.cs index 0ab268de671e7..5e94fed93fc31 100644 --- a/Files/ViewModels/Previews/PDFPreviewViewModel.cs +++ b/Files/ViewModels/Previews/PDFPreviewViewModel.cs @@ -6,6 +6,7 @@ using System.Diagnostics; using System.Threading.Tasks; using Windows.Data.Pdf; +using Windows.Storage; using Windows.Storage.Streams; using Windows.UI.Xaml; using Windows.UI.Xaml.Media.Imaging; @@ -35,7 +36,12 @@ public Visibility LoadingBarVisibility public async override Task> LoadPreviewAndDetails() { - var pdf = await PdfDocument.LoadFromFileAsync(Item.ItemFile); + if (Item.StorageItem is not StorageFile file) + { + return new List(); + } + + var pdf = await PdfDocument.LoadFromFileAsync(file); TryLoadPagesAsync(pdf); var details = new List { diff --git a/Files/ViewModels/Previews/RichTextPreviewViewModel.cs b/Files/ViewModels/Previews/RichTextPreviewViewModel.cs index 375432ec90853..ee6b15315e4d5 100644 --- a/Files/ViewModels/Previews/RichTextPreviewViewModel.cs +++ b/Files/ViewModels/Previews/RichTextPreviewViewModel.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Threading.Tasks; +using Windows.Storage; using Windows.Storage.Streams; namespace Files.ViewModels.Previews @@ -22,7 +23,11 @@ public RichTextPreviewViewModel(ListedItem item) : base(item) public async override Task> LoadPreviewAndDetails() { - Stream = await Item.ItemFile.OpenReadAsync(); + if (Item.StorageItem is StorageFile file) + { + Stream = await file.OpenReadAsync(); + } + return new List(); } } diff --git a/Files/ViewModels/Previews/TextPreviewViewModel.cs b/Files/ViewModels/Previews/TextPreviewViewModel.cs index 6413be9b34413..073560f9db44f 100644 --- a/Files/ViewModels/Previews/TextPreviewViewModel.cs +++ b/Files/ViewModels/Previews/TextPreviewViewModel.cs @@ -44,8 +44,9 @@ public static async Task TryLoadAsTextAsync(ListedItem item) try { - item.ItemFile = await StorageFile.GetFileFromPathAsync(item.ItemPath); - var text = await FileIO.ReadTextAsync(item.ItemFile); + var storageFile = await StorageFile.GetFileFromPathAsync(item.ItemPath); + item.StorageItem = storageFile; + var text = await FileIO.ReadTextAsync(storageFile); // Check if file is binary if (text.Contains("\0\0\0\0")) @@ -74,7 +75,12 @@ public async override Task> LoadPreviewAndDetails() try { - var text = TextValue ?? await FileIO.ReadTextAsync(Item.ItemFile); + if (Item.StorageItem is not StorageFile file) + { + return details; + } + + var text = TextValue ?? await FileIO.ReadTextAsync(file); details.Add(new FileProperty() { diff --git a/Files/ViewModels/Properties/FileProperties.cs b/Files/ViewModels/Properties/FileProperties.cs index 5f0e2c9646a59..8d9cb0b6f3cdd 100644 --- a/Files/ViewModels/Properties/FileProperties.cs +++ b/Files/ViewModels/Properties/FileProperties.cs @@ -346,7 +346,7 @@ private async void ViewModel_PropertyChanged(object sender, System.ComponentMode private async Task GetHashForFileAsync(ListedItem fileItem, string nameOfAlg, CancellationToken token, IProgress progress, IShellPage associatedInstance) { HashAlgorithmProvider algorithmProvider = HashAlgorithmProvider.OpenAlgorithm(nameOfAlg); - StorageFile file = await StorageItemHelpers.ToStorageItem((fileItem as ShortcutItem)?.TargetPath ?? fileItem.ItemPath, associatedInstance); + StorageFile file = await StorageItemHelpers.PathToStorageItemAsync((fileItem as ShortcutItem)?.TargetPath ?? fileItem.ItemPath); if (file == null) { return ""; diff --git a/Files/Views/ColumnShellPage.xaml.cs b/Files/Views/ColumnShellPage.xaml.cs index 77dc4253280b5..4805d906600e8 100644 --- a/Files/Views/ColumnShellPage.xaml.cs +++ b/Files/Views/ColumnShellPage.xaml.cs @@ -26,6 +26,7 @@ using Windows.ApplicationModel.Resources.Core; using Windows.Foundation.Collections; using Windows.Storage; +using Windows.Storage.Search; using Windows.System; using Windows.UI.Core; using Windows.UI.Text; @@ -398,27 +399,27 @@ private async void SetAddressBarSuggestions(AutoSuggestBox sender, int maxSugges var expandedPath = StorageFileExtensions.GetPathWithoutEnvironmentVariable(sender.Text); var folderPath = Path.GetDirectoryName(expandedPath) ?? expandedPath; var folder = await FilesystemViewModel.GetFolderWithPathFromPathAsync(folderPath); - var currPath = await folder.Result.GetFoldersWithPathAsync(Path.GetFileName(expandedPath), (uint)maxSuggestions); + var currPath = await folder.Result.GetFoldersAsync(CommonFolderQuery.DefaultQuery, 0, (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().GetFoldersAsync(CommonFolderQuery.DefaultQuery, 0, (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 @@ -489,12 +490,12 @@ private async Task SetPathBoxDropDownFlyoutAsync(MenuFlyout flyout, PathBoxItem { var nextPathItemTitle = NavigationToolbar.PathComponents [NavigationToolbar.PathComponents.IndexOf(pathItem) + 1].Title; - IList childFolders = null; + IReadOnlyList childFolders = null; - StorageFolderWithPath folder = await FilesystemViewModel.GetFolderWithPathFromPathAsync(pathItem.Path); + StorageFolder folder = await FilesystemViewModel.GetFolderWithPathFromPathAsync(pathItem.Path); if (folder != null) { - childFolders = (await FilesystemTasks.Wrap(() => folder.GetFoldersWithPathAsync(string.Empty))).Result; + childFolders = (await FilesystemTasks.Wrap(() => folder.GetFoldersAsync().AsTask())).Result; } flyout.Items?.Clear(); @@ -519,7 +520,7 @@ private async Task SetPathBoxDropDownFlyoutAsync(MenuFlyout flyout, PathBoxItem Path?.TrimEnd(Path.DirectorySeparatorChar); foreach (var childFolder in childFolders) { - var isPathItemFocused = childFolder.Item.Name == nextPathItemTitle; + var isPathItemFocused = childFolder.Name == nextPathItemTitle; var flyoutItem = new MenuFlyoutItem { @@ -528,7 +529,7 @@ private async Task SetPathBoxDropDownFlyoutAsync(MenuFlyout flyout, PathBoxItem Glyph = "\uED25", FontWeight = isPathItemFocused ? boldFontWeight : normalFontWeight }, - Text = childFolder.Item.Name, + Text = childFolder.Name, FontSize = 12, FontWeight = isPathItemFocused ? boldFontWeight : normalFontWeight }; @@ -602,7 +603,7 @@ public async void CheckPathInput(ItemViewModel instance, string currentInput, st var item = await FilesystemTasks.Wrap(() => DrivesManager.GetRootFromPathAsync(currentInput)); - var resFolder = await FilesystemTasks.Wrap(() => StorageFileExtensions.DangerousGetFolderWithPathFromPathAsync(currentInput, item)); + var resFolder = await FilesystemTasks.Wrap(() => StorageFileExtensions.DangerousGetFolderFromPathAsync(currentInput, item)); if (resFolder || FolderHelpers.CheckFolderAccessWithWin32(currentInput)) { var pathToNavigate = resFolder.Result?.Path ?? currentInput; @@ -615,7 +616,7 @@ public async void CheckPathInput(ItemViewModel instance, string currentInput, st } else // Not a folder or inaccessible { - var resFile = await FilesystemTasks.Wrap(() => StorageFileExtensions.DangerousGetFileWithPathFromPathAsync(currentInput, item)); + var resFile = await FilesystemTasks.Wrap(() => StorageFileExtensions.DangerousGetFileFromPathAsync(currentInput, item)); if (resFile) { var pathToInvoke = resFile.Result.Path; @@ -955,9 +956,7 @@ private async void KeyboardAccelerator_Invoked(KeyboardAccelerator sender, Keybo if (ContentPage.IsItemSelected && !NavigationToolbar.IsEditModeEnabled && !InstanceViewModel.IsPageTypeSearchResults) { await FilesystemHelpers.DeleteItemsAsync( - ContentPage.SelectedItems.Select((item) => StorageItemHelpers.FromPathAndType( - item.ItemPath, - item.PrimaryItemAttribute == StorageItemTypes.File ? FilesystemItemType.File : FilesystemItemType.Directory)).ToList(), + ContentPage.SelectedItems.Select((item) => item.StorageItem).ToList(), true, true, true); } @@ -999,9 +998,7 @@ await FilesystemHelpers.DeleteItemsAsync( if (ContentPage.IsItemSelected && !ContentPage.IsRenamingItem && !InstanceViewModel.IsPageTypeSearchResults) { await FilesystemHelpers.DeleteItemsAsync( - ContentPage.SelectedItems.Select((item) => StorageItemHelpers.FromPathAndType( - item.ItemPath, - item.PrimaryItemAttribute == StorageItemTypes.File ? FilesystemItemType.File : FilesystemItemType.Directory)).ToList(), + ContentPage.SelectedItems.Select((item) => item.StorageItem).ToList(), true, false, true); } diff --git a/Files/Views/ModernShellPage.xaml.cs b/Files/Views/ModernShellPage.xaml.cs index b7c1b681dfb14..787b92a693f51 100644 --- a/Files/Views/ModernShellPage.xaml.cs +++ b/Files/Views/ModernShellPage.xaml.cs @@ -28,6 +28,7 @@ using Windows.ApplicationModel.Resources.Core; using Windows.Foundation.Collections; using Windows.Storage; +using Windows.Storage.Search; using Windows.System; using Windows.UI.Core; using Windows.UI.Text; @@ -408,27 +409,27 @@ private async void SetAddressBarSuggestions(AutoSuggestBox sender, int maxSugges var expandedPath = StorageFileExtensions.GetPathWithoutEnvironmentVariable(sender.Text); var folderPath = Path.GetDirectoryName(expandedPath) ?? expandedPath; var folder = await FilesystemViewModel.GetFolderWithPathFromPathAsync(folderPath); - var currPath = await folder.Result.GetFoldersWithPathAsync(Path.GetFileName(expandedPath), (uint)maxSuggestions); + var currPath = await folder.Result.GetFoldersAsync(CommonFolderQuery.DefaultQuery, 0, (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().GetFoldersAsync(CommonFolderQuery.DefaultQuery, 0, (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 @@ -499,12 +500,12 @@ private async Task SetPathBoxDropDownFlyoutAsync(MenuFlyout flyout, PathBoxItem { var nextPathItemTitle = NavigationToolbar.PathComponents [NavigationToolbar.PathComponents.IndexOf(pathItem) + 1].Title; - IList childFolders = null; + IReadOnlyList childFolders = null; - StorageFolderWithPath folder = await FilesystemViewModel.GetFolderWithPathFromPathAsync(pathItem.Path); + StorageFolder folder = await FilesystemViewModel.GetFolderWithPathFromPathAsync(pathItem.Path); if (folder != null) { - childFolders = (await FilesystemTasks.Wrap(() => folder.GetFoldersWithPathAsync(string.Empty))).Result; + childFolders = (await FilesystemTasks.Wrap(() => folder.GetFoldersAsync().AsTask())).Result; } flyout.Items?.Clear(); @@ -529,7 +530,7 @@ private async Task SetPathBoxDropDownFlyoutAsync(MenuFlyout flyout, PathBoxItem Path?.TrimEnd(Path.DirectorySeparatorChar); foreach (var childFolder in childFolders) { - var isPathItemFocused = childFolder.Item.Name == nextPathItemTitle; + var isPathItemFocused = childFolder.Name == nextPathItemTitle; var flyoutItem = new MenuFlyoutItem { @@ -538,7 +539,7 @@ private async Task SetPathBoxDropDownFlyoutAsync(MenuFlyout flyout, PathBoxItem Glyph = "\uED25", FontWeight = isPathItemFocused ? boldFontWeight : normalFontWeight }, - Text = childFolder.Item.Name, + Text = childFolder.Name, FontSize = 12, FontWeight = isPathItemFocused ? boldFontWeight : normalFontWeight }; @@ -612,7 +613,7 @@ public async void CheckPathInput(ItemViewModel instance, string currentInput, st var item = await FilesystemTasks.Wrap(() => DrivesManager.GetRootFromPathAsync(currentInput)); - var resFolder = await FilesystemTasks.Wrap(() => StorageFileExtensions.DangerousGetFolderWithPathFromPathAsync(currentInput, item)); + var resFolder = await FilesystemTasks.Wrap(() => StorageFileExtensions.DangerousGetFolderFromPathAsync(currentInput, item)); if (resFolder || FolderHelpers.CheckFolderAccessWithWin32(currentInput)) { var pathToNavigate = resFolder.Result?.Path ?? currentInput; @@ -625,7 +626,7 @@ public async void CheckPathInput(ItemViewModel instance, string currentInput, st } else // Not a folder or inaccessible { - var resFile = await FilesystemTasks.Wrap(() => StorageFileExtensions.DangerousGetFileWithPathFromPathAsync(currentInput, item)); + var resFile = await FilesystemTasks.Wrap(() => StorageFileExtensions.DangerousGetFileFromPathAsync(currentInput, item)); if (resFile) { var pathToInvoke = resFile.Result.Path; @@ -971,9 +972,7 @@ private async void KeyboardAccelerator_Invoked(KeyboardAccelerator sender, Keybo if (ContentPage.IsItemSelected && !NavigationToolbar.IsEditModeEnabled && !InstanceViewModel.IsPageTypeSearchResults) { await FilesystemHelpers.DeleteItemsAsync( - ContentPage.SelectedItems.Select((item) => StorageItemHelpers.FromPathAndType( - item.ItemPath, - item.PrimaryItemAttribute == StorageItemTypes.File ? FilesystemItemType.File : FilesystemItemType.Directory)).ToList(), + ContentPage.SelectedItems.Select((item) => item.StorageItem).ToList(), true, true, true); } @@ -1015,9 +1014,7 @@ await FilesystemHelpers.DeleteItemsAsync( if (ContentPage.IsItemSelected && !ContentPage.IsRenamingItem && !InstanceViewModel.IsPageTypeSearchResults) { await FilesystemHelpers.DeleteItemsAsync( - ContentPage.SelectedItems.Select((item) => StorageItemHelpers.FromPathAndType( - item.ItemPath, - item.PrimaryItemAttribute == StorageItemTypes.File ? FilesystemItemType.File : FilesystemItemType.Directory)).ToList(), + ContentPage.SelectedItems.Select((item) => item.StorageItem).ToList(), true, false, true); } diff --git a/Files/Views/Pages/PropertiesGeneral.xaml.cs b/Files/Views/Pages/PropertiesGeneral.xaml.cs index e76de87f3aabf..0fc8576d5a726 100644 --- a/Files/Views/Pages/PropertiesGeneral.xaml.cs +++ b/Files/Views/Pages/PropertiesGeneral.xaml.cs @@ -8,6 +8,7 @@ using System.Threading.Tasks; using Windows.ApplicationModel.Core; using Windows.Foundation.Collections; +using Windows.Storage; namespace Files.Views { @@ -59,7 +60,7 @@ public override async Task SaveChangesAsync(ListedItem item) if (AppInstance.FilesystemViewModel != null && App.LibraryManager.CanCreateLibrary(newName).result) { var libraryPath = library.ItemPath; - var renamed = await AppInstance.FilesystemHelpers.RenameAsync(new StorageFileWithPath(null, libraryPath), newName, Windows.Storage.NameCollisionOption.FailIfExists, false); + var renamed = await AppInstance.FilesystemHelpers.RenameAsync(await StorageFile.GetFileFromPathAsync(libraryPath), newName, Windows.Storage.NameCollisionOption.FailIfExists, false); if (renamed == Enums.ReturnResult.Success) { var newPath = Path.Combine(Path.GetDirectoryName(libraryPath), $"{newName}{ShellLibraryItem.EXTENSION}"); diff --git a/Files/Views/WidgetsPage.xaml.cs b/Files/Views/WidgetsPage.xaml.cs index d1f8659cd6505..ba690184b9216 100644 --- a/Files/Views/WidgetsPage.xaml.cs +++ b/Files/Views/WidgetsPage.xaml.cs @@ -9,6 +9,7 @@ using System.IO; using System.Linq; using System.Runtime.InteropServices; +using Windows.Storage; using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Navigation; @@ -184,7 +185,7 @@ private async void LibraryWidget_LibraryCardPropertiesInvoked(object sender, Lib private async void LibraryWidget_LibraryCardDeleteInvoked(object sender, LibraryCardEventArgs e) { - await AppInstance.FilesystemHelpers.DeleteItemAsync(new StorageFileWithPath(null, e.Library.Path), false, false, false); + await AppInstance.FilesystemHelpers.DeleteItemAsync(await StorageFile.GetFileFromPathAsync(e.Library.Path), false, false, false); } private void DrivesWidget_DrivesWidgetNewPaneInvoked(object sender, DrivesWidget.DrivesWidgetInvokedEventArgs e)