• Which the release of FS2020 we see an explosition of activity on the forun and of course we are very happy to see this. But having all questions about FS2020 in one forum becomes a bit messy. So therefore we would like to ask you all to use the following guidelines when posting your questions:

    • Tag FS2020 specific questions with the MSFS2020 tag.
    • Questions about making 3D assets can be posted in the 3D asset design forum. Either post them in the subforum of the modelling tool you use or in the general forum if they are general.
    • Questions about aircraft design can be posted in the Aircraft design forum
    • Questions about airport design can be posted in the FS2020 airport design forum. Once airport development tools have been updated for FS2020 you can post tool speciifc questions in the subforums of those tools as well of course.
    • Questions about terrain design can be posted in the FS2020 terrain design forum.
    • Questions about SimConnect can be posted in the SimConnect forum.

    Any other question that is not specific to an aspect of development or tool can be posted in the General chat forum.

    By following these guidelines we make sure that the forums remain easy to read for everybody and also that the right people can find your post to answer it.

Reading the Aircraft.cfg File...

n4gix

Resource contributor
Messages
11,674
Country
unitedstates
This doesn't seem like it should be that difficult, but it's not working... :(

I've used GetPrivateProfileString(); successfully to read my own .ini type files, as well as WritePrivateProfileString(); to record updated variables, so I'm quite familiar with the process.

I currently have a generic blackbox gauge that will create a custom folder if one does not exist, and create/save a custom file based on the 5th parameter in the panel.cfg entry.

If no 5th parameter exists, it will default to writing the file in the currently selected a/c folder:

char total_name[100] = "./blackbox.dat\0";

IOW, one folder UP from the \panel folder.

Okay, so much for what DOES WORK correctly, without fail, everytime!

Here's the current problem. I wish to 'read' the current values stored in the station_load.n entries of the aircraft.cfg file. This then should work:

CHAR totalpathname[MAX_PATH] = "./aircraft.cfg\0";

Alas, it does not...

...even specifying the complete path\filename doesn't work...
Code:
CHAR totalpathname[MAX_PATH] = "D:\FS9\Aircraft\Eaglesoft Liberty XL2/aircraft.cfg\0";

CHAR chStation_load0[MAX_PATH] = "";
CHAR chStation_load1[MAX_PATH] = "";
CHAR chStation_load2[MAX_PATH] = "";

CHAR chFailure[MAX_PATH] = "Failed to Find File\0";
//---------------------------

case PANEL_SERVICE_POST_INSTALL:
	GetPrivateProfileString("WEIGHT_AND_BALANCE", "station_load.0", chFailure, chStation_load0, 100, totalpathname);
	GetPrivateProfileString("WEIGHT_AND_BALANCE", "station_load.1", chFailure, chStation_load1, 100, totalpathname);
	GetPrivateProfileString("WEIGHT_AND_BALANCE", "station_load.2", chFailure, chStation_load2, 100, totalpathname);
break;

//----------------------------

FLOAT64 FSAPI callback2( PELEMENT_STRING pelement)
{
	float rwert=pelement->source_var[0].var_value.n;
	rwert = (float)station1 ; 
	sprintf(pelement->string,"%s",chStation_load0);
	return 0;
}

etc.

All I get for all this bother is the darn default failure message I've provided:

Failed to Find File

Any ideas? <humbly holding hat in hand> :confused:
 
Well, color me embarrased!

I see where my problem is now...


This...
char total_name[100] = "./blackbox.dat\0";
...will default to the sim's root folder...

So trying to use that method to locate the current aircraft.cfg will never work! :eek:

What I need is to find out what the path to the currently loaded aircraft.cfg file is! :tongue-ti

I just noticed the notes in one of my functions I use to determine the simVersion running...

// no need for a directory qualifier because all DLL's run within
// the simulator's main folder since they run as children of the main
// simulator executable.

So, this will work:

CHAR totalpathname[MAX_PATH] = "./Aircraft/Eaglesoft Liberty XL2/aircraft.cfg\0";

No need to lookup the Registry to locate the FS root folder then, but I still need to find a method to obtain the current sub-folder path...
 
Last edited:
I think you first need to read fsx.cfg and extract SimObjectPaths to find the active aircraft paths then search all aircraft.cfg's for the "TITLE" string returned by SimConnect from the Aircraft String Data.

George
 
Hi Folks

Bill -
Further to George's suggestion on reading SimObjectPaths.

Assuming you wish this 'gauge' to work on multiple aircraft.

Would be worth testing for all existing SimObjectPaths in a user's config.
i.e.
the user may have installed to a non-standard location.



Default FSX -
Code:
SimObjectPaths.0=SimObjects\Airplanes
SimObjectPaths.1=SimObjects\Rotorcraft
SimObjectPaths.2=SimObjects\GroundVehicles
SimObjectPaths.3=SimObjects\Boats
SimObjectPaths.4=SimObjects\Animals
SimObjectPaths.5=SimObjects\Misc



To keep my FSX Default installation 'clean'
my setup additionally includes -
Code:
// Pilotable Fixed-Wing Addon Store
//SimObjectPaths.6="I:\Program Files\Microsoft Games\Microsoft Flight Simulator X\SimObjects\Airplanes"

// Pilotable Rotorcraft Addon Store
//SimObjectPaths.7="I:\Program Files\Microsoft Games\Microsoft Flight Simulator X\SimObjects\Rotorcraft"

// AI Addon Store
//SimObjectPaths.8="L:\Program Files\Microsoft Games\Microsoft Flight Simulator X\SimObjects\Airplanes"

// AI Rotorcraft Addon Store
//SimObjectPaths.9="L:\Program Files\Microsoft Games\Microsoft Flight Simulator X\SimObjects\Rotorcraft"



HTH
ATB
Paul
 
Last edited:
I think you first need to read fsx.cfg and extract SimObjectPaths to find the active aircraft paths then search all aircraft.cfg's for the "TITLE" string returned by SimConnect from the Aircraft String Data.

George

Um, that is an elegant and simple suggestion were this for FSX only. This project needs to work in both FS9 and FSX for the forseeable future...

As I said previously "./" assumes the root of any version of FS currently running. What is unknown is the sub-folder path inbetween the 'fs root folder' and the 'aircraft.cfg' filename, call it 'x-path'...

A simple concantenation will paste together the complete path for me:

"./" + x-path + "\aircraft.cfg" :D
 
A simple concantenation will paste together the complete path for me:

"./" + x-path + "\aircraft.cfg" :D

Unfortunately that will not work for FSX, the current cfg may not be in the ./ tree, however, it will be in ./aircraft/ for FS9.

BUT, you still need to find the current aircraft ;)

