2010-05-05 64 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