Browse Source

Centralize single instancing logic back in MainWindow, fix Skip(1) error due to .Args property implementation

pull/3212/head
Christoph Wille 12 months ago
parent
commit
7946f72024
  1. 8
      ILSpy/App.xaml.cs
  2. 7
      ILSpy/AppEnv/SingleInstance.cs
  3. 16
      ILSpy/MainWindow.xaml.cs

8
ILSpy/App.xaml.cs

@ -106,13 +106,7 @@ namespace ICSharpCode.ILSpy @@ -106,13 +106,7 @@ namespace ICSharpCode.ILSpy
private static void SingleInstance_NewInstanceDetected(object? sender, NewInstanceEventArgs e)
{
var mainWindow = ICSharpCode.ILSpy.MainWindow.Instance;
var args = new CommandLineArguments(e.Args);
if (mainWindow.HandleCommandLineArguments(args))
{
mainWindow.HandleCommandLineArgumentsAfterShowList(args);
}
ICSharpCode.ILSpy.MainWindow.Instance.HandleSingleInstanceCommandLineArguments(e.Args);
}
static Assembly ResolvePluginDependencies(AssemblyLoadContext context, AssemblyName assemblyName)

7
ILSpy/AppEnv/SingleInstance.cs

@ -54,9 +54,10 @@ public static class SingleInstance @@ -54,9 +54,10 @@ public static class SingleInstance
private static string[] GetILSpyCommandLineArgs()
{
var cmdArgs = Environment.GetCommandLineArgs().Skip(1);
cmdArgs = cmdArgs.Select(CommandLineTools.FullyQualifyPath);
return cmdArgs.ToArray();
// Note: NO Skip(1) here because .Args property on SingleInstanceArguments does this for us
return Environment.GetCommandLineArgs().AsEnumerable()
.Select(CommandLineTools.FullyQualifyPath)
.ToArray();
}
/// <summary>

16
ILSpy/MainWindow.xaml.cs

@ -652,7 +652,19 @@ namespace ICSharpCode.ILSpy @@ -652,7 +652,19 @@ namespace ICSharpCode.ILSpy
List<LoadedAssembly> commandLineLoadedAssemblies = new List<LoadedAssembly>();
internal bool HandleCommandLineArguments(CommandLineArguments args)
internal async Task HandleSingleInstanceCommandLineArguments(string[] args)
{
var cmdArgs = new CommandLineArguments(args);
await Dispatcher.InvokeAsync(() => {
if (HandleCommandLineArguments(cmdArgs))
{
HandleCommandLineArgumentsAfterShowList(cmdArgs);
}
});
}
bool HandleCommandLineArguments(CommandLineArguments args)
{
LoadAssemblies(args.AssembliesToLoad, commandLineLoadedAssemblies, focusNode: false);
if (args.Language != null)
@ -664,7 +676,7 @@ namespace ICSharpCode.ILSpy @@ -664,7 +676,7 @@ namespace ICSharpCode.ILSpy
/// Called on startup or when passed arguments via WndProc from a second instance.
/// In the format case, spySettings is non-null; in the latter it is null.
/// </summary>
internal void HandleCommandLineArgumentsAfterShowList(CommandLineArguments args, ILSpySettings spySettings = null)
void HandleCommandLineArgumentsAfterShowList(CommandLineArguments args, ILSpySettings spySettings = null)
{
var relevantAssemblies = commandLineLoadedAssemblies.ToList();
commandLineLoadedAssemblies.Clear(); // clear references once we don't need them anymore

Loading…
Cancel
Save