2010-05-05 61 views
2

我一直在使用INI文件添加的自定义页面NSIS安装,这里是一个代码NSIS:访问自定义页面组合框的值?

. 
. 
. 

    ; Welcome page 
    !insertmacro MUI_PAGE_WELCOME 
    Page custom customPage "" ": custom page" 
. 
. 
. 
Function customPage 
    GetTempFileName $R0 
    File /oname=$R0 customPage.ini 
    InstallOptions::dialog $R0 
    Pop $R1 
    StrCmp $R1 "cancel" done 
    StrCmp $R1 "back" done 
    StrCmp $R1 "success" done 
    error: MessageBox MB_OK|MB_ICONSTOP "InstallOptions error:$\r$\n$R1" 
    done: 
FunctionEnd 
. 
. 
. 

下面是一个customPage.ini文件

; Ini file generated by the HM NIS Edit IO designer. 
[Settings] 
NumFields=2 

[Field 1] 
Type=Label 
Text=Select Version: 
Left=4 
Right=53 
Top=16 
Bottom=26 

[Field 2] 
Type=Combobox 
Text=Combobox 
ListItems= 
Left=53 
Right=138 
Top=14 
Bottom=107 

我想设置组合框的值使用动态脚本NSIS ,如何在nsis中访问组合框?

回答

2

我没有代码,方便,但基本上你要做的就是写INI值到ini文件,您只提取后,但在运行之前InstallOptions:dialog

!insertmacro INSTALLOPTIONS_WRITE "customPage.ini" "Field 2" "State" "Blah|Value2|Foo|Bar" 

参见:http://nsis.sourceforge.net/Docs/InstallOptions/Readme.html

请注意,在您的代码中,您没有像在链接网页中看到的那样使用InstallOptions宏。相反,你正在手动做所有事情。通常情况下,InstallOptions宏将自定义页面的ini文件解压缩到plugins目录。这意味着我的代码段可能不起作用,因为你没有遵循通常的模式。所以相反,如果上述不起作用,请尝试使用WriteINI。但是概念是相同的,只需在提取之后将值写入ini文件,但在显示之前。

+1

就像Aaron说的,使用GetTempFileName很愚蠢,$ pluginsdir是最好的放置它的地方,因为它会自动删除你 – Anders 2010-05-05 19:41:01

+0

这是太棒了!但有一点意见,要改变ListItems中的选项,你需要在你的代码片段中将“State”改为“ListItems” – 2015-11-13 13:03:39