NSIsIs used to generate and installProgramSoftware,NSIThe script can easily write out an installation package. The biggest advantage is free.VSBuilt-in CreationMsiThe functions of the installation package are relatively simple. I heard that Microsoft has another software dedicated to the installation package to achieve more powerful functions.Vs proMore expensive ....... Therefore, if the installation and uninstallation are simple,MsiEnough. If you want to provide more functions without spending more money,NSIsOrInnoThey are all good choices. WhereNSIsMore flexible.InnoIt is simpler.
CurrentlyNSIsThe main disadvantage is that the installation cannot be canceled during the installation process. If you think this function is very important, do not use it.NSIs.
Let's start with the simplest one: how to useNSIsCreate an installation package. For more information, seeNSIs. This is because the following content mainly introduces what is not mentioned in the help document.
NSIsOfUser ManualChapter 2"Tutorial: the BasicThis describes the structure of the script.
Required is the OUTFILE instruction, which tells NSIs where to write the installer, and one section.
That is to sayNSIOnly one scriptOUTFILECommand and oneSectionYou can. This is what it looks like:
OUTFILE"Min.exe"
Section
Sectionend
Nothing to doInstallerThis is all done. However, this example isNSIThe script has no help at all. Because what we need is an installer that can complete basic functions, rather than a"Hello WorldNo executable files are output. WhileNSIsOfUser ManualA complete example is not provided from start to end. This articleArticleWe will introduce you to an installation script with complete functions and correct behaviors. Not described in this articleNSIFor the syntax, seeUser Manual.
Environment preparation:
First, if you have not installedNSIs, Please firstHttp://sourceforge.net/projects/nsis/Download the latest installation package. To2.44For example, you need to downloadNsis-2.44-setup.exeAndNsis-2.44-log.zipTwo files. After installationNSIsThenNsis-2.44-log.zipTo overwrite the files in the installation directory. ThisNisi-2.44-logUsed to enableNSIs. The default installation package does not have this function.
NSIRecommended Script EditorNotepad ++. FromHttp://notepad-plus.sourceforge.net/tw/site.htmDownload the latest version. (Previously usedEmeditorBut it does not currently supportNSIScript. UsedNotepad ++I'm amazed at the number of languages it supports .)
Requirement Description:
What we will implementInstallerThe following requirements must be met:
1.The interface does not look too earthy: Unfortunately,NSIsThe default style of the compiled program is very good.WIN 98. To useMui2Library to generate a comparisonXPStyle installation package. AboutMui2For more information about how to use the package, seeOnline help documentation.
2.Support installation logs: the installation files are recorded during installation. They are mainly used to delete only the files installed by the installation program.
3.Supports multiple languages. You don't need to explain this.
4.Basic page. This is built-in and does not need to be explained.
ExampleCode:
The following is a relatively complete installation, but the function is not complete, because the specific function must be added by yourself.
;The header file should be placed at the top,C ++The same is true.
! Include"Mui2.nsh"
! Include"Uninstallfromlog. nsh";The header file used for uninstallation is not in the default installation package.HereDownload
;Then there are some basic settings
Name"Yourapp"
OUTFILE"Yourappsetup.exe"
Installdir"C: \ Program Files \ XXXX \ yourapp"
RequestexecutionlevelUser
;Parameter Definition
! DefineMui_abortwarning
! DefineMui_finishpage_norebootsupport
;Installation Page Definition
! InsertmacroMui_page_welcome
! InsertmacroMui_page_license "license.txt"
! InsertmacroMui_page_directory
! InsertmacroMui_page_instfiles
! InsertmacroMui_page_finish
;Unmount Page Definition
! InsertmacroMui_unpage_welcome
! InsertmacroMui_unpage_confirm
! InsertmacroMui_unpage_instfiles
! InsertmacroMui_unpage_finish
;The interface language is defined. If you want to support more, you need to add more languages.OSRestrictions may not be displayed,Must be placed after the page definition.
! InsertmacroMui_language "simpchinese"
! InsertmacroMui_language "English"
;During installationLogFunction,Must be the firstSection
Section"-Logseton"
LogsetOn
Sectionend
;Then the installation and uninstallation sections
Section"Install"
Setoutpath $ Instdir
Writeuninstaller $ Instdir\ Uninstaller.exe
File".. \ Yourapp \ bin \ release \*.*"
Sectionend
SectionUninstall
CallUn. createlogfromfile
CallUn. removedirectoriesfromlog
Delete $ Instdir\ Install. Log
Delete $ Instdir\ Uninstaller.exe
Rmdir $ Instdir
Sectionend
;Finally, it is best to put each function at the end.
;The language selection page is displayed for the initialization function of the installer.
Function. Oninit
! Insertmacro mui_langdll_display
Functionend
FunctionUn. oninit
! Insertmacro mui_ungetlanguage
Functionend
Happy promise blogIt also provides a basisLogAnother header file for file uninstallation, the same principle, you can refer.
Come here first. The next article will introduceMui2Library configuration.