Find scenery.cfg

arno

Administrator
Staff member
FSDevConf team
Resource contributor
#1
Hi all,

I'm working on a new tool that will run when FS starts, using the exe.xml file. I'm wondering what is the best way to find the scenery.cfg file in that case.

The tool can run from FSX or P3D v2, so how do I know which folder to use to find the scenery.cfg file?

The best approach I can think of now is check what exe is in the FS folder (I know that folder because that's the working folder when started by FS). But it feels a bit clumsy to do it like this. Am I missing another approach?
 

ddawson

Resource contributor
#2
I think this is just as clumsy...
Call FindWindow to get a handle to the FS Window.
Call GetWindowThreadProcessID to get the FS process ID.
Call OpenProcess to get a handle to the FS process.
Call GetModuleFileNameEx to get the path qualified name of the FS process.
 
#3
Why not have a choice for the user to select what sim they are using and have it link to the correct location. Or just have a location field that the user can enter the location of their sim.
 

arno

Administrator
Staff member
FSDevConf team
Resource contributor
#4
Hi,

The idea is that the tool automatically runs at FS startup and it should be installed as part of addons. So idealy there is no user involvement at all, that's why I prefer to not let the user select things.

Maybe I could let the installer of the tool put some command line arguments in the exe.xml file, that I can use as pointers.
 

ddawson

Resource contributor
#5
...
Maybe I could let the installer of the tool put some command line arguments in the exe.xml file, that I can use as pointers.
That is the advantage of what I suggested. You determine FS location at run time, rather than at install time, and it doesn't matter where the user has installed either FS or your add-on.
 

arno

Administrator
Staff member
FSDevConf team
Resource contributor
#6
Hi,

But the idea is that the tool runs automatically when FS starts anyway. So the exe.xml file needs to be edited by the installer to achieve that. So adding some parameter in that file should be OK.

Then it should indeed not matter anymore where FS is installed and where the tool is installed (although the tool will probably go in the FS folder soemwhere to keep things easy).
 

ollyau

Resource contributor
#7
You could establish a SimConnect connection to get the simulator version, then use that information to find the relevant scenery.cfg perhaps?
 
#8
used scenery.cfg for FSX, P3D v.1 and P3D v2/3 place in different folder, if using exe.xml you need to find the folder contain exe.xml

FSX
C:\Users\user account name\AppData\Roaming\Microsoft\FSX
P3D v2
C:\Users\user account name\AppData\Roaming\Lockheed Martin\Prepar3D v2
P3D v3
C:\ProgramData\Lockheed Martin\Prepar3D v3

is this possible if find exe.xml address from registry ?
 
#9
I doubt it's practical to look for a file. Many users will have multiple version installed. In fact I currently hold installations for all 5 relevant versions (MSFSX, FSXSE, P3D 1/2/3).

Runtime detection is the best option. From DLL you can just call the running process itself to identify itself, with .exe it's a bit more complicated.
Probably what I would do.

-Install time, put an argument in exe.xml, just fsx or p3d.

-Runtime, first, try to find a running exe according to argument. If not found, try the alternative.

-Once found, determine version, now there are basically two options.
--if you want to connect to SimConnect anyway, just connect and ask.
--if you potentially don't want to connect, get a major and a build version of the executable

Now, depending on version, you can ascertain:
-an FSX with a build version of less than 62000 is an MS FSX.
-an FSX with a build version of more than 62000 is an FSX Steam. (now you need to see if it's standalone or side-by-side)
-a P3D will have a major version fitting the marketed version. 1/2/3
 
Top