Skip to content

Commit f358692

Browse files
committed
Use default file explorer when possible (fix #4063)
1 parent 311cd14 commit f358692

File tree

8 files changed

+50
-74
lines changed

8 files changed

+50
-74
lines changed

src/UniGetUI.Core.Tools/Tools.cs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Security.Principal;
66
using System.Text;
77
using Windows.Networking.Connectivity;
8+
using ABI.Windows.ApplicationModel.UserDataTasks;
89
using UniGetUI.Core.Classes;
910
using UniGetUI.Core.Data;
1011
using UniGetUI.Core.Language;
@@ -720,13 +721,36 @@ public static async Task ShowFileOnExplorer(string path)
720721
}
721722
}
722723

724+
public static void Launch(string? path)
725+
{
726+
try
727+
{
728+
if (path is null) return;
729+
730+
var p = new Process()
731+
{
732+
StartInfo = new()
733+
{
734+
FileName = path,
735+
UseShellExecute = true,
736+
CreateNoWindow = true,
737+
}
738+
};
739+
p.Start();
740+
}
741+
catch (Exception ex)
742+
{
743+
Logger.Error(ex);
744+
}
745+
}
746+
723747
public static string GetCurrentLocale()
724748
{
725749
return LanguageEngine?.Locale ?? "Unset/Unknown";
726750
}
727751

728-
private static readonly HashSet<char> illegalPathChars = Path.GetInvalidFileNameChars().ToHashSet();
752+
private static readonly HashSet<char> _illegalPathChars = Path.GetInvalidFileNameChars().ToHashSet();
729753
public static string MakeValidFileName(string name)
730-
=> string.Concat(name.Where(x => !illegalPathChars.Contains(x)));
754+
=> string.Concat(name.Where(x => !_illegalPathChars.Contains(x)));
731755
}
732756
}

src/UniGetUI/CLIHandler.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using UniGetUI.Core.Logging;
22
using UniGetUI.Core.SettingsEngine;
33
using UniGetUI.Core.SettingsEngine.SecureSettings;
4+
using UniGetUI.Core.Tools;
45

56
namespace UniGetUI;
67

@@ -37,11 +38,8 @@ private enum HRESULT
3738

3839
public static int Help()
3940
{
40-
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo
41-
{
42-
FileName = "https://github.com/marticliment/UniGetUI/blob/main/cli-arguments.md#unigetui-command-line-parameters",
43-
UseShellExecute = true
44-
});
41+
var url = "https://github.com/marticliment/UniGetUI/blob/main/cli-arguments.md#unigetui-command-line-parameters";
42+
CoreTools.Launch(url);
4543
return 0;
4644
}
4745

src/UniGetUI/Controls/OperationWidgets/OperationControl.cs

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -629,14 +629,7 @@ public List<MenuFlyoutItemBase> GetOperationOptions()
629629
Text = CoreTools.Translate("Open install location"),
630630
IconName = IconType.OpenFolder,
631631
};
632-
openLocation.Click += (_, _) =>
633-
{
634-
Process.Start(new ProcessStartInfo {
635-
FileName = location ?? "",
636-
UseShellExecute = true,
637-
Verb = "open"
638-
});
639-
};
632+
openLocation.Click += (_, _) => CoreTools.Launch(location);
640633
openLocation.IsEnabled = location is not null && Directory.Exists(location);
641634
optionsMenu.Add(openLocation);
642635
}
@@ -647,22 +640,7 @@ public List<MenuFlyoutItemBase> GetOperationOptions()
647640
Text = CoreTools.Translate("Open"),
648641
IconName = IconType.Launch,
649642
};
650-
launchInstaller.Click += (_, _) =>
651-
{
652-
try
653-
{
654-
Process.Start(new ProcessStartInfo
655-
{
656-
FileName = downloadOp.DownloadLocation,
657-
UseShellExecute = true
658-
});
659-
}
660-
catch (Exception ex)
661-
{
662-
Logger.Error($"An error occurred while attempting to launch the file {downloadOp.DownloadLocation}.");
663-
Logger.Error(ex);
664-
}
665-
};
643+
launchInstaller.Click += (_, _) => CoreTools.Launch(downloadOp.DownloadLocation);
666644
launchInstaller.IsEnabled = downloadOp.Status is OperationStatus.Succeeded;
667645
optionsMenu.Add(launchInstaller);
668646

src/UniGetUI/Pages/HelpPage.xaml.cs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Diagnostics;
22
using Microsoft.UI.Xaml;
33
using Microsoft.UI.Xaml.Controls;
4+
using UniGetUI.Core.Tools;
45
using UniGetUI.Interface.Pages;
56

