Compare commits

..

3 Commits

Author SHA1 Message Date
copilot-swe-agent[bot]
94ec17d62a Fix startup crash by adding safe wrappers for assembly location access
Co-authored-by: emako <24737061+emako@users.noreply.github.com>
2025-08-12 02:01:11 +00:00
Copilot
a5241251d4 Initial plan 2025-08-12 01:49:28 +00:00
ema
14a5bea926 Code Cleanup
Some checks failed
MSBuild / build (push) Has been cancelled
MSBuild / publish (push) Has been cancelled
2025-08-09 00:38:43 +08:00
13 changed files with 197 additions and 204 deletions

View File

@@ -37,16 +37,72 @@ namespace QuickLook;
public partial class App : Application public partial class App : Application
{ {
public static readonly string LocalDataPath = SettingHelper.LocalDataPath; public static readonly string LocalDataPath = GetSafeLocalDataPath();
public static readonly string UserPluginPath = Path.Combine(SettingHelper.LocalDataPath, @"QuickLook.Plugin\"); public static readonly string UserPluginPath = Path.Combine(LocalDataPath, @"QuickLook.Plugin\");
public static readonly string AppFullPath = Assembly.GetExecutingAssembly().Location; public static readonly string AppFullPath = Assembly.GetExecutingAssembly().Location ?? string.Empty;
public static readonly string AppPath = Path.GetDirectoryName(AppFullPath); public static readonly string AppPath = GetSafeAppPath();
public static readonly bool Is64Bit = Environment.Is64BitProcess; public static readonly bool Is64Bit = Environment.Is64BitProcess;
public static readonly bool IsUWP = ProcessHelper.IsRunningAsUWP(); public static readonly bool IsUWP = ProcessHelper.IsRunningAsUWP();
public static readonly bool IsWin11 = Environment.OSVersion.Version >= new Version(10, 0, 21996); 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 IsWin10 = !IsWin11 && Environment.OSVersion.Version >= new Version(10, 0);
public static readonly bool IsGPUInBlacklist = SystemHelper.IsGPUInBlacklist(); public static readonly bool IsGPUInBlacklist = SystemHelper.IsGPUInBlacklist();
public static readonly bool IsPortable = SettingHelper.IsPortableVersion(); 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;
}
private bool _cleanExit = true; private bool _cleanExit = true;
private Mutex _isRunning; private Mutex _isRunning;

View File

@@ -81,8 +81,7 @@ public class BackgroundVisualHost : FrameworkElement
private readonly CreateContentFunction _createContent; private readonly CreateContentFunction _createContent;
private readonly Action _invalidateMeasure; private readonly Action _invalidateMeasure;
private readonly AutoResetEvent _sync = private readonly AutoResetEvent _sync = new(false);
new AutoResetEvent(false);
public ThreadedVisualHelper( public ThreadedVisualHelper(
CreateContentFunction createContent, CreateContentFunction createContent,
@@ -125,15 +124,9 @@ public class BackgroundVisualHost : FrameworkElement
} }
} }
#region Private Fields
public ThreadedVisualHelper ThreadedHelper; public ThreadedVisualHelper ThreadedHelper;
private HostVisual _hostVisual; private HostVisual _hostVisual;
#endregion Private Fields
#region IsContentShowingProperty
/// <summary> /// <summary>
/// Identifies the IsContentShowing dependency property. /// Identifies the IsContentShowing dependency property.
/// </summary> /// </summary>
@@ -163,10 +156,6 @@ public class BackgroundVisualHost : FrameworkElement
bvh.HideContentHelper(); bvh.HideContentHelper();
} }
#endregion IsContentShowingProperty
#region CreateContent Property
/// <summary> /// <summary>
/// Identifies the CreateContent dependency property. /// Identifies the CreateContent dependency property.
/// </summary> /// </summary>
@@ -196,6 +185,4 @@ public class BackgroundVisualHost : FrameworkElement
bvh.CreateContentHelper(); bvh.CreateContentHelper();
} }
} }
#endregion CreateContent Property
} }

View File

@@ -58,50 +58,16 @@ public partial class InfoPanel : UserControl
Dispatcher.BeginInvoke(new Action(() => image.Source = source)); Dispatcher.BeginInvoke(new Action(() => image.Source = source));
}); });
string name; var name = Path.GetFileName(path);
try
{
name = Path.GetFileName(path);
}
catch (ArgumentException)
{
// Handle invalid path characters gracefully
name = path;
}
catch (PathTooLongException)
{
// Handle path too long scenarios
name = path;
}
filename.Text = string.IsNullOrEmpty(name) ? path : name; filename.Text = string.IsNullOrEmpty(name) ? path : name;
try
{
var last = File.GetLastWriteTime(path); var last = File.GetLastWriteTime(path);
modDate.Text = string.Format(TranslationHelper.Get("InfoPanel_LastModified"), modDate.Text = string.Format(TranslationHelper.Get("InfoPanel_LastModified"),
last.ToString(CultureInfo.CurrentCulture)); last.ToString(CultureInfo.CurrentCulture));
}
catch (ArgumentException)
{
// Handle invalid path characters gracefully
modDate.Text = TranslationHelper.Get("InfoPanel_LastModified_Unavailable") ?? "Last modified: Unavailable";
}
catch (UnauthorizedAccessException)
{
// Handle access denied scenarios
modDate.Text = TranslationHelper.Get("InfoPanel_LastModified_Unavailable") ?? "Last modified: Unavailable";
}
catch (PathTooLongException)
{
// Handle path too long scenarios
modDate.Text = TranslationHelper.Get("InfoPanel_LastModified_Unavailable") ?? "Last modified: Unavailable";
}
Stop = false; Stop = false;
_ = Task.Run(() => _ = Task.Run(() =>
{
try
{ {
if (File.Exists(path)) if (File.Exists(path))
{ {
@@ -151,22 +117,6 @@ public partial class InfoPanel : UserControl
$"{totalSizeL.ToPrettySize(2)} {t}"; $"{totalSizeL.ToPrettySize(2)} {t}";
}); });
} }
}
catch (ArgumentException)
{
// Handle invalid path characters gracefully
Dispatcher.Invoke(() => { totalSize.Text = "Size: Unavailable"; });
}
catch (UnauthorizedAccessException)
{
// Handle access denied scenarios
Dispatcher.Invoke(() => { totalSize.Text = "Size: Unavailable"; });
}
catch (PathTooLongException)
{
// Handle path too long scenarios
Dispatcher.Invoke(() => { totalSize.Text = "Size: Unavailable"; });
}
}); });
} }
} }