From ffeb2b1fff8dc6232823dac4d28dd6dc582db9cd Mon Sep 17 00:00:00 2001 From: MaxIsJoe <34368774+MaxIsJoe@users.noreply.github.com> Date: Mon, 11 Mar 2024 22:46:48 +0200 Subject: [PATCH 1/3] Allow paths in the installations page to be clickable --- .../Views/InstallationView.axaml | 8 +++- .../Views/InstallationView.axaml.cs | 37 +++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) 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..978ac23 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,37 @@ 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; + } } From 9086adf0a88fb6e973a34542648677dc806d9c02 Mon Sep 17 00:00:00 2001 From: MaxIsJoe <34368774+MaxIsJoe@users.noreply.github.com> Date: Tue, 12 Mar 2024 22:15:37 +0200 Subject: [PATCH 2/3] Update InstallationView.axaml.cs --- UnitystationLauncher/Views/InstallationView.axaml.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/UnitystationLauncher/Views/InstallationView.axaml.cs b/UnitystationLauncher/Views/InstallationView.axaml.cs index 978ac23..dc7578f 100644 --- a/UnitystationLauncher/Views/InstallationView.axaml.cs +++ b/UnitystationLauncher/Views/InstallationView.axaml.cs @@ -22,7 +22,10 @@ private void InitializeComponent() private void HandlePathClick(object sender, PointerPressedEventArgs e) { TextBlock? block = sender as TextBlock; - if (block?.Text == null) return; + if (block?.Text == null) + { + return; + } string path = Path.GetFullPath(block.Text); string protcol = GetManagerProtocl(); Process.Start(protcol, new Uri(RemoveLastPart(path)).ToString()); From eddd7090219e428534761eb2f92ceb2df72c65e8 Mon Sep 17 00:00:00 2001 From: MaxIsJoe <34368774+MaxIsJoe@users.noreply.github.com> Date: Tue, 12 Mar 2024 22:17:27 +0200 Subject: [PATCH 3/3] Update InstallationView.axaml.cs --- UnitystationLauncher/Views/InstallationView.axaml.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/UnitystationLauncher/Views/InstallationView.axaml.cs b/UnitystationLauncher/Views/InstallationView.axaml.cs index dc7578f..04bf14a 100644 --- a/UnitystationLauncher/Views/InstallationView.axaml.cs +++ b/UnitystationLauncher/Views/InstallationView.axaml.cs @@ -18,7 +18,6 @@ private void InitializeComponent() { AvaloniaXamlLoader.Load(this); } - private void HandlePathClick(object sender, PointerPressedEventArgs e) { TextBlock? block = sender as TextBlock;