< Summary

Information
Class: MyNet.UI.Helpers.IoHelper
Assembly: MyNet.UI
File(s): https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.UI/Helpers/IoHelper.cs
Tag: 323_28699572109
Line coverage
100%
Covered lines: 7
Uncovered lines: 0
Coverable lines: 7
Total lines: 42
Line coverage: 100%
Branch coverage
83%
Covered branches: 5
Total branches: 6
Branch coverage: 83.3%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
OpenFolderLocation(...)83.33%66100%

File(s)

https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.UI/Helpers/IoHelper.cs

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="IoHelper.cs" company="Stéphane ANDRE">
 3// Copyright (c) Stéphane ANDRE. All rights reserved.
 4// </copyright>
 5// -----------------------------------------------------------------------
 6
 7using System.Globalization;
 8using System.IO;
 9using MyNet.Primitives;
 10using MyNet.Primitives.Helpers;
 11using MyNet.UI.Notifications;
 12using MyNet.UI.Resources;
 13
 14namespace MyNet.UI.Helpers;
 15
 16/// <summary>
 17/// Provides helper methods for input/output operations, such as opening folders and handling file paths.
 18/// </summary>
 19public 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    {
 629        var directory = Path.GetDirectoryName(filePath);
 30
 631        if (!string.IsNullOrEmpty(directory) && Directory.Exists(directory))
 32        {
 333            ProcessHelper.OpenFolder(directory);
 334            return true;
 35        }
 36
 337        var message = MessageResources.FileXNotFoundError.FormatWith(CultureInfo.CurrentCulture, filePath);
 338        notificationPublisher?.PublishError(message);
 339        return false;
 40    }
 41}
 42