[Peek] Open file in Read only (#25945)

* Only open FilStream in read-only mode; Release propertyStore handle after getting the file properties

(cherry picked from commit 3b1481da2c)

* Update calls to PropertyStoreHelper

* Add disposable property store

* Make GetPropertyStoreFromPath return Disposable property store

* correct typo

* correct typo

* Remove nullable in DisposablePropertyStore

* Add property getters

* Remove usued method

* Correct typo

* Correct typo again...

* Update description
This commit is contained in:
Yawen Hou
2023-05-10 19:00:13 -04:00
committed by GitHub
parent 648f30d1ab
commit 83574c578a
9 changed files with 98 additions and 70 deletions

View File

@@ -210,7 +210,7 @@ namespace Peek.FilePreviewer.Previewers
{
cancellationToken.ThrowIfCancellationRequested();
using FileStream stream = File.OpenRead(Item.Path);
using FileStream stream = ReadHelper.OpenReadOnly(Item.Path);
await Dispatcher.RunOnUiThread(async () =>
{

View File

@@ -12,11 +12,16 @@ namespace Peek.FilePreviewer.Previewers
{
public static async Task<string> Read(string path)
{
using var fs = new FileStream(path, FileMode.Open, FileAccess.Read);
using var fs = OpenReadOnly(path);
using var sr = new StreamReader(fs, Encoding.UTF8);
string content = await sr.ReadToEndAsync();
return content;
}
public static FileStream OpenReadOnly(string path)
{
return new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete);
}
}
}