Hello, you can get them in a sort of “tricky” way. I have done it in my FSAutomator application I released some minutes ago. Let me describe how I achieved it.
- Get the aircraft loaded via the SimConnect API:
Connection.OnRecvSystemState += new SimConnect.RecvSystemStateEventHandler(GetAirCraftCfgPath);
Connection.RequestSystemState(DATA_REQUESTS.REQUEST_1, "AircraftLoaded");
- On you method “GetAirCraftCfgPath”, do:
- Get all airplanes dfg files installed in the official and the community folders. These files are “aircraft.cfg”. This way you get the full path to them.
- Get the correct “aircraft.cfg” file path by matching the end of the file paths. In my case, I keep the first one and it has always worked.
- Now that you have the file path, you can get the “flight_model.cfg” and read it as an INI file.
This is my code:
public class FlightModel
{
private string flightModelPath;
public ReferenceSpeeds ReferenceSpeeds { get; set; }
public FlightModel(SimConnect Connection)
{
if (Connection != null)
{
Connection.OnRecvSystemState += new SimConnect.RecvSystemStateEventHandler(GetAirCraftCfgPath);
Connection.RequestSystemState(DATA_REQUESTS.REQUEST_1, "AircraftLoaded");
}
}
private void GetAirCraftCfgPath(SimConnect Connection, SIMCONNECT_RECV_SYSTEM_STATE data)
{
var baseFSPathOfficial = @"C:\Users\Albert\AppData\Roaming\Microsoft Flight Simulator\Packages\Official";
var baseFSPathCommunity = @"C:\Users\Albert\AppData\Roaming\Microsoft Flight Simulator\Packages\Community";
List<string> installedAircrafts = SearchFileInAllDirectories(baseFSPathOfficial, "aircraft.cfg");
installedAircrafts.AddRange(SearchFileInAllDirectories(baseFSPathCommunity, "aircraft.cfg"));
var currentAircraftCfgPath = installedAircrafts.Where(z => z.EndsWith(data.szString, StringComparison.CurrentCultureIgnoreCase)).FirstOrDefault().ToString();
if (currentAircraftCfgPath != "")
{
this.flightModelPath = Path.Combine(Path.GetDirectoryName(currentAircraftCfgPath), "flight_model.cfg");
IniFile ini = new IniFile(flightModelPath);
this.ReferenceSpeeds = new ReferenceSpeeds(ini);
}
}
private List<string> SearchFileInAllDirectories(string parentDirectory, string filename)
{
return Directory.GetFiles(parentDirectory, filename, SearchOption.AllDirectories).ToList();
}
}