Welcome to mirror list, hosted at ThFree Co, Russian Federation.

macOS.cs « SystemOS « UVtools.Core - github.com/sn4k3/UVtools.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: fca55b35617e4950bd885fb9a0f86306f03c77c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
 *                     GNU AFFERO GENERAL PUBLIC LICENSE
 *                       Version 3, 19 November 2007
 *  Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
 *  Everyone is permitted to copy and distribute verbatim copies
 *  of this license document, but changing it is not allowed.
 */

using System;
using System.IO;

namespace UVtools.Core.SystemOS;

/// <summary>
/// MacOS specific methods
/// </summary>
public static class macOS
{
    /// <summary>
    /// Gets if is running under MacOS and under .app format
    /// </summary>
    public static bool IsRunningApp => OperatingSystem.IsMacOS() && AppContext.BaseDirectory.EndsWith(Path.Combine(".app", "Contents", $"MacOS{Path.DirectorySeparatorChar}"));

    /// <summary>
    /// Gets if is running under macOS and under .app format and return the full root path for the running .app
    /// </summary>
    public static bool IsRunningAppGetPath(out string? path)
    {
        path = RunningAppRootPath;
        return !string.IsNullOrWhiteSpace(path);
    }

    /// <summary>
    /// Gets the full root path for the running .app. Returns null or empty if not running an macOS .app
    /// </summary>
    public static string? RunningAppRootPath => IsRunningApp ? Directory.GetParent(AppContext.BaseDirectory)?.Parent?.Parent?.FullName : null;


    /// <summary>
    /// Gets the name of the running .app. Returns null or empty if not running an macOS .app
    /// </summary>
    public static string? RunningAppName => IsRunningApp ? Directory.GetParent(AppContext.BaseDirectory)?.Parent?.Parent?.Name : null;
}