Fix the same previous issue in other plugins
Some checks failed
MSBuild / build (push) Has been cancelled
MSBuild / publish (push) Has been cancelled

This commit is contained in:
ema
2025-08-15 02:17:50 +08:00
parent ebb48366a0
commit 21a3dd3d4b
10 changed files with 20 additions and 20 deletions

View File

@@ -61,8 +61,8 @@ public class AppImageReader
public AppImageReader(string path)
{
using FileStream fs = File.OpenRead(path);
Open(fs);
using var fileStream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete);
Open(fileStream);
}
private void Open(Stream stream)

View File

@@ -29,7 +29,7 @@ internal static class WgtParser
{
public static WgtInfo Parse(string path)
{
using var fileStream = File.OpenRead(path);
using var fileStream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete);
using var zipArchive = new ZipArchive(fileStream, ZipArchiveMode.Read);
var manifestEntry = zipArchive.GetEntry("manifest.json");

View File

@@ -134,14 +134,14 @@ public partial class ArchiveInfoPanel : UserControl, IDisposable, INotifyPropert
private void LoadItemsFromArchive(string path)
{
using var stream = File.OpenRead(path);
using var fileStream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete);
// ReaderFactory is slow... so limit its usage
string[] useReader = [".tar.gz", ".tgz", ".tar.bz2", ".tar.lz", ".tar.xz"];
if (useReader.Any(path.ToLower().EndsWith))
{
var reader = ReaderFactory.Open(stream, new ChardetReaderOptions());
var reader = ReaderFactory.Open(fileStream, new ChardetReaderOptions());
_type = reader.ArchiveType.ToString();
@@ -149,13 +149,13 @@ public partial class ArchiveInfoPanel : UserControl, IDisposable, INotifyPropert
{
if (_disposed)
return;
LoadPercent = 100d * stream.Position / stream.Length;
LoadPercent = 100d * fileStream.Position / fileStream.Length;
ProcessByLevel(reader.Entry);
}
}
else
{
var archive = ArchiveFactory.Open(stream, new ChardetReaderOptions());
var archive = ArchiveFactory.Open(fileStream, new ChardetReaderOptions());
_type = archive.Type.ToString();
@@ -163,7 +163,7 @@ public partial class ArchiveInfoPanel : UserControl, IDisposable, INotifyPropert
{
if (_disposed)
return;
LoadPercent = 100d * stream.Position / stream.Length;
LoadPercent = 100d * fileStream.Position / fileStream.Length;
ProcessByLevel(entry);
}
}

View File

@@ -153,7 +153,7 @@ public class WebfontPanel : WebpagePanel
if (File.Exists(localPath))
{
var fileStream = File.OpenRead(localPath);
var fileStream = new FileStream(localPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete);
var response = _webView.CoreWebView2.Environment.CreateWebResourceResponse(
fileStream, 200, "OK", MimeTypes.GetContentType());
args.Response = response;

View File

@@ -210,7 +210,7 @@ public class WebpagePanel : UserControl
if (File.Exists(fallbackFilePath))
{
// Serve the file from the fallback directory
var fileStream = File.OpenRead(fallbackFilePath);
var fileStream = new FileStream(fallbackFilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete);
var response = _webView.CoreWebView2.Environment.CreateWebResourceResponse(
fileStream, 200, "OK", "Content-Type: application/octet-stream");
args.Response = response;

View File

@@ -27,7 +27,7 @@ internal static class LottieExtractor
{
public static string GetJsonContent(string path)
{
using var fileStream = File.OpenRead(path);
using var fileStream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete);
using var zipArchive = new ZipArchive(fileStream, ZipArchiveMode.Read);
var manifestEntry = zipArchive.GetEntry("manifest.json");

View File

@@ -130,11 +130,11 @@ public class SvgImagePanel : WebpagePanel, IWebImagePanel
}
else
{
var localPath = _fallbackPath + requestedUri.AbsolutePath.Replace('/', '\\');
var localPath = _fallbackPath + Uri.UnescapeDataString(requestedUri.AbsolutePath).Replace('/', '\\');
if (File.Exists(localPath))
{
var fileStream = File.OpenRead(localPath);
var fileStream = new FileStream(localPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete);
var response = _webView.CoreWebView2.Environment.CreateWebResourceResponse(
fileStream, 200, "OK", MimeTypes.GetContentTypeHeader());
args.Response = response;
@@ -149,7 +149,7 @@ public class SvgImagePanel : WebpagePanel, IWebImagePanel
{
if (File.Exists(localPath))
{
var fileStream = File.OpenRead(localPath);
var fileStream = new FileStream(localPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete);
var response = _webView.CoreWebView2.Environment.CreateWebResourceResponse(
fileStream, 200, "OK",
$"""

View File

@@ -124,11 +124,11 @@ public class MarkdownPanel : WebpagePanel
}
else
{
var localPath = _fallbackPath + requestedUri.AbsolutePath.Replace('/', '\\');
var localPath = _fallbackPath + Uri.UnescapeDataString(requestedUri.AbsolutePath).Replace('/', '\\');
if (File.Exists(localPath))
{
var fileStream = File.OpenRead(localPath);
var fileStream = new FileStream(localPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete);
var response = _webView.CoreWebView2.Environment.CreateWebResourceResponse(
fileStream, 200, "OK", MimeTypes.GetContentType());
args.Response = response;

View File

@@ -69,9 +69,9 @@ public class Plugin : IViewer
if (path.EndsWith(".rtf", StringComparison.OrdinalIgnoreCase))
{
var rtfBox = new RichTextBox();
using FileStream fs = File.OpenRead(path);
using var fileStream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete);
rtfBox.Background = new SolidColorBrush(Colors.Transparent);
rtfBox.Selection.Load(fs, DataFormats.Rtf);
rtfBox.Selection.Load(fileStream, DataFormats.Rtf);
rtfBox.IsReadOnly = true;
rtfBox.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
rtfBox.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;

View File

@@ -187,8 +187,8 @@ public class HighlightingThemeManager
{
Debug.WriteLine(file);
var ext = Path.GetFileNameWithoutExtension(file);
using Stream s = File.OpenRead(Path.GetFullPath(file));
using var reader = new XmlTextReader(s);
using var fileStream = new FileStream(Path.GetFullPath(file), FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete);
using var reader = new XmlTextReader(fileStream);
var xshd = HighlightingLoader.LoadXshd(reader);
var highlightingDefinition = HighlightingLoader.Load(xshd, hlm);
if (xshd.Extensions.Count > 0)