本文以一个完整的、传统界面的网易云音乐安装包的脚本为示例,来介绍 NSIS 传统用户界面的开发流程。
网易云音乐安装脚本
完整的示例脚本如下,脚本中包含了详细的注释加以解释说明。请将下面脚本保存为.nsi 文件(需使用 ANSI 编码保存),编译即可生成安装包。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
|
!define PRODUCT_NAME "网易云音乐" !define EXE_NAME "cloudmusic.exe" !define PRODUCT_VERSION "1.0.0.1" !define PRODUCT_PUBLISHER "NetEase" !define PRODUCT_LEGAL "NetEase 1999-2014" !define TEMP_DIR ""
VIProductVersion "${PRODUCT_VERSION}" VIAddVersionKey "ProductVersion" "${PRODUCT_VERSION}" VIAddVersionKey "ProductName" "${PRODUCT_NAME}" VIAddVersionKey "CompanyName" "${PRODUCT_PUBLISHER}" VIAddVersionKey "FileVersion" "${PRODUCT_VERSION}" VIAddVersionKey "InternalName" "${EXE_NAME}" VIAddVersionKey "FileDescription" "${PRODUCT_NAME}" VIAddVersionKey "LegalCopyright" "${PRODUCT_LEGAL}"
SetCompressor lzma
Name "$PRODUCT_NAME"
OutFile "网易云音乐安装-Basic UI.exe"
InstallDir "$PROGRAMFILES\Netease\CloudMusic"
ShowInstDetails hide
ShowUnInstDetails hide
RequestExecutionLevel admin
Icon "image\logo.ico" UninstallIcon "image\un_logo.ico"
PageEx license LicenseData "license.rtf" PageExEnd
PageEx components Caption "组件选择" ComponentText "选择安装组件:" "主程序" "快捷方式" PageExEnd
PageEx directory Caption "安装目录" DirText "请选择安装目录:" PageExEnd
PageEx instfiles PageExEnd
Section "!Files" "des_files"
SetOutPath $INSTDIR
File /r "app\*.*"
SectionEnd
Section "Shortcut" "des_shortcut" SetShellVarContext all CreateDirectory "$SMPROGRAMS\${PRODUCT_NAME}" CreateShortCut "$SMPROGRAMS\${PRODUCT_NAME}\${PRODUCT_NAME}.lnk" "$INSTDIR\${EXE_NAME}" CreateShortCut "$SMPROGRAMS\${PRODUCT_NAME}\卸载${PRODUCT_NAME}.lnk" "$INSTDIR\uninst.exe" SetShellVarContext current SectionEnd
Section "-Necessary"
WriteUninstaller "$INSTDIR\uninst.exe"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" "DisplayName" "${PRODUCT_NAME}" WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" "UninstallString" "$INSTDIR\uninst.exe"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" "DisplayIcon" "$INSTDIR\${EXE_NAME}" WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" "Publisher" "$INSTDIR\${PRODUCT_PUBLISHER}" SectionEnd
Section "Uninstall"
SetShellVarContext all Delete "$SMPROGRAMS\${PRODUCT_NAME}\${PRODUCT_NAME}.lnk" Delete "$SMPROGRAMS\${PRODUCT_NAME}\卸载${PRODUCT_NAME}.lnk" RMDir "$SMPROGRAMS\${PRODUCT_NAME}\" Delete "$DESKTOP\${PRODUCT_NAME}.lnk" SetShellVarContext current
SetOutPath "$INSTDIR"
Delete "$INSTDIR\*.*"
SetOutPath "$DESKTOP"
RMDir /r "$INSTDIR" RMDir "$INSTDIR"
SetAutoClose true SectionEnd
Function .onInit FunctionEnd
Function .onGUIInit
FunctionEnd
Function .onInstSuccess
FunctionEnd
Function un.onInit MessageBox MB_ICONQUESTION|MB_YESNO "你确实要完全删除网易云音乐,及其所有组件吗?" /SD IDYES IDYES +2 IDNO +1 Abort FunctionEnd
Function un.onUninstSuccess MessageBox MB_ICONINFORMATION|MB_OK "${PRODUCT_NAME} 已成功地从你的计算机移除" /SD IDOK FunctionEnd
|
上述脚本会将与脚本相同级别的 app 目录下的全部文件(含子目录)打包进安装包。image\logo.ico
和image\un_logo.ico
分别是安装包和卸载程序的图标。
运行截图