Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Removal of IStorageItemWithPath #4825

Closed
wants to merge 2 commits into from
Closed
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
12 changes: 1 addition & 11 deletions Files/Files.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<AppxBundlePlatforms>x86|x64|arm|arm64</AppxBundlePlatforms>
<HoursBetweenUpdateChecks>0</HoursBetweenUpdateChecks>
<Win32Resource>Resources\MiddleClickScrolling-CursorType.res</Win32Resource>
<LangVersion>9.0</LangVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -40,7 +41,6 @@
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
<LangVersion>9.0</LangVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<UseDotNetNativeToolchain>false</UseDotNetNativeToolchain>
<UseAppLocalCoreFramework>true</UseAppLocalCoreFramework>
Expand All @@ -56,7 +56,6 @@
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
<UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>
<LangVersion>9.0</LangVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|ARM'">
Expand All @@ -69,7 +68,6 @@
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
<LangVersion>9.0</LangVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<UseAppLocalCoreFramework>true</UseAppLocalCoreFramework>
</PropertyGroup>
Expand All @@ -84,7 +82,6 @@
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
<UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>
<LangVersion>9.0</LangVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|ARM64'">
Expand All @@ -98,7 +95,6 @@
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
<UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>
<LangVersion>9.0</LangVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<UseAppLocalCoreFramework>true</UseAppLocalCoreFramework>
</PropertyGroup>
Expand All @@ -113,7 +109,6 @@
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
<UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>
<LangVersion>9.0</LangVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
Expand All @@ -126,7 +121,6 @@
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
<LangVersion>9.0</LangVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<UseAppLocalCoreFramework>true</UseAppLocalCoreFramework>
</PropertyGroup>
Expand All @@ -141,7 +135,6 @@
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
<UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>
<LangVersion>9.0</LangVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup>
Expand Down Expand Up @@ -423,9 +416,6 @@
<Compile Include="Filesystem\Search\FolderSearch.cs" />
<Compile Include="Filesystem\StorageFileHelpers\FilesystemResult.cs" />
<Compile Include="Filesystem\StorageFileHelpers\StorageFileExtensions.cs" />
<Compile Include="Filesystem\StorageFileHelpers\IStorageItemWithPath.cs" />
<Compile Include="Filesystem\StorageFileHelpers\StorageFileWithPath.cs" />
<Compile Include="Filesystem\StorageFileHelpers\StorageFolderWithPath.cs" />
<Compile Include="Filesystem\StorageHistory\Helpers\StorageHistoryHelpers.cs" />
<Compile Include="Filesystem\StorageHistory\IStorageHistory.cs" />
<Compile Include="Filesystem\StorageHistory\IStorageHistoryOperations.cs" />
Expand Down
6 changes: 3 additions & 3 deletions Files/Filesystem/Drives.cs
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ private DriveType GetDriveType(DriveInfo drive)
return type;
}

public static async Task<StorageFolderWithPath> GetRootFromPathAsync(string devicePath)
public static async Task<IStorageFolder> GetRootFromPathAsync(string devicePath)
{
if (!Path.IsPathRooted(devicePath))
{
Expand Down Expand Up @@ -419,13 +419,13 @@ public static async Task<StorageFolderWithPath> 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;
Expand Down
106 changes: 17 additions & 89 deletions Files/Filesystem/FilesystemOperations/FilesystemOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ public FilesystemOperations(IShellPage associatedInstance)

#region IFilesystemOperations

public async Task<(IStorageHistory, IStorageItem)> CreateAsync(IStorageItemWithPath source, IProgress<FileSystemStatusCode> errorCode, CancellationToken cancellationToken)
public async Task<(IStorageHistory, IStorageItem)> CreateAsync(IStorageItem source, IProgress<FileSystemStatusCode> 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)
Expand All @@ -73,20 +73,14 @@ 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));

break;
}

case FilesystemItemType.Symlink:
{
Debugger.Break();
throw new NotImplementedException();
}

default:
Debugger.Break();
break;
Expand All @@ -108,21 +102,6 @@ public async Task<IStorageHistory> CopyAsync(IStorageItem source,
IProgress<float> progress,
IProgress<FileSystemStatusCode> errorCode,
CancellationToken cancellationToken)
{
return await CopyAsync(source.FromStorageItem(),
destination,
collision,
progress,
errorCode,
cancellationToken);
}

public async Task<IStorageHistory> CopyAsync(IStorageItemWithPath source,
string destination,
NameCollisionOption collision,
IProgress<float> progress,
IProgress<FileSystemStatusCode> errorCode,
CancellationToken cancellationToken)
{
if (destination.StartsWith(App.AppSettings.RecycleBinPath))
{
Expand All @@ -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
Expand Down Expand Up @@ -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));

