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
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<PackageVersion Include="Microsoft.Extensions.Logging" Version="9.0.2" />
<PackageVersion Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.26100.1742" />
<PackageVersion Include="Microsoft.Xaml.Behaviors.WinUI.Managed" Version="3.0.0" />
<PackageVersion Include="OwlCore.Storage" Version="0.12.2" />
<PackageVersion Include="Sentry" Version="5.1.1" />
<PackageVersion Include="SevenZipSharp" Version="1.0.2" />
<PackageVersion Include="SQLitePCLRaw.bundle_green" Version="2.1.10" />
Expand Down
4 changes: 2 additions & 2 deletions src/Files.App.Controls/BladeView/BladeView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@
FontSize="14"
Foreground="{TemplateBinding CloseButtonForeground}"
Style="{StaticResource ButtonRevealStyle}"
Visibility="{TemplateBinding CloseButtonVisibility}"
TabIndex="0" />
TabIndex="0"
Visibility="{TemplateBinding CloseButtonVisibility}" />
</Grid>
</ControlTemplate>
</Setter.Value>
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App.Storage/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
global using global::Files.Core.Storage.Enums;
global using global::Files.Core.Storage.EventArguments;
global using global::Files.Core.Storage.Extensions;
global using global::Files.Core.Storage.StorageEnumeration;
global using global::OwlCore.Storage;

// Files.App.Storage

Expand Down
12 changes: 4 additions & 8 deletions src/Files.App.Storage/Storables/FtpStorage/FtpStorable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@

namespace Files.App.Storage.Storables
{
public abstract class FtpStorable : ILocatableStorable, INestedStorable
public abstract class FtpStorable : IStorableChild
{
/// <inheritdoc/>
public virtual string Path { get; protected set; }

/// <inheritdoc/>
public virtual string Name { get; protected set; }

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

protected internal FtpStorable(string path, string name, IFolder? parent)
{
Path = FtpHelpers.GetFtpPath(path);
Id = FtpHelpers.GetFtpPath(path);
Name = name;
Id = Path;
Parent = parent;
}

/// <inheritdoc/>
public Task<IFolder?> GetParentAsync(CancellationToken cancellationToken = default)
{
return Task.FromResult<IFolder?>(Parent);
return Task.FromResult(Parent);
}

protected AsyncFtpClient GetFtpClient()
{
return FtpHelpers.GetFtpClient(Path);
return FtpHelpers.GetFtpClient(Id);
}
}
}
6 changes: 3 additions & 3 deletions src/Files.App.Storage/Storables/FtpStorage/FtpStorageFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

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

if (access.HasFlag(FileAccess.Write))
return await ftpClient.OpenWrite(Path, token: cancellationToken);
return await ftpClient.OpenWrite(Id, token: cancellationToken);
else if (access.HasFlag(FileAccess.Read))
return await ftpClient.OpenRead(Path, token: cancellationToken);
return await ftpClient.OpenRead(Id, token: cancellationToken);
else
throw new ArgumentException($"Invalid {nameof(access)} flag.");
}
Expand Down
69 changes: 32 additions & 37 deletions src/Files.App.Storage/Storables/FtpStorage/FtpStorageFolder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,68 +8,57 @@

