Skip to content

Commit

Permalink
DCSFP uses internal file to read info about DCS-BIOS modules. (#359)
Browse files Browse the repository at this point in the history
User can add new modules, no need to wait for release.
  • Loading branch information
jdahlblom authored Sep 15, 2023
1 parent 63d1d49 commit 0bf40c1
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 39 deletions.
2 changes: 1 addition & 1 deletion Source/ClassLibraryCommon/ClassLibraryCommon.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
<OutputType>Library</OutputType>
Expand Down
53 changes: 19 additions & 34 deletions Source/ClassLibraryCommon/DCSAircraft.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;

/// <summary>
/// Holds information about currently selected aircraft / module (DCS aircraft/helicopter).
Expand Down Expand Up @@ -105,13 +106,13 @@ private static void AddInternalModules()

public static void FillModulesListFromDcsBios(string dcsbiosJsonFolder, bool loadMetaFiles = false, bool loadInternalModules = true)
{
var biosLua = Path.Combine(dcsbiosJsonFolder, "..\\..\\", "BIOS.lua");

if (!File.Exists(biosLua))
var dcsbiosConfigFile = $"{AppDomain.CurrentDomain.BaseDirectory}dcs-bios_modules.txt";
if (!File.Exists(dcsbiosConfigFile))
{
LogErrorAndThrowException($"Failed to find {dcsbiosConfigFile}");
return;
}

lock (Lock)
{
ModulesList.Clear();
Expand All @@ -121,50 +122,34 @@ public static void FillModulesListFromDcsBios(string dcsbiosJsonFolder, bool loa
}
}

var stringArray = File.ReadAllLines(biosLua);
var stringArray = File.ReadAllLines(dcsbiosConfigFile);

var searchFilterList = new List<string>()
{
"MetadataEnd",
"MetadataStart",
"CommonData"
};
//Inject these static DCS-BIOS modules

var metaFileId = 500;
lock (Lock)
{
ModulesList.Add(new DCSAircraft(500, "MetadataEnd", "MetadataEnd.json"));
ModulesList.Add(new DCSAircraft(501, "MetadataStart", "MetadataStart.json"));
ModulesList.Add(new DCSAircraft(502, "CommonData", "CommonData.json"));
}

// dofile(lfs.writedir()..[[Scripts\DCS-BIOS\lib\A-10C.lua]]) -- ID = 5, ProperName = A-10C Thunderbolt II
// A-10C|5|A-10C Thunderbolt/II
foreach (var s in stringArray)
{
if (!s.StartsWith("--") && s.ToLower().Contains(@"dofile(lfs.writedir()..[[Scripts\DCS-BIOS\lib\".ToLower()) && s.Contains("ProperName"))
if (!s.StartsWith("--") && s.Contains('|'))
{
var parts = s.Split(new string[] { "--" }, StringSplitOptions.RemoveEmptyEntries);
var parts = s.Split(new [] { "|" }, StringSplitOptions.RemoveEmptyEntries);

// dofile(lfs.writedir()..[[Scripts\DCS-BIOS\lib\A-10C.lua]])
var json = parts[0].ToLower().Replace(@"dofile(lfs.writedir()..[[Scripts\DCS-BIOS\lib\".ToLower(), string.Empty).Replace(".lua]])", string.Empty).Trim() + ".json";

// ID = 5, ProperName = A-10C Thunderbolt II
var info = parts[1].Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);

// ID = 5
var id = int.Parse(info[0].Split(new[] { "=" }, StringSplitOptions.None)[1]);

// ProperName = A-10C Thunderbolt II
var properName = info[1].Split(new[] { "=" }, StringSplitOptions.None)[1].Trim();
var json = parts[0]+ ".json";
var id = int.Parse(parts[1]);
var properName = parts[2];

lock (Lock)
{
ModulesList.Add(new DCSAircraft(id, properName, json));
}
}
else if (loadMetaFiles && searchFilterList.Any(o => s.Contains(o)))
{
var json = s.ToLower().Replace(@"dofile(lfs.writedir()..[[Scripts\DCS-BIOS\lib\".ToLower(), string.Empty).Replace(".lua]])", string.Empty).Trim() + ".json";
var properName = json.Replace(".json", "");
lock (Lock)
{
ModulesList.Add(new DCSAircraft(metaFileId++, properName, json));
}
}
}
}

