| | | 1 | | // ----------------------------------------------------------------------- |
| | | 2 | | // <copyright file="IoHelper.cs" company="Stéphane ANDRE"> |
| | | 3 | | // Copyright (c) Stéphane ANDRE. All rights reserved. |
| | | 4 | | // </copyright> |
| | | 5 | | // ----------------------------------------------------------------------- |
| | | 6 | | |
| | | 7 | | using System.Globalization; |
| | | 8 | | using System.IO; |
| | | 9 | | using MyNet.Primitives; |
| | | 10 | | using MyNet.Primitives.Helpers; |
| | | 11 | | using MyNet.UI.Notifications; |
| | | 12 | | using MyNet.UI.Resources; |
| | | 13 | | |
| | | 14 | | namespace MyNet.UI.Helpers; |
| | | 15 | | |
| | | 16 | | /// <summary> |
| | | 17 | | /// Provides helper methods for input/output operations, such as opening folders and handling file paths. |
| | | 18 | | /// </summary> |
| | | 19 | | public static class IoHelper |
| | | 20 | | { |
| | | 21 | | /// <summary> |
| | | 22 | | /// Opens the folder containing the specified file path. If the directory does not exist, shows an error message. |
| | | 23 | | /// </summary> |
| | | 24 | | /// <param name="filePath">The file path whose containing folder should be opened.</param> |
| | | 25 | | /// <param name="notificationPublisher">Optional notification publisher used to report UI errors without static depe |
| | | 26 | | /// <returns><c>true</c> when the folder was opened; otherwise <c>false</c>.</returns> |
| | | 27 | | public static bool OpenFolderLocation(string filePath, INotificationPublisher? notificationPublisher = null) |
| | | 28 | | { |
| | 6 | 29 | | var directory = Path.GetDirectoryName(filePath); |
| | | 30 | | |
| | 6 | 31 | | if (!string.IsNullOrEmpty(directory) && Directory.Exists(directory)) |
| | | 32 | | { |
| | 3 | 33 | | ProcessHelper.OpenFolder(directory); |
| | 3 | 34 | | return true; |
| | | 35 | | } |
| | | 36 | | |
| | 3 | 37 | | var message = MessageResources.FileXNotFoundError.FormatWith(CultureInfo.CurrentCulture, filePath); |
| | 3 | 38 | | notificationPublisher?.PublishError(message); |
| | 3 | 39 | | return false; |
| | | 40 | | } |
| | | 41 | | } |
| | | 42 | | |