Select 按变量划分
Select section by variable
!include "MUI2.nsh"
!include "FileFunc.nsh"
!include "LogicLib.nsh"
;---------------------------------------------------------------------------
;---------------------------------------------------------------------------
ShowInstDetails show
RequestExecutionLevel admin
;---------------------------------------------------------------------------
Name "Test"
Outfile "Test.exe"
;---------------------------------------------------------------------------
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
;---------------------------------------------------------------------------
!insertmacro MUI_LANGUAGE "English"
;---------------------------------------------------------------------------
LangString DESC_sec1 ${LANG_ENGLISH} "sec1 files"
Section /o "sec1" sec1
SectionEnd
LangString DESC_sec2 ${LANG_ENGLISH} "sec2 files"
Section /o "sec2" sec2
SectionEnd
LangString DESC_sec3 ${LANG_ENGLISH} "sec3 files"
Section /o "sec3" sec3
SectionEnd
Var test
Function .OnInit
StrCpy $test "sec2"
!insertmacro SelectSection $test
FunctionEnd
如何 select 在运行时按节名称节?
在示例中总是 select 编辑第一部分(认为这是一个错误)
但是如果我这样重写
!insertmacro SelectSection ${sec2}
一切正常...
有没有办法从变量中按名称 select 部分?
一些长文一些长文一些长文一些长文
一些长文本一些长文本一些长文本一些长文本
节通过其 ID 访问,该 ID 是在编译时设置的数字:
Section "Foo"
SectionEnd
Section "Bar" SID_BAR
SectionEnd
Section "Baz"
SectionEnd
Page Components
Page InstFiles
!include Sections.nsh
Function .onInit
!insertmacro UnselectSection ${SID_BAR}
FunctionEnd
如果您想使用显示名称,则必须手动枚举这些部分:
Section "Foo"
SectionEnd
Section "Bar"
SectionEnd
Section "Baz"
SectionEnd
Page Components
Page InstFiles
!macro GetSectionIdFromName name outvar
Push "${name}"
Call GetSectionIdFromName
Pop ${outvar} ; ID of section, "" if not found
!macroend
Function GetSectionIdFromName
Exch ; Name
Push
Push
StrCpy -1
ClearErrors
loop:
IntOp + 1
SectionGetText
IfErrors fail
StrCmp "" loop
StrCpy
Goto done
fail:
StrCpy ""
done:
Pop
Pop
Exch
FunctionEnd
!include Sections.nsh
!include LogicLib.nsh
Function .onInit
StrCpy "Bar" ; The name we are looking for
!insertmacro GetSectionIdFromName [=11=]
${If} [=11=] != ""
!insertmacro UnselectSection [=11=]
${EndIf}
FunctionEnd
!include "MUI2.nsh"
!include "FileFunc.nsh"
!include "LogicLib.nsh"
;---------------------------------------------------------------------------
;---------------------------------------------------------------------------
ShowInstDetails show
RequestExecutionLevel admin
;---------------------------------------------------------------------------
Name "Test"
Outfile "Test.exe"
;---------------------------------------------------------------------------
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
;---------------------------------------------------------------------------
!insertmacro MUI_LANGUAGE "English"
;---------------------------------------------------------------------------
LangString DESC_sec1 ${LANG_ENGLISH} "sec1 files"
Section /o "sec1" sec1
SectionEnd
LangString DESC_sec2 ${LANG_ENGLISH} "sec2 files"
Section /o "sec2" sec2
SectionEnd
LangString DESC_sec3 ${LANG_ENGLISH} "sec3 files"
Section /o "sec3" sec3
SectionEnd
Var test
Function .OnInit
StrCpy $test "sec2"
!insertmacro SelectSection $test
FunctionEnd
如何 select 在运行时按节名称节? 在示例中总是 select 编辑第一部分(认为这是一个错误)
但是如果我这样重写
!insertmacro SelectSection ${sec2}
一切正常...
有没有办法从变量中按名称 select 部分?
一些长文一些长文一些长文一些长文 一些长文本一些长文本一些长文本一些长文本
节通过其 ID 访问,该 ID 是在编译时设置的数字:
Section "Foo"
SectionEnd
Section "Bar" SID_BAR
SectionEnd
Section "Baz"
SectionEnd
Page Components
Page InstFiles
!include Sections.nsh
Function .onInit
!insertmacro UnselectSection ${SID_BAR}
FunctionEnd
如果您想使用显示名称,则必须手动枚举这些部分:
Section "Foo"
SectionEnd
Section "Bar"
SectionEnd
Section "Baz"
SectionEnd
Page Components
Page InstFiles
!macro GetSectionIdFromName name outvar
Push "${name}"
Call GetSectionIdFromName
Pop ${outvar} ; ID of section, "" if not found
!macroend
Function GetSectionIdFromName
Exch ; Name
Push
Push
StrCpy -1
ClearErrors
loop:
IntOp + 1
SectionGetText
IfErrors fail
StrCmp "" loop
StrCpy
Goto done
fail:
StrCpy ""
done:
Pop
Pop
Exch
FunctionEnd
!include Sections.nsh
!include LogicLib.nsh
Function .onInit
StrCpy "Bar" ; The name we are looking for
!insertmacro GetSectionIdFromName [=11=]
${If} [=11=] != ""
!insertmacro UnselectSection [=11=]
${EndIf}
FunctionEnd