NSIS学习笔记

NSIS默想笔记

Date:2015-05-20

Author:kagula

Env:VS2013Update4、、、eclipse-jee-kepler-SR2-win32、Win7-64bits

建造NSIS境况
着手处理1:(校订的NSIS本子)

从网站下载记录并直竖的它。

着手处理2:(NSIS本子措辞高亮显示)
翻阅文献〔3〕直竖的NSIS可插件用于Eclipse,用于校订NSIS本子。
[月食] main 卡特尔> > >扶助> >直竖的 new software…]->type the nsis http address and select component to 直竖的。
嗨理所当然坚持到底的是
〔1〕伊柯丽斯 NSIS可插件不支持或高尚的版本。不支持Windows 8或高尚的版本。
〔2〕率先建造空使突出,之后经过有指导意义的事物添加NSIS 本子会出错。错误报文为空。
(3)经过有指导意义的事物添加直竖的 选择权记录(ini)记录

出口记录名只得是[使突出确定] /记录名,要不,它将举报记录名出口的违法的导致。。

(4)你可以经过轮廓子窗口,NSI本子中变量和有或起作用的感觉最敏锐的名列前茅确定方向。

现时您可以直接地将NSI记录拖到Eclipse中举行校订。。

最新版本(多姿多彩的版本)可以直接地从FO下载。

https://github.com/henrikor2/eclipsensis

着手处理3:(自清晰度图形用户相互作用)
经过援用(1)下载.exe,咱们需求从直竖的啮合的清晰度来清晰度大约器。。

