This repository has been archived by the owner on May 6, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from NickvisionApps/sysdirs
Add SystemDirectories
- Loading branch information
Showing
2 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace Nickvision.Aura.Tests; | ||
|
||
public class SystemDirectoriesTest | ||
{ | ||
[Fact] | ||
public void Path() | ||
{ | ||
var path = new []{ "test0", "test1" }; | ||
Environment.SetEnvironmentVariable("PATH", string.Join(RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ";" : ":", path)); | ||
Assert.True(SystemDirectories.Path.SequenceEqual(path)); | ||
} | ||
|
||
[Fact] | ||
public void Config() | ||
{ | ||
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) | ||
{ | ||
Assert.True(SystemDirectories.Config.Length == 0); | ||
} | ||
var config = new []{ "test0", "test1" }; | ||
Environment.SetEnvironmentVariable("XDG_CONFIG_DIRS", string.Join(":", config)); | ||
Assert.True(SystemDirectories.Config.SequenceEqual(config)); | ||
} | ||
|
||
[Fact] | ||
public void Data() | ||
{ | ||
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) | ||
{ | ||
Assert.True(SystemDirectories.Data.Length == 0); | ||
} | ||
var data = new []{ "test0", "test1" }; | ||
Environment.SetEnvironmentVariable("XDG_DATA_DIRS", string.Join(":", data)); | ||
Assert.True(SystemDirectories.Data.SequenceEqual(data)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace Nickvision.Aura; | ||
|
||
/// <summary> | ||
/// System directories paths | ||
/// </summary> | ||
public class SystemDirectories { | ||
private static string[]? _path; | ||
private static string[]? _config; | ||
private static string[]? _data; | ||
|
||
/// <summary> | ||
/// Array of paths from PATH variable | ||
/// </summary> | ||
public static string[] Path | ||
{ | ||
get | ||
{ | ||
_path ??= Environment.GetEnvironmentVariable("PATH")?.Split(RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ';' : ':').ToArray() ?? Array.Empty<string>(); | ||
return _path; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Array of paths from XDG_CONFIG_DIRS | ||
/// </summary> | ||
/// <remarks>Returns empty array when accessed not on Linux</remarks> | ||
public static string[] Config | ||
{ | ||
get | ||
{ | ||
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) | ||
{ | ||
return Array.Empty<string>(); | ||
} | ||
_config ??= Environment.GetEnvironmentVariable("XDG_CONFIG_DIRS")?.Split(':').ToArray() ?? Array.Empty<string>(); | ||
return _config; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Array of paths from XDG_DATA_DIRS | ||
/// </summary> | ||
/// <remarks>Returns empty array when accessed not on Linux</remarks> | ||
public static string[] Data | ||
{ | ||
get | ||
{ | ||
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) | ||
{ | ||
return Array.Empty<string>(); | ||
} | ||
_data ??= Environment.GetEnvironmentVariable("XDG_DATA_DIRS")?.Split(':').ToArray() ?? Array.Empty<string>(); | ||
return _data; | ||
} | ||
} | ||
} |