Catalog/imagecatalog/Services/PathShellService.cs
Maddo 398cfa310e
Some checks failed
Build Windows Avalonia / build (push) Failing after 1m46s
Build Windows Avalonia / release (push) Has been skipped
Refactor path handling in UI components
- Removed redundant folder and file opening methods from AiTabView and FaceAiTabView.
- Introduced PathPickerField control to streamline path selection and opening functionality across multiple views.
- Updated FaceAiTabView and GeneralTabView to utilize PathPickerField for source and destination path selection.
- Created PathShellService to encapsulate logic for opening paths in the file explorer.
- Simplified XAML structure by replacing manual grid definitions with PathPickerField components.
- Removed unused namespaces and cleaned up code for better readability and maintainability.
2026-05-24 19:07:17 +02:00

50 lines
No EOL
1.3 KiB
C#

using System.Diagnostics;
using System.IO;
namespace ImageCatalog_2.Services;
public static class PathShellService
{
public static void OpenInExplorer(string? path)
{
if (string.IsNullOrWhiteSpace(path))
{
return;
}
var normalizedPath = path.Trim().Trim('"');
try
{
if (File.Exists(normalizedPath))
{
Process.Start("explorer.exe", $"/select,\"{normalizedPath}\"");
return;
}
if (Directory.Exists(normalizedPath))
{
Process.Start(new ProcessStartInfo
{
FileName = normalizedPath,
UseShellExecute = true
});
return;
}
var containingDirectory = Path.GetDirectoryName(normalizedPath);
if (!string.IsNullOrWhiteSpace(containingDirectory) && Directory.Exists(containingDirectory))
{
Process.Start(new ProcessStartInfo
{
FileName = containingDirectory,
UseShellExecute = true
});
}
}
catch
{
// Ignore failures when opening Explorer.
}
}
}