Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

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 interface IStorageItemWithPath
{
public string Name { get; }
public string Path { get; set; }
public IStorageItem Item { get; set; }
public string Path { get; }

public IStorageItem Item { get; }
public FilesystemItemType ItemType { get; }
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Files.Shared;
using Files.DataModels.NavigationControlItems;
using Files.DataModels.NavigationControlItems;
using Files.Extensions;
using Files.Filesystem.StorageItems;
using Files.Helpers;
Expand Down Expand Up @@ -106,7 +105,7 @@ public async static Task<StorageFolderWithPath> DangerousGetFolderWithPathFromPa
}
else if (parentFolder != null && value.IsSubPathOf(parentFolder.Path))
{
var folder = parentFolder.Folder;
var folder = parentFolder.Item;
var prevComponents = GetDirectoryPathComponents(parentFolder.Path);
var path = parentFolder.Path;
foreach (var component in currComponents.ExceptBy(prevComponents, c => c.Path))
Expand All @@ -118,7 +117,7 @@ public async static Task<StorageFolderWithPath> DangerousGetFolderWithPathFromPa
}
else if (value.IsSubPathOf(rootFolder.Path))
{
var folder = rootFolder.Folder;
var folder = rootFolder.Item;
var path = rootFolder.Path;
foreach (var component in currComponents.Skip(1))
{
Expand All @@ -145,7 +144,7 @@ public async static Task<BaseStorageFolder> DangerousGetFolderFromPathAsync(stri
StorageFolderWithPath rootFolder = null,
StorageFolderWithPath parentFolder = null)
{
return (await DangerousGetFolderWithPathFromPathAsync(value, rootFolder, parentFolder)).Folder;
return (await DangerousGetFolderWithPathFromPathAsync(value, rootFolder, parentFolder)).Item;
}

public async static Task<StorageFileWithPath> DangerousGetFileWithPathFromPathAsync(string value,
Expand All @@ -158,7 +157,7 @@ public async static Task<StorageFileWithPath> DangerousGetFileWithPathFromPathAs

if (parentFolder != null && value.IsSubPathOf(parentFolder.Path))
{
var folder = parentFolder.Folder;
var folder = parentFolder.Item;
var prevComponents = GetDirectoryPathComponents(parentFolder.Path);
var path = parentFolder.Path;
foreach (var component in currComponents.ExceptBy(prevComponents, c => c.Path).SkipLast(1))
Expand All @@ -172,7 +171,7 @@ public async static Task<StorageFileWithPath> DangerousGetFileWithPathFromPathAs
}
else if (value.IsSubPathOf(rootFolder.Path))
{
var folder = rootFolder.Folder;
var folder = rootFolder.Item;
var path = rootFolder.Path;
foreach (var component in currComponents.Skip(1).SkipLast(1))
{
Expand Down Expand Up @@ -201,18 +200,18 @@ public async static Task<BaseStorageFile> DangerousGetFileFromPathAsync(string v
StorageFolderWithPath rootFolder = null,
StorageFolderWithPath parentFolder = null)
{
return (await DangerousGetFileWithPathFromPathAsync(value, rootFolder, parentFolder)).File;
return (await DangerousGetFileWithPathFromPathAsync(value, rootFolder, parentFolder)).Item;
}

public async static Task<IList<StorageFolderWithPath>> GetFoldersWithPathAsync(this StorageFolderWithPath parentFolder, uint maxNumberOfItems = uint.MaxValue)
{
return (await parentFolder.Folder.GetFoldersAsync(CommonFolderQuery.DefaultQuery, 0, maxNumberOfItems))
return (await parentFolder.Item.GetFoldersAsync(CommonFolderQuery.DefaultQuery, 0, maxNumberOfItems))
.Select(x => new StorageFolderWithPath(x, PathNormalization.Combine(parentFolder.Path, x.Name))).ToList();
}

public async static Task<IList<StorageFileWithPath>> GetFilesWithPathAsync(this StorageFolderWithPath parentFolder, uint maxNumberOfItems = uint.MaxValue)
{
return (await parentFolder.Folder.GetFilesAsync(CommonFileQuery.DefaultQuery, 0, maxNumberOfItems))
return (await parentFolder.Item.GetFilesAsync(CommonFileQuery.DefaultQuery, 0, maxNumberOfItems))
.Select(x => new StorageFileWithPath(x, PathNormalization.Combine(parentFolder.Path, x.Name))).ToList();
}

Expand All @@ -225,7 +224,7 @@ public async static Task<IList<StorageFolderWithPath>> GetFoldersWithPathAsync(t

var queryOptions = new QueryOptions();
queryOptions.ApplicationSearchFilter = $"System.FileName:{nameFilter}*";
BaseStorageFolderQueryResult queryResult = parentFolder.Folder.CreateFolderQueryWithOptions(queryOptions);
BaseStorageFolderQueryResult queryResult = parentFolder.Item.CreateFolderQueryWithOptions(queryOptions);

return (await queryResult.GetFoldersAsync(0, maxNumberOfItems)).Select(x => new StorageFolderWithPath(x, PathNormalization.Combine(parentFolder.Path, x.Name))).ToList();
}
Expand Down
33 changes: 9 additions & 24 deletions src/Files.Uwp/Filesystem/StorageFileHelpers/StorageFileWithPath.cs
Original file line number Diff line number Diff line change
@@ -1,37 +1,22 @@
using Files.Filesystem.StorageItems;
using Windows.Storage;
using IO = System.IO;

namespace Files.Filesystem
{
public class StorageFileWithPath : IStorageItemWithPath
{
public BaseStorageFile File
{
get
{
return (BaseStorageFile)Item;
}
set
{
Item = value;
}
}
public string Path { get; }
public string Name => Item?.Name ?? IO.Path.GetFileName(Path);

IStorageItem IStorageItemWithPath.Item => Item;
public BaseStorageFile Item { get; }

public string Path { get; set; }
public string Name => Item?.Name ?? System.IO.Path.GetFileName(Path);
public IStorageItem Item { get; set; }
public FilesystemItemType ItemType => FilesystemItemType.File;

public StorageFileWithPath(BaseStorageFile file)
{
File = file;
Path = File.Path;
}

: this(file, file.Path) {}
public StorageFileWithPath(BaseStorageFile file, string path)
{
File = file;
Path = path;
}
=> (Item, Path) = (file, path);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,37 +1,22 @@
using Files.Filesystem.StorageItems;
using Windows.Storage;
using IO = System.IO;

namespace Files.Filesystem
{
public class StorageFolderWithPath : IStorageItemWithPath
{
public BaseStorageFolder Folder
{
get
{
return (BaseStorageFolder)Item;
}
set
{
Item = value;
}
}
public string Path { get; }
public string Name => Item?.Name ?? IO.Path.GetFileName(Path);

IStorageItem IStorageItemWithPath.Item => Item;
public BaseStorageFolder Item { get; }

public string Path { get; set; }
public string Name => Item?.Name ?? System.IO.Path.GetFileName(Path);
public IStorageItem Item { get; set; }
public FilesystemItemType ItemType => FilesystemItemType.Directory;

public StorageFolderWithPath(BaseStorageFolder folder)
{
Folder = folder;
Path = folder.Path;
}

: this(folder, folder.Path) {}
public StorageFolderWithPath(BaseStorageFolder folder, string path)
{
Folder = folder;
Path = path;
}
=> (Item, Path) = (folder, path);
}
}
}
24 changes: 12 additions & 12 deletions src/Files.Uwp/Helpers/NavigationHelpers.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using Files.Shared;
using Files.Shared.Enums;
using CommunityToolkit.Mvvm.DependencyInjection;
using Files.Backend.Services.Settings;
using Files.Filesystem;
using Files.Filesystem.StorageItems;
using Files.Backend.Services.Settings;
using Files.Shared;
using Files.Shared.Enums;
using Files.ViewModels;
using Files.Views;
using CommunityToolkit.Mvvm.DependencyInjection;
using Microsoft.Toolkit.Uwp;
using Newtonsoft.Json;
using System;
Expand Down Expand Up @@ -342,10 +342,10 @@ private static async Task<FilesystemResult> OpenDirectory(string path, IShellPag
.OnSuccess(async (childFolder) =>
{
// Add location to MRU List
if (childFolder.Folder is SystemStorageFolder)
if (childFolder.Item is SystemStorageFolder)
{
var mostRecentlyUsed = Windows.Storage.AccessCache.StorageApplicationPermissions.MostRecentlyUsedList;
mostRecentlyUsed.Add(await childFolder.Folder.ToStorageFolderAsync(), childFolder.Path);
mostRecentlyUsed.Add(await childFolder.Item.ToStorageFolderAsync(), childFolder.Path);
}
});
if (!opened)
Expand Down Expand Up @@ -392,10 +392,10 @@ private static async Task<FilesystemResult> OpenFile(string path, IShellPage ass
if (childFile != null)
{
// Add location to MRU List
if (childFile.File is SystemStorageFile)
if (childFile.Item is SystemStorageFile)
{
var mostRecentlyUsed = Windows.Storage.AccessCache.StorageApplicationPermissions.MostRecentlyUsedList;
mostRecentlyUsed.Add(await childFile.File.ToStorageFileAsync(), childFile.Path);
mostRecentlyUsed.Add(await childFile.Item.ToStorageFileAsync(), childFile.Path);
}
}
}
Expand All @@ -413,10 +413,10 @@ private static async Task<FilesystemResult> OpenFile(string path, IShellPage ass
.OnSuccess(async childFile =>
{
// Add location to MRU List
if (childFile.File is SystemStorageFile)
if (childFile.Item is SystemStorageFile)
{
var mostRecentlyUsed = Windows.Storage.AccessCache.StorageApplicationPermissions.MostRecentlyUsedList;
mostRecentlyUsed.Add(await childFile.File.ToStorageFileAsync(), childFile.Path);
mostRecentlyUsed.Add(await childFile.Item.ToStorageFileAsync(), childFile.Path);
}

if (openViaApplicationPicker)
Expand All @@ -425,7 +425,7 @@ private static async Task<FilesystemResult> OpenFile(string path, IShellPage ass
{
DisplayApplicationPicker = true
};
if (!await Launcher.LaunchFileAsync(childFile.File, options))
if (!await Launcher.LaunchFileAsync(childFile.Item, options))
{
var connection = await AppServiceConnectionHelper.Instance;
if (connection != null)
Expand Down Expand Up @@ -512,7 +512,7 @@ await connection.SendMessageAsync(new ValueSet()
}

// Now launch file with options.
launchSuccess = await Launcher.LaunchFileAsync(await childFile.File.ToStorageFileAsync(), options);
launchSuccess = await Launcher.LaunchFileAsync(await childFile.Item.ToStorageFileAsync(), options);
}

if (!launchSuccess)
Expand Down
6 changes: 3 additions & 3 deletions src/Files.Uwp/ViewModels/ItemViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1309,7 +1309,7 @@ private async Task RapidAddItemsToCollection(string path, LibraryItem library =
case 1: // Enumerated with StorageFolder
PageTypeUpdated?.Invoke(this, new PageTypeUpdatedEventArgs() { IsTypeCloudDrive = false });
currentStorageFolder ??= await FilesystemTasks.Wrap(() => StorageFileExtensions.DangerousGetFolderWithPathFromPathAsync(path));
WatchForStorageFolderChanges(currentStorageFolder?.Folder);
WatchForStorageFolderChanges(currentStorageFolder?.Item);
break;

case 2: // Watch for changes using FTP in Box Drive folder (#7428) and network drives (#5869)
Expand Down Expand Up @@ -1527,7 +1527,7 @@ public async Task<int> EnumerateItemsFromStandardFolderAsync(string path, Type s
return -1;
}
currentStorageFolder = res.Result;
rootFolder = currentStorageFolder.Folder;
rootFolder = currentStorageFolder.Item;
enumFromStorageFolder = true;
}
else
Expand All @@ -1536,7 +1536,7 @@ public async Task<int> EnumerateItemsFromStandardFolderAsync(string path, Type s
if (res)
{
currentStorageFolder = res.Result;
rootFolder = currentStorageFolder.Folder;
rootFolder = currentStorageFolder.Item;
}
else if (res == FileSystemStatusCode.Unauthorized)
{
Expand Down
22 changes: 11 additions & 11 deletions src/Files.Uwp/ViewModels/NavToolbarViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
using Files.Shared.Extensions;
using Files.Shared.Enums;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.DependencyInjection;
using CommunityToolkit.Mvvm.Input;
using Files.Backend.Services;
using Files.Backend.Services.Settings;
using Files.Filesystem;
using Files.Filesystem.StorageItems;
using Files.Helpers;
using Files.Backend.Services.Settings;
using Files.Shared.Enums;
using Files.Shared.EventArguments;
using Files.Shared.Extensions;
using Files.UserControls;
using Files.Views;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.DependencyInjection;
using CommunityToolkit.Mvvm.Input;
using Microsoft.Toolkit.Uwp;
using Microsoft.Toolkit.Uwp.UI;
using System;
Expand All @@ -27,11 +29,9 @@
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Input;
using Files.Backend.Services;
using static Files.UserControls.INavigationToolbar;
using SearchBox = Files.UserControls.SearchBox;
using SortDirection = Files.Shared.Enums.SortDirection;
using Files.Shared.EventArguments;

namespace Files.ViewModels
{
Expand Down Expand Up @@ -1055,7 +1055,7 @@ public async void SetAddressBarSuggestions(AutoSuggestBox sender, IShellPage she
suggestions = currPath.Select(x => new ListedItem(null)
{
ItemPath = x.Path,
ItemNameRaw = x.Folder.DisplayName
ItemNameRaw = x.Item.DisplayName
}).ToList();
}
else if (currPath.Any())
Expand All @@ -1064,12 +1064,12 @@ public async void SetAddressBarSuggestions(AutoSuggestBox sender, IShellPage she
suggestions = currPath.Select(x => new ListedItem(null)
{
ItemPath = x.Path,
ItemNameRaw = x.Folder.DisplayName
ItemNameRaw = x.Item.DisplayName
}).Concat(
subPath.Select(x => new ListedItem(null)
{
ItemPath = x.Path,
ItemNameRaw = PathNormalization.Combine(currPath.First().Folder.DisplayName, x.Folder.DisplayName)
ItemNameRaw = PathNormalization.Combine(currPath.First().Item.DisplayName, x.Item.DisplayName)
})).ToList();
}
else
Expand Down