From 922a7a45f90d084664c6dc8c9efaaa5ca1376d56 Mon Sep 17 00:00:00 2001 From: Takoooooo Date: Thu, 11 Aug 2022 16:26:03 +0300 Subject: [PATCH] Simplify class creation for BclStorageFile\BclStorageFolder --- .../Platform/Storage/FileIO/BclStorageFile.cs | 12 ++++++++---- .../Platform/Storage/FileIO/BclStorageFolder.cs | 9 +++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/Avalonia.Base/Platform/Storage/FileIO/BclStorageFile.cs b/src/Avalonia.Base/Platform/Storage/FileIO/BclStorageFile.cs index cf21e9b8b5..cec20678cf 100644 --- a/src/Avalonia.Base/Platform/Storage/FileIO/BclStorageFile.cs +++ b/src/Avalonia.Base/Platform/Storage/FileIO/BclStorageFile.cs @@ -12,6 +12,11 @@ public class BclStorageFile : IStorageBookmarkFile { private readonly FileInfo _fileInfo; + public BclStorageFile(string fileName) + { + _fileInfo = new FileInfo(fileName); + } + public BclStorageFile(FileInfo fileInfo) { _fileInfo = fileInfo ?? throw new ArgumentNullException(nameof(fileInfo)); @@ -27,15 +32,14 @@ public class BclStorageFile : IStorageBookmarkFile public Task GetBasicPropertiesAsync() { - var props = new StorageItemProperties(); if (_fileInfo.Exists) { - props = new StorageItemProperties( + return Task.FromResult(new StorageItemProperties( (ulong)_fileInfo.Length, _fileInfo.CreationTimeUtc, - _fileInfo.LastAccessTimeUtc); + _fileInfo.LastAccessTimeUtc)); } - return Task.FromResult(props); + return Task.FromResult(new StorageItemProperties()); } public Task GetParentAsync() diff --git a/src/Avalonia.Base/Platform/Storage/FileIO/BclStorageFolder.cs b/src/Avalonia.Base/Platform/Storage/FileIO/BclStorageFolder.cs index cd6c8be1ae..b91e910777 100644 --- a/src/Avalonia.Base/Platform/Storage/FileIO/BclStorageFolder.cs +++ b/src/Avalonia.Base/Platform/Storage/FileIO/BclStorageFolder.cs @@ -14,6 +14,15 @@ public class BclStorageFolder : IStorageBookmarkFolder { private readonly DirectoryInfo _directoryInfo; + public BclStorageFolder(string path) + { + _directoryInfo = new DirectoryInfo(path); + if (!_directoryInfo.Exists) + { + throw new ArgumentException("Directory must exist"); + } + } + public BclStorageFolder(DirectoryInfo directoryInfo) { _directoryInfo = directoryInfo ?? throw new ArgumentNullException(nameof(directoryInfo));