67
// To learn more about WinUI, the WinUI project structure,
@@ -83,27 +84,27 @@ private void RightButton_Click(object sender, RoutedEventArgs e)
8384

8485
private void HomeButton_Click(object sender, RoutedEventArgs e)
8586
{
87+
if (!Initialized || webView is null)
88+
return;
8689

87-
if (Initialized && webView is not null)
88-
{
89-
webView.Source = new Uri("https://marticliment.com/unigetui/help");
90-
}
90+
webView.Source = new Uri("https://marticliment.com/unigetui/help");
9191
}
9292

9393
private void ReloadButton_Click(object sender, RoutedEventArgs e)
9494
{
95-
if (Initialized && webView is not null)
96-
{
97-
webView.Reload();
98-
}
95+
if (!Initialized || webView is null)
96+
return;
97+
98+
webView.Reload();
9999
}
100100

101101
private void BrowserButton_Click(object sender, RoutedEventArgs e)
102102
{
103-
if (Initialized && webView is not null)
104-
{
105-
Process.Start(new ProcessStartInfo { FileName = webView.Source.ToString().Replace("?isWingetUIIframe", "").Replace("&isWingetUIIframe", ""), UseShellExecute = true });
106-
}
103+
if (!Initialized || webView is null)
104+
return;
105+
106+
string uri = webView.Source.ToString().Replace("?isWingetUIIframe", "").Replace("&isWingetUIIframe", "");
107+
CoreTools.Launch(uri);
107108
}
108109

109110
public void Dispose()

src/UniGetUI/Pages/SettingsPages/GeneralPages/Backup.xaml.cs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -100,19 +100,12 @@ private void ResetBackupPath_Click(object sender, RoutedEventArgs e)
100100
private void OpenBackupPath_Click(object sender, RoutedEventArgs e)
101101
{
102102
string directory = Settings.GetValue(Settings.K.ChangeBackupOutputDirectory);
103-
if (directory == "")
104-
{
105-
directory = CoreData.UniGetUI_DefaultBackupDirectory;
106-
}
103+
if (directory == "") directory = CoreData.UniGetUI_DefaultBackupDirectory;
107104

108105
directory = directory.Replace("/", "\\");
106+
if (!Directory.Exists(directory)) Directory.CreateDirectory(directory);
109107

110-
if (!Directory.Exists(directory))
111-
{
112-
Directory.CreateDirectory(directory);
113-
}
114-
115-
Process.Start("explorer.exe", directory);
108+
CoreTools.Launch(directory);
116109
}
117110

118111
private void DoBackup_LOCAL_Click(object sender, EventArgs e) => _ = _doBackup_LOCAL_Click();

src/UniGetUI/Pages/SettingsPages/GeneralPages/Interface_P.xaml.cs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,6 @@ private void ThemeSelector_ValueChanged(object sender, EventArgs e)
9191
=> MainApp.Instance.MainWindow.ApplyTheme();
9292

9393
private void EditAutostartSettings_Click(object sender, EventArgs e)
94-
{
95-
using Process p = new()
96-
{
97-
StartInfo = new ProcessStartInfo
98-
{
99-
FileName = "ms-settings:startupapps",
100-
UseShellExecute = true,
101-
CreateNoWindow = true
102-
}
103-
};
104-
p.Start();
105-
}
94+
=> CoreTools.Launch("ms-settings:startupapps");
10695
}
10796
}

src/UniGetUI/Pages/SettingsPages/ManagersPages/PackageManager.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ protected override void OnNavigatedTo(NavigationEventArgs e)
314314
OpenVcPkgRootLabel.Click += (_, _) =>
315315
{
316316
string directory = Settings.GetValue(Settings.K.CustomVcpkgRoot).Replace("/", "\\");
317-
if (directory.Any()) Process.Start("explorer.exe", directory);
317+
if (directory.Any()) CoreTools.Launch(directory);
318318
};
319319

320320
Vcpkg_CustomVcpkgRoot.Click += (_, _) =>

src/UniGetUI/Pages/SoftwarePages/AbstractPackagesPage.xaml.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,14 +1014,7 @@ protected void ShowDetailsForPackage(IPackage? package, TEL_InstallReferral refe
10141014
protected void OpenPackageInstallLocation(IPackage? package)
10151015
{
10161016
string? path = package?.Manager.DetailsHelper.GetInstallLocation(package);
1017-
1018-
if (path is not null)
1019-
Process.Start(new ProcessStartInfo
1020-
{
1021-
FileName = path,
1022-
UseShellExecute = true,
1023-
Verb = "open"
1024-
});
1017+
CoreTools.Launch(path);
10251018
}
10261019

10271020
protected void SharePackage(IPackage? package)

0 commit comments

Comments
 (0)