Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 33 additions & 9 deletions QuickLook/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
using System.IO;
using System.Linq;
using System.Reflection;
using System.Security;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
Expand Down Expand Up @@ -126,8 +127,20 @@ protected override void OnStartup(StartupEventArgs e)
RunListener(e);

// First instance: run and preview this file
if (e.Args.Any() && (Directory.Exists(e.Args.First()) || File.Exists(e.Args.First())))
PipeServerManager.SendMessage(PipeMessages.Toggle, e.Args.First());
if (e.Args.Any())
{
try
{
var path = Path.GetFullPath(e.Args.First());
if (Directory.Exists(path) || File.Exists(path))
PipeServerManager.SendMessage(PipeMessages.Toggle, path);
}
catch (Exception ex) when (ex is ArgumentException || ex is SecurityException ||
ex is NotSupportedException || ex is PathTooLongException)
{
// Invalid path, ignore
}
}

// Exception handling events which are not caught in the Task thread
TaskScheduler.UnobservedTaskException += (_, e) =>
Expand Down Expand Up @@ -290,16 +303,27 @@ private bool EnsureFirstInstance(string[] args)
return true;

// Second instance: preview this file
if (args.Any() && (Directory.Exists(args.First()) || File.Exists(args.First())))
if (args.Any())
{
PipeServerManager.SendMessage(PipeMessages.Toggle, args.First(), [.. args.Skip(1)]);
try
{
var path = Path.GetFullPath(args.First());
if (Directory.Exists(path) || File.Exists(path))
{
PipeServerManager.SendMessage(PipeMessages.Toggle, path, [.. args.Skip(1)]);
return false;
}
}
catch (Exception ex) when (ex is ArgumentException || ex is SecurityException ||
ex is NotSupportedException || ex is PathTooLongException)
{
// Invalid path, continue to show duplicate message
}
}

// Second instance: duplicate
else
{
MessageBox.Show(TranslationHelper.Get("APP_SECOND_TEXT"), TranslationHelper.Get("APP_SECOND"),
MessageBoxButton.OK, MessageBoxImage.Information);
}
MessageBox.Show(TranslationHelper.Get("APP_SECOND_TEXT"), TranslationHelper.Get("APP_SECOND"),
MessageBoxButton.OK, MessageBoxImage.Information);

return false;
}
Expand Down