-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8847cfd
commit 975deed
Showing
3 changed files
with
48 additions
and
1 deletion.
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
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,46 @@ | ||
using OneWare.Essentials.Helpers; | ||
using OneWare.Essentials.Services; | ||
|
||
namespace OneWare.Core.Services; | ||
|
||
public class EnvironmentService : IEnvironmentService | ||
{ | ||
private static readonly string InitialPath = Environment.GetEnvironmentVariable("PATH")!; | ||
private readonly Dictionary<string, string> _paths = new(); | ||
|
||
public void SetEnvironmentVariable(string key, string? value) | ||
{ | ||
Environment.SetEnvironmentVariable(key, value); | ||
} | ||
|
||
public void SetPath(string key, string? path) | ||
{ | ||
if (path != null) | ||
_paths[key] = path; | ||
else _paths.Remove(key); | ||
UpdateEnvironment(); | ||
} | ||
|
||
public void RemovePath(string key) | ||
{ | ||
_paths.Remove(key); | ||
UpdateEnvironment(); | ||
} | ||
|
||
private void UpdateEnvironment() | ||
{ | ||
//var currentPath = Environment.GetEnvironmentVariable("PATH"); | ||
|
||
var pathSeparator = PlatformHelper.Platform switch | ||
{ | ||
PlatformId.WinArm64 or PlatformId.WinX64 => ';', | ||
_ => ':' | ||
}; | ||
|
||
var paths = string.Join(pathSeparator, _paths); | ||
|
||
Console.WriteLine(InitialPath); | ||
|
||
Environment.SetEnvironmentVariable("PATH", $"{paths}{pathSeparator}{InitialPath}"); | ||
} | ||
} |
Submodule OneWare.Essentials
updated
2 files
+1 −1 | src/OneWare.Essentials/OneWare.Essentials.csproj | |
+8 −0 | src/OneWare.Essentials/Services/IEnvironmentService.cs |