Expand Down
5 changes: 3 additions & 2 deletions Source/DCS-BIOS/DCSBIOSConstants.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
namespace DCS_BIOS
{
internal class DCSBIOSConstants
public static class DCSBIOSConstants
{
internal const int MAX_VALUE = 65535;
public const int MAX_VALUE = 65535;
public const int META_MODULE_START_RANGE = 500;
}
}
4 changes: 4 additions & 0 deletions Source/DCSFlightpanels/DCSFlightpanels.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="dcs-bios_modules.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
<Resource Include="flightpanels02_8Rc_icon.ico" />
</ItemGroup>
<ItemGroup>
Expand All @@ -110,6 +113,7 @@
</ItemGroup>
<ItemGroup>
<Compile Remove="Windows\LinkMappingWindow.xaml.cs" />
<None Remove="dcs-bios_modules.txt" />
<None Remove="Images\cdu737.png" />
<None Remove="Images\rio-cap-f14.png" />
<None Remove="PanelUserControls\PreProgrammed\Apache_1_0001.jpg" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
Expand Down Expand Up @@ -66,12 +67,12 @@ private void PopulateAirframeCombobox()
ComboBoxAirframe.Items.Clear();
foreach (var module in DCSAircraft.Modules)
{
if (!DCSAircraft.IsNoFrameLoadedYet(module)) //!DCSAircraft.IsNS430(module) &&
if (!DCSAircraft.IsNoFrameLoadedYet(module) && module.ID < DCSBIOSConstants.META_MODULE_START_RANGE) //!DCSAircraft.IsNS430(module) &&
{
itemsSource.Add(module);
}
}

itemsSource = itemsSource.OrderBy(o => o.Description).ToList();
ComboBoxAirframe.DisplayMemberPath = "Description";
ComboBoxAirframe.ItemsSource = itemsSource;
ComboBoxAirframe.SelectedIndex = 0;
Expand Down
49 changes: 49 additions & 0 deletions Source/DCSFlightpanels/dcs-bios_modules.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
-- Following text is used by DCSFlightpanels GUI to pick up DCS-BIOS modules.
-- ID range 1-3 is used internally in DCSFlightpanels. New modules must have an uniques ID.

-- Format:
-- Module(JSON Name)|ID|Pretty Name

FC3|4|Flaming Cliffs 3
A-10C|5|A-10C Thunderbolt/II
A-4E-C|6|A-4E Skyhawk
AH-6J|7|AH-6J Littlebird
AJS37|8|AJS-37 Viggen
Alphajet|9|Alphajet
AV8BNA|10|AV-8B Night Attack
Bf-109K-4|11|Bf 109 K-4 Kurfurst
C-101|12|C-101 Aviojet
MirageF1|13|Mirage F1
Christen Eagle II|14|Christen Eagle II
Edge540|15|Edge 540
F-14|16|F-14A/B Tomcat
F-16C_50|17|F-16C Viper
F-5E-3|18|F-5E Tiger II
F-86F Sabre|19|F-86F Sabre
FA-18C_hornet|20|F/A-18C Hornet
FW-190A8|21|Fw 190 A-8 Anton
FW-190D9|22|Fw 190 D-9 Dora
I-16|23|I-16
JF-17|24|JF-17 Thunder
Ka-50|25|Ka-50 Black Shark/III
L-39|26|L-39 Albatros
M-2000C|27|M-2000C
MB-339|28|MB-339A/PAN
Mi-8MT|29|Mi-8MT
Mig-15bis|30|MiG-15bis
Mig-19P|31|MiG-19P Farmer
Mig-21Bis|32|MiG-21bis
NS430|33|NS 430 GPS
P-47D|34|P-47D Thunderbolt
P-51D|35|TF/P-51D Mustang
SA342|36|SA342 Gazelle
SpitfireLFMkIX|37|Spitfire LF Mk. IX
UH-1H|38|UH-1H Huey
Yak-52|39|Yak-52
F-22A|40|F-22A Raptor
A-29B|41|A-29B Super Tucano
Mi-24P|42|Mi-24P HIND
VNAO_T-45|43|T-45 Goshawk
F-15E|44|F-15E Strike Eagle
Mosquito|45|Mosquito FB Mk. VI
AH-64D|46|AH-64D Apache

0 comments on commit 0bf40c1

Please sign in to comment.