+Function LeaveInstallPage
+ Push "$INSTDIR\install.log"
+ Call DumpLog
+FunctionEnd
+
+Function EnterWriteTemplates
+ Push $R0
+ Push $R1
+
+ Call GetSelectedComponents
+ Pop $R0
+
+ IntOp $R0 $R0 & ${ComponentDirector}
+ IntOp $R1 $NewComponents & ${ComponentsFileAndStorage}
+
+ ${If} $R0 <> 0
+ ${OrIf} $R1 = 0
+ Pop $R1
+ Pop $R0
+ Abort
+ ${EndIf}
+
+ IntOp $R0 $NewComponents & ${ComponentFile}
+ ${If} $R0 = 0
+ WriteINIStr "$PLUGINSDIR\WriteTemplates.ini" "Field 2" State 0
+ WriteINIStr "$PLUGINSDIR\WriteTemplates.ini" "Field 2" Flags DISABLED
+ DeleteINIStr "$PLUGINSDIR\WriteTemplates.ini" "Field 3" State
+ WriteINIStr "$PLUGINSDIR\WriteTemplates.ini" "Field 3" Flags REQ_SAVE|FILE_EXPLORER|WARN_IF_EXIST|DISABLED
+ ${Else}
+ WriteINIStr "$PLUGINSDIR\WriteTemplates.ini" "Field 2" State 1
+ DeleteINIStr "$PLUGINSDIR\WriteTemplates.ini" "Field 2" Flags
+ WriteINIStr "$PLUGINSDIR\WriteTemplates.ini" "Field 3" State "C:\$ConfigClientName.conf"
+ WriteINIStr "$PLUGINSDIR\WriteTemplates.ini" "Field 5" Flags REQ_SAVE|FILE_EXPLORER|WARN_IF_EXIST
+ ${EndIf}
+
+ IntOp $R0 $NewComponents & ${ComponentStorage}
+ ${If} $R0 = 0
+ WriteINIStr "$PLUGINSDIR\WriteTemplates.ini" "Field 4" State 0
+ WriteINIStr "$PLUGINSDIR\WriteTemplates.ini" "Field 4" Flags DISABLED
+ DeleteINIStr "$PLUGINSDIR\WriteTemplates.ini" "Field 5" State
+ WriteINIStr "$PLUGINSDIR\WriteTemplates.ini" "Field 5" Flags REQ_SAVE|FILE_EXPLORER|WARN_IF_EXIST|DISABLED
+ ${Else}
+ WriteINIStr "$PLUGINSDIR\WriteTemplates.ini" "Field 4" State 1
+ DeleteINIStr "$PLUGINSDIR\WriteTemplates.ini" "Field 4" Flags
+ WriteINIStr "$PLUGINSDIR\WriteTemplates.ini" "Field 5" State "C:\$ConfigStorageName.conf"
+ WriteINIStr "$PLUGINSDIR\WriteTemplates.ini" "Field 5" Flags REQ_SAVE|FILE_EXPLORER|WARN_IF_EXIST
+ ${EndIf}
+
+ !InsertMacro MUI_HEADER_TEXT "$(TITLE_WriteTemplates)" "$(SUBTITLE_WriteTemplates)"
+ !InsertMacro MUI_INSTALLOPTIONS_DISPLAY "WriteTemplates.ini"
+
+ !InsertMacro MUI_INSTALLOPTIONS_READ $R0 "WriteTemplates.ini" "Field 2" State
+ ${If} $R0 <> 0
+ File "/oname=$PLUGINSDIR\client.conf.in" "client.conf.in"
+
+ nsExec::ExecToLog '$PLUGINSDIR\sed.exe -f "$PLUGINSDIR\config.sed" -i.bak "$PLUGINSDIR\client.conf.in"'
+ !InsertMacro MUI_INSTALLOPTIONS_READ $R0 "WriteTemplates.ini" "Field 3" State
+ ${If} $R0 != ""
+ CopyFiles "$PLUGINSDIR\client.conf.in" "$R0"
+ ${EndIf}
+ ${EndIf}
+
+ !InsertMacro MUI_INSTALLOPTIONS_READ $R0 "WriteTemplates.ini" "Field 4" State
+ ${If} $R0 <> 0
+ File "/oname=$PLUGINSDIR\storage.conf.in" "storage.conf.in"
+
+ nsExec::ExecToLog '$PLUGINSDIR\sed.exe -f "$PLUGINSDIR\config.sed" -i.bak "$PLUGINSDIR\storage.conf.in"'
+ !InsertMacro MUI_INSTALLOPTIONS_READ $R0 "WriteTemplates.ini" "Field 5" State
+ ${If} $R0 != ""
+ CopyFiles "$PLUGINSDIR\storage.conf.in" "$R0"
+ ${EndIf}
+ ${EndIf}
+
+ Pop $R1
+ Pop $R0
+FunctionEnd
+
+Function SelectPreviousComponents
+ ${If} $InstallType <> ${NewInstall}
+ IntOp $R1 $PreviousComponents & ${ComponentFile}
+ ${If} $R1 <> 0
+ !InsertMacro SelectSection ${SecFileDaemon}
+ !InsertMacro SetSectionFlag ${SecFileDaemon} ${SF_RO}
+ ${Else}
+ !InsertMacro UnselectSection ${SecFileDaemon}
+ !InsertMacro ClearSectionFlag ${SecFileDaemon} ${SF_RO}
+ ${EndIf}
+ IntOp $R1 $PreviousComponents & ${ComponentStorage}
+ ${If} $R1 <> 0
+ !InsertMacro SelectSection ${SecStorageDaemon}
+ !InsertMacro SetSectionFlag ${SecStorageDaemon} ${SF_RO}
+ ${Else}
+ !InsertMacro UnselectSection ${SecStorageDaemon}
+ !InsertMacro ClearSectionFlag ${SecStorageDaemon} ${SF_RO}
+ ${EndIf}
+ IntOp $R1 $PreviousComponents & ${ComponentDirector}
+ ${If} $R1 <> 0
+ !InsertMacro SelectSection ${SecDirectorDaemon}
+ !InsertMacro SetSectionFlag ${SecDirectorDaemon} ${SF_RO}
+ ${Else}
+ !InsertMacro UnselectSection ${SecDirectorDaemon}
+ !InsertMacro ClearSectionFlag ${SecDirectorDaemon} ${SF_RO}
+ ${EndIf}
+ IntOp $R1 $PreviousComponents & ${ComponentTextConsole}
+ ${If} $R1 <> 0
+ !InsertMacro SelectSection ${SecConsole}
+ !InsertMacro SetSectionFlag ${SecConsole} ${SF_RO}
+ ${Else}
+ !InsertMacro UnselectSection ${SecConsole}
+ !InsertMacro ClearSectionFlag ${SecConsole} ${SF_RO}
+ ${EndIf}
+ IntOp $R1 $PreviousComponents & ${ComponentGUIConsole}
+ ${If} $R1 <> 0
+ !InsertMacro SelectSection ${SecWxConsole}
+ !InsertMacro SetSectionFlag ${SecWxConsole} ${SF_RO}
+ ${Else}
+ !InsertMacro UnselectSection ${SecWxConsole}
+ !InsertMacro ClearSectionFlag ${SecWxConsole} ${SF_RO}
+ ${EndIf}
+ IntOp $R1 $PreviousComponents & ${ComponentPDFDocs}
+ ${If} $R1 <> 0
+ !InsertMacro SelectSection ${SecDocPdf}
+ !InsertMacro SetSectionFlag ${SecDocPdf} ${SF_RO}
+ ${Else}
+ !InsertMacro UnselectSection ${SecDocPdf}
+ !InsertMacro ClearSectionFlag ${SecDocPdf} ${SF_RO}
+ ${EndIf}
+ IntOp $R1 $PreviousComponents & ${ComponentHTMLDocs}
+ ${If} $R1 <> 0
+ !InsertMacro SelectSection ${SecDocHtml}
+ !InsertMacro SetSectionFlag ${SecDocHtml} ${SF_RO}
+ ${Else}
+ !InsertMacro UnselectSection ${SecDocHtml}
+ !InsertMacro ClearSectionFlag ${SecDocHtml} ${SF_RO}
+ ${EndIf}
+ ${EndIf}
+FunctionEnd
+