mirror of
https://github.com/hawkeye-stan/msfs-popout-panel-manager.git
synced 2024-11-22 13:50:14 +00:00
77 lines
No EOL
3.2 KiB
C#
77 lines
No EOL
3.2 KiB
C#
using MSFSPopoutPanelManager.Shared;
|
|
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
|
|
namespace MSFSPopoutPanelManager.SimConnectAgent.TouchPanel
|
|
{
|
|
public class ConfigurationReader
|
|
{
|
|
public static List<SimConnectDataDefinition> GetSimConnectDataDefinitions(string planeId)
|
|
{
|
|
try
|
|
{
|
|
string filePath;
|
|
if (Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == "Development")
|
|
filePath = Path.Combine(GetSolutionPath(), @$"ReactClient\public\config\profiles\{planeId}\SimConnectDataDefinition.json");
|
|
else
|
|
filePath = @$"ReactClient\config\profiles\{planeId}\SimConnectDataDefinition.json";
|
|
|
|
|
|
var definitions = new List<SimConnectDataDefinition>();
|
|
|
|
// Add the special TITLE string variable first. It has to be to first property in SimConnectStruct
|
|
definitions.Add(new SimConnectDataDefinition() { PropName = "Title", VariableName = "TITLE", DataType = DataType.String, DataDefinitionType = DataDefinitionType.SimConnect, DefaultValue = "" });
|
|
|
|
using (StreamReader reader = new StreamReader(Path.Combine(AppContext.BaseDirectory, filePath)))
|
|
{
|
|
var definitionGroup = JsonConvert.DeserializeObject<List<SimConnectDataDefinition>>(reader.ReadToEnd());
|
|
|
|
foreach (var def in definitionGroup)
|
|
{
|
|
if (!definitions.Exists(d => d.PropName == def.PropName))
|
|
definitions.Add(def);
|
|
else
|
|
FileLogger.WriteLog(@$"config\profiles\{planeId}\SimConnectDataDefinition.json has duplicate entry with PropName: {def.PropName}", StatusMessageType.Error);
|
|
}
|
|
}
|
|
|
|
definitions.Add(new SimConnectDataDefinition() { PropName = "CameraState", VariableName = "CAMERA STATE", DataType = DataType.Float64, DataDefinitionType = DataDefinitionType.SimConnect, SimConnectUnit = "Number", DefaultValue = String.Empty, JavaScriptFormatting = null });
|
|
|
|
return definitions;
|
|
}
|
|
catch
|
|
{
|
|
FileLogger.WriteLog("TouchPanel: SimConnectDataDefinition.json file is not found or is invalid.", StatusMessageType.Error);
|
|
return new List<SimConnectDataDefinition>();
|
|
}
|
|
}
|
|
|
|
public static string[] GetMobiFlightPresets(string fileName)
|
|
{
|
|
try
|
|
{
|
|
var filePath = Path.Combine(AppContext.BaseDirectory, $@"Resources\MobiFlightPresets\{fileName}");
|
|
|
|
if (File.Exists(filePath))
|
|
return File.ReadAllLines(filePath);
|
|
|
|
return null;
|
|
}
|
|
catch
|
|
{
|
|
FileLogger.WriteLog("TouchPanel: Unable to read MobilFlightPresets cip files.", StatusMessageType.Error);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
private static string GetSolutionPath()
|
|
{
|
|
var currentDir = Directory.GetCurrentDirectory();
|
|
var path = currentDir.Substring(0, currentDir.IndexOf("WpfApp") - 1);
|
|
|
|
return path;
|
|
}
|
|
}
|
|
} |