最复杂的办法是
第一步:率先在Eclipse中调解本子(或另外NSIS本子校订器)
其次步:启动NSIS compiler。NSIS 卡特尔> ->校订器[ > >校订器 NSI 本子。
第三步:NSI记录,拖到NSIS compiler里,NSIS 校订器将自动行为校订,的行进。

要运用NSIS,率先只得学会运用它的本子语言。,NSIS本子的每一排代表命令。,源记录扩展名是NSI,头记录扩展名是.NSH。。

软件可能性有很多子群。,NSIS用节表现每个子群。。示例行为准则如次:
Section “My Program”
SetOutPath $INSTDIR
File “My Program.exe”
File “”
SectionEnd

上面是独一典型的NSIS示例行为准则,更自清晰度重要事件样品,它们中某个。。

# All the other settings can be 健康状态 by editing the !defines at the top of this script
!define APPNAME       "平等体系"
!define COMPANYNAME   浙江袜口贸易科技股份有限公司
!define SETUPFILENAME ""
!define DESCRIPTION   ""

!define APPEXENAME    ""

# These three must be integers
# 嗨清晰度的是直竖的包的版本。,它理所当然与一般版本的主顺序划一(EXFI)
!define VERSIONMAJOR    2
!define VERSIONMINOR    0
!define VERSIONBUILD    0
!define VERSIONREVISION 0

清晰度一般版本的软件(EXE记录)
!define VERSIONLONG  "${VERSIONMAJOR}.${VERSIONMINOR}.${VERSIONBUILD}.${VERSIONREVISION}"

直竖的顺序ICO记录确定和得第二名
!define ICOFILENAME ""
!define ICOFULLPATH "..\PriceComparingSystem\res\${ICOFILENAME}"

# These will be displayed by the "Click here for support information" link in "Add/Remove Programs"
# It is possible to use "mailto:" links in here to open the email client
!define HELPURL   "" # "Support Information" link
!define UPDATEURL "" # "Product Updates" link
!define ABOUTURL  "" # "Publisher" link

# This is the size 中 KB) of all the files copied into "Program Files"
# issue 清单的大多数
!define INSTALLSIZE 84379885
 
RequestExecutionLevel admin ;Require admin rights on NT6+ (究竟什么时候 UAC is turned 在)
  
InstallDir "$PROGRAMFILES\${COMPANYNAME}\${APPNAME}"

# rtf or txt file - remember if it is txt, it must be in the DOS text format (\r\n)

#MUI macro define
!define MUI_PAGE_HEADER_TEXT ${COMPANYNAME}
!define MUI_PAGE_HEADER_SUBTEXT ''${APPNAME} v${VERSIONLONG}''
!define MUI_ICON ${ICOFULLPATH}

# This will be in the installer/uninstaller''s title bar
Name    "${APPNAME}"
Icon    "${ICOFULLPATH}"
outFile "${SETUPFILENAME}"
;BrandingText ''${APPNAME} v${VERSIONLONG}''
 BrandingText ''$0''
 
!include LogicLib.nsh
!include nsProcess.nsh

#include custom page reference
!include ""
!include ""
!include ""
 
# Just three pages - license agreement, install location, and installation
#!insertmacro MUI_PAGE_WELCOME
;Page custom fnc_kagulaWelcomePage_Show
;page license
;page directory
;Page instfiles
!insertmacro MUI_PAGE_LICENSE ""
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES

!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_UNPAGE_FINISH


!insertmacro MUI_LANGUAGE "SimpChinese"

!macro VerifyUserIsAdmin
UserInfo::GetAccountType
pop $0
${If} $0 != "admin" ;Require admin rights on NT4+
        messageBox mb_iconstop 需求管理员标准的的!"
        setErrorLevel 740 ;ERROR_ELEVATION_REQUIRED
        quit
${EndIf}
!macroend
 
!include ""
Var VersionNumber

Function VerCheck
pop $0
;${GetFileVersion} "$INSTDIR\${APPEXENAME}" $VersionNumber
${GetFileVersion} "$0" $VersionNumber
FunctionEnd

Function VersionCompare
    !define VersionCompare `!insertmacro VersionCompareCall`
 
    !macro VersionCompareCall _VER1 _VER2 _RESULT
        Push `${_VER1}`
        Push `${_VER2}`
        Call VersionCompare
        Pop ${_RESULT}
    !macroend
 
    Exch $1
    Exch
    Exch $0
    Exch
    Push $2
    Push $3
    Push $4
    Push $5
    Push $6
    Push $7
 
    begin:
    StrCpy $2 -1
    IntOp $2 $2 + 1
    StrCpy $3 $0 1 $2
    StrCmp $3 '''' +2
    StrCmp $3 ''.'' 0 -3
    StrCpy $4 $0 $2
    IntOp $2 $2 + 1
    StrCpy $0 $0 '''' $2
 
    StrCpy $2 -1
    IntOp $2 $2 + 1
    StrCpy $3 $1 1 $2
    StrCmp $3 '''' +2
    StrCmp $3 ''.'' 0 -3
    StrCpy $5 $1 $2
    IntOp $2 $2 + 1
    StrCpy $1 $1 '''' $2
 
    StrCmp $4$5 '''' equal
 
    StrCpy $6 -1
    IntOp $6 $6 + 1
    StrCpy $3 $4 1 $6
    StrCmp $3 ''0'' -2
    StrCmp $3 '''' 0 +2
    StrCpy $4 0
 
    StrCpy $7 -1
    IntOp $7 $7 + 1
    StrCpy $3 $5 1 $7
    StrCmp $3 ''0'' -2
    StrCmp $3 '''' 0 +2
    StrCpy $5 0
 
    StrCmp $4 0 0 +2
    StrCmp $5 0 begin newer2
    StrCmp $5 0 newer1
    IntCmp $6 $7 0 newer1 newer2
 
    StrCpy $4 ''1$4''
    StrCpy $5 ''1$5''
    IntCmp $4 $5 begin newer2 newer1
 
    equal:
    StrCpy $0 0
    goto end
    newer1:
    StrCpy $0 1
    goto end
    newer2:
    StrCpy $0 2
 
    end:
    Pop $7
    Pop $6
    Pop $5
    Pop $4
    Pop $3
    Pop $2
    Pop $1
    Exch $0
FunctionEnd

function .onInit
    setShellVarContext all
    !insertmacro VerifyUserIsAdmin
    
    #check program 跑步。
    ${nsProcess::FindProcess} ${APPEXENAME} $R0
    ${If} $R0 == "0"
        # it''s running
        MessageBox MB_OK 软件在运转,决定放弃!"
        Quit
    ${EndIf}
    
;    MessageBox MB_OK 一般版本的软件是:${VERSIONLONG}"
    #check version from custom install place    
    ReadRegStr $0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "MainProgramLocation"
    ${If} $0 != ""
;      MessageBox MB_OK "记录得第二名:$0"
      ${If} ${FileExists} $0
;        #if installed version is greater, return 2        
;        #else if equality, return 0.
;        #else if less, return 1 and resume install 转换。
;        #MessageBox MB_OK "Version=$R0"      
;       MessageBox MB_OK "before push the parameter for VerCheck function.$0"
       push $0
       Call VerCheck
       ${VersionCompare} $VersionNumber ${VERSIONLONG} $R0
       ${if} $R0 != "1"
           MessageBox MB_OK 您先前直竖的了${AppNord}软件的同上版本或交换版本,决定放弃直竖的!"
           Quit 
        ${Endif}
      ${EndIf}
;    ${Else}
;      MessageBox MB_ICONSTOP "Not found"
    ${EndIf}
functionEnd
 
section "install"
    # Files for the install directory - to build the installer, these should be in the same directory as the install script (大约 记录)
    setOutPath $INSTDIR
    
    # Files added here should be removed by the uninstaller (见 section 卸载软件
    File /r "..\issue\"
    file "${ICOFULLPATH}"
    # Add any other files for the install directory (依据) files, app data, 等) here
 
    # Uninstaller - See function un.onInit and section "uninstall" for configuration
    writeUninstaller "$INSTDIR\"
 
    # Start Menu
    createDirectory "$SMPROGRAMS\${COMPANYNAME}"
    createShortCut "$SMPROGRAMS\${COMPANYNAME}\${APPNAME}.lnk" "$INSTDIR\${APPEXENAME}" "" "$INSTDIR\${ICOFILENAME}"
    
    # create a shortcut named "new shortcut" in the start menu programs directory
    # point the new shortcut at the program uninstaller
    CreateShortCut "$SMPROGRAMS\${COMPANYNAME}\卸载软件.lnk" "$INSTDIR\"
 
    # Registry information for add/remove programs
    WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "DisplayName" "${COMPANYNAME} - ${APPNAME} - ${DESCRIPTION}"
    WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "UninstallString" "$\"$INSTDIR\$\""
    WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "QuietUninstallString" "$\"$INSTDIR\$\" /S"
    WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "InstallLocation" "$\"$INSTDIR$\""
    WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "DisplayIcon" "$\"$INSTDIR\${ICOFILENAME}$\""
    WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "Publisher" "$\"${COMPANYNAME}$\""
    WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "HelpLink" "$\"${HELPURL}$\""
    WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "URLUpdateInfo" "$\"${UPDATEURL}$\""
    WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "URLInfoAbout" "$\"${ABOUTURL}$\""
    WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "DisplayVersion" "$\"${VERSIONMAJOR}.${VERSIONMINOR}.${VERSIONBUILD}.${VERSIONREVISION}$\""
    WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "VersionMajor" ${VERSIONMAJOR}
    WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "VersionMinor" ${VERSIONMINOR}
    
    # There is no option for modifying or repairing the install
    WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "NoModify" 1
    WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "NoRepair" 1
    
    # Set the INSTALLSIZE constant (!defined at the top of this 本子) so Add/Remove Programs can accurately report the size
    WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "EstimatedSize" ${INSTALLSIZE}
    
    #Write file install location to register 表。
    WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "MainProgramLocation" "$INSTDIR\${APPEXENAME}"
sectionEnd
 
# Uninstaller
 
function un.onInit
    SetShellVarContext all 
 
    #Verify the uninstaller - last chance to back out
    MessageBox MB_OKCANCEL 一定要自成一格它 ${APPNAME} 吗?" IDOK next
        Abort
    next:
    !insertmacro VerifyUserIsAdmin
functionEnd

section "uninstall"
 
    # Remove Start Menu launcher
    delete "$SMPROGRAMS\${COMPANYNAME}\${APPNAME}.lnk"
    delete "$SMPROGRAMS\${COMPANYNAME}\卸载软件.lnk"
    
    # Try to remove the Start Menu folder - this will only happen if it is empty
    rmDir "$SMPROGRAMS\${COMPANYNAME}"
 
    # Remove files
    delete $INSTDIR\${ICOFILENAME}
 
    # Always delete uninstaller as the last action
    delete $INSTDIR\
 
    # Try to remove the install directory - this will only happen if it is empty
    rmDir /r $INSTDIR
 
    # Remove uninstaller information from the registry
    DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}"
sectionEnd

FQA:
Q1、国文成绩
翻阅材料[1]里的nsis-3.0b1-是不支持国文的,下载。
源记录被设置为UTF-8编码典型。。
运用上面的行为准则受考验
CreateShortCut “$SMPROGRAMS\国文受考验.lnk” “$INSTDIR\”
MessageBox MB_OK  “国文受考验” 
是可以标准的显示国文的。

请翻阅上面的行为准则段,把直竖的相互作用弄成国文
!include “”
………………
!insertmacro MUI_LANGUAGE “SimpChinese”

Q2、受考验转换方法运转?
答:需求四分染色体着手处理。
第一步:从下载
其次步:叠层NSIS Unicode直竖的清单的清单树
第三步:将一般可插件清单达到目标记录准备排印的书面材料到可插件清单中。
四个步:可以修正限制因素下的行为准则更改。
${nsProcess::FindProcess} “” $R0
${If} $R0 == “0”
# it”s running
MessageBox MB_OK 大约顺序一向在运转。,决定放弃!”
Quit
${EndIf}

Q3、方法运用NSISDIAL设计器
A1:
运用NSISDeAcLogic设计器行进记录
在您的NSI主记录中,专修重要事件命令的名列前茅,添加以下行为准则
!include “”
!include “”
!include “”

Page custom fnc_kagulaWelcomePage_Show
您的自清晰度重要事件将被显示,但你会撞见它的骨架构架。

Q4、计划中的现代主义者 User 相互作用与NSIS移交的分别
显示批准页,MUI运用以下命令行
LicenseData “”
page license
在MUI模特儿中运用以下命令。
!insertmacro MUI_PAGE_LICENSE “”

Q5 方法实现预期的结果高减速比

SetCompressor LZMA

Q6 NSIS 打包 Win 7 无法自成一格快捷方式

限制因素材料

〔1〕NSIS Dialog Designer

〔2〕NSIS home page

〔3〕伊柯丽斯 NSIS

[4]Auto-uninstall old before installing new

〔5〕NSIS常见成绩集 建议老手翻阅默想

〔6〕Unicode NSIS呼唤NSurPro可插件来出错

〔7〕NSIS detection of a 32-bit process in Win 7 X64

〔8〕NSIS Modern User Interface

〔9〕用户化 an 在的 NSIS MUI2 page

〔10〕 sample script that uses several cool functions (交换) txt, mutually exclusive functions, MUI, patch install, etc.)

(交换)_txt,_mutually_exclusive_functions,_MUI,_patch_install,_etc.)

〔11〕NSIS 自清晰度直竖的相互作用,正确出口直竖的时刻表PERP

〔12〕dB 数据库地址和方法和资源配给功用

(13)NSIS软件直竖的履行了添加首页行为准则的相互作用。