Skip to content

Commit

Permalink
Added config file
Browse files Browse the repository at this point in the history
  • Loading branch information
Somfic committed Dec 30, 2022
1 parent 0983752 commit 4121b1e
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 23 deletions.
45 changes: 32 additions & 13 deletions EliteVA.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,33 +25,53 @@ public Plugin(IEliteDangerousApi api)
_api = api;
}

async Task WriteMapping(string name)
{

}

public async Task Initialize()
{
if(!File.Exists(Path.Combine(Dir, "config.yml")))
{
using var stream = Assembly.GetExecutingAssembly()
.GetManifestResourceStream($"EliteVA.config.yml");
using var reader = new StreamReader(stream);
var content = reader.ReadToEnd();

File.WriteAllText(Path.Combine(Dir, "config.yml"), content);
}

var config = File.ReadAllText(Path.Combine(Dir, "config.yml"))
.Split('\n')
.Where(x => x.Contains(":") && !x.Trim().StartsWith("#"))
.Select(x => x.Split(':'))
.ToDictionary(x => x[0].Trim(), x => x[1].Contains("#") ? x[1].Substring(x[1].IndexOf('#')).Trim() : x[1].Trim());

if (config.ContainsKey("journalsPath"))
_api.Config.JournalsPath = config["journalsPath"];

if (config.ContainsKey("optionsPath"))
_api.Config.OptionsPath = config["optionsPath"];

if (config.ContainsKey("journalPattern"))
_api.Config.JournalPattern = config["journalPattern"];

_api.Config.Apply();

_api.Bindings.OnBindings(bindings =>
{
try
{
if (!File.Exists(Path.Combine(Dir, "layout.yml")))
{
using var stream = Assembly.GetExecutingAssembly()
.GetManifestResourceStream($"EliteVA.Mappings.default.yml");
.GetManifestResourceStream($"EliteVA.layout.yml");
using var reader = new StreamReader(stream);
var content = reader.ReadToEnd();
// Write the resource to disk
File.WriteAllText(Path.Combine(Dir, "layout.yml"), content);
}
var layout = File.ReadAllText(Path.Combine(Dir, "layout.yml"));
// Parse the layout: key: value
var parsed = layout.Split('\n')
.Where(x => x.Contains(":"))
var layout = File.ReadAllText(Path.Combine(Dir, "layout.yml"))
.Split('\n')
.Where(x => x.Contains(":") && !x.Trim().StartsWith("#"))
.Select(x => x.Split(':'))
.ToDictionary(x => x[0].Trim(), x => x[1].Contains("#") ? x[1].Substring(x[1].IndexOf('#')).Trim() : x[1].Trim());
Expand All @@ -70,7 +90,7 @@ public async Task Initialize()
continue;
key = key.Replace("Key_", "");
var keycode = parsed.FirstOrDefault(x => x.Key == key).Value ?? "NOT_SET";
var keycode = layout.FirstOrDefault(x => x.Key == key).Value ?? "NOT_SET";
if (keycode == "NOT_SET")
{
Expand Down Expand Up @@ -137,7 +157,6 @@ public async Task Initialize()
});

await _api.StartAsync();
Proxy.Log.Write("EliteVA is running", VoiceAttackColor.Green);
}
}

Expand Down
15 changes: 8 additions & 7 deletions EliteVA.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@
<HintPath>packages\Costura.Fody.5.7.0\lib\netstandard1.0\Costura.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="EliteAPI, Version=3.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\EliteAPI.3.0.0\lib\netstandard2.0\EliteAPI.dll</HintPath>
<Reference Include="EliteAPI, Version=3.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\EliteAPI.3.1.0-alpha0001\lib\netstandard2.0\EliteAPI.dll</HintPath>
</Reference>
<Reference Include="EliteAPI.Abstractions, Version=3.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\EliteAPI.Abstractions.3.0.0\lib\netstandard2.0\EliteAPI.Abstractions.dll</HintPath>
<Reference Include="EliteAPI.Abstractions, Version=3.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\EliteAPI.Abstractions.3.1.0-alpha0001\lib\netstandard2.0\EliteAPI.Abstractions.dll</HintPath>
</Reference>
<Reference Include="EliteAPI.Events, Version=3.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\EliteAPI.Events.3.0.0\lib\netstandard2.0\EliteAPI.Events.dll</HintPath>
<Reference Include="EliteAPI.Events, Version=3.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\EliteAPI.Events.3.1.0-alpha0001\lib\netstandard2.0\EliteAPI.Events.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Bcl.AsyncInterfaces, Version=7.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>packages\Microsoft.Bcl.AsyncInterfaces.7.0.0\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
Expand Down Expand Up @@ -287,7 +287,8 @@
</Reference>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Mappings\default.yml" />
<EmbeddedResource Include="layout.yml" />
<EmbeddedResource Include="config.yml" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
Expand Down
12 changes: 12 additions & 0 deletions config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
## EliteVA configuration
##
## Remove the # from a line to configure the plugin

# Path of the Journals directory
# journalsPath: "C:\Users\%USERNAME%\Saved Games\Frontier Developments\Elite Dangerous"

# Path of the Options directory
# optionsPath: "C:\Users\%USERNAME%\AppData\Local\Frontier Developments\Elite Dangerous"

# Pattern to filter Journal files
# journalPattern: "Journal.*.log"
File renamed without changes.
6 changes: 3 additions & 3 deletions packages.config
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Costura.Fody" version="5.7.0" targetFramework="net48" developmentDependency="true" />
<package id="EliteAPI" version="3.0.0" targetFramework="net472" />
<package id="EliteAPI.Abstractions" version="3.0.0" targetFramework="net472" />
<package id="EliteAPI.Events" version="3.0.0" targetFramework="net472" />
<package id="EliteAPI" version="3.1.0-alpha0001" targetFramework="net472" />
<package id="EliteAPI.Abstractions" version="3.1.0-alpha0001" targetFramework="net472" />
<package id="EliteAPI.Events" version="3.1.0-alpha0001" targetFramework="net472" />
<package id="Fody" version="6.6.4" targetFramework="net472" developmentDependency="true" />
<package id="Microsoft.Bcl.AsyncInterfaces" version="7.0.0" targetFramework="net472" />
<package id="Microsoft.CSharp" version="4.7.0" targetFramework="net472" />
Expand Down

0 comments on commit 4121b1e

Please sign in to comment.