Skip to content

Commit a0be3a8

Browse files
committed
feat: dotenv
1 parent 1a42791 commit a0be3a8

3 files changed

Lines changed: 37 additions & 0 deletions

File tree

‎Torch/Torch.csproj‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@
272272
<Compile Include="Managers\MultiplayerManagerBase.cs" />
273273
<Compile Include="Persistent.cs" />
274274
<Compile Include="Plugins\PluginManifest.cs" />
275+
<Compile Include="Utils\DotEnv.cs" />
275276
<Compile Include="Utils\ModItemUtils.cs" />
276277
<Compile Include="Utils\SteamWorkshopTools\KeyValueExtensions.cs" />
277278
<Compile Include="Utils\MiscExtensions.cs" />

‎Torch/TorchBase.cs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ public abstract class TorchBase : ViewModel, ITorchBase, IPlugin
6565
{
6666
static TorchBase()
6767
{
68+
DotEnv.Load();
69+
6870
MyVRageWindows.Init("SpaceEngineersDedicated", MySandboxGame.Log, null, false);
6971
ReflectedManager.Process(typeof(TorchBase).Assembly);
7072
ReflectedManager.Process(typeof(ITorchBase).Assembly);

‎Torch/Utils/DotEnv.cs‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using System;
2+
using System.IO;
3+
using System.Text;
4+
5+
namespace Torch.Utils
6+
{
7+
public static class DotEnv
8+
{
9+
public static void Load()
10+
{
11+
const string filePath = ".env";
12+
if (!File.Exists(filePath)) return;
13+
14+
var txt = File.ReadAllText(filePath, Encoding.Default);
15+
var newline = new[] { "\r\n", Environment.NewLine };
16+
var equal = new[] { "=" };
17+
foreach (var cmp in txt.Split(newline, StringSplitOptions.RemoveEmptyEntries))
18+
{
19+
var strArray = cmp.Split(equal, StringSplitOptions.None);
20+
switch (strArray.Length)
21+
{
22+
case 0:
23+
continue;
24+
case 1:
25+
Environment.SetEnvironmentVariable(strArray[0].Trim(), null);
26+
continue;
27+
default:
28+
Environment.SetEnvironmentVariable(strArray[0].Trim(), strArray[1].Trim());
29+
continue;
30+
}
31+
}
32+
}
33+
}
34+
}

0 commit comments

Comments
 (0)