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