Hello!
What I found out by now is that the scenery.cfg file contains the scenery areas and layer order.
I'm able to write a new section and values into that file with my setup script, but how can I get the next avaiable Layer/Area number for my scenery?
Thanks for help.
Carsten
I'm not sure how Inno does things, but I can give a rough idea of what my NSIS script does.
NSIS has 'ini' editing tools, which are quite useful here, you just treat the .cfg file as a .ini file, but as you've discovered it varies a bit from a normal ini file in that the area/layer numbers need to be incremented. To do this, I use NSIS's normal file reading, which just reads a single line, then I use a script to figure out if it is a layer or area.
Once I know the highest layer and area numbers, I can then use the ini instructions to check to see if the scenery already exists, and if not add the new entry.
Here's a description of one of the ini instructions from the manual:
4.9.2.10 ReadINIStr
user_var(output) ini_filename section_name entry_name
Reads from entry_name in [section_name] of ini_filename and stores the value into user variable $x. The error flag will be set and $x will be assigned to an empty string if the entry is not found.
ReadINIStr $0 $INSTDIR\winamp.ini winamp outname
If it helps, here's the first part of my script which determines the highest area and layer numbers:
Code:
FileOpen $SceneryCfgFile "$APPDATA\Microsoft\FSX\Scenery.CFG" "r"
${If} ${Errors}
Messagebox MB_ICONEXCLAMATION "Could not open $APPDATA\Microsoft\FSX\Scenery.CFG, so unable to activate the scenery. Refer to the install manual for details."
${Else}
StrCpy $AreaCount 0
StrCpy $SceneryexistingArea 0
StrCpy $SceneryLocalisOK 0
StrCpy $AddtoAreaNumber 1
StrCpy $NonFatalErrorFlag 0
${Do} ; this loop runs through scenery.cfg to determine highest Area and Layer numbers
FileRead $SceneryCfgFile $cfgline
${If} ${Errors}
${ExitDo}
${Else}
StrCpy $AreaString $cfgline 6
StrCmp $AreaString "[Area." 0 NotAnArea
StrCpy $AreaNumber $cfgline 3 6
${If} $AreaNumber > $AreaCount
StrCpy $AreaCount $AreaNumber
${EndIf}
${EndIf}
NotAnArea:
StrCmp $AreaString "Layer=" 0 NotLayerEither
StrCpy $LayerNumber $cfgline 3 6
${If} $LayerNumber > $LayerCount
StrCpy $LayerCount $LayerNumber
${EndIf}
NotLayerEither:
${Loop}
If Inno offers similar instructions, then you should be able to make a start.
I'm not a coder, I just stumble through the manuals looking for solutions, so don't judge my skills too harshly!