diff options
author | Tiago Conceição <Tiago_caza@hotmail.com> | 2022-10-24 00:19:38 +0300 |
---|---|---|
committer | Tiago Conceição <Tiago_caza@hotmail.com> | 2022-10-24 00:19:38 +0300 |
commit | 18b208bf3170cf42de5f409cd984aedbf34b6e95 (patch) | |
tree | 89257d56050c1f2c78e6462bcbaaf91f250e5bb6 /UVtools.Core/SystemOS | |
parent | ab11d40d33145e88cf47ebc736349af6eae2dcb9 (diff) |
(Improvement) Auto-upgrade procedure for non-Windows systems
Diffstat (limited to 'UVtools.Core/SystemOS')
-rw-r--r-- | UVtools.Core/SystemOS/Linux.cs | 44 | ||||
-rw-r--r-- | UVtools.Core/SystemOS/SystemAware.cs | 18 | ||||
-rw-r--r-- | UVtools.Core/SystemOS/macOS.cs | 43 |
3 files changed, 91 insertions, 14 deletions
diff --git a/UVtools.Core/SystemOS/Linux.cs b/UVtools.Core/SystemOS/Linux.cs new file mode 100644 index 0000000..c73fb5a --- /dev/null +++ b/UVtools.Core/SystemOS/Linux.cs @@ -0,0 +1,44 @@ +/* + * 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> +/// Linux specific methods +/// </summary> +public static class Linux +{ + /// <summary> + /// Gets if is running under Linux and under AppImage format + /// </summary> + public static bool IsRunningAppImage => !string.IsNullOrWhiteSpace(RunningAppImageRootPath); + + /// <summary> + /// Gets if is running under Linux and under AppImage format and return the full root path for the running AppImage + /// </summary> + public static bool IsRunningAppImageGetPath(out string? path) + { + path = RunningAppImageRootPath; + return !string.IsNullOrWhiteSpace(path); + } + + /// <summary> + /// <para>Gets the full root path for the running AppImage. Returns null is not Linux and null/empty if not an AppImage</para> + /// <para>The return path is the source file location and not the execution path location.</para> + /// </summary> + public static string? RunningAppImageRootPath => OperatingSystem.IsLinux() ? Environment.GetEnvironmentVariable("APPIMAGE") : null; + + + /// <summary> + /// Gets the name of the running *.app. Returns null or empty if not running an macOS .app. Returns null or empty if not an AppImage + /// </summary> + public static string? RunningAppName => Path.GetFileName(RunningAppImageRootPath); +}
\ No newline at end of file diff --git a/UVtools.Core/SystemOS/SystemAware.cs b/UVtools.Core/SystemOS/SystemAware.cs index a3781cb..c73c0aa 100644 --- a/UVtools.Core/SystemOS/SystemAware.cs +++ b/UVtools.Core/SystemOS/SystemAware.cs @@ -363,24 +363,14 @@ public static class SystemAware /// <summary> /// Gets if is running under Linux and under AppImage format /// </summary> - public static bool IsRunningLinuxAppImage(out string? path) - { - path = null; - if (!OperatingSystem.IsLinux()) return false; - path = Environment.GetEnvironmentVariable("APPIMAGE"); - return !string.IsNullOrWhiteSpace(path); - } - - /// <summary> - /// Gets if is running under Linux and under AppImage format - /// </summary> /// <returns></returns> - public static bool IsRunningLinuxAppImage() => IsRunningLinuxAppImage(out _); + public static bool IsRunningLinuxAppImage => Linux.IsRunningAppImage; /// <summary> - /// Gets if is running under MacOS and under app format + /// Gets if is running under MacOS and under *.app format /// </summary> - public static bool IsRunningMacOSApp => OperatingSystem.IsMacOS() && AppContext.BaseDirectory.EndsWith(Path.Combine(".app", "Contents", $"MacOS{Path.DirectorySeparatorChar}")); + public static bool IsRunningMacOSApp => macOS.IsRunningApp; + /// <summary> /// Gets the main name of the operative system diff --git a/UVtools.Core/SystemOS/macOS.cs b/UVtools.Core/SystemOS/macOS.cs new file mode 100644 index 0000000..fca55b3 --- /dev/null +++ b/UVtools.Core/SystemOS/macOS.cs @@ -0,0 +1,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; +}
\ No newline at end of file |