Expand Down Expand Up @@ -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<IStorageHistory> MoveAsync(IStorageItem source,
Expand All @@ -302,21 +279,6 @@ public async Task<IStorageHistory> MoveAsync(IStorageItem source,
IProgress<float> progress,
IProgress<FileSystemStatusCode> errorCode,
CancellationToken cancellationToken)
{
return await MoveAsync(source.FromStorageItem(),
destination,
collision,
progress,
errorCode,
cancellationToken);
}

public async Task<IStorageHistory> MoveAsync(IStorageItemWithPath source,
string destination,
NameCollisionOption collision,
IProgress<float> progress,
IProgress<FileSystemStatusCode> errorCode,
CancellationToken cancellationToken)
{
if (source.Path == destination)
{
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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));

Expand Down Expand Up @@ -496,29 +458,14 @@ 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<IStorageHistory> DeleteAsync(IStorageItem source,
IProgress<float> progress,
IProgress<FileSystemStatusCode> errorCode,
bool permanently,
CancellationToken cancellationToken)
{
return await DeleteAsync(source.FromStorageItem(),
progress,
errorCode,
permanently,
cancellationToken);
}

public async Task<IStorageHistory> DeleteAsync(IStorageItemWithPath source,
IProgress<float> progress,
IProgress<FileSystemStatusCode> errorCode,
bool permanently,
CancellationToken cancellationToken)
{
bool deleteFromRecycleBin = recycleBinHelpers.IsPathUnderRecycleBin(source.Path);

Expand All @@ -533,12 +480,12 @@ public async Task<IStorageHistory> 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());
Expand Down Expand Up @@ -631,15 +578,6 @@ public async Task<IStorageHistory> RenameAsync(IStorageItem source,
NameCollisionOption collision,
IProgress<FileSystemStatusCode> errorCode,
CancellationToken cancellationToken)
{
return await RenameAsync(StorageItemHelpers.FromStorageItem(source), newName, collision, errorCode, cancellationToken);
}

public async Task<IStorageHistory> RenameAsync(IStorageItemWithPath source,
string newName,
NameCollisionOption collision,
IProgress<FileSystemStatusCode> errorCode,
CancellationToken cancellationToken)
{
if (Path.GetFileName(source.Path) == newName && collision == NameCollisionOption.FailIfExists)
{
Expand Down Expand Up @@ -668,7 +606,7 @@ public async Task<IStorageHistory> 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)
{
Expand Down Expand Up @@ -747,7 +685,7 @@ public async Task<IStorageHistory> RenameAsync(IStorageItemWithPath source,
return null;
}

public async Task<IStorageHistory> RestoreFromTrashAsync(IStorageItemWithPath source,
public async Task<IStorageHistory> RestoreFromTrashAsync(IStorageItem source,
string destination,
IProgress<float> progress,
IProgress<FileSystemStatusCode> errorCode,
Expand All @@ -760,7 +698,7 @@ public async Task<IStorageHistory> RestoreFromTrashAsync(IStorageItemWithPath so

if (!fsResult)
{
if (source.ItemType == FilesystemItemType.Directory)
if (source is IStorageFolder)
{
FilesystemResult<StorageFolder> sourceFolder = await associatedInstance.FilesystemViewModel.GetFolderFromPathAsync(source.Path);
FilesystemResult<StorageFolder> destinationFolder = await associatedInstance.FilesystemViewModel.GetFolderFromPathAsync(Path.GetDirectoryName(destination));
Expand Down Expand Up @@ -953,12 +891,7 @@ public async Task<IStorageHistory> CopyItemsAsync(IEnumerable<IStorageItemWithPa
return null;
}

public async Task<IStorageHistory> MoveItemsAsync(IEnumerable<IStorageItem> source, IEnumerable<string> destination, IEnumerable<FileNameConflictResolveOptionType> collisions, IProgress<float> progress, IProgress<FileSystemStatusCode> errorCode, CancellationToken cancellationToken)
{
return await MoveItemsAsync(source.Select((item) => item.FromStorageItem()).ToList(), destination, collisions, progress, errorCode, cancellationToken);
}

public async Task<IStorageHistory> MoveItemsAsync(IEnumerable<IStorageItemWithPath> source, IEnumerable<string> destination, IEnumerable<FileNameConflictResolveOptionType> collisions, IProgress<float> progress, IProgress<FileSystemStatusCode> errorCode, CancellationToken token)
public async Task<IStorageHistory> MoveItemsAsync(IEnumerable<IStorageItem> source, IEnumerable<string> destination, IEnumerable<FileNameConflictResolveOptionType> collisions, IProgress<float> progress, IProgress<FileSystemStatusCode> errorCode, CancellationToken token)
{
var rawStorageHistory = new List<IStorageHistory>();

Expand Down Expand Up @@ -993,12 +926,7 @@ public async Task<IStorageHistory> MoveItemsAsync(IEnumerable<IStorageItemWithPa
return null;
}

public async Task<IStorageHistory> DeleteItemsAsync(IEnumerable<IStorageItem> source, IProgress<float> progress, IProgress<FileSystemStatusCode> errorCode, bool permanently, CancellationToken cancellationToken)
{
return await DeleteItemsAsync(source.Select((item) => item.FromStorageItem()), progress, errorCode, permanently, cancellationToken);
}

public async Task<IStorageHistory> DeleteItemsAsync(IEnumerable<IStorageItemWithPath> source, IProgress<float> progress, IProgress<FileSystemStatusCode> errorCode, bool permanently, CancellationToken token)
public async Task<IStorageHistory> DeleteItemsAsync(IEnumerable<IStorageItem> source, IProgress<float> progress, IProgress<FileSystemStatusCode> errorCode, bool permanently, CancellationToken token)
{
bool originalPermanently = permanently;
var rawStorageHistory = new List<IStorageHistory>();
Expand Down
Loading