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
13 changed files with 38 additions and 86 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

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

View File

@@ -149,11 +149,11 @@ public class WebfontPanel : 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

@@ -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

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

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)

View File

@@ -37,72 +37,16 @@ namespace QuickLook;
public partial class App : Application
{
public static readonly string LocalDataPath = GetSafeLocalDataPath();
public static readonly string UserPluginPath = Path.Combine(LocalDataPath, @"QuickLook.Plugin\");
public static readonly string AppFullPath = Assembly.GetExecutingAssembly().Location ?? string.Empty;
public static readonly string AppPath = GetSafeAppPath();
public static readonly string LocalDataPath = SettingHelper.LocalDataPath;
public static readonly string UserPluginPath = Path.Combine(SettingHelper.LocalDataPath, @"QuickLook.Plugin\");
public static readonly string AppFullPath = Assembly.GetExecutingAssembly().Location;
public static readonly string AppPath = Path.GetDirectoryName(AppFullPath);
public static readonly bool Is64Bit = Environment.Is64BitProcess;
public static readonly bool IsUWP = ProcessHelper.IsRunningAsUWP();
public static readonly bool IsWin11 = Environment.OSVersion.Version >= new Version(10, 0, 21996);
public static readonly bool IsWin10 = !IsWin11 && Environment.OSVersion.Version >= new Version(10, 0);
public static readonly bool IsGPUInBlacklist = SystemHelper.IsGPUInBlacklist();
public static readonly bool IsPortable = SafeIsPortableVersion();
private static string GetSafeLocalDataPath()
{
try
{
return SettingHelper.LocalDataPath;
}
catch (ArgumentException)
{
// Fallback: determine data path based on portable mode detection
var isPortable = SafeIsPortableVersion();
if (isPortable)
{
var assemblyLocation = Assembly.GetExecutingAssembly().Location;
var assemblyDir = !string.IsNullOrEmpty(assemblyLocation)
? Path.GetDirectoryName(assemblyLocation)
: AppDomain.CurrentDomain.BaseDirectory;
return Path.Combine(assemblyDir ?? string.Empty, @"UserData\");
}
else
{
return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
@"pooi.moe\QuickLook\");
}
}
}
private static bool SafeIsPortableVersion()
{
try
{
return SettingHelper.IsPortableVersion();
}
catch (ArgumentException)
{
// Fallback: check for portable.lock file in current directory or base directory
var assemblyLocation = Assembly.GetExecutingAssembly().Location;
var assemblyDir = !string.IsNullOrEmpty(assemblyLocation)
? Path.GetDirectoryName(assemblyLocation)
: AppDomain.CurrentDomain.BaseDirectory;
var lck = Path.Combine(assemblyDir ?? string.Empty, "portable.lock");
return File.Exists(lck);
}
}
private static string GetSafeAppPath()
{
var assemblyLocation = Assembly.GetExecutingAssembly().Location;
if (!string.IsNullOrEmpty(assemblyLocation))
{
return Path.GetDirectoryName(assemblyLocation) ?? string.Empty;
}
return AppDomain.CurrentDomain.BaseDirectory;
}
public static readonly bool IsPortable = SettingHelper.IsPortableVersion();
private bool _cleanExit = true;
private Mutex _isRunning;