namespace Files.App.Storage.Storables
{
public sealed class FtpStorageFolder : FtpStorable, ILocatableFolder, IModifiableFolder, IFolderExtended, INestedFolder, IDirectCopy, IDirectMove
public sealed class FtpStorageFolder : FtpStorable, IModifiableFolder, IChildFolder, IDirectCopy, IDirectMove, IGetFirstByName
{
public FtpStorageFolder(string path, string name, IFolder? parent)
: base(path, name, parent)
{
}

/// <inheritdoc/>
public async Task<INestedFile> GetFileAsync(string fileName, CancellationToken cancellationToken = default)
public async Task<IStorableChild> GetFirstByNameAsync(string folderName, CancellationToken cancellationToken = default)
{
using var ftpClient = GetFtpClient();
await ftpClient.EnsureConnectedAsync(cancellationToken);

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

if (item is null || item.Type != FtpObjectType.File)
if (item is null)
throw new FileNotFoundException();

return new FtpStorageFile(path, item.Name, this);
}

/// <inheritdoc/>
public async Task<INestedFolder> GetFolderAsync(string folderName, CancellationToken cancellationToken = default)
{
using var ftpClient = GetFtpClient();
await ftpClient.EnsureConnectedAsync(cancellationToken);

var path = FtpHelpers.GetFtpPath(PathHelpers.Combine(Path, folderName));
var item = await ftpClient.GetObjectInfo(path, token: cancellationToken);

if (item is null || item.Type != FtpObjectType.Directory)
throw new DirectoryNotFoundException();
if (item.Type == FtpObjectType.Directory)
return new FtpStorageFolder(path, item.Name, this);
else
return new FtpStorageFile(path, item.Name, this);

return new FtpStorageFolder(path, item.Name, this);
}

/// <inheritdoc/>
public async IAsyncEnumerable<INestedStorable> GetItemsAsync(StorableKind kind = StorableKind.All, [EnumeratorCancellation] CancellationToken cancellationToken = default)
public async IAsyncEnumerable<IStorableChild> GetItemsAsync(StorableType kind = StorableType.All, [EnumeratorCancellation] CancellationToken cancellationToken = default)
{
using var ftpClient = GetFtpClient();
await ftpClient.EnsureConnectedAsync(cancellationToken);

if (kind == StorableKind.Files)
if (kind == StorableType.File)
{
foreach (var item in await ftpClient.GetListing(Path, cancellationToken))
foreach (var item in await ftpClient.GetListing(Id, cancellationToken))
{
if (item.Type == FtpObjectType.File)
yield return new FtpStorageFile(item.FullName, item.Name, this);
}
}
else if (kind == StorableKind.Folders)
else if (kind == StorableType.Folder)
{
foreach (var item in await ftpClient.GetListing(Path, cancellationToken))
foreach (var item in await ftpClient.GetListing(Id, cancellationToken))
{
if (item.Type == FtpObjectType.Directory)
yield return new FtpStorageFolder(item.FullName, item.Name, this);
}
}
else
{
foreach (var item in await ftpClient.GetListing(Path, cancellationToken))
foreach (var item in await ftpClient.GetListing(Id, cancellationToken))
{
if (item.Type == FtpObjectType.File)
yield return new FtpStorageFile(item.FullName, item.Name, this);
Expand All @@ -81,18 +70,24 @@ public async IAsyncEnumerable<INestedStorable> GetItemsAsync(StorableKind kind =
}

/// <inheritdoc/>
public async Task DeleteAsync(INestedStorable item, bool permanently = false, CancellationToken cancellationToken = default)
public Task<IFolderWatcher> GetFolderWatcherAsync(CancellationToken cancellationToken = default)
{
return Task.FromException<IFolderWatcher>(new NotSupportedException());
}

/// <inheritdoc/>
public async Task DeleteAsync(IStorableChild item, CancellationToken cancellationToken = default)
{
using var ftpClient = GetFtpClient();
await ftpClient.EnsureConnectedAsync(cancellationToken);

if (item is ILocatableFile locatableFile)
if (item is IFile locatableFile)
{
await ftpClient.DeleteFile(locatableFile.Path, cancellationToken);
await ftpClient.DeleteFile(locatableFile.Id, cancellationToken);
}
else if (item is ILocatableFolder locatableFolder)
else if (item is IFolder locatableFolder)
{
await ftpClient.DeleteDirectory(locatableFolder.Path, cancellationToken);
await ftpClient.DeleteDirectory(locatableFolder.Id, cancellationToken);
}
else
{
Expand All @@ -101,7 +96,7 @@ public async Task DeleteAsync(INestedStorable item, bool permanently = false, Ca
}

/// <inheritdoc/>
public async Task<INestedStorable> CreateCopyOfAsync(INestedStorable itemToCopy, bool overwrite = default, CancellationToken cancellationToken = default)
public async Task<IStorableChild> CreateCopyOfAsync(IStorableChild itemToCopy, bool overwrite = default, CancellationToken cancellationToken = default)
{
if (itemToCopy is IFile sourceFile)
{
Expand All @@ -117,24 +112,24 @@ public async Task<INestedStorable> CreateCopyOfAsync(INestedStorable itemToCopy,
}

/// <inheritdoc/>
public async Task<INestedStorable> MoveFromAsync(INestedStorable itemToMove, IModifiableFolder source, bool overwrite = default, CancellationToken cancellationToken = default)
public async Task<IStorableChild> MoveFromAsync(IStorableChild itemToMove, IModifiableFolder source, bool overwrite = default, CancellationToken cancellationToken = default)
{
using var ftpClient = GetFtpClient();
await ftpClient.EnsureConnectedAsync(cancellationToken);

var newItem = await CreateCopyOfAsync(itemToMove, overwrite, cancellationToken);
await source.DeleteAsync(itemToMove, true, cancellationToken);
await source.DeleteAsync(itemToMove, cancellationToken);

return newItem;
}

/// <inheritdoc/>
public async Task<INestedFile> CreateFileAsync(string desiredName, bool overwrite = default, CancellationToken cancellationToken = default)
public async Task<IChildFile> CreateFileAsync(string desiredName, bool overwrite = default, CancellationToken cancellationToken = default)
{
using var ftpClient = GetFtpClient();
await ftpClient.EnsureConnectedAsync(cancellationToken);

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

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

/// <inheritdoc/>
public async Task<INestedFolder> CreateFolderAsync(string desiredName, bool overwrite = default, CancellationToken cancellationToken = default)
public async Task<IChildFolder> CreateFolderAsync(string desiredName, bool overwrite = default, CancellationToken cancellationToken = default)
{
using var ftpClient = GetFtpClient();
await ftpClient.EnsureConnectedAsync(cancellationToken);

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

Expand Down
35 changes: 0 additions & 35 deletions src/Files.App.Storage/Storables/NativeStorageLegacy/NativeFile.cs

This file was deleted.

Loading
Loading