Compare commits

...

5 Commits

Author SHA1 Message Date
copilot-swe-agent[bot]
c97f924055 Add OFD file format support to OfficeViewer plugin
Co-authored-by: emako <24737061+emako@users.noreply.github.com>
2025-09-07 07:15:27 +00:00
copilot-swe-agent[bot]
67168e51aa Initial plan 2025-09-07 07:10:57 +00:00
ema
21a3dd3d4b Fix the same previous issue in other plugins
Some checks failed
MSBuild / build (push) Has been cancelled
MSBuild / publish (push) Has been cancelled
2025-08-15 02:17:50 +08:00
ema
ebb48366a0 Fix font file unicode name is not supported 2025-08-15 02:09:38 +08:00
ema
e12bb2201b Fix issue where font file stays locked #77 2025-08-15 02:01:59 +08:00
12 changed files with 33 additions and 25 deletions

View File

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

View File

@@ -29,7 +29,7 @@ internal static class WgtParser
{ {
public static WgtInfo Parse(string path) 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); using var zipArchive = new ZipArchive(fileStream, ZipArchiveMode.Read);
var manifestEntry = zipArchive.GetEntry("manifest.json"); var manifestEntry = zipArchive.GetEntry("manifest.json");

View File

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

View File

@@ -40,12 +40,19 @@ internal unsafe static class FreeTypeApi
error = FT_New_Face(lib, (byte*)Marshal.StringToHGlobalAnsi(path), IntPtr.Zero, &face); error = FT_New_Face(lib, (byte*)Marshal.StringToHGlobalAnsi(path), IntPtr.Zero, &face);
try
{
if (error == FT_Error.FT_Err_Ok) if (error == FT_Error.FT_Err_Ok)
{ {
var familyName = Marshal.PtrToStringAnsi((nint)face->family_name); var familyName = Marshal.PtrToStringAnsi((nint)face->family_name);
return familyName; return familyName;
} }
}
finally
{
FT_Done_Face(face);
FT_Done_FreeType(lib);
}
return null; return null;
} }
} }

View File

@@ -149,11 +149,11 @@ public class WebfontPanel : WebpagePanel
} }
else else
{ {
var localPath = _fallbackPath + requestedUri.AbsolutePath.Replace('/', '\\'); var localPath = _fallbackPath + Uri.UnescapeDataString(requestedUri.AbsolutePath).Replace('/', '\\');
if (File.Exists(localPath)) 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( var response = _webView.CoreWebView2.Environment.CreateWebResourceResponse(
fileStream, 200, "OK", MimeTypes.GetContentType()); fileStream, 200, "OK", MimeTypes.GetContentType());
args.Response = response; args.Response = response;

View File

@@ -210,7 +210,7 @@ public class WebpagePanel : UserControl
if (File.Exists(fallbackFilePath)) if (File.Exists(fallbackFilePath))
{ {
// Serve the file from the fallback directory // 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( var response = _webView.CoreWebView2.Environment.CreateWebResourceResponse(
fileStream, 200, "OK", "Content-Type: application/octet-stream"); fileStream, 200, "OK", "Content-Type: application/octet-stream");
args.Response = response; args.Response = response;

View File

@@ -27,7 +27,7 @@ internal static class LottieExtractor
{ {
public static string GetJsonContent(string path) 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); using var zipArchive = new ZipArchive(fileStream, ZipArchiveMode.Read);
var manifestEntry = zipArchive.GetEntry("manifest.json"); var manifestEntry = zipArchive.GetEntry("manifest.json");

View File

@@ -130,11 +130,11 @@ public class SvgImagePanel : WebpagePanel, IWebImagePanel
} }
else else
{ {
var localPath = _fallbackPath + requestedUri.AbsolutePath.Replace('/', '\\'); var localPath = _fallbackPath + Uri.UnescapeDataString(requestedUri.AbsolutePath).Replace('/', '\\');
if (File.Exists(localPath)) 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( var response = _webView.CoreWebView2.Environment.CreateWebResourceResponse(
fileStream, 200, "OK", MimeTypes.GetContentTypeHeader()); fileStream, 200, "OK", MimeTypes.GetContentTypeHeader());
args.Response = response; args.Response = response;
@@ -149,7 +149,7 @@ public class SvgImagePanel : WebpagePanel, IWebImagePanel
{ {
if (File.Exists(localPath)) 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( var response = _webView.CoreWebView2.Environment.CreateWebResourceResponse(
fileStream, 200, "OK", fileStream, 200, "OK",
$""" $"""

View File

@@ -124,11 +124,11 @@ public class MarkdownPanel : WebpagePanel
} }
else else
{ {
var localPath = _fallbackPath + requestedUri.AbsolutePath.Replace('/', '\\'); var localPath = _fallbackPath + Uri.UnescapeDataString(requestedUri.AbsolutePath).Replace('/', '\\');
if (File.Exists(localPath)) 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( var response = _webView.CoreWebView2.Environment.CreateWebResourceResponse(
fileStream, 200, "OK", MimeTypes.GetContentType()); fileStream, 200, "OK", MimeTypes.GetContentType());
args.Response = response; args.Response = response;

View File

@@ -34,6 +34,7 @@ public class Plugin : IViewer
".xls", ".xlsx", ".xlsm", ".xlsb", ".ods", ".xls", ".xlsx", ".xlsm", ".xlsb", ".ods",
".ppt", ".pptx", ".odp", ".ppt", ".pptx", ".odp",
".vsd", ".vsdx", ".vsd", ".vsdx",
".ofd",
]; ];
private PreviewPanel _panel; private PreviewPanel _panel;

View File

@@ -69,9 +69,9 @@ public class Plugin : IViewer
if (path.EndsWith(".rtf", StringComparison.OrdinalIgnoreCase)) if (path.EndsWith(".rtf", StringComparison.OrdinalIgnoreCase))
{ {
var rtfBox = new RichTextBox(); 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.Background = new SolidColorBrush(Colors.Transparent);
rtfBox.Selection.Load(fs, DataFormats.Rtf); rtfBox.Selection.Load(fileStream, DataFormats.Rtf);
rtfBox.IsReadOnly = true; rtfBox.IsReadOnly = true;
rtfBox.VerticalScrollBarVisibility = ScrollBarVisibility.Auto; rtfBox.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
rtfBox.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto; rtfBox.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;

View File

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