-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Introduce abstract storage layer #9544
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
f10d2a9
Restructure a bit
d2dyno1 42d9842
Fixed conflicts
d2dyno1 1e62998
Solution update
d2dyno1 e6f0d97
Added storage base
d2dyno1 0922cd8
Implemented FTP storage
d2dyno1 17e8ea1
Merge remote-tracking branch 'upstream/main' into infra_storage
d2dyno1 8d9da12
Rewritten storage a bit
d2dyno1 8ec2e67
Fix project config
gave92 509e982
Removed devices abstraction
d2dyno1 80e7baf
Changed docs of IFileSystemService
d2dyno1 290d08d
Merge branch 'infra_storage' of https://github.com/d2dyno1/Files into…
gave92 068504e
Fixed build
d2dyno1 44aa3ae
Removed FtpDrive
d2dyno1 2dd9189
Update Files.Uwp.Storage.rd.xml
yaira2 8a8fb0e
Update Files.Uwp.Storage.rd.xml
yaira2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Files.Sdk.Storage.LocatableStorage; | ||
|
||
namespace Files.Backend.Services | ||
{ | ||
/// <summary> | ||
/// A service that interacts with the system file explorer. | ||
/// </summary> | ||
public interface IFileExplorerService | ||
{ | ||
/// <summary> | ||
/// Opens the app folder. | ||
/// </summary> | ||
/// <param name="cancellationToken">A <see cref="CancellationToken"/> that cancels this action.</param> | ||
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns> | ||
Task OpenAppFolderAsync(CancellationToken cancellationToken = default); | ||
|
||
/// <summary> | ||
/// Opens provided <paramref name="folder"/> in file explorer. | ||
/// </summary> | ||
/// <param name="folder">The folder to open file explorer in.</param> | ||
/// <param name="cancellationToken">A <see cref="CancellationToken"/> that cancels this action.</param> | ||
/// <returns>A <see cref="Task"/> that represents the asynchronous operation.</returns> | ||
Task OpenInFileExplorerAsync(ILocatableFolder folder, CancellationToken cancellationToken = default); | ||
|
||
/// <summary> | ||
/// Awaits the user input and picks single file from the file explorer dialog. | ||
/// </summary> | ||
/// <param name="filter">The filter to apply when picking files.</param> | ||
/// <param name="cancellationToken">A <see cref="CancellationToken"/> that cancels this action.</param> | ||
/// <returns>A <see cref="Task"/> that represents the asynchronous operation. If successful and a file has been picked, returns <see cref="ILocatableFile"/>, otherwise null.</returns> | ||
Task<ILocatableFile?> PickSingleFileAsync(IEnumerable<string>? filter, CancellationToken cancellationToken = default); | ||
|
||
/// <summary> | ||
/// Awaits the user input and picks single folder from the file explorer dialog. | ||
/// </summary> | ||
/// <param name="cancellationToken">A <see cref="CancellationToken"/> that cancels this action.</param> | ||
/// <returns>A <see cref="Task"/> that represents the asynchronous operation. If successful and a folder has been picked, returns <see cref="ILocatableFolder"/>, otherwise null.</returns> | ||
Task<ILocatableFolder?> PickSingleFolderAsync(CancellationToken cancellationToken = default); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace Files.Sdk.Storage.Enums | ||
{ | ||
public enum CreationCollisionOption : byte | ||
yaira2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
GenerateUniqueName = 0, | ||
ReplaceExisting = 1, | ||
OpenIfExists = 2, | ||
FailIfExists = 3, | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace Files.Sdk.Storage.Enums | ||
{ | ||
public enum NameCollisionOption : byte | ||
{ | ||
GenerateUniqueName = 0, | ||
ReplaceExisting = 1, | ||
FailIfExists = 2 | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System; | ||
|
||
namespace Files.Sdk.Storage.Enums | ||
{ | ||
[Flags] | ||
public enum StorableKind : byte | ||
{ | ||
None = 0, | ||
Files = 1, | ||
Folders = 2, | ||
All = Files | Folders | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System.IO; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace Files.Sdk.Storage.Extensions | ||
{ | ||
public static class StorageExtensions | ||
{ | ||
public static async Task CopyContentsToAsync(this IFile source, IFile destination, CancellationToken cancellationToken = default) | ||
yaira2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
// Internal Stream.GetCopyBufferSize() - https://github.com/dotnet/runtime/blob/main/src/libraries/System.Private.CoreLib/src/System/IO/Stream.cs | ||
const int DEFAULT_COPY_BUFFER_SIZE = 81920; | ||
|
||
using var sourceStream = await source.OpenStreamAsync(FileAccess.Read, FileShare.Read, cancellationToken); | ||
using var destinationStream = await destination.OpenStreamAsync(FileAccess.Read, FileShare.None, cancellationToken); | ||
|
||
await sourceStream.CopyToAsync(destinationStream, DEFAULT_COPY_BUFFER_SIZE, cancellationToken); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
<Platforms>x86;x64;arm64</Platforms> | ||
<RuntimeIdentifiers>win-arm64;win-x86;win-x64</RuntimeIdentifiers> | ||
<LangVersion>9</LangVersion> | ||
<Nullable>enable</Nullable> | ||
<Configurations>Debug;Release;Sideload</Configurations> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="6.0.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Folder Include="StorageEnumeration\" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
<Platforms>x86;x64;arm64</Platforms> | ||
<RuntimeIdentifiers>win-arm64;win-x86;win-x64</RuntimeIdentifiers> | ||
<LangVersion>9</LangVersion> | ||
<Nullable>enable</Nullable> | ||
<Configurations>Debug;Release;Sideload</Configurations> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="6.0.0" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System.IO; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace Files.Sdk.Storage | ||
{ | ||
/// <summary> | ||
/// Represents a file on the file system. | ||
/// </summary> | ||
public interface IFile : IStorable | ||
{ | ||
/// <summary> | ||
/// Opens and returns a stream to the file. | ||
/// </summary> | ||
/// <param name="access">The file access to open the file with.</param> | ||
/// <param name="cancellationToken">A <see cref="CancellationToken"/> that cancels this action.</param> | ||
/// <returns>A <see cref="Task"/> that represents the asynchronous operation. If successful, returns a <see cref="Stream"/>, otherwise null.</returns> | ||
Task<Stream> OpenStreamAsync(FileAccess access, FileShare share = FileShare.None, CancellationToken cancellationToken = default); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Files.Sdk.Storage.Enums; | ||
|
||
namespace Files.Sdk.Storage | ||
{ | ||
/// <summary> | ||
/// Represents a folder on the file system. | ||
/// </summary> | ||
public interface IFolder : IStorable | ||
{ | ||
/// <summary> | ||
/// Gets a file in the current directory by name. | ||
/// </summary> | ||
/// <param name="fileName">The name of the file.</param> | ||
/// <param name="cancellationToken">A <see cref="CancellationToken"/> that cancels this action.</param> | ||
/// <returns>A <see cref="Task"/> that represents the asynchronous operation. If file is found and access is granted, returns <see cref="IFile"/> otherwise null.</returns> | ||
Task<IFile> GetFileAsync(string fileName, CancellationToken cancellationToken = default); | ||
|
||
/// <summary> | ||
/// Gets a folder in the current directory by name. | ||
/// </summary> | ||
/// <param name="folderName">The name of the folder.</param> | ||
/// <param name="cancellationToken">A <see cref="CancellationToken"/> that cancels this action.</param> | ||
/// <returns>A <see cref="Task"/> that represents the asynchronous operation. If folder is found and access is granted, returns <see cref="IFolder"/> otherwise null.</returns> | ||
Task<IFolder> GetFolderAsync(string folderName, CancellationToken cancellationToken = default); | ||
|
||
/// <summary> | ||
/// Gets all items of this directory. | ||
/// </summary> | ||
/// <param name="kind">The type of items to enumerate.</param> | ||
/// <param name="cancellationToken">A <see cref="CancellationToken"/> that cancels this action.</param> | ||
/// <returns>Returns an async operation represented by <see cref="IAsyncEnumerable{T}"/> of type <see cref="IStorable"/> of items in the directory.</returns> | ||
IAsyncEnumerable<IStorable> GetItemsAsync(StorableKind kind = StorableKind.All, CancellationToken cancellationToken = default); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
namespace Files.Sdk.Storage | ||
{ | ||
/// <summary> | ||
/// Represents a base storage object on the file system. | ||
/// </summary> | ||
public interface IStorable | ||
{ | ||
/// <summary> | ||
/// Gets the unique and consistent identifier for this file or folder. | ||
/// </summary> | ||
public string Id { get; } | ||
|
||
/// <summary> | ||
/// Gets the name of the storage object. | ||
/// </summary> | ||
string Name { get; } | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace Files.Sdk.Storage.LocatableStorage | ||
{ | ||
/// <summary> | ||
/// Represents a file that resides within a folder structure. | ||
/// </summary> | ||
public interface ILocatableFile : IFile, ILocatableStorable | ||
{ | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace Files.Sdk.Storage.LocatableStorage | ||
{ | ||
/// <summary> | ||
/// Represents a folder that resides within a folder structure. | ||
/// </summary> | ||
public interface ILocatableFolder : IFolder, ILocatableStorable | ||
{ | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/Files.Sdk.Storage/LocatableStorage/ILocatableStorable.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace Files.Sdk.Storage.LocatableStorage | ||
{ | ||
/// <summary> | ||
/// Represents a file or folder that resides within a folder structure. | ||
/// </summary> | ||
public interface ILocatableStorable : IStorable | ||
{ | ||
/// <summary> | ||
/// Gets the path where the item resides. | ||
/// </summary> | ||
string Path { get; } | ||
|
||
/// <summary> | ||
/// Gets the containing folder for this item, if any. | ||
/// </summary> | ||
Task<ILocatableFolder?> GetParentAsync(CancellationToken cancellationToken = default); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace Files.Sdk.Storage.ModifiableStorage | ||
{ | ||
/// <summary> | ||
/// Represents a file that can be modified. | ||
/// </summary> | ||
public interface IModifiableFile : IFile, IModifiableStorable | ||
{ | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.