Jump to content
Sign in to follow this  
WarpD

Reading Aircraft.cfg File

Recommended Posts

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.dat0";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.cfg0";Alas, it does not......even specifying the complete pathfilename doesn't work...--------------------------CHAR totalpathname[MAX_PATH] = "D:FS9AircraftEaglesoft Liberty XL2/aircraft.cfg0";CHAR chStation_load0[MAX_PATH] = "";CHAR chStation_load1[MAX_PATH] = "";CHAR chStation_load2[MAX_PATH] = "";CHAR chFailure[MAX_PATH] = "Failed to Find File0";---------------------------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 FileAny ideas?


Fr. Bill    

AOPA Member: 07141481 AARP Member: 3209010556


     Avsim Board of Directors | Avsim Forums Moderator

Share this post


Link to post
Share on other sites

Hi Bill,Did you try?:CHAR totalpathname[MAX_PATH] ="D:FS9AircraftEaglesoft Liberty XL2aircraft.cfg";I always use in path names, but for std file io, haven't tested GetPrivateProfileName yet...Tom

Share this post


Link to post
Share on other sites

Well! That specific pathfilename works splendidly, and allowed the GetPrivateProfile(); to populate the CHAR vars immediately.Now, I just need to figure out why this won't work:CHAR totalpathname[MAX_PATH] = "..aircraft.cfg0";Since I have no way of knowing where anyone's installed FS9 or FSX, I need to code a more 'generalized' method...


Fr. Bill    

AOPA Member: 07141481 AARP Member: 3209010556


     Avsim Board of Directors | Avsim Forums Moderator

Share this post


Link to post
Share on other sites

I'm not on my PC that has FS on it so can't check, but I suggwst you may have to read the registry to find out where FS is installed and then build the string.

Share this post


Link to post
Share on other sites

I understand the default path is that in where the calling gauge /dll is located. Then for example, if it is located in Panel, you should do "../aircraft.cfg", if in the same directory, "aircraft.cfg" directly; and for example in a subdirectory, just "./subdirectory/file"The idea is "etc" for direct path reference, "../etc/" for up indirection and "./etc/" for down indirectionTomEDIT: etc for down indirection and "./etc/" for up indirection I guess :-)

Share this post


Link to post
Share on other sites

I may well end up having to do that... but nothing explains why this "short path" bit does work in my existing blackbox.gau file:If no 5th parameter exists, it will default to writing thefile in the sim's root folder: char total_name[100] = "./blackbox.dat0";IOW, one folder UP from the panel folder.Okay, so much for what DOES WORK correctly, without fail,everytime!EDIT: Oh... I see where my problem is now... No, what I need is to find out what the path to the currently loaded aircraft.cfg file is! I just noticed the notes in one of my functions I used 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 also will work:CHAR totalpathname[MAX_PATH] = "./Aircraft/Eaglesoft Liberty XL2/aircraft.cfg0";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...


Fr. Bill    

AOPA Member: 07141481 AARP Member: 3209010556


     Avsim Board of Directors | Avsim Forums Moderator

Share this post


Link to post
Share on other sites

Bill, I got tons of lines of VB/InstallShield code :) that reliably looks up the registry where FS is installed - I use it for Installation/Registration ops. Let me know if you need a snippet.


P3D SpacePort Team

Share this post


Link to post
Share on other sites

Thanks, Misho.Just using the characters "." will put my "path" in the root folder of any FS version. What I need to find is the part of the path underlined in bold below... ;)CHAR fs9_totalpathname = "./Aircraft/Eaglesoft Liberty XL2/aircraft.cfg0";CHAR fsx_totalpathname = "./SimObjects/Airplanes/Eaglesoft Liberty XL2/aircraft.cfg0";Obviously, I'd like to find a method that's agnostic and generic so I can use the same gauge with any aircraft and not have to bother with either a 5th parameter entry or an external .ini file just to find the aircraft.cfg file! :-lol


Fr. Bill    

AOPA Member: 07141481 AARP Member: 3209010556


     Avsim Board of Directors | Avsim Forums Moderator

Share this post


Link to post
Share on other sites

>I'm not on my PC that has FS on it so can't check, but I>suggwst you may have to read the registry to find out where FS>is installed and then build the string.Well, there's an easier method to find out where FS9 or FSX is installed without checking the registry:char fullpath[_MAX_PATH];case PANEL_SERVICE_POST_INSTALL:_getcwd( fullpath, _MAX_PATH );break;Which will return "D:FSX" or "D:FS9" in my specific case...Which is, of course nothing I didn't already know from simply using "." to begin with! :)Worse yet, I've just realized that there are some severe non-conformists who actually have their non-default FSX aircraft on a completely separate hard drive, and thus not within the scope of a simple search of the FSX root folder...


Fr. Bill    

