• 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.

NSI Scripts...Activating Scenery

Messages
1,964
Country
unitedkingdom
I think someone mentioned that an NSI script can activate a scenery. Could somebody help or show some examples? I will need two folders activated with one being at a higher priority than the other. Thanks!
 
Here's the script I use. Note that I'm not a coder, so everything I write is a learning experience:) However I've used (and improved) this script over the last 6 years, without problems. At least without problems that didn't relate to stupid errors on my part...



;Here are the variables

var SceneryCfgFile ; Points to Scenery.cfg
var TempSceneryCfgFile ; Points to tempCfgfile used to rebuild Scenery.cfg
var AreaCount ; the highest Area number?
var LayerCount ; the highest layer number?
var AreaNumber ; current working area number
var LayerNumber ; Current working layer number
var cfgline ; reads a single line of Scenery.cfg
var AreaString ; the first 5 chars of cfgline, used to test whether '[Area.' or 'Layer='
;var LayerString
var Title
var Local
var AreaNumberStr ; The area number as a 4 digit string

var Folder1_Area ;
var Folder1_Layer ;
var Folder2_Area ;
var Folder1_LocalisOK ; folder1 already installed ok flag
var Folder2_LocalisOK ; folder2 already installed ok flag
var OldSceneryArea
var NonFatalErrorFlag ; Any non fatal error -- may not be required




var SIM_PRODUCT_NAME
var SIM_CONFIG_PATH
var SIM_CONFIG_FILE


;This script requires the Logic Library

!include "LogicLib.nsh"


Code:
Section "Activate Library" SEC03 ;'/o' -- unselected by default


ClearErrors
SetShellVarContext all
StrCpy $SIM_CONFIG_FILE $SIM_CONFIG_PATHscenery.cfg
; the config-related variables are defined in the simulator-chooser script previously

FileOpen $SceneryCfgFile $SIM_CONFIG_FILE "r"
${If} ${Errors}
        Messagebox MB_ICONEXCLAMATION "Could not open $SIM_CONFIG_FILE, so unable to activate the scenery. Refer to the install manual for details."
${Else}
    StrCpy $AreaCount 0
    StrCpy $Folder1_Area 0
    StrCpy $Folder1_Layer 0
    StrCpy $Folder2_Area 0
    StrCpy $Folder1_LocalisOK 0
    StrCpy $Folder2_LocalisOK 0
    StrCpy $NonFatalErrorFlag 0

    ${Do} ; this loop runs through scenery.cfg to determine highest Area and Layer numbers
             FileRead $SceneryCfgFile $cfgline
             IfErrors 0 +2
             ${ExitDo}
         StrCpy $AreaString $cfgline 6
         StrCmp $AreaString "[Area." 0 NotAnArea
         StrCpy $AreaNumber $cfgline 3 6
         ${If} $AreaNumber > $AreaCount
               StrCpy $AreaCount $AreaNumber
         ${EndIf}

             NotAnArea:
             StrCmp $AreaString "Layer=" 0 NotLayerEither
             StrCpy $LayerNumber $cfgline 3 6
             ${If} $LayerNumber > $LayerCount
                   StrCpy $LayerCount $LayerNumber
             ${EndIf}
             NotLayerEither:
    ${Loop}

; Now that I know the highest Area and Layer numbers, I can treat the file as an ini.
; This For loop reads through each Area number in order, to find the Area and Layer numbers of the scenery folders,

        ${For} $AreaNumber 1 $AreaCount
           IntFmt $AreaNumberStr "%0.3u" $AreaNumber
           ReadINIStr $Title $SIM_CONFIG_FILE "Area.$AreaNumberStr" Title
               ${if} $Title == "GodzoneNZRO"
; GodzoneNZRO is the name of the first folder I'm adding. This could better be defined once, rather that find/replace 
                     StrCpy $Folder1_Area $AreaNumber
                     ReadINIStr $Local $SIM_CONFIG_FILE "Area.$AreaNumberStr" Local
                     ${if} $Local == "Godzone\GodzoneNZRO"
                           StrCpy $Folder1_LocalisOK 1 ; 1st folder already exists, and points to correct location
                     ${EndIf}
                ${EndIf}

                ${if} $Title == "GZ9545Photo"
; this is my second folder
                  StrCpy $Folder2_Area $AreaNumber
                  ReadINIStr $Local $SIM_CONFIG_FILE "Area.$AreaNumberStr" Local
                  ${if} $Local == "Godzone\GZ9545Photo"
                    StrCpy $Folder2_LocalisOK 1
                  ${EndIf}

               ${EndIf}
        ${Next}
    Fileclose $SceneryCfgFile

