NSIS 的现代用户界面(Modern UI)只是相对于传统(丑陋)的界面而言的“现代”而已。它定义在MUI2.nsh
中,nsh 文件类似 C++中的头文件,可以被其他模块包含引用。
📌 推荐:NSIS-UI-Plugin 开源 NSIS UI 插件框架,支持任意第三方界面库。默认使用 Qt 作为界面库的安装包示例。
使用 MUI2 界面需要包含MUI2.nsh
:
MUI2 界面和传统界面不同之处在于,传统界面使用的Page
(或PageEx
)语法来标识显示哪些页面,如:
1 2 3
| PageEx license LicenseData "license.rtf" PageExEnd
|
而 MUI2 使用的是MUI2.nsh
中定义的一系列宏来标识显示哪些页面,如:
1
| !insertmacro MUI_PAGE_LICENSE "license.rtf"
|
和NSIS教程(4)-传统界面示例类似,这里提供制作网易云音乐的现代用户界面的安装包示例,脚本代码中包含了详细的注释。
高仿网易云音乐安装脚本
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
| !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 ""
!include "MUI2.nsh"
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 "网易云音乐安装0.exe"
InstallDir "$PROGRAMFILES\Netease\CloudMusic"
ShowInstDetails hide
ShowUnInstDetails hide
RequestExecutionLevel admin
!define MUI_ICON "image\logo.ico" !define MUI_UNICON "image\un_logo.ico"
!define MUI_CUSTOMFUNCTION_GUIINIT onGUIInit
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_LICENSE "license.rtf"
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_UNPAGE_FINISH
!insertmacro MUI_LANGUAGE "SimpChinese"
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
!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN !insertmacro MUI_DESCRIPTION_TEXT ${des_files} "主程序文件" !insertmacro MUI_DESCRIPTION_TEXT ${des_shortcut} "创建开始菜单和桌面快捷方式" !insertmacro MUI_FUNCTION_DESCRIPTION_END
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
|
运行效果