출처: http://blog.naver.com/ysh0425a?Redirect=Log&logNo=14886206
Nullsoft SuperPiMP Install System (NSIS) 통합시디만들기
2005/07/11 07:47 http://blog.naver.com/ysh0425a/14886206 |
|
출처: http://blog.naver.com/ysh0425a?Redirect=Log&logNo=14886206
Nullsoft SuperPiMP Install System (NSIS) 통합시디만들기
2005/07/11 07:47 http://blog.naver.com/ysh0425a/14886206 |
|
헬마입니다.
이번에 회사에서 인스톨러 제작하면서 더욱 더 많은 것을 시도해보게 되는 것 같네요.
제작하는 인스톨러가 환영페이지 앞에 특정조건에 따라 비밀번호를 묻는 사용자페이지가 삽입되어 있었는데 이 페이지로 인해 환영페이지에서 무조건 뒤로 버튼이 출력되는 문제가 있었습니다.
NSIS 포럼에 가보니 역시 문제 해결책이 있더군요.
예제 코드는 환영 페이지 에서 뒤로 버튼을 감춥니다.
!define MUI_PAGE_CUSTOMFUNCTION_PRE Welcome_Pre
!insertmacro MUI_PAGE_WELCOME
<--- 위와 같이 조작하려는 페이지 앞에 사용자 함수를 호출하도록 선언합니다.
Function Welcome_Pre
GetDlgItem $R0 $HWNDPARENT 3
ShowWindow $R0 ${SW_HIDE}
FunctionEnd
<--- 위와 같이 함수를 작성하면 뒤로 버튼이 나타나지 않습니다.
PS. 뒤로 버튼 3
다음 버튼 1
취소 버튼 2 입니다.
출처: http://nsis.sourceforge.net/Go_to_a_NSIS_page
Author: deguix (talk, contrib) |
Contents[hide] |
This function makes NSIS to go to a specified page relatively from the current page. Use it only on normal functions, the ".onUserAbort" callback function (w/o MUI) or the !define MUI_CUSTOMFUNCTION_ABORT "Function" (w/ MUI) (see more information at the bottom of the page).
This function also allows InstallOptions and InstallOptionsEx to use its features so you can choose which controls will take the place of the default NSIS buttons.
It doesn't use the stack because changing pages makes the code execution to stop. So instead it uses the variable "$R9".
StrCpy $R9 "(number|X)" ;Relative page number. See below. Call RelGotoPage
;---------------------------------------------------------------------------- ; Title : Go to a NSIS page ; Short Name : RelGotoPage ; Last Changed : 22/Feb/2005 ; Code Type : Function ; Code Sub-Type : Special Restricted Call, One-way StrCpy Input ;---------------------------------------------------------------------------- ; Description : Makes NSIS to go to a specified page relatively from ; the current page. See this below for more information: ; "http://nsis.sf.net/wiki/Go to a NSIS page" ;---------------------------------------------------------------------------- ; Function Call : StrCpy $R9 "(number|X)" ; ; - If a number > 0: Goes foward that number of ; pages. Code of that page will be executed, not ; returning to this point. If it excess the number of ; pages that are after that page, it simulates a ; "Cancel" click. ; ; - If a number < 0: Goes back that number of pages. ; Code of that page will be executed, not returning to ; this point. If it excess the number of pages that ; are before that page, it simulates a "Cancel" click. ; ; - If X: Simulates a "Cancel" click. Code will go to ; callback functions, not returning to this point. ; ; - If 0: Continues on the same page. Code will still ; be running after the call. ; ; Call RelGotoPage ;---------------------------------------------------------------------------- ; Author : Diego Pedroso ; Author Reg. Name : deguix ;---------------------------------------------------------------------------- Function RelGotoPage IntCmp $R9 0 0 Move Move StrCmp $R9 "X" 0 Move StrCpy $R9 "120" Move: SendMessage $HWNDPARENT "0x408" "$R9" "" FunctionEnd
The .onUserAbort callback function (w/o MUI) and the function indicated by the !define MUI_CUSTOMFUNCTION_PRE (w/ MUI) are totally special in fact that they handle all "Cancel" and "X" clicks the user does, and secondly, that the code still runs if you run the RelGotoPage function, but goes to the page specified after the function is aborted. We can make this "Cancel" and "X" buttons to have a different effect like skipping to the next page, by using the following codes:
Use the normal call that I described on the top of this page but on the function ".onUserAbort":
Function .onUserAbort StrCpy $R9 1 ;Goto the next page Call RelGotoPage Abort FunctionEnd
Use the normal call that I described on the top of this page on the function indicated by the !define MUI_CUSTOMFUNCTION_ABORT:
!insert "MUI.nsh" ;Required by MUI !define MUI_CUSTOMFUNCTION_ABORT "FunctionName" !insertmacro MUI_LANGUAGE "English" ;Required by MUI Function FunctionName StrCpy $R9 1 ;Goto the next page Call RelGotoPage Abort FunctionEnd
Use a variable to hold the page index inside the PreFunction of every page and before InstallOptions plugin first call inside every custom page main function, and compare this variable inside the ".onUserAbort" callback function. An example:
Page custom CustomPage Page components Components_PreFunction Page directory Directory_PreFunction Function CustomPage StrCpy $R8 1 ;This is the first page InstallOptions::dialog "C:\MyDir\MyIOPage.ini" Pop $0 FunctionEnd Function Components_PreFunction StrCpy $R8 2 ;This is the second page FunctionEnd Function Directory_PreFunction StrCpy $R8 3 ;This is the third page FunctionEnd Function .onUserAbort StrCmp $R8 1 0 End ;Compare the variable with the ;page index of your choice StrCpy $R9 1 Call RelGotoPage Abort End: FunctionEnd
Use a variable to hold the page index inside the function indicated by each !define MUI_PAGE_CUSTOMFUNCTION_PRE of every page and before MUI_INSTALLOPTIONS_* macro first call inside every custom page main function (except for MUI_INSTALLOPTIONS_READ and MUI_INSTALLOPTIONS_WRITE macros), and compare this variable inside the function indicated by the !define MUI_CUSTOMFUNCTION_ABORT. An example:
!include "MUI.nsh" ;Required by MUI Page custom CustomPage !define MUI_PAGE_CUSTOMFUNCTION_PRE Components_PreFunction !insertmacro MUI_PAGE_COMPONENTS !define MUI_PAGE_CUSTOMFUNCTION_PRE Directory_PreFunction !insertmacro MUI_PAGE_DIRECTORY !define MUI_CUSTOMFUNCTION_ABORT "FunctionName" !insertmacro MUI_LANGUAGE "English" ;Required by MUI Function CustomPage StrCpy $R8 1 ;This is the first page InstallOptions::dialog "C:\MyDir\MyIOPage.ini" Pop $0 FunctionEnd Function Components_PreFunction StrCpy $R8 2 ;This is the second page FunctionEnd Function Directory_PreFunction StrCpy $R8 3 ;This is the third page FunctionEnd Function FunctionName StrCmp $R8 1 0 End ;Compare the variable with the ;page index of your choice StrCpy $R9 1 Call RelGotoPage Abort End: FunctionEnd
출처: http://forums.winamp.com/showthread.php?postid=2056841
disable next button in a custom page
I am having a weird problem. I can not seem to be able to disable the install button in the following script. Just to make sure I am doing everything right I played with disabling the Cancel button and it worked! But I have no idea why the Install button is stubborn or is it me being stupid?
The script creates a simple license custom page and I want to disable the Install button until the I Agree Radio button is selected otherwise it needs to stay disabled.
PHP:
[Settings]
NumFields=3
[Field 1]
Type=Text
Left=10
Right=-10
Top=10
Bottom=110
State=blabla
Flags=MULTILINE|VSCROLL|READONLY
[Field 2]
Type=RadioButton
Text=I AGREE
Flags=NOTIFY
State=0
Left=10
Right=110
Top=120
Bottom=128
[Field 3]
Type=RadioButton
Text=I DO NOT AGREE
Flags=NOTIFY
State=1
Left=10
Right=110
Top=131
Bottom=139
PHP:
!define FILE_INI "LicensePage.ini"
!include "MUI.nsh"
!include "Sections.nsh"
!include WinMessages.nsh
Page custom License LicenseLeave ""
!insertmacro MUI_PAGE_INSTFILES
OutFile "test.exe"
Section "dummy"
SectionEnd
Function .onInit
!insertmacro MUI_INSTALLOPTIONS_EXTRACT ${FILE_INI}
FunctionEnd
Function License
!insertmacro MUI_HEADER_TEXT "License the product" "Please read the license carefully."
InstallOptions::initDialog /NOUNLOAD "$PLUGINSDIR\${FILE_INI}"
GetDlgItem $1 $HWNDPARENT 1
EnableWindow $1 0
InstallOptions::show
FunctionEnd
Function LicenseLeave
ReadINIStr $0 "$PLUGINSDIR\${FILE_INI}" "Settings" "State"
IntCmp $0 0 validate
IntCmp $0 2 I_AGREE
IntCmp $0 3 I_DO_NOT_AGREE
Abort
I_DO_NOT_AGREE:
GetDlgItem $1 $HWNDPARENT 1
EnableWindow $1 0
GetDlgItem $1 $HWNDPARENT 2
EnableWindow $1 0
Abort
I_AGREE:
GetDlgItem $1 $HWNDPARENT 1
EnableWindow $1 1
GetDlgItem $1 $HWNDPARENT 2
EnableWindow $1 1
Abort
validate:
FunctionEnd
Function RelGotoPage
IntCmp $R9 0 0 Move Move
StrCmp $R9 "X" 0 Move
StrCpy $R9 "120"
Move:
SendMessage $HWNDPARENT "0x408" "$R9" ""
FunctionEnd
StrCpy $R9 "(number|X)" ;Relative page number. See below.
Call RelGotoPage
출처; http://nsis.sourceforge.net/Contrib/InstallOptions/Readme.html
InstallOptions is a NSIS plugin which allows you to create custom pages for NSIS installers, to prompt the user for extra information.
InstallOptions will create a dialog which will be displayed inside the NSIS window. The controls on the dialog can be defined in an INI file.
NSIS 2 has a new page system, which allows you to add custom pages to your installer without messing with Prev/Next functions. With the new plugin system, you also don't have to worry anymore about extracting and deleting the DLL file. When you store the INI files in the plugins directory, NSIS will also delete them automatically.
This new version of InstallOptions has been designed for NSIS 2. It supports customized user interfaces and custom font and DPI settings.
The INI file has one required section. This section includes the number of controls to be created as well as general window attributes. The INI file also includes a variable number of Field sections which are used to create the controls to be displayed.
The required section is named "Settings". It can contain the following values:
NumFields | (required) | The number of control elements to be displayed on the dialog window. |
Title | (optional) | If specified, gives the text to set the titlebar to. Otherwise, the titlebar text is not changed. |
CancelEnabled | (optional) | If specified, overrides NSIS settings and enables or disables the cancel button. If set to 1, the cancel button will be enabled. If set to 0, the cancel button will be disabled. |
CancelShow | (optional) | If specified, overrides NSIS settings and shows or hides the cancel button If set to 1, the cancel button will be shown. If set to 0, the cancel button will be hidden. |
BackEnabled | (optional) | If specified, overrides NSIS settings and enables or disables the back button. If set to 1, the back button will be enabled. If set to 0, the back button will be disabled. |
CancelButtonText | (optional) | Overrides the text for the cancel button. If not specified, the cancel button text will not be changed. |
NextButtonText | (optional) | Overrides the text for the next button. If not specified, the next button text will not be changed. |
BackButtonText | (optional) | Overrides the text for the back button. If not specified, the back button text will not be changed. |
Rect | (optional) | Overrides the default rect ID to run over. This will make IO resize itself according to a different rect than NSIS's dialogs rect. |
RTL | (optional) | If 1 is specified the dialog will be mirrored and all texts will be aligned to the right. Use NSIS's $(^RTL) to fill this field, it's the easiest way. |
State | (output) | This is not something you have to supply yourself but is set by InstallOptions, before calling your custom page validation function, to the field number of the custom Button control (or other control having the Notify flag) the user pressed, if any. |
Each field section has the heading "Field #" where # must be sequential numbers from 1 to NumFields. Each Field section can contain the following values:
Type | (required) | Type of control to be created. Valid values are "Label", "Text", "Password", "Combobox", "DropList", "Listbox", "CheckBox", "RadioButton", "FileRequest", "DirRequest" "Icon", "Bitmap", "GroupBox", "Link" or "Button". A "Label" is used to display static text. (i.e. a caption for a textbox) A "Text" and "Password" accept text input from the user. "Password" masks the input with * characters. A "Combobox" allows the user to type text not in the popup list, a "Droplist" only allows selection of items in the list. A "Listbox" shows multiple items and can optionally allow the user to select more than one item. A "CheckBox" control displays a check box with label. A "RadioButton" control displays a radio button with label. A "FileRequest" control displays a textbox and a browse button. Clicking the browse button will display a file requester where the user can browse for a file. A "DirRequest" control displays a textbox and a browse button. Clicking the browse button will display a directory requester where the user can browse for a directory. An "Icon" control displays an icon. Use no Text to use the installer icon. A "Bitmap" control displays a bitmap. A "GroupBox" control displays a frame to group controls. A "Link" control displays a static hot text. When the user clicks the control the contents of State (e.g. http://...) will be executed using ShellExecute. Alternatively State can be omitted and the NOTIFY flag used to have your NSIS script called. See the "NOTIFY" flag below for more information. A "Button" control displays a push button that can be used in the same way as the "Link" control above. | ||||||||||||||||||||||||||||||||||||||||||||||||
Text | (optional) | Specifies the caption of a label, checkbox, or radio button control. For DirRequest control this specifies the title of the browse dialog. For icon and bitmaps control this specifies the path to the image. Note: For labels, \r\n will be converted to a newline. To use a back-slash in your text you have to escape it using another back-slash - \\. Described below are NSIS functions for converting text to/from this format. | ||||||||||||||||||||||||||||||||||||||||||||||||
State | (optional) | Specifies the state of the control. This is updated when the user closes the window, so you can read from it from NSIS. For edit texts and dir and file request boxes, this is the string that is specified. For radio button and check boxes, this can be '0' or '1' (for unchecked or checked). For list boxes, combo boxes and drop lists this is the selected items separated by pipes ('|'). For Links and Buttons this can specify something to be executed or opened (using ShellExecute). Note: For Text fields with the MULTILINE flag, \r\n will be converted to a newline. To use a back-slash in your text you have to escape it using another back-slash - \\. Described below are NSIS functions for converting text to/from this format. | ||||||||||||||||||||||||||||||||||||||||||||||||
ListItems | (optional) | A list of items to display in a combobox, droplist, or listbox. This is a single line of text with each item separated by a pipe character '|' | ||||||||||||||||||||||||||||||||||||||||||||||||
MaxLen | (optional) | Causes validation on the selected control to limit the maximum length of text. If the user specifies more text than this, a message box will appear when they click "OK" and the dialog will not be dismissed. You should not use this on a "combobox" since the user can not control what is selected. This should be set to a maximum of 260 for "FileRequest" and "DirRequest" controls. Ignored on "Label" controls. | ||||||||||||||||||||||||||||||||||||||||||||||||
MinLen | (optional) | Causes validation on the selected control to force the user to enter a minimum amount of text. If the user specifies less text than this, a message box will appear when they click "OK" and the dialog will not be dismissed. Unlike MaxLen, this is useful for "Combobox" controls. By setting this to a value of "1" the program will force the user to select an item. Ignored on "Label" controls. | ||||||||||||||||||||||||||||||||||||||||||||||||
ValidateText | (optional) | If the field fails the test for "MinLen" or "MaxLen", a messagebox will be displayed with this text. Note: \r\n will be converted to a newline, two back-slashes will be converted to one - \\. Described below are NSIS functions for converting text to/from this format. | ||||||||||||||||||||||||||||||||||||||||||||||||
Left Right Top Bottom |
(required) | The position on the dialog where this control appears. All sizes should be set in dialog units. To get the right dimensions for your controls, design your dialog using a resource editor and copy the dimensions to the INI file. Note: You can specify negative coordinates to specify the distance from the right or bottom edge. Note (2): For combobox or droplist, the "bottom" value is not used in the same way. In this case, the bottom value is the maximum size of the window when the pop-up list is being displayed. All other times, the combobox is automatically sized to be one element tall. If you have trouble where you can not see the combobox drop-down, then check the bottom value and ensure it is large enough. A rough guide for the height required is the number of items in the list multiplied by 8, plus 20. Note (3): FileRequest and DirRequest controls will allocate 15 dialog units to the browse button. Make this control wide enough the contents of the textbox can be seen. | ||||||||||||||||||||||||||||||||||||||||||||||||
Filter | (optional) | Specifies the filter to be used in the "FileRequest" control. This is constructed by putting pairs of entries together, each item separated by a | character. The first value in each pair is the text to display for the filter. The second value is the pattern to use to match files. For example, you might specify: Filter=Text Files|*.txt|Programs|*.exe;*.com|All Files|*.* If not specified, then the filter defaults to All Files|*.* Note: you should not put any extra spaces around the | characters. | ||||||||||||||||||||||||||||||||||||||||||||||||
Root | (optional) | Used by DirRequest controls to specify the root directory of the search. By default, this allows the user to browse any directory on the computer. This will limit the search to a particular directory on the system. | ||||||||||||||||||||||||||||||||||||||||||||||||
Flags | (optional) | This specifies additional flags for the display of different controls. Each value should be separated by a | character, and you should be careful not to put any spaces around the | character.
| ||||||||||||||||||||||||||||||||||||||||||||||||
TxtColor | (optional) | Used by Link controls to specify the foreground color of the text. Format: 0xBBRRGG (hexadecimal). |
For information about using InstallOptions with the Modern UI, have a look at the Modern UI documentation.
First, you have to extract the INI files for the dialogs in the .onInit function:
Function .onInit InitPluginsDir File /oname=$PLUGINSDIR\test.ini test.ini FunctionEnd
You can call InstallOptions in a page function, check the NSIS documentation for information about the page system. Example:
Page custom SetCustom ValidateCustom
The InstallOptions DLL has three functions:
Usually, you only need to use the dialog function:
Function SetCustom ;FunctionName defined with Page command ;Display the Install Options dialog Push $R0 InstallOptions::dialog $PLUGINSDIR\test.ini Pop $R0 FunctionEnd
To get the input of the user, read the State value of a Field using ReadINIStr:
ReadINIStr $R0 "$PLUGINSDIR\test.ini" "Field 1" "State"
Note:
Some InstallOptions values are escaped (in a similar manner to "C" strings) to allow characters to be used that are not normally valid in INI file values. The affected values are:
The escape character is the back-slash character ("\") and the available escape sequences are:
"\\" | Back-slash |
"\r" | Carriage return (ASCII 13) |
"\n" | Line feed (ASCII 10) |
"\t" | Tab (ASCII 9) |
The following functions can be used to convert a string to and from this format:
; Convert an NSIS string to a form suitable for use by InstallOptions ; Usage: ; Push <NSIS-string> ; Call Nsis2Io ; Pop <IO-string> Function Nsis2Io Exch $0 ; The source Push $1 ; The output Push $2 ; Temporary char StrCpy $1 "" ; Initialise the output loop: StrCpy $2 $0 1 ; Get the next source char StrCmp $2 "" done ; Abort when none left StrCpy $0 $0 "" 1 ; Remove it from the source StrCmp $2 "\" "" +3 ; Back-slash? StrCpy $1 "$1\\" Goto loop StrCmp $2 "$\r" "" +3 ; Carriage return? StrCpy $1 "$1\r" Goto loop StrCmp $2 "$\n" "" +3 ; Line feed? StrCpy $1 "$1\n" Goto loop StrCmp $2 "$\t" "" +3 ; Tab? StrCpy $1 "$1\t" Goto loop StrCpy $1 "$1$2" ; Anything else Goto loop done: StrCpy $0 $1 Pop $2 Pop $1 Exch $0 FunctionEnd ; Convert an InstallOptions string to a form suitable for use by NSIS ; Usage: ; Push <IO-string> ; Call Io2Nsis ; Pop <NSIS-string> Function Io2Nsis Exch $0 ; The source Push $1 ; The output Push $2 ; Temporary char StrCpy $1 "" ; Initialise the output loop: StrCpy $2 $0 1 ; Get the next source char StrCmp $2 "" done ; Abort when none left StrCpy $0 $0 "" 1 ; Remove it from the source StrCmp $2 "\" +3 ; Escape character? StrCpy $1 "$1$2" ; If not just output Goto loop StrCpy $2 $0 1 ; Get the next source char StrCpy $0 $0 "" 1 ; Remove it from the source StrCmp $2 "\" "" +3 ; Back-slash? StrCpy $1 "$1\" Goto loop StrCmp $2 "r" "" +3 ; Carriage return? StrCpy $1 "$1$\r" Goto loop StrCmp $2 "n" "" +3 ; Line feed? StrCpy $1 "$1$\n" Goto loop StrCmp $2 "t" "" +3 ; Tab? StrCpy $1 "$1$\t" Goto loop StrCpy $1 "$1$2" ; Anything else (should never get here) Goto loop done: StrCpy $0 $1 Pop $2 Pop $1 Exch $0 FunctionEnd
If you want to validate the input on the page, for example, you want to check whether the user has filled in a textbox, use the leave function of the Page command and Abort when the validation has failed:
Function ValidateCustom ReadINIStr $R0 "$PLUGINSDIR\test.ini" "Field 1" "State" StrCmp $R0 "" 0 +3 MessageBox MB_ICONEXCLAMATION|MB_OK "Please enter your name." Abort FunctionEnd
After you have called the DLL, InstallOptions adds one string to the stack, with one of the following values:
Usually, you don't need to check this value, but you still have to remove it from the stack (have a look at the example above).
You only have to check this value if you need something really special, such as doing something when the user pressed the Back button.
If you are using BZIP2 (solid) compression, it's important that files which are being extracted in init- or page functions function are located before other files in the data block, because this will make your installer faster.
If there are File commands in your sections or functions above the init- or page functions, add ReserveFile commands above your sections and functions:
ReserveFile "test.ini" ReserveFile "${NSISDIR}\Plugins\InstallOptions.dll"
If you want to use custom fonts or colors on your InstallOptions dialogs, you should use the initDialog and show functions. initDialog creates the dialog in memory, but does not show it. After calling initDialog, you can set the fonts and colors, and call show to show the dialog. initDialog pushes the HWND of the custom dialog to the stack. To get the HWND of the controls use:
GetDlgItem (output var) (hwnd of the custom dialog) (1200 + Field number - 1)
Example of using a custom font:
Function FunctionName ;FunctionName defined with Page command ;Display the Install Options dialog Push $R0 Push $R1 Push $R2 InstallOptions::initDialog /NOUNLOAD $PLUGINSDIR\test.ini Pop $R0 GetDlgItem $R1 $R0 1200 ;1200 + Field number - 1 ;$R1 contains the HWND of the first field CreateFont $R2 "Tahoma" 10 700 SendMessage $R1 ${WM_SETFONT} $R2 0 InstallOptions::show Pop $R0 Pop $R2 Pop $R1 Pop $R0 FunctionEnd
Original version by Michael Bishop
DLL version by Nullsoft, Inc.
DLL version 2 by Amir Szekely, ORTIM, Joost Verburg
New documentation by Joost Verburg
Original version Copyright © 2001 Michael Bishop DLL version 1 Copyright © 2001-2002 Nullsoft, Inc., ORTIM DLL version 2 Copyright © 2003-2005 Amir Szekely, Joost Verburg, Dave Laundon This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any distribution
출처: http://nsis.sourceforge.net/Add-on_Custom_Installer_Sample_/w_InstallOptions
Author: psyalien (talk, contrib) |
This is an installer I wrote to add on files to an already installed application called "APP" in this example. It uses a custom window defined in "installtype.ini" for InstallOptions.
;Author: Joey Cz. ;Contact: psyalien69 [at] yahoo [dot] com ; Modern interface settings !include "MUI.nsh" !include WinMessages.nsh ; Define your application name !define APPNAME "Add-on Installer Sample" !define APPNAMEANDVERSION "${APPNAME} 1.0" !define APP_INST_DIR $8 ;define global APP Database Dir alias !define APP_DB_DIR $9 !define MUI_ABORTWARNING ; Window handle of the custom page Var hwnd ; Install type variables Var dbInst Var fullInst Var autoInst ; The name of the installer Name "${APPNAMEANDVERSION}" InstallDir "" InstallDirRegKey HKLM "Software\${APPNAMEANDVERSION}" "" ; The installer file OutFile "${APPNAMEANDVERSION} Installer.exe" ; Show install details ShowInstDetails show ; Called before anything else as installer initialises Function .onInit ;NOTE: ; following is a sample for reading from the Registry ; read the APP installation directory from the registry ReadRegStr ${APP_INST_DIR} HKLM "Software\Vendor\App\Version" "InstallDir" ; read the database location if APP installation was found ReadRegStr ${APP_DB_DIR} HKCU "Software\Vendor\App\Version" "Database File Type" ; Check for APP installation existence StrCmp ${APP_INST_DIR} "" 0 NoAbortInst MessageBox MB_OK "APP installtion was not found. Please install APP before runing this installer." Abort ; abort if APP installation is not found NoAbortInst: ; Check for APP Database dir existence StrCmp ${APP_DB_DIR} "" 0 NoAbortDb MessageBox MB_OK "APP Database location was not defined. Please configure APP before runing this installer." Abort ; abort if APP installation is not found NoAbortDb: ; ExtrAPP InstallOptions files ; $PLUGINSDIR will automatically be removed when the installer closes InitPluginsDir File /oname=$PLUGINSDIR\test.ini "installtype.ini" FunctionEnd ; NOTE : ; ************************ ; Pages Displayed in order ; ************************ ; Welcome Page !insertmacro MUI_PAGE_WELCOME ; License Page !insertmacro MUI_PAGE_LICENSE "License.txt" ; Our custom page ;Page custom ShowCustom LeaveCustom ": Select Install Type" Page custom ShowCustom LeaveCustom ; APP Installation directory Page !define MUI_DIRECTORYPAGE_VARIABLE ${APP_INST_DIR} !define MUI_PAGE_HEADER_TEXT "APP Installation folder location." !define MUI_PAGE_HEADER_SUBTEXT "" !define MUI_DIRECTORYPAGE_TEXT_TOP "Please select the folder where APP has been installed. If you are unsure where APP! has been installed, please keep the default value." !define MUI_DIRECTORYPAGE_TEXT_DESTINATION "APP Folder" !define MUI_DIRECTORYPAGE_VERIFYONLEAVE !define MUI_PAGE_CUSTOMFUNCTION_PRE APPInstallDirectoryPage_Pre !insertmacro MUI_PAGE_DIRECTORY ; APP Database directory Page !define MUI_DIRECTORYPAGE_VARIABLE ${APP_DB_DIR} !define MUI_PAGE_HEADER_TEXT "APP Database folder location." !define MUI_PAGE_HEADER_SUBTEXT "" !define MUI_DIRECTORYPAGE_TEXT_TOP "Please select the folder where APP! keeps its Database files. If you are unsure where the APP! Database folder is, please keep the default value." !define MUI_DIRECTORYPAGE_TEXT_DESTINATION "APP Database Folder" !define MUI_PAGE_CUSTOMFUNCTION_PRE APPDBDirectoryPage_Pre !insertmacro MUI_PAGE_DIRECTORY ; Components Page !define MUI_COMPONENTSPAGE_TEXT_TOP "Select the Components you want to install and uncheck the ones you you do not want to install. Click next to continue." !define MUI_COMPONENTSPAGE_TEXT_DESCRIPTION_TITLE "Description" !define MUI_COMPONENTSPAGE_TEXT_DESCRIPTION_INFO "Description info" !define MUI_PAGE_CUSTOMFUNCTION_PRE ComponentsPage_Pre !insertmacro MUI_PAGE_COMPONENTS ; Install Files Page !insertmacro MUI_PAGE_INSTFILES ; Finish Page !define MUI_FINISHPAGE_RUN "${APP_INST_DIR}\APP.exe" !define MUI_FINISHPAGE_RUN_NOTCHECKED !define MUI_FINISHPAGE_SHOWREADME "${APP_INST_DIR}\MyAddon\Readme.txt" !define MUI_FINISHPAGE_SHOWREADME_NOTCHECKED !insertmacro MUI_PAGE_FINISH ; Uninstall Confirm Page !insertmacro MUI_UNPAGE_CONFIRM ; Uninstall Files Page !insertmacro MUI_UNPAGE_INSTFILES ; Set languages (first is default language) !insertmacro MUI_LANGUAGE "English" !insertmacro MUI_RESERVEFILE_LANGDLL Function APPInstallDirectoryPage_Pre StrCmp $autoInst true 0 end ; MessageBox MB_ICONEXCLAMATION|MB_OK "install dir PRE page" Abort end: FunctionEnd Function APPDBDirectoryPage_Pre StrCmp $autoInst true 0 end ; MessageBox MB_ICONEXCLAMATION|MB_OK "db dir PRE page" Abort end: FunctionEnd Function ComponentsPage_Pre StrCmp $autoInst true 0 end ; MessageBox MB_ICONEXCLAMATION|MB_OK "component PRE page" Abort end: FunctionEnd Function ShowCustom InstallOptions::initDialog /NOUNLOAD "$PLUGINSDIR\test.ini" ; In this mode InstallOptions returns the window handle so we can use it Pop $hwnd !insertmacro MUI_HEADER_TEXT "Installation Type" "Please select the installation type, then click Next to proceede with the install." ; Now show the dialog and wait for it to finish InstallOptions::show ; Finally fetch the InstallOptions status value (we don't care what it is though) Pop $0 FunctionEnd Function LeaveCustom ; At this point the user has either pressed Next or one of our custom buttons ; We find out which by reading from the INI file ReadINIStr $0 "$PLUGINSDIR\test.ini" "Settings" "State" StrCmp $0 0 validate ; Next button? StrCmp $0 2 automaticRadio ; Automatic install StrCmp $0 3 customRadio ; custom install StrCmp $0 7 comboBox ; Full install or DB Abort ; Return to the page automaticRadio: GetDlgItem $1 $hwnd 1206 ; PathRequest control (1200 + field 7 - 1) EnableWindow $1 1 Abort ; Return to the page customRadio: WriteINIStr "$PLUGINSDIR\test.ini" "Field 7" "Flags" "DISABLED" GetDlgItem $1 $hwnd 1206 ; PathRequest control (1200 + field 7 - 1) EnableWindow $1 0 Abort ; Return to the page comboBox: Abort ; Return to the page validate: ReadINIStr $0 "$PLUGINSDIR\test.ini" "Field 2" "State" StrCmp $0 1 automaticInst ReadINIStr $0 "$PLUGINSDIR\test.ini" "Field 3" "State" StrCmp $0 1 customInst automaticInst: StrCpy $autoInst true Call AutomaticInstall Goto done customInst: StrCpy $autoInst false Call CustomInstall done: FunctionEnd Function AutomaticInstall ;MessageBox MB_ICONEXCLAMATION|MB_OK "You selected Automatic install" ReadINIStr $0 "$PLUGINSDIR\test.ini" "Field 7" "State" StrCmp $0 "Database Only" dbonly full full: StrCpy $fullInst true StrCpy $dbInst true Goto end dbonly: StrCpy $fullInst false StrCpy $dbInst true end: FunctionEnd Function CustomInstall ;MessageBox MB_ICONEXCLAMATION|MB_OK "You selected Custom install" FunctionEnd Section "Database" DBSection StrCmp $dbInst true dbFiles done dbFiles: ;MessageBox MB_ICONEXCLAMATION|MB_OK "Installing DB Files" ; Set Section properties SetOverwrite try ; Set Section Files and Shortcuts SetOutPath "${APP_DB_DIR}\MyAddon\" File "Database\File1" File "Database\File2" File "Database\File3" done: ;MessageBox MB_ICONEXCLAMATION|MB_OK "DONE Installing DB Files" SectionEnd SubSection /e "!Add-On Files" AddOnSection Section "Layout" LayoutSection StrCmp $fullInst true layout done layout: ;MessageBox MB_ICONEXCLAMATION|MB_OK "Installing Layout Files" ; LAYOUT SECTION ; Set Section properties SetOverwrite try ; Set Section Files and Shortcuts SetOutPath "${APP_INST_DIR}\Layout" File "Layout\File1" File "Layout\File2" done: ;MessageBox MB_ICONEXCLAMATION|MB_OK "DONE Installing Layout Files" SectionEnd Section "Templates" TemplatesSection StrCmp $fullInst true templates done templates: ;MessageBox MB_ICONEXCLAMATION|MB_OK "Installing Template Files" ; TEMPLATE SECTION ; Set Section Files and Shortcuts SetOutPath "${APP_INST_DIR}\Template\To Insured\" File "Template\File1" File "Template\File2" File "Template\File3" done: ;MessageBox MB_ICONEXCLAMATION|MB_OK "DONE Installing Template Files" SectionEnd Section "Reports" ReportsSection StrCmp $fullInst true reports done reports: ;MessageBox MB_ICONEXCLAMATION|MB_OK "Installing Reports Files" ; REPORTS SECTION ; Set Section Files and Shortcuts SetOutPath "${APP_INST_DIR}\Report" File "Report\File1" done: ;MessageBox MB_ICONEXCLAMATION|MB_OK "DONE Installing Reports Files" SectionEnd Section "Documentation" DocumentationSection ;MessageBox MB_ICONEXCLAMATION|MB_OK "Installing Documentation Files" ; DOCUMENTATION SECTION ; Set Section Files and Shortcuts SetOutPath "${APP_INST_DIR}\MyAddon\" File "Readme.txt" File "License.txt" SectionEnd SubSectionEnd Section -FinishSection ; set the default layout for APP WriteRegStr HKCU "Software\Symantec\APP\Database" "Layout" "${APP_INST_DIR}\Layout\FILE1" ; set the default database for APP WriteRegStr HKCU "Software\Symantec\APP\Database" "Database Name" "${APP_DB_DIR}\MyAddon\DBFILE" ; set the default Word Procesor for APP WriteRegStr HKCU "Software\Symantec\APP" "WPDefaultDriver" "APPWrite" ; set uninstall stuff WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAMEANDVERSION}" "DisplayName" "${APPNAMEANDVERSION}" WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAMEANDVERSION}" "UninstallString" "${APP_DB_DIR}\MyAddon\uninstall.exe" CreateDirectory "${APP_INST_DIR}\MyAddon" WriteUninstaller "${APP_INST_DIR}\MyAddon\uninstall.exe" CreateDirectory "$SMPROGRAMS\${APPNAMEANDVERSION}" CreateShortCut "$SMPROGRAMS\${APPNAMEANDVERSION}\Uninstall.lnk" "${APP_INST_DIR}\MyAddon\uninstall.exe" CreateShortCut "$SMPROGRAMS\${APPNAMEANDVERSION}\Operating Manual.lnk" "${APP_INST_DIR}\MyAddon\Installation and Operating Manual.doc" CreateShortCut "$DESKTOP\${APPNAMEANDVERSION}.lnk" "${APP_DB_DIR}\MyAddon\FILE" CreateShortCut "$SMPROGRAMS\${APPNAMEANDVERSION}\${APPNAMEANDVERSION}.lnk" "${APP_DB_DIR}\MyAddon\FILE" SectionEnd ; Modern install component descriptions !insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN !insertmacro MUI_DESCRIPTION_TEXT ${DBSection} "MyAddon Database files for APP" !insertmacro MUI_DESCRIPTION_TEXT ${AddOnSection} "MyAddon Add-On files" !insertmacro MUI_DESCRIPTION_TEXT ${LayoutSection} "- Layout Files" !insertmacro MUI_DESCRIPTION_TEXT ${TemplatesSection} "- Template Files" !insertmacro MUI_DESCRIPTION_TEXT ${ReportsSection} "- Report Files" !insertmacro MUI_DESCRIPTION_TEXT ${DocumentationSection} "- Documentation Files" !insertmacro MUI_FUNCTION_DESCRIPTION_END ;Uninstall section Section Uninstall ; read APP Installation dir from registry ReadRegStr ${APP_INST_DIR} HKLM "Software\Vendor\APP\Version" "InstallDir" ; read APP Database dir from registry ReadRegStr ${APP_DB_DIR} HKCU "Software\Vendor\APP\Version" "Database File Type" ;Remove installer misc stuff from registry... DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAMEANDVERSION}" DeleteRegKey HKLM "SOFTWARE\${APPNAMEANDVERSION}" ; Delete self Delete "${APP_INST_DIR}\MyAddon\uninstall.exe" ; Clean up Documenation Delete "${APP_INST_DIR}\MyAddon\Readme.txt" Delete "${APP_INST_DIR}\MyAddon\License.txt" Delete "${APP_INST_DIR}\MyAddon\File1" Delete "${APP_INST_DIR}\MyAddon\File2" Delete "${APP_INST_DIR}\MyAddon\File3" ; etc.. RMDir "${APP_INST_DIR}\MyAddon" ; Delete Shortcuts Delete "$DESKTOP\${APPNAMEANDVERSION}.lnk" Delete "$SMPROGRAMS\${APPNAMEANDVERSION}\${APPNAMEANDVERSION}.lnk" Delete "$SMPROGRAMS\${APPNAMEANDVERSION}\Uninstall.lnk" ; Clean up MyAddon Insurance Database Delete "${APP_DB_DIR}\MyAddon\File1" ; etc.. ; Clean up MyAddon Insurance Layout Delete "${APP_INST_DIR}\Layout\File1" ; etc.. ; Clean up MyAddon Report files Delete "${APP_INST_DIR}\Report\File1" ; etc.. ; Clean up MyAddon Templates Delete "${APP_INST_DIR}\Template\File1" ; etc.. ; Remove remaining directories RMDir "$SMPROGRAMS\${APPNAMEANDVERSION}" RMDir "${APP_DB_DIR}" ; etc.. SectionEnd
; Ini file generated by the HM NIS Edit IO designer. [Settings] NumFields=7 Title=APP Add-On 1.0.0 Setup NextButtonText=Next BackButtonText=Back [Field 1] Type=Groupbox Text=Select Install Type Flags=NOTABSTOP Left=30 Right=270 Top=0 Bottom=54 [Field 2] Type=RadioButton Text=Automatic Flags=NOTIFY State=1 Left=46 Right=122 Top=14 Bottom=25 [Field 3] Type=RadioButton Text=Custom Flags=NOTIFY Left=46 Right=122 Top=33 Bottom=43 [Field 4] Type=Groupbox Flags=NOTABSTOP Left=30 Right=270 Top=59 Bottom=132 [Field 5] Type=Text Flags=MULTILINE|WANTRETURN|READONLY|NOWORDWRAP State=Automatic Install : (default)\r\n - Full Install : Installs Database and Add-On Files\r\n - Database Only : Installs only the Database Files\r\n\r\nCustom Install:\r\n - User driven customizable components installer Left=35 Right=264 Top=68 Bottom=124 [Field 6] Type=Groupbox Text=Automatic Left=150 Right=256 Top=8 Bottom=49 [Field 7] Type=Droplist Flags=NOTIFY State=Full Install ListItems=Full Install|Database Only Left=156 Right=252 Top=18 Bottom=59
출처: http://jgh0721.egloos.com/2501999
출처: http://blog.naver.com/hoonlike71?Redirect=Log&logNo=28397650
|
출처: http://nsis.sourceforge.net/How_can_I_let_the_compiled_script_depend_on_something_dynamic
Compile your script with /DNAME=value or /X"nsis command" passed on to makensis.exe as command line arguments. The /D switch of the compiler will define NAME as value in the script. The /X switch will add "nsis command" to the top of the script.
Example:
In the compiling script:
ExecWait "makensis.exe /DVERSION=1.2 myscript.nsi"
In the compiled dynamic script:
OutFile myprog${VERSION}.exe
Note - These flags *must* be specified on a makensis command line before you specify the script name. If you have "makensis.exe myscript.nsi /DVERSION=1.2 " then VERSION will not be set.