Skip to content

Commit 84efbc2

Browse files
authored
Code Quality: Implemented OwlCore.Storage (#16900)
Co-authored-by: d2dyno006 <[email protected]>
1 parent 3c5e3aa commit 84efbc2

File tree

60 files changed

+142
-1132
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+142
-1132
lines changed

Directory.Packages.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
<PackageVersion Include="Microsoft.Extensions.Logging" Version="9.0.2" />
3030
<PackageVersion Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.26100.1742" />
3131
<PackageVersion Include="Microsoft.Xaml.Behaviors.WinUI.Managed" Version="3.0.0" />
32+
<PackageVersion Include="OwlCore.Storage" Version="0.12.2" />
3233
<PackageVersion Include="Sentry" Version="5.1.1" />
3334
<PackageVersion Include="SevenZipSharp" Version="1.0.2" />
3435
<PackageVersion Include="SQLitePCLRaw.bundle_green" Version="2.1.10" />

src/Files.App.Storage/GlobalUsings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
global using global::Files.Core.Storage.Enums;
2424
global using global::Files.Core.Storage.EventArguments;
2525
global using global::Files.Core.Storage.Extensions;
26-
global using global::Files.Core.Storage.StorageEnumeration;
26+
global using global::OwlCore.Storage;
2727

2828
// Files.App.Storage
2929

src/Files.App.Storage/Storables/FtpStorage/FtpStorable.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@
55

66
namespace Files.App.Storage.Storables
77
{
8-
public abstract class FtpStorable : ILocatableStorable, INestedStorable
8+
public abstract class FtpStorable : IStorableChild
99
{
10-
/// <inheritdoc/>
11-
public virtual string Path { get; protected set; }
12-
1310
/// <inheritdoc/>
1411
public virtual string Name { get; protected set; }
1512

@@ -23,21 +20,20 @@ public abstract class FtpStorable : ILocatableStorable, INestedStorable
2320

2421
protected internal FtpStorable(string path, string name, IFolder? parent)
2522
{
26-
Path = FtpHelpers.GetFtpPath(path);
23+
Id = FtpHelpers.GetFtpPath(path);
2724
Name = name;
28-
Id = Path;
2925
Parent = parent;
3026
}
3127

3228
/// <inheritdoc/>
3329
public Task<IFolder?> GetParentAsync(CancellationToken cancellationToken = default)
3430
{
35-
return Task.FromResult<IFolder?>(Parent);
31+
return Task.FromResult(Parent);
3632
}
3733

3834
protected AsyncFtpClient GetFtpClient()
3935
{
40-
return FtpHelpers.GetFtpClient(Path);
36+
return FtpHelpers.GetFtpClient(Id);
4137
}
4238
}
4339
}

src/Files.App.Storage/Storables/FtpStorage/FtpStorageFile.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace Files.App.Storage.Storables
77
{
8-
public sealed class FtpStorageFile : FtpStorable, IModifiableFile, ILocatableFile, INestedFile
8+
public sealed class FtpStorageFile : FtpStorable, IChildFile
99
{
1010
public FtpStorageFile(string path, string name, IFolder? parent)
1111
: base(path, name, parent)
@@ -19,9 +19,9 @@ public async Task<Stream> OpenStreamAsync(FileAccess access, CancellationToken c
1919
await ftpClient.EnsureConnectedAsync(cancellationToken);
2020

2121
if (access.HasFlag(FileAccess.Write))
22-
return await ftpClient.OpenWrite(Path, token: cancellationToken);
22+
return await ftpClient.OpenWrite(Id, token: cancellationToken);
2323
else if (access.HasFlag(FileAccess.Read))
24-
return await ftpClient.OpenRead(Path, token: cancellationToken);
24+
return await ftpClient.OpenRead(Id, token: cancellationToken);
2525
else
2626
throw new ArgumentException($"Invalid {nameof(access)} flag.");
2727
}

src/Files.App.Storage/Storables/FtpStorage/FtpStorageFolder.cs

Lines changed: 32 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -8,68 +8,57 @@
88

99
namespace Files.App.Storage.Storables
1010
{
11-
public sealed class FtpStorageFolder : FtpStorable, ILocatableFolder, IModifiableFolder, IFolderExtended, INestedFolder, IDirectCopy, IDirectMove
11+
public sealed class FtpStorageFolder : FtpStorable, IModifiableFolder, IChildFolder, IDirectCopy, IDirectMove, IGetFirstByName
1212
{
1313
public FtpStorageFolder(string path, string name, IFolder? parent)
1414
: base(path, name, parent)
1515
{
1616
}
1717

1818
/// <inheritdoc/>
19-
public async Task<INestedFile> GetFileAsync(string fileName, CancellationToken cancellationToken = default)
19+
public async Task<IStorableChild> GetFirstByNameAsync(string folderName, CancellationToken cancellationToken = default)
2020
{
2121
using var ftpClient = GetFtpClient();
2222
await ftpClient.EnsureConnectedAsync(cancellationToken);
2323

24-
var path = FtpHelpers.GetFtpPath(PathHelpers.Combine(Path, fileName));
24+
var path = FtpHelpers.GetFtpPath(PathHelpers.Combine(Id, folderName));
2525
var item = await ftpClient.GetObjectInfo(path, token: cancellationToken);
2626

27-
if (item is null || item.Type != FtpObjectType.File)
27+
if (item is null)
2828
throw new FileNotFoundException();
2929

30-
return new FtpStorageFile(path, item.Name, this);
31-
}
32-
33-
/// <inheritdoc/>
34-
public async Task<INestedFolder> GetFolderAsync(string folderName, CancellationToken cancellationToken = default)
35-
{
36-
using var ftpClient = GetFtpClient();
37-
await ftpClient.EnsureConnectedAsync(cancellationToken);
38-
39-
var path = FtpHelpers.GetFtpPath(PathHelpers.Combine(Path, folderName));
40-
var item = await ftpClient.GetObjectInfo(path, token: cancellationToken);
41-
42-
if (item is null || item.Type != FtpObjectType.Directory)
43-
throw new DirectoryNotFoundException();
30+
if (item.Type == FtpObjectType.Directory)
31+
return new FtpStorageFolder(path, item.Name, this);
32+
else
33+
return new FtpStorageFile(path, item.Name, this);
4434

45-
return new FtpStorageFolder(path, item.Name, this);
4635
}
4736

4837
/// <inheritdoc/>
49-
public async IAsyncEnumerable<INestedStorable> GetItemsAsync(StorableKind kind = StorableKind.All, [EnumeratorCancellation] CancellationToken cancellationToken = default)
38+
public async IAsyncEnumerable<IStorableChild> GetItemsAsync(StorableType kind = StorableType.All, [EnumeratorCancellation] CancellationToken cancellationToken = default)
5039
{
5140
using var ftpClient = GetFtpClient();
5241
await ftpClient.EnsureConnectedAsync(cancellationToken);
5342

54-
if (kind == StorableKind.Files)
43+
if (kind == StorableType.File)
5544
{
56-
foreach (var item in await ftpClient.GetListing(Path, cancellationToken))
45+
foreach (var item in await ftpClient.GetListing(Id, cancellationToken))
5746
{
5847
if (item.Type == FtpObjectType.File)
5948
yield return new FtpStorageFile(item.FullName, item.Name, this);
6049
}
6150
}
62-
else if (kind == StorableKind.Folders)
51+
else if (kind == StorableType.Folder)
6352
{
64-
foreach (var item in await ftpClient.GetListing(Path, cancellationToken))
53+
foreach (var item in await ftpClient.GetListing(Id, cancellationToken))
6554
{
6655
if (item.Type == FtpObjectType.Directory)
6756
yield return new FtpStorageFolder(item.FullName, item.Name, this);
6857
}
6958
}
7059
else
7160
{
72-
foreach (var item in await ftpClient.GetListing(Path, cancellationToken))
61+
foreach (var item in await ftpClient.GetListing(Id, cancellationToken))
7362
{
7463
if (item.Type == FtpObjectType.File)
7564
yield return new FtpStorageFile(item.FullName, item.Name, this);
@@ -81,18 +70,24 @@ public async IAsyncEnumerable<INestedStorable> GetItemsAsync(StorableKind kind =
8170
}
8271

8372
/// <inheritdoc/>
84-
public async Task DeleteAsync(INestedStorable item, bool permanently = false, CancellationToken cancellationToken = default)
73+
public Task<IFolderWatcher> GetFolderWatcherAsync(CancellationToken cancellationToken = default)
74+
{
75+
return Task.FromException<IFolderWatcher>(new NotSupportedException());
76+
}
77+
78+
/// <inheritdoc/>
79+
public async Task DeleteAsync(IStorableChild item, CancellationToken cancellationToken = default)
8580
{
8681
using var ftpClient = GetFtpClient();
8782
await ftpClient.EnsureConnectedAsync(cancellationToken);
8883

89-
if (item is ILocatableFile locatableFile)
84+
if (item is IFile locatableFile)
9085
{
91-
await ftpClient.DeleteFile(locatableFile.Path, cancellationToken);
86+
await ftpClient.DeleteFile(locatableFile.Id, cancellationToken);
9287
}
93-
else if (item is ILocatableFolder locatableFolder)
88+
else if (item is IFolder locatableFolder)
9489
{
95-
await ftpClient.DeleteDirectory(locatableFolder.Path, cancellationToken);
90+
await ftpClient.DeleteDirectory(locatableFolder.Id, cancellationToken);
9691
}
9792
else
9893
{
@@ -101,7 +96,7 @@ public async Task DeleteAsync(INestedStorable item, bool permanently = false, Ca
10196
}
10297

10398
/// <inheritdoc/>
104-
public async Task<INestedStorable> CreateCopyOfAsync(INestedStorable itemToCopy, bool overwrite = default, CancellationToken cancellationToken = default)
99+
public async Task<IStorableChild> CreateCopyOfAsync(IStorableChild itemToCopy, bool overwrite = default, CancellationToken cancellationToken = default)
105100
{
106101
if (itemToCopy is IFile sourceFile)
107102
{
@@ -117,24 +112,24 @@ public async Task<INestedStorable> CreateCopyOfAsync(INestedStorable itemToCopy,
117112
}
118113

119114
/// <inheritdoc/>
120-
public async Task<INestedStorable> MoveFromAsync(INestedStorable itemToMove, IModifiableFolder source, bool overwrite = default, CancellationToken cancellationToken = default)
115+
public async Task<IStorableChild> MoveFromAsync(IStorableChild itemToMove, IModifiableFolder source, bool overwrite = default, CancellationToken cancellationToken = default)
121116
{
122117
using var ftpClient = GetFtpClient();
123118
await ftpClient.EnsureConnectedAsync(cancellationToken);
124119

125120
var newItem = await CreateCopyOfAsync(itemToMove, overwrite, cancellationToken);
126-
await source.DeleteAsync(itemToMove, true, cancellationToken);
121+
await source.DeleteAsync(itemToMove, cancellationToken);
127122

128123
return newItem;
129124
}
130125

131126
/// <inheritdoc/>
132-
public async Task<INestedFile> CreateFileAsync(string desiredName, bool overwrite = default, CancellationToken cancellationToken = default)
127+
public async Task<IChildFile> CreateFileAsync(string desiredName, bool overwrite = default, CancellationToken cancellationToken = default)
133128
{
134129
using var ftpClient = GetFtpClient();
135130
await ftpClient.EnsureConnectedAsync(cancellationToken);
136131

137-
var newPath = $"{Path}/{desiredName}";
132+
var newPath = $"{Id}/{desiredName}";
138133
if (overwrite && await ftpClient.FileExists(newPath, cancellationToken))
139134
throw new IOException("File already exists.");
140135

@@ -159,12 +154,12 @@ public async Task<INestedFile> CreateFileAsync(string desiredName, bool overwrit
159154
}
160155

161156
/// <inheritdoc/>
162-
public async Task<INestedFolder> CreateFolderAsync(string desiredName, bool overwrite = default, CancellationToken cancellationToken = default)
157+
public async Task<IChildFolder> CreateFolderAsync(string desiredName, bool overwrite = default, CancellationToken cancellationToken = default)
163158
{
164159
using var ftpClient = GetFtpClient();
165160
await ftpClient.EnsureConnectedAsync(cancellationToken);
166161

167-
var newPath = $"{Path}/{desiredName}";
162+
var newPath = $"{Id}/{desiredName}";
168163
if (overwrite && await ftpClient.DirectoryExists(newPath, cancellationToken))
169164
throw new IOException("Directory already exists.");
170165

src/Files.App.Storage/Storables/NativeStorageLegacy/NativeFile.cs

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
 (0)