;let's create a temporary Scenery.cfg file
${If} $Folder1_Area > 0
        ${AndIf} $Folder2_Area > 0
        ${AndIf} $Folder1_LocalisOK == 1
        ${AndIf} $Folder2_LocalisOk == 1
                Messagebox MB_ICONINFORMATION "This scenery already exists in the Scenery Library."
        ;${EndIf}

${Else}

        ClearErrors
    SetShellVarContext all

    FileOpen $SceneryCfgFile $SIM_CONFIG_FILE r
    FileOpen $TempSceneryCfgFile "$SIM_CONFIG_PATHtempSubcfg.txt" w
    ${If} ${Errors}
          Messagebox MB_ICONEXCLAMATION "Unable to create Scenery.cfg. Refer to the install manual for details."
       ; DetailPrint "Could not create temp file"
    ${Else}
           ${Do} ; this loop reads each line of scenery.cfg, adds any new scenery folders, 

                 FileRead $SceneryCfgFile $cfgline
                 IfErrors 0 +2 ; end of file
                     ${ExitDo}
             StrCpy $AreaString $cfgline 6
             StrCmp $AreaString "[Area." 0 NotAnArea2
             StrCpy $AreaNumber $cfgline 3 6
                     NotAnArea2:
                     StrCmp $AreaString "Layer=" 0 NotaLayer
                     StrCpy $LayerNumber $cfgline 3 6
                     ${If} $LayerNumber > $Folder1_Layer
                           StrCpy $cfgline "Layer=$LayerNumber$\r$\n"
                     ${EndIf}
                     NotaLayer:
                     StrCmp $AreaString "Local=" 0 NotaLocal

                     ${If} $AreaNumber == $Folder1_Area
                     ${AndIf} $Folder1_LocalisOK == 0 ; ...but the local doesn't point to the correct folder...
                              StrCpy $cfgline "Local=Godzone\GodzoneNZRO$\r$\n" ; then we fix it.
                     ${EndIf}
                     ${If} $AreaNumber == $Folder2_Area ; same with DTM
                     ${AndIf} $Folder2_LocalisOk == 0
                              StrCpy $cfgline "Local=Godzone\GZ9545Photo$\r$\n"
                     ${EndIf}
                     NotaLocal:
 ;this may seem a bit weird, but sometimes I put a little script here to disable a previous folder if necessary                                         

                     NotActive:
                     FileWrite $TempSceneryCfgFile $cfgline ; write the current line to the new cfg
            ${Loop}

        ${If} $Folder1_Area == 0
              IntOp $AreaNumber $AreaNumber + 1
              IntOp $LayerNumber $layerNumber + 1
          IntFmt $AreaNumberStr "%0.3u" $AreaNumber
              FileWrite $TempSceneryCfgFile "$\r$\n[Area.$AreaNumberStr]$\r$\n"
              FileWrite $TempSceneryCfgFile "Title=GodzoneNZRO$\r$\n"
              FileWrite $TempSceneryCfgFile "Local=Godzone\GodzoneNZRO$\r$\n"
              FileWrite $TempSceneryCfgFile "Layer=$LayerNumber$\r$\n"
              FileWrite $TempSceneryCfgFile "Active=TRUE$\r$\n"
              FileWrite $TempSceneryCfgFile "Required=FALSE$\r$\n$\r$\n"
        ${EndIf}
        ${If} $Folder2_Area == 0
              IntOp $AreaNumber $AreaNumber + 1
              IntOp $LayerNumber $layerNumber + 1
              IntFmt $AreaNumberStr "%0.3u" $AreaNumber
              FileWrite $TempSceneryCfgFile "[Area.$AreaNumberStr]$\r$\n"
              FileWrite $TempSceneryCfgFile "Title=GZ9545Photo$\r$\n"
              FileWrite $TempSceneryCfgFile "Local=Godzone\GZ9545Photo$\r$\n"
              FileWrite $TempSceneryCfgFile "Layer=$LayerNumber$\r$\n"
              FileWrite $TempSceneryCfgFile "Active=TRUE$\r$\n"
              FileWrite $TempSceneryCfgFile "Required=FALSE$\r$\n$\r$\n"
        ${EndIf}
${EndIf}

    FileClose $TempSceneryCfgFile
    FileClose $SceneryCfgFile
    IfFileExists "$SIM_CONFIG_PATHScenery.CFG_sub7_BAK" 0 +2
;each time this script creates a scenery.cfg, it will back up the existing file with a filename relating to the scenery. 
    Delete "$SIM_CONFIG_PATHScenery.CFG_sub7_BAK"
    Rename "$SIM_CONFIG_FILE" "$SIM_CONFIG_PATHScenery.CFG_sub7_BAK"
        Rename "$SIM_CONFIG_PATHtempSubcfg.txt" "$SIM_CONFIG_FILE"


${EndIf}
${EndIf}
ClearErrors
;Done:
SectionEnd
 
Back
Top