36 lines
946 B
C#
36 lines
946 B
C#
using System;
|
|
using System.IO;
|
|
|
|
namespace Mirea.Api.Endpoint.Configuration;
|
|
|
|
internal static class EnvironmentManager
|
|
{
|
|
public static void LoadEnvironment(string envFile)
|
|
{
|
|
if (!File.Exists(envFile)) return;
|
|
|
|
foreach (var line in File.ReadAllLines(envFile))
|
|
{
|
|
if (string.IsNullOrEmpty(line)) continue;
|
|
|
|
var commentIndex = line.IndexOf('#', StringComparison.Ordinal);
|
|
|
|
string arg = line;
|
|
|
|
if (commentIndex != -1)
|
|
arg = arg.Remove(commentIndex, arg.Length - commentIndex);
|
|
|
|
var parts = arg.Split(
|
|
'=',
|
|
StringSplitOptions.RemoveEmptyEntries);
|
|
|
|
if (parts.Length > 2)
|
|
parts = [parts[0], string.Join("=", parts[1..])];
|
|
|
|
if (parts.Length != 2)
|
|
continue;
|
|
|
|
Environment.SetEnvironmentVariable(parts[0].Trim(), parts[1].Trim());
|
|
}
|
|
}
|
|
} |