diff --git a/UnitystationLauncher/Views/InstallationView.axaml b/UnitystationLauncher/Views/InstallationView.axaml index f0c51dc..235457b 100644 --- a/UnitystationLauncher/Views/InstallationView.axaml +++ b/UnitystationLauncher/Views/InstallationView.axaml @@ -3,6 +3,7 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:viewModels="clr-namespace:UnitystationLauncher.ViewModels" + xmlns:drawing="clr-namespace:System.Drawing;assembly=System.Drawing.Primitives" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="120" FontSize="16" x:Class="UnitystationLauncher.Views.InstallationView" x:DataType="viewModels:InstallationViewModel"> @@ -18,7 +19,12 @@ - + + + + diff --git a/UnitystationLauncher/Views/InstallationView.axaml.cs b/UnitystationLauncher/Views/InstallationView.axaml.cs index 4f7aef5..04bf14a 100644 --- a/UnitystationLauncher/Views/InstallationView.axaml.cs +++ b/UnitystationLauncher/Views/InstallationView.axaml.cs @@ -1,4 +1,8 @@ +using System; +using System.Diagnostics; +using System.IO; using Avalonia.Controls; +using Avalonia.Input; using Avalonia.Markup.Xaml; namespace UnitystationLauncher.Views; @@ -14,4 +18,39 @@ private void InitializeComponent() { AvaloniaXamlLoader.Load(this); } + private void HandlePathClick(object sender, PointerPressedEventArgs e) + { + TextBlock? block = sender as TextBlock; + if (block?.Text == null) + { + return; + } + string path = Path.GetFullPath(block.Text); + string protcol = GetManagerProtocl(); + Process.Start(protcol, new Uri(RemoveLastPart(path)).ToString()); + } + + private string GetManagerProtocl() + { + string protocol = "Explorer.exe"; + if (OperatingSystem.IsWindows()) + { + protocol = "Explorer.exe"; + } + else if (OperatingSystem.IsMacOS()) + { + protocol = "open"; + } + else if (OperatingSystem.IsLinux()) + { + protocol = "xdg-open"; + } + return protocol; + } + + private string RemoveLastPart(string path) + { + int lastBackslashIndex = path.LastIndexOf('\\'); + return lastBackslashIndex >= 0 ? path.Substring(0, lastBackslashIndex) : path; + } }