AOPA Member: 07141481 AARP Member: 3209010556


     Avsim Board of Directors | Avsim Forums Moderator

Share this post


Link to post
Share on other sites

Do we know if FS9/FSX actually store the fule names you are looking for or, having foulnd them simply use a handle to access them?I believe the aircraft's Title from aircraft.cfg is available as a Key Parameter in FS9. An inelegant solution would to use the file search functions (FindFfirstFile & FfileNextFile) to find the FS aircraft directory initially and then to scan all the aircraft.cfg files looking for the line "title=..." and finally use the full path to that file.

Share this post


Link to post
Share on other sites

-SNIP->Worse yet, I've just realized that there are some severe>non-conformists who actually have their non-default FSX>aircraft on a completely separate hard drive, and thus not>within the scope of a simple search of the FSX root folder...>Well, I've been called a lot of things in my day but this is thefirst time I've been labeled "a severe non-conformist"... :)Not only do I keep addon aircraft in folders such as "Aircraft",for my FS9 imports to FSX, but also "Propliners" and on a differentdrive, "Military Aircraft", "Military AI Aircraft", "AI Aircraft","Razbam" and "Alphasim"....My addon scenery and traffic folders are similarly spread over2 hard drives and 4 different logical drives.What's more, where I install new addons is usually my "FSX Temp"directory before copying the folder(s) to thier final resting place, thus making any registry entries invalid.Just my way of keeping developers on their toes :) Paul


Wide-5.jpg

Share this post


Link to post
Share on other sites

>Do we know if FS9/FSX actually store the fule names you are>looking for or, having foulnd them simply use a handle to>access them?>>I believe the aircraft's Title from aircraft.cfg is available>as a Key Parameter in FS9. An inelegant solution would to use>the file search functions (FindFfirstFile & FfileNextFile) to>find the FS aircraft directory initially and then to scan all>the aircraft.cfg files looking for the line "title=..." and>finally use the full path to that file. Yes, that is the technique that Arne Bartels used when he published his source code a few years ago. Unfortunately, I've not been able to get it to work for me, as his FindAircraft(); function never gives a TRUE return to result, so of course 'cfgname' and 'section' returns are likewise NULL... :( BOOL result=FALSE; switch(service_id) { case PANEL_SERVICE_CONNECT_TO_WINDOW: result=FindAircraft(cfgname,MAX_PATH,section,MAX_PATH); break; } According to his "Usage Notes," this is what should occur:"If FindAircraft finds the aircraft.cfg, it returns TRUE and"cfgname" contains the full pathname,"section" the section associated with the current aircraft("fltsim.x"). There is NO check if there more than one aircraft matching to this parameter combination. It might also take some time, if there are really a lot of aircraft installed."I've attached his original source here in case anyone wants to look at it and see if they can get it to work... ;)


Fr. Bill    

AOPA Member: 07141481 AARP Member: 3209010556


     Avsim Board of Directors | Avsim Forums Moderator

Share this post


Link to post
Share on other sites

>Well, I've been called a lot of things in my day but this is>the first time I've been labeled "a severe non-conformist"... :)LOL! Well, that just sounded a lot nicer than "wierd" or "strange..." ;)Actually, I have a solution in hand already to take such non-conformist paths into account: simply look in the user's current fsx.cfg file and parse the paths listed... ;)...but, that's useless unless I can solve the more specific problem first, which is locating the currently active aircraft.cfg file!


Fr. Bill    

AOPA Member: 07141481 AARP Member: 3209010556


     Avsim Board of Directors | Avsim Forums Moderator

Share this post


Link to post
Share on other sites

In the "FindAircraft" function... find this line:while( _findnext( file, &path ) == 0 );and replace it with this line:while( _findnext( file, &path ) == 0 && !result);However, I will warn you. This function assumes the aircraft's folder is in the default "Aircraft" folder as it's written. Thus it's not very reliable based on how users who think they should be able to store anything on another planet may install. ;)


Ed Wilson

Mindstar Aviation
My Playland - I69

Share this post


Link to post
Share on other sites

Thanks. To be fair to Arne though he wrote this function for use in FS9......long before ACES decided to let folks put their add-ons anywhere, including USB Thumbnail drives if they like! LOL!


Fr. Bill    

AOPA Member: 07141481 AARP Member: 3209010556


     Avsim Board of Directors | Avsim Forums Moderator

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Tom Allensworth,
    Founder of AVSIM Online


  • Flight Simulation's Premier Resource!

    AVSIM is a free service to the flight simulation community. AVSIM is staffed completely by volunteers and all funds donated to AVSIM go directly back to supporting the community. Your donation here helps to pay our bandwidth costs, emergency funding, and other general costs that crop up from time to time. Thank you for your support!

    Click here for more information and to see all donations year to date.
×
×
  • Create New...