From d4074578443b997a8902e6e0a112a5e164e9c8f7 Mon Sep 17 00:00:00 2001 From: Jeffrey Ye Date: Fri, 7 Sep 2018 19:09:11 +0200 Subject: [PATCH] Fix external actions on macOS --- ILSpy.Core/MainWindow.xaml.cs | 78 +++++++++++++++++++++--- ILSpy.Core/TreeNodes/AssemblyTreeNode.cs | 8 +-- 2 files changed, 74 insertions(+), 12 deletions(-) diff --git a/ILSpy.Core/MainWindow.xaml.cs b/ILSpy.Core/MainWindow.xaml.cs index 9806a22..d39e987 100644 --- a/ILSpy.Core/MainWindow.xaml.cs +++ b/ILSpy.Core/MainWindow.xaml.cs @@ -24,6 +24,7 @@ using System.ComponentModel; using System.Diagnostics; using System.IO; using System.Linq; +using System.Runtime.InteropServices; using System.Threading.Tasks; using System.Windows.Input; using Avalonia; @@ -699,24 +700,85 @@ namespace ICSharpCode.ILSpy return decompilationTask; } + /// + /// TODO: Opens the link in browser. + /// + /// Link. public static void OpenLink(string link) { try { - Process.Start(link); + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + Process.Start(link); + } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + { + Process.Start("open", link); + } + else + { + // TODO: open folder in linux and other os + } #pragma warning disable RECS0022 // A catch clause that catches System.Exception and has an empty body - } catch (Exception) { + } catch (Exception) { #pragma warning restore RECS0022 // A catch clause that catches System.Exception and has an empty body // Process.Start can throw several errors (not all of them documented), // just ignore all of them. } - } + } - public static void ExecuteCommand(string fileName, string arguments) - { - try { - Process.Start(fileName, arguments); + /// + /// open conatiner folder + /// + /// full path + public static void OpenFolder(string path) + { + try + { + if(RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + Process.Start("explorer.exe", $"/select,\"{path}\""); + } + else if(RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + { + Process.Start("open", path); + } + else + { + // TODO: open folder in linux and other os + } #pragma warning disable RECS0022 // A catch clause that catches System.Exception and has an empty body - } catch (Exception) { + } + catch (Exception) + { +#pragma warning restore RECS0022 // A catch clause that catches System.Exception and has an empty body + // Process.Start can throw several errors (not all of them documented), + // just ignore all of them. + } + } + + /// + /// Open command line interface + /// + /// Full path. + public static void OpenCommandLine(string path) + { + try + { + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + Process.Start("cmd.exe", $"/k \"cd {path}\""); + } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + { + Process.Start("/Applications/Utilities/Terminal.app/Contents/MacOS/Terminal", path); + } + else + { + // TODO: open folder in linux and other os + } +#pragma warning disable RECS0022 // A catch clause that catches System.Exception and has an empty body + } catch (Exception) { #pragma warning restore RECS0022 // A catch clause that catches System.Exception and has an empty body // Process.Start can throw several errors (not all of them documented), // just ignore all of them. diff --git a/ILSpy.Core/TreeNodes/AssemblyTreeNode.cs b/ILSpy.Core/TreeNodes/AssemblyTreeNode.cs index 80c1773..91f718a 100644 --- a/ILSpy.Core/TreeNodes/AssemblyTreeNode.cs +++ b/ILSpy.Core/TreeNodes/AssemblyTreeNode.cs @@ -467,9 +467,9 @@ namespace ICSharpCode.ILSpy.TreeNodes if (context.SelectedTreeNodes == null) return; foreach (var node in context.SelectedTreeNodes.OfType()) { - var path = node.LoadedAssembly.FileName; - if (File.Exists(path)) { - MainWindow.ExecuteCommand("explorer.exe", $"/select,\"{path}\""); + var path = Path.GetDirectoryName(node.LoadedAssembly.FileName); + if (Directory.Exists(path)) { + MainWindow.OpenFolder(path); } } } @@ -501,7 +501,7 @@ namespace ICSharpCode.ILSpy.TreeNodes foreach (var node in context.SelectedTreeNodes.OfType()) { var path = Path.GetDirectoryName(node.LoadedAssembly.FileName); if (Directory.Exists(path)) { - MainWindow.ExecuteCommand("cmd.exe", $"/k \"cd {path}\""); + MainWindow.OpenCommandLine(path); } } }