mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 19:26:39 +02:00
[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:
@@ -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 () =>
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user