diff --git a/src/Files.App.Storage/Storables/NativeStorage/NativeFile.cs b/src/Files.App.Storage/Storables/NativeStorageLegacy/NativeFile.cs similarity index 72% rename from src/Files.App.Storage/Storables/NativeStorage/NativeFile.cs rename to src/Files.App.Storage/Storables/NativeStorageLegacy/NativeFile.cs index d930426f77b7..21c9aaebd546 100644 --- a/src/Files.App.Storage/Storables/NativeStorage/NativeFile.cs +++ b/src/Files.App.Storage/Storables/NativeStorageLegacy/NativeFile.cs @@ -6,14 +6,15 @@ namespace Files.App.Storage.Storables { /// - public class NativeFile : NativeStorable, ILocatableFile, IModifiableFile, IFileExtended, INestedFile + [Obsolete("Use the new WindowsStorable")] + public class NativeFileLegacy : NativeStorableLegacy, ILocatableFile, IModifiableFile, IFileExtended, INestedFile { - public NativeFile(FileInfo fileInfo, string? name = null) + public NativeFileLegacy(FileInfo fileInfo, string? name = null) : base(fileInfo, name) { } - public NativeFile(string path, string? name = null) + public NativeFileLegacy(string path, string? name = null) : this(new FileInfo(path), name) { } diff --git a/src/Files.App.Storage/Storables/NativeStorage/NativeFolder.cs b/src/Files.App.Storage/Storables/NativeStorageLegacy/NativeFolder.cs similarity index 83% rename from src/Files.App.Storage/Storables/NativeStorage/NativeFolder.cs rename to src/Files.App.Storage/Storables/NativeStorageLegacy/NativeFolder.cs index e364cfb3b8c2..ec392bab3af9 100644 --- a/src/Files.App.Storage/Storables/NativeStorage/NativeFolder.cs +++ b/src/Files.App.Storage/Storables/NativeStorageLegacy/NativeFolder.cs @@ -7,14 +7,15 @@ namespace Files.App.Storage.Storables { /// - public class NativeFolder : NativeStorable, ILocatableFolder, IModifiableFolder, IMutableFolder, IFolderExtended, INestedFolder, IDirectCopy, IDirectMove + [Obsolete("Use the new WindowsStorable")] + public class NativeFolderLegacy : NativeStorableLegacy, ILocatableFolder, IModifiableFolder, IMutableFolder, IFolderExtended, INestedFolder, IDirectCopy, IDirectMove { - public NativeFolder(DirectoryInfo directoryInfo, string? name = null) + public NativeFolderLegacy(DirectoryInfo directoryInfo, string? name = null) : base(directoryInfo, name) { } - public NativeFolder(string path, string? name = null) + public NativeFolderLegacy(string path, string? name = null) : this(new DirectoryInfo(path), name) { } @@ -27,7 +28,7 @@ public virtual Task GetFileAsync(string fileName, CancellationToken if (!File.Exists(path)) throw new FileNotFoundException(); - return Task.FromResult(new NativeFile(path)); + return Task.FromResult(new NativeFileLegacy(path)); } /// @@ -37,7 +38,7 @@ public virtual Task GetFolderAsync(string folderName, Cancellatio if (!Directory.Exists(path)) throw new FileNotFoundException(); - return Task.FromResult(new NativeFolder(path)); + return Task.FromResult(new NativeFolderLegacy(path)); } /// @@ -46,21 +47,21 @@ public virtual async IAsyncEnumerable GetItemsAsync(StorableKin if (kind == StorableKind.Files) { foreach (var item in Directory.EnumerateFiles(Path)) - yield return new NativeFile(item); + yield return new NativeFileLegacy(item); } else if (kind == StorableKind.Folders) { foreach (var item in Directory.EnumerateDirectories(Path)) - yield return new NativeFolder(item); + yield return new NativeFolderLegacy(item); } else { foreach (var item in Directory.EnumerateFileSystemEntries(Path)) { if (File.Exists(item)) - yield return new NativeFile(item); + yield return new NativeFileLegacy(item); else - yield return new NativeFolder(item); + yield return new NativeFolderLegacy(item); } } @@ -96,7 +97,7 @@ public virtual async Task CreateCopyOfAsync(INestedStorable ite var newPath = System.IO.Path.Combine(Path, itemToCopy.Name); File.Copy(sourceLocatableFile.Path, newPath, overwrite); - return new NativeFile(newPath); + return new NativeFileLegacy(newPath); } var copiedFile = await CreateFileAsync(itemToCopy.Name, overwrite, cancellationToken); @@ -124,7 +125,7 @@ public virtual async Task MoveFromAsync(INestedStorable itemToM var newPath = System.IO.Path.Combine(Path, itemToMove.Name); File.Move(sourceLocatableFile.Path, newPath, overwrite); - return new NativeFile(newPath); + return new NativeFileLegacy(newPath); } else { @@ -150,7 +151,7 @@ public virtual async Task CreateFileAsync(string desiredName, bool if (overwrite || !File.Exists(path)) await File.Create(path).DisposeAsync(); - return new NativeFile(path); + return new NativeFileLegacy(path); } /// @@ -161,7 +162,7 @@ public virtual Task CreateFolderAsync(string desiredName, bool ov Directory.Delete(path, true); _ = Directory.CreateDirectory(path); - return Task.FromResult(new NativeFolder(path)); + return Task.FromResult(new NativeFolderLegacy(path)); } } } diff --git a/src/Files.App.Storage/Storables/NativeStorage/NativeStorable.cs b/src/Files.App.Storage/Storables/NativeStorageLegacy/NativeStorable.cs similarity index 83% rename from src/Files.App.Storage/Storables/NativeStorage/NativeStorable.cs rename to src/Files.App.Storage/Storables/NativeStorageLegacy/NativeStorable.cs index 1aab43b33a5a..a6fd33617745 100644 --- a/src/Files.App.Storage/Storables/NativeStorage/NativeStorable.cs +++ b/src/Files.App.Storage/Storables/NativeStorageLegacy/NativeStorable.cs @@ -6,7 +6,8 @@ namespace Files.App.Storage.Storables { /// - public abstract class NativeStorable : ILocatableStorable, INestedStorable + [Obsolete("Use the new WindowsStorable")] + public abstract class NativeStorableLegacy : ILocatableStorable, INestedStorable where TStorage : FileSystemInfo { protected readonly TStorage storage; @@ -20,7 +21,7 @@ public abstract class NativeStorable : ILocatableStorable, INestedStor /// public virtual string Id { get; } - protected NativeStorable(TStorage storage, string? name = null) + protected NativeStorableLegacy(TStorage storage, string? name = null) { this.storage = storage; Path = storage.FullName; @@ -35,7 +36,7 @@ protected NativeStorable(TStorage storage, string? name = null) if (parent is null) return Task.FromResult(null); - return Task.FromResult(new NativeFolder(parent)); + return Task.FromResult(new NativeFolderLegacy(parent)); } /// diff --git a/src/Files.App.Storage/Storables/NativeStorage/NativeStorageService.cs b/src/Files.App.Storage/Storables/NativeStorageLegacy/NativeStorageService.cs similarity index 78% rename from src/Files.App.Storage/Storables/NativeStorage/NativeStorageService.cs rename to src/Files.App.Storage/Storables/NativeStorageLegacy/NativeStorageService.cs index a94d4f2b801a..da9e1b2086e7 100644 --- a/src/Files.App.Storage/Storables/NativeStorage/NativeStorageService.cs +++ b/src/Files.App.Storage/Storables/NativeStorageLegacy/NativeStorageService.cs @@ -8,7 +8,8 @@ namespace Files.App.Storage.Storables { /// - public sealed class NativeStorageService : IStorageService + [Obsolete("Use the new WindowsStorable")] + public sealed class NativeStorageLegacyService : IStorageService { /// public Task GetFileAsync(string id, CancellationToken cancellationToken = default) @@ -16,7 +17,7 @@ public Task GetFileAsync(string id, CancellationToken cancellationToken = if (!File.Exists(id)) throw new FileNotFoundException(); - return Task.FromResult(new NativeFile(id)); + return Task.FromResult(new NativeFileLegacy(id)); } /// @@ -29,10 +30,10 @@ public async Task GetFolderAsync(string id, CancellationToken cancellat if (PathHelpers.IsSpecialFolder(id)) { var storageFolder = await TryGetStorageFolderAsync(id); - return new NativeFolder(id, storageFolder?.DisplayName); + return new NativeFolderLegacy(id, storageFolder?.DisplayName); } - return new NativeFolder(id); + return new NativeFolderLegacy(id); async Task TryGetStorageFolderAsync(string path) { diff --git a/src/Files.App.Storage/Storables/WindowsStorage/WindowsStorageService.cs b/src/Files.App.Storage/Storables/WindowsStorage/WindowsStorageService.cs deleted file mode 100644 index f642a7aed968..000000000000 --- a/src/Files.App.Storage/Storables/WindowsStorage/WindowsStorageService.cs +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (c) 2024 Files Community -// Licensed under the MIT License. See the LICENSE. - -using Windows.Storage; - -namespace Files.App.Storage.Storables -{ - /// - internal sealed class WindowsStorageService : IStorageService - { - /// - public async Task GetFileAsync(string id, CancellationToken cancellationToken = default) - { - var file = await StorageFile.GetFileFromPathAsync(id).AsTask(cancellationToken); - return new WindowsStorageFile(file); - } - - /// - public async Task GetFolderAsync(string id, CancellationToken cancellationToken = default) - { - var folder = await StorageFolder.GetFolderFromPathAsync(id).AsTask(cancellationToken); - return new WindowsStorageFolder(folder); - } - } -} diff --git a/src/Files.App.Storage/Storables/WindowsStorage/WindowsStorable.cs b/src/Files.App.Storage/Storables/WindowsStorageLegacy/WindowsStorable.cs similarity index 80% rename from src/Files.App.Storage/Storables/WindowsStorage/WindowsStorable.cs rename to src/Files.App.Storage/Storables/WindowsStorageLegacy/WindowsStorable.cs index f730db243c85..2ae2ae22844c 100644 --- a/src/Files.App.Storage/Storables/WindowsStorage/WindowsStorable.cs +++ b/src/Files.App.Storage/Storables/WindowsStorageLegacy/WindowsStorable.cs @@ -7,7 +7,8 @@ namespace Files.App.Storage.Storables { /// - public abstract class WindowsStorable : ILocatableStorable, INestedStorable + [Obsolete("Use the new WindowsStorable")] + public abstract class WindowsStorableLegacy : ILocatableStorable, INestedStorable where TStorage : class, IStorageItem { private string? _computedId; @@ -22,7 +23,7 @@ public abstract class WindowsStorable : ILocatableStorable, INestedSto /// public virtual string Id => _computedId ??= ChecksumHelpers.CalculateChecksumForPath(Path); - protected internal WindowsStorable(TStorage storage) + protected internal WindowsStorableLegacy(TStorage storage) { this.storage = storage; Path = storage.Path; diff --git a/src/Files.App.Storage/Storables/WindowsStorage/WindowsStorageFile.cs b/src/Files.App.Storage/Storables/WindowsStorageLegacy/WindowsStorageFile.cs similarity index 87% rename from src/Files.App.Storage/Storables/WindowsStorage/WindowsStorageFile.cs rename to src/Files.App.Storage/Storables/WindowsStorageLegacy/WindowsStorageFile.cs index 15d856a34fe3..1f744082ecf3 100644 --- a/src/Files.App.Storage/Storables/WindowsStorage/WindowsStorageFile.cs +++ b/src/Files.App.Storage/Storables/WindowsStorageLegacy/WindowsStorageFile.cs @@ -7,9 +7,10 @@ namespace Files.App.Storage.Storables { /// - public sealed class WindowsStorageFile : WindowsStorable, ILocatableFile, IModifiableFile, IFileExtended, INestedFile + [Obsolete("Use the new WindowsStorable")] + public sealed class WindowsStorageFileLegacy : WindowsStorableLegacy, ILocatableFile, IModifiableFile, IFileExtended, INestedFile { - public WindowsStorageFile(StorageFile storage) + public WindowsStorageFileLegacy(StorageFile storage) : base(storage) { } @@ -38,7 +39,7 @@ public async Task OpenStreamAsync(FileAccess access, FileShare share = F var parentFolderTask = storage.GetParentAsync().AsTask(cancellationToken); var parentFolder = await parentFolderTask; - return new WindowsStorageFolder(parentFolder); + return new WindowsStorageFolderLegacy(parentFolder); } private static FileAccessMode GetFileAccessMode(FileAccess access) diff --git a/src/Files.App.Storage/Storables/WindowsStorage/WindowsStorageFolder.cs b/src/Files.App.Storage/Storables/WindowsStorageLegacy/WindowsStorageFolder.cs similarity index 78% rename from src/Files.App.Storage/Storables/WindowsStorage/WindowsStorageFolder.cs rename to src/Files.App.Storage/Storables/WindowsStorageLegacy/WindowsStorageFolder.cs index e2467acc9ae9..03ff972885e6 100644 --- a/src/Files.App.Storage/Storables/WindowsStorage/WindowsStorageFolder.cs +++ b/src/Files.App.Storage/Storables/WindowsStorageLegacy/WindowsStorageFolder.cs @@ -7,11 +7,12 @@ namespace Files.App.Storage.Storables { /// - public sealed class WindowsStorageFolder : WindowsStorable, ILocatableFolder, IFolderExtended, INestedFolder, IDirectCopy, IDirectMove + [Obsolete("Use the new WindowsStorable")] + public sealed class WindowsStorageFolderLegacy : WindowsStorableLegacy, ILocatableFolder, IFolderExtended, INestedFolder, IDirectCopy, IDirectMove { // TODO: Implement IMutableFolder - public WindowsStorageFolder(StorageFolder storage) + public WindowsStorageFolderLegacy(StorageFolder storage) : base(storage) { } @@ -20,14 +21,14 @@ public WindowsStorageFolder(StorageFolder storage) public async Task GetFileAsync(string fileName, CancellationToken cancellationToken = default) { var file = await storage.GetFileAsync(fileName).AsTask(cancellationToken); - return new WindowsStorageFile(file); + return new WindowsStorageFileLegacy(file); } /// public async Task GetFolderAsync(string folderName, CancellationToken cancellationToken = default) { var folder = await storage.GetFolderAsync(folderName).AsTask(cancellationToken); - return new WindowsStorageFolder(folder); + return new WindowsStorageFolderLegacy(folder); } /// @@ -40,7 +41,7 @@ public async IAsyncEnumerable GetItemsAsync(StorableKind kind = var files = await storage.GetFilesAsync().AsTask(cancellationToken); foreach (var item in files) { - yield return new WindowsStorageFile(item); + yield return new WindowsStorageFileLegacy(item); } break; @@ -51,7 +52,7 @@ public async IAsyncEnumerable GetItemsAsync(StorableKind kind = var folders = await storage.GetFoldersAsync().AsTask(cancellationToken); foreach (var item in folders) { - yield return new WindowsStorageFolder(item); + yield return new WindowsStorageFolderLegacy(item); } break; @@ -63,10 +64,10 @@ public async IAsyncEnumerable GetItemsAsync(StorableKind kind = foreach (var item in items) { if (item is StorageFile storageFile) - yield return new WindowsStorageFile(storageFile); + yield return new WindowsStorageFileLegacy(storageFile); if (item is StorageFolder storageFolder) - yield return new WindowsStorageFolder(storageFolder); + yield return new WindowsStorageFolderLegacy(storageFolder); } break; @@ -82,11 +83,11 @@ public Task DeleteAsync(INestedStorable item, bool permanently = default, Cancel { return item switch { - WindowsStorable storageFile => storageFile.storage + WindowsStorableLegacy storageFile => storageFile.storage .DeleteAsync(GetWindowsStorageDeleteOption(permanently)) .AsTask(cancellationToken), - WindowsStorable storageFolder => storageFolder.storage + WindowsStorableLegacy storageFolder => storageFolder.storage .DeleteAsync(GetWindowsStorageDeleteOption(permanently)) .AsTask(cancellationToken), @@ -97,10 +98,10 @@ public Task DeleteAsync(INestedStorable item, bool permanently = default, Cancel /// public async Task CreateCopyOfAsync(INestedStorable itemToCopy, bool overwrite = default, CancellationToken cancellationToken = default) { - if (itemToCopy is WindowsStorable sourceFile) + if (itemToCopy is WindowsStorableLegacy sourceFile) { var copiedFile = await sourceFile.storage.CopyAsync(storage, itemToCopy.Name, GetWindowsNameCollisionOption(overwrite)).AsTask(cancellationToken); - return new WindowsStorageFile(copiedFile); + return new WindowsStorageFileLegacy(copiedFile); } throw new ArgumentException($"Could not copy type {itemToCopy.GetType()}"); @@ -109,10 +110,10 @@ public async Task CreateCopyOfAsync(INestedStorable itemToCopy, /// public async Task MoveFromAsync(INestedStorable itemToMove, IModifiableFolder source, bool overwrite = default, CancellationToken cancellationToken = default) { - if (itemToMove is WindowsStorable sourceFile) + if (itemToMove is WindowsStorableLegacy sourceFile) { await sourceFile.storage.MoveAsync(storage, itemToMove.Name, GetWindowsNameCollisionOption(overwrite)).AsTask(cancellationToken); - return new WindowsStorageFile(sourceFile.storage); + return new WindowsStorageFileLegacy(sourceFile.storage); } throw new ArgumentException($"Could not copy type {itemToMove.GetType()}"); @@ -122,21 +123,21 @@ public async Task MoveFromAsync(INestedStorable itemToMove, IMo public async Task CreateFileAsync(string desiredName, bool overwrite = default, CancellationToken cancellationToken = default) { var file = await storage.CreateFileAsync(desiredName, GetWindowsCreationCollisionOption(overwrite)).AsTask(cancellationToken); - return new WindowsStorageFile(file); + return new WindowsStorageFileLegacy(file); } /// public async Task CreateFolderAsync(string desiredName, bool overwrite = default, CancellationToken cancellationToken = default) { var folder = await storage.CreateFolderAsync(desiredName, GetWindowsCreationCollisionOption(overwrite)).AsTask(cancellationToken); - return new WindowsStorageFolder(folder); + return new WindowsStorageFolderLegacy(folder); } /// public override async Task GetParentAsync(CancellationToken cancellationToken = default) { var parentFolder = await storage.GetParentAsync().AsTask(cancellationToken); - return new WindowsStorageFolder(parentFolder); + return new WindowsStorageFolderLegacy(parentFolder); } private static StorageDeleteOption GetWindowsStorageDeleteOption(bool permanently) diff --git a/src/Files.App/Data/Items/DriveItem.cs b/src/Files.App/Data/Items/DriveItem.cs index 46793728ab4c..b624f0c2161b 100644 --- a/src/Files.App/Data/Items/DriveItem.cs +++ b/src/Files.App/Data/Items/DriveItem.cs @@ -341,25 +341,25 @@ private string GetSizeString() public Task GetFileAsync(string fileName, CancellationToken cancellationToken = default) { - var folder = new WindowsStorageFolder(Root); + var folder = new WindowsStorageFolderLegacy(Root); return folder.GetFileAsync(fileName, cancellationToken); } public Task GetFolderAsync(string folderName, CancellationToken cancellationToken = default) { - var folder = new WindowsStorageFolder(Root); + var folder = new WindowsStorageFolderLegacy(Root); return folder.GetFolderAsync(folderName, cancellationToken); } public IAsyncEnumerable GetItemsAsync(StorableKind kind = StorableKind.All, CancellationToken cancellationToken = default) { - var folder = new WindowsStorageFolder(Root); + var folder = new WindowsStorageFolderLegacy(Root); return folder.GetItemsAsync(kind, cancellationToken); } public Task GetParentAsync(CancellationToken cancellationToken = default) { - var folder = new WindowsStorageFolder(Root); + var folder = new WindowsStorageFolderLegacy(Root); return folder.GetParentAsync(cancellationToken); } } diff --git a/src/Files.App/Helpers/Application/AppLifecycleHelper.cs b/src/Files.App/Helpers/Application/AppLifecycleHelper.cs index 4804f6c001e4..6d5b75f5eba4 100644 --- a/src/Files.App/Helpers/Application/AppLifecycleHelper.cs +++ b/src/Files.App/Helpers/Application/AppLifecycleHelper.cs @@ -183,7 +183,7 @@ public static IHost ConfigureHost() .AddSingleton() .AddSingleton() .AddSingleton() - .AddSingleton() + .AddSingleton() .AddSingleton() .AddSingleton() #if STABLE || PREVIEW diff --git a/src/Files.App/Services/Storage/StorageDevicesService.cs b/src/Files.App/Services/Storage/StorageDevicesService.cs index 8493a260c03c..dbb05a36c707 100644 --- a/src/Files.App/Services/Storage/StorageDevicesService.cs +++ b/src/Files.App/Services/Storage/StorageDevicesService.cs @@ -61,7 +61,7 @@ public async IAsyncEnumerable GetDrivesAsync() public async Task GetPrimaryDriveAsync() { string cDrivePath = $@"{Constants.UserEnvironmentPaths.SystemDrivePath}\"; - return new WindowsStorageFolder(await StorageFolder.GetFolderFromPathAsync(cDrivePath)); + return new WindowsStorageFolderLegacy(await StorageFolder.GetFolderFromPathAsync(cDrivePath)); } public async Task UpdateDrivePropertiesAsync(ILocatableFolder drive)