George
 
Unfortunately that will not work for FSX, the current cfg may not be in the ./ tree, however, it will be in ./aircraft/ for FS9.

BUT, you still need to find the current aircraft ;)

George

Why would any aircraft.cfg file NOT be within the ..\FSX tree?

I did find a .c source for a method to locate the currently loaded aircraft.cfg file in my ..\Gauge Projects folder. Arne uses the retrieved XML variables as shown below as the basis for a system wide search to find the exact path. It's a bit complex, but I'll give it a whirl! ;)
Code:
	GetModuleFileName(NULL,aircraftpath,MAX_PATH);
	if((helper=strrchr(aircraftpath,'\\'))!=NULL)
		*helper='\0';


	strcat(aircraftpath,"\\aircraft\\");
	sprintf(searchpath,"%s*.*",aircraftpath);

	
	if( (file = _findfirst(searchpath, &path )) == -1L )
		return	FALSE;

	title			=	ExecAndAlloc("(A:TITLE,string)");
	atc_id			=	ExecAndAlloc("(A:ATC ID,string)");
	ui_manufacturer	        =	ExecAndAlloc("(A:ATC TYPE,string)");
	atc_airline		=	ExecAndAlloc("(A:ATC AIRLINE,string)");
	
	do
	{
		if( (path.attrib & _A_SUBDIR)  &&
		    (strcmp(path.name,".")!=0) &&
			(strcmp(path.name,"..")!=0)
		  )
// et cetera...
 
Why would any aircraft.cfg file NOT be within the ..\FSX tree?

All of my add-on aircraft are on a different drive from FSX:

SimObjectPaths.6=H:\!FSXAircraft

and my AI aircraft also:

SimObjectPaths.7=H:\!AIAircraft
SimObjectPaths.8=H:\!FTXAI_AIRCRAFT


George
 
All of my add-on aircraft are on a different drive from FSX:

SimObjectPaths.6=H:\!FSXAircraft

and my AI aircraft also:

SimObjectPaths.7=H:\!AIAircraft
SimObjectPaths.8=H:\!FTXAI_AIRCRAFT


George

Well, that certainly blows Arne's method out of the water, as it assumes all aircraft.cfg files are within the .\FS9 or .\FSX root!

So, a different method will need to be developed to accomodate the relatively few exceptions for FSX locations. Most users though at least keep their a/c within the .\FSX structure... ;)

I thought I might have found a solution with this, but...
Code:
char fullpath[_MAX_PATH];

_getcwd( fullpath, _MAX_PATH );

...unfortunately it simply returns a bit of data I already know:

fullpath = "D:\FSX" in my instance... :rolleyes:

But, even so that's a lot simpler than a Registry search! :D
 
Last edited:
Sorry to disappoint you Bill, but I keep my aircraft (user and AI) on three different drives, the only aircraft I have within the FSX main folder are the default.
 
Sorry to disappoint you Bill, but I keep my aircraft (user and AI) on three different drives, the only aircraft I have within the FSX main folder are the default.

No disappointment here, it simply means that those who opt to be "non-conformists" won't be able to use the interactive, real-time (re)configuration guage... :tapedshut
 
Here is the solution in one easy function.

This function will find the currently loaded aircraft.cfg
based on the gauge .dll's absolute path.

It will return incorrect results only if the panel loaded
has been "aliased" from another aircraft.cfg file.

Thanks to WarpD for providing the easy way out. :D

Code:
#include	"fs9gauges.h"
#include        <io.h>
#include	<stdio.h>

#define	MAX_SECTIONS	512
EXTERN_C	BOOL FindAircraft();

BOOL FindAircraft()
{
	char aircraftpath[MAX_PATH+1] = "",
	 searchpath[MAX_PATH+1]       = "",
	 cfgname[MAX_PATH+1]	      =	"",
 	 *helper   		      =	NULL;
	BOOL result		      =	FALSE;

  // dll_instance is the hInstance value of the DLL.
	GetModuleFileNameA(dll_instance,aircraftpath,MAX_PATH);
  // have the path to this gauge... delete the gauge name and the "\Panel" from it.
	if((helper=strrchr(aircraftpath,'\\'))!=NULL)
		*helper='\0';
	if((helper=strrchr(aircraftpath,'\\'))!=NULL)
		*helper='\0';
  // now, add '\aircraft.cfg' to it.
	strcat(aircraftpath,"\\aircraft.cfg");
  // it's all set for use.
  // do your .ini reads here

  //
  result = TRUE;

	return	result;
}
 
Last edited:
Back
Top