Browse Source

Remove unused CanOpenRead/CanOpenWrite

Max Katz 2 years ago
parent
commit
e975468e92

+ 15 - 20
samples/ControlCatalog/Pages/DialogsPage.xaml.cs

@@ -223,7 +223,7 @@ namespace ControlCatalog.Pages
                     ShowOverwritePrompt = false
                 });
 
-                if (file is not null && file.CanOpenWrite)
+                if (file is not null)
                 {
                     // Sync disposal of StreamWriter is not supported on WASM
 #if NET6_0_OR_GREATER
@@ -298,31 +298,26 @@ namespace ControlCatalog.Pages
                     if (item is IStorageFile file)
                     {
                         resultText += @$"
-            CanOpenRead: {file.CanOpenRead}
-            CanOpenWrite: {file.CanOpenWrite}
             Content:
             ";
-                        if (file.CanOpenRead)
-                        {
 #if NET6_0_OR_GREATER
-                            await using var stream = await file.OpenReadAsync();
+                        await using var stream = await file.OpenReadAsync();
 #else
-                                        using var stream = await file.OpenReadAsync();
+                        using var stream = await file.OpenReadAsync();
 #endif
-                            using var reader = new System.IO.StreamReader(stream);
+                        using var reader = new System.IO.StreamReader(stream);
 
-                            // 4GB file test, shouldn't load more than 10000 chars into a memory.
-                            const int length = 10000;
-                            var buffer = ArrayPool<char>.Shared.Rent(length);
-                            try
-                            {
-                                var charsRead = await reader.ReadAsync(buffer, 0, length);
-                                resultText += new string(buffer, 0, charsRead);
-                            }
-                            finally
-                            {
-                                ArrayPool<char>.Shared.Return(buffer);
-                            }
+                        // 4GB file test, shouldn't load more than 10000 chars into a memory.
+                        const int length = 10000;
+                        var buffer = ArrayPool<char>.Shared.Rent(length);
+                        try
+                        {
+                            var charsRead = await reader.ReadAsync(buffer, 0, length);
+                            resultText += new string(buffer, 0, charsRead);
+                        }
+                        finally
+                        {
+                            ArrayPool<char>.Shared.Return(buffer);
                         }
                     }
 

+ 1 - 5
src/Android/Avalonia.Android/Platform/Storage/AndroidStorageItem.cs

@@ -177,11 +177,7 @@ internal sealed class AndroidStorageFile : AndroidStorageItem, IStorageBookmarkF
     public AndroidStorageFile(Activity activity, AndroidUri uri) : base(activity, uri, false)
     {
     }
-
-    public bool CanOpenRead => true;
-
-    public bool CanOpenWrite => true;
-
+    
     public Task<Stream> OpenReadAsync() => Task.FromResult(OpenContentStream(Activity, Uri, false)
         ?? throw new InvalidOperationException("Failed to open content stream"));
 

+ 1 - 5
src/Avalonia.Base/Platform/Storage/FileIO/BclStorageFile.cs

@@ -18,11 +18,7 @@ internal class BclStorageFile : IStorageBookmarkFile
     }
 
     public FileInfo FileInfo { get; }
-
-    public bool CanOpenRead => true;
-
-    public bool CanOpenWrite => true;
-
+    
     public string Name => FileInfo.Name;
 
     public virtual bool CanBookmark => true;

+ 1 - 11
src/Avalonia.Base/Platform/Storage/IStorageFile.cs

@@ -10,22 +10,12 @@ namespace Avalonia.Platform.Storage;
 [NotClientImplementable]
 public interface IStorageFile : IStorageItem
 {
-    /// <summary>
-    /// Returns true, if file is readable.
-    /// </summary>
-    bool CanOpenRead { get; }
-
     /// <summary>
     /// Opens a stream for read access.
     /// </summary>
     /// <exception cref="System.UnauthorizedAccessException" />
     Task<Stream> OpenReadAsync();
-
-    /// <summary>
-    /// Returns true, if file is writeable. 
-    /// </summary>
-    bool CanOpenWrite { get; }
-
+    
     /// <summary>
     /// Opens stream for writing to the file.
     /// </summary>

+ 0 - 4
src/Avalonia.Diagnostics/Diagnostics/Screenshots/FilePickerHandler.cs

@@ -68,10 +68,6 @@ namespace Avalonia.Diagnostics.Screenshots
             {
                 return null;
             }
-            if (!result.CanOpenWrite)
-            {
-                throw new InvalidOperationException("Read-only file was selected.");
-            }
 
             return await result.OpenWriteAsync();
         }

+ 0 - 2
src/Browser/Avalonia.Browser/Storage/BrowserStorageProvider.cs

@@ -216,7 +216,6 @@ internal class JSStorageFile : JSStorageItem, IStorageBookmarkFile
     {
     }
 
-    public bool CanOpenRead => true;
     public async Task<Stream> OpenReadAsync()
     {
         try
@@ -230,7 +229,6 @@ internal class JSStorageFile : JSStorageItem, IStorageBookmarkFile
         }
     }
 
-    public bool CanOpenWrite => true;
     public async Task<Stream> OpenWriteAsync()
     {
         try

+ 1 - 5
src/iOS/Avalonia.iOS/Storage/IOSStorageItem.cs

@@ -94,11 +94,7 @@ internal sealed class IOSStorageFile : IOSStorageItem, IStorageBookmarkFile
     public IOSStorageFile(NSUrl url) : base(url)
     {
     }
-
-    public bool CanOpenRead => true;
-
-    public bool CanOpenWrite => true;
-
+    
     public Task<Stream> OpenReadAsync()
     {
         return Task.FromResult<Stream>(new IOSSecurityScopedStream(Url, FileAccess.Read));