NotePad2-mod.nsi 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  1. # 安装包防解压
  2. !packhdr temp.dat "cmd /c Copy /B temp.dat /B +Nanlon.7z temp.dat"
  3. #=================================================================
  4. /************************
  5. * 引入 nsh 脚本
  6. ************************/
  7. # 头文件目录
  8. !addincludedir ".\Include"
  9. !include "MUI2.nsh"
  10. !include "x64.nsh"
  11. /************************
  12. * 安装程序初始定义常量
  13. ************************/
  14. !define APPNAME "wlt"
  15. !define PRODUCT_NAME "wlt"
  16. !define PRODUCT_VERSION "5.0.1.0"
  17. !define PRODUCT_PUBLISHER "aaaaaa"
  18. !define PRODUCT_WEBSITE ""
  19. !define WEBSITE_LINK ""
  20. !define APPNAMESRT "王老头加速器"
  21. # 定义注册表
  22. !define PRODUCT_KEY_ROOT "HKLM"
  23. !define PRODUCT_KEY_UNINST "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
  24. !define PRODUCT_KEY_APPDIR "SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\${APPNAME}.exe"
  25. /************************
  26. * 初始化定义变量
  27. ************************/
  28. # 声明变量
  29. Var BIT
  30. Var BITSUFFIX
  31. # 标题
  32. Caption "${PRODUCT_NAME} ${PRODUCT_VERSION} $BITSUFFIX"
  33. # 设置文件覆盖标记
  34. SetOverwrite try
  35. # 设置压缩选项
  36. SetCompress auto
  37. # 选择压缩方式
  38. SetCompressor /SOLID lzma
  39. SetCompressorDictSize 32
  40. # 设置数据块优化
  41. SetDatablockOptimize on
  42. # 设置在数据中写入文件时间
  43. SetDateSave on
  44. # 请求应用程序管理员权限
  45. RequestExecutionLevel admin
  46. # 是否允许安装在根目录下
  47. AllowRootDirInstall false
  48. # 设置是否显示安装详细信息
  49. ShowInstDetails hide
  50. # 设置是否显示卸载详细信息
  51. ShowUnInstDetails hide
  52. # 设置安装类型
  53. InstType "推荐安装"
  54. InstType "全部安装"
  55. /************************
  56. * MUI 预定义常量
  57. ************************/
  58. !define MUI_UI ".\Resource\mui_sdesc.exe"
  59. /*** 安装界面 ***/
  60. !define MUI_ICON ".\Resource\Install.ico"
  61. !define MUI_WELCOMEFINISHPAGE_BITMAP ".\Resource\nsis3-grey.bmp"
  62. !define MUI_FINISHPAGE_RUN "$INSTDIR\${APPNAME}.exe"
  63. !define MUI_FINISHPAGE_RUN_TEXT "运行 ${PRODUCT_NAME}"
  64. /*** 卸载界面 ***/
  65. !define MUI_UNICON ".\Resource\Uninst.ico"
  66. !define MUI_UNWELCOMEFINISHPAGE_BITMAP ".\Resource\nsis3-grey.bmp"
  67. /************************
  68. * 安装/卸载 页面设置
  69. ************************/
  70. /*** 加快载入界面资源 ***/
  71. ReserveFile ".\Resource\Install.ico"
  72. ReserveFile ".\Resource\nsis3-grey.bmp"
  73. # 插件目录
  74. !ifdef NSIS_PACKEDVERSION
  75. !define /math NSIS_VERSON_MAJOR ${NSIS_PACKEDVERSION} >> 24
  76. !else
  77. !define NSIS_VERSON_MAJOR 2
  78. !endif
  79. !if ${NSIS_VERSON_MAJOR} > 2
  80. # NSIS 3.x 方式引用插件
  81. !addplugindir "/x86-unicode" ".\Plugins\x86-unicode"
  82. !addplugindir "/x86-ansi" ".\Plugins\x86-ansi"
  83. !else
  84. # NSIS 2.x 方式引用插件
  85. !ifdef NSIS_UNICODE
  86. !addplugindir ".\Plugins\x86-unicode"
  87. !else
  88. !addplugindir ".\Plugins\x86-ansi"
  89. !endif
  90. !endif
  91. # dll
  92. ReserveFile /plugin "System.dll"
  93. ReserveFile /plugin "Process.dll"
  94. /*** 安装页面 ***/
  95. # 欢迎页面
  96. !insertmacro MUI_PAGE_WELCOME
  97. # 组件选择页面
  98. !insertmacro MUI_PAGE_COMPONENTS
  99. # 安装目录选择页面
  100. !define MUI_PAGE_CUSTOMFUNCTION_show OnDirPageshow
  101. !insertmacro MUI_PAGE_DIRECTORY
  102. # 安装过程页面
  103. !insertmacro MUI_PAGE_INSTFILES
  104. # 安装完成页面
  105. !insertmacro MUI_PAGE_FINISH
  106. /*** 卸载页面 ***/
  107. # 卸载欢迎页面
  108. !insertmacro MUI_UNPAGE_WELCOME
  109. # 卸载目录选择页面
  110. !insertmacro MUI_UNPAGE_DIRECTORY
  111. # 卸载过程页面
  112. !insertmacro MUI_UNPAGE_INSTFILES
  113. # 卸载完成页面
  114. !insertmacro MUI_UNPAGE_FINISH
  115. /*** 语言文件 ***/
  116. !insertmacro MUI_LANGUAGE "SimpChinese"
  117. /************************
  118. * 版本声明
  119. ************************/
  120. VIProductVersion "${PRODUCT_VERSION}"
  121. VIAddVersionKey /LANG=${LANG_SIMPCHINESE} "ProductName" "${PRODUCT_NAME}"
  122. VIAddVersionKey /LANG=${LANG_SIMPCHINESE} "Comments" "${PRODUCT_NAME}"
  123. VIAddVersionKey /LANG=${LANG_SIMPCHINESE} "LegalCopyright" "Copyright ? 2017 ${PRODUCT_PUBLISHER}"
  124. VIAddVersionKey /LANG=${LANG_SIMPCHINESE} "FileDescription" "${PRODUCT_NAME}"
  125. VIAddVersionKey /LANG=${LANG_SIMPCHINESE} "FileVersion" "${PRODUCT_VERSION}"
  126. VIAddVersionKey /LANG=${LANG_SIMPCHINESE} "ProductVersion" "${PRODUCT_VERSION}"
  127. /************************
  128. * 安装文件定义
  129. ************************/
  130. Name "${PRODUCT_NAME}"
  131. OutFile "${PRODUCT_NAME}_${PRODUCT_VERSION}.exe"
  132. InstallDir "$PROGRAMFILES64\${PRODUCT_NAME}"
  133. InstallDirRegKey HKLM "${PRODUCT_UNINST_KEY}" "UninstallString"
  134. BrandingText " ${WEBSITE_LINK}"
  135. /************************
  136. * 安装 Section 段
  137. ************************/
  138. !macro ProcessCleanup # 进程清理
  139. ProcessFindLoop:
  140. Process::Find "$INSTDIR\${APPNAME}.exe"
  141. Pop $R0
  142. IntCmp $R0 0 ProcessFindDone
  143. Process::Kill $R0
  144. Pop $R1
  145. IntCmp $R1 0 ProcessFindDone
  146. Goto ProcessFindLoop
  147. ProcessFindDone:
  148. !macroend
  149. !macro AddUninstReg
  150. # 将卸载信息写入注册表
  151. WriteRegStr HKLM "${PRODUCT_KEY_UNINST}" "DisplayName" "${PRODUCT_NAME} $BITSUFFIX"
  152. WriteRegStr HKLM "${PRODUCT_KEY_UNINST}" "UninstallString" "$INSTDIR\uninst.exe"
  153. WriteRegStr HKLM "${PRODUCT_KEY_UNINST}" "DisplayIcon" "$INSTDIR\${APPNAME}.exe"
  154. WriteRegStr HKLM "${PRODUCT_KEY_UNINST}" "DisplayVersion" "${PRODUCT_VERSION}"
  155. WriteRegStr HKLM "${PRODUCT_KEY_UNINST}" "URLInfoAbout" "${PRODUCT_WEBSITE}"
  156. WriteRegStr HKLM "${PRODUCT_KEY_UNINST}" "Publisher" "${PRODUCT_PUBLISHER}"
  157. # 获取安装段的大小(KB)写入注册表
  158. SectionGetSize ${CoreFiles} $R0
  159. WriteRegDWORD HKLM "${PRODUCT_KEY_UNINST}" "EstimatedSize" "$R0"
  160. WriteRegStr HKLM "${PRODUCT_KEY_APPDIR}" "" "$INSTDIR\${APPNAME}.exe"
  161. SetRegView lastused
  162. !macroend
  163. Section "主程序(必选)" CoreFiles
  164. SectionIn RO 1 2
  165. SetDetailsPrint textonly
  166. DetailPrint "正在安装${PRODUCT_NAME}..."
  167. SetDetailsPrint listonly
  168. # 进程清理
  169. !insertmacro ProcessCleanup
  170. SetOutPath "$INSTDIR"
  171. ${If} ${RunningX64}
  172. File /r ".\${PRODUCT_NAME}\x64\*.*"
  173. ${Else}
  174. File /r ".\${PRODUCT_NAME}\x86\*.*"
  175. ${EndIf}
  176. WriteUninstaller "$INSTDIR\uninst.exe"
  177. SectionEnd
  178. SectionGroup /e "快捷方式" Shortcuts
  179. Section "桌面" ShortcutsDesktop
  180. SectionIn 1 2
  181. SetDetailsPrint textonly
  182. DetailPrint "正在创建桌面快捷方式..."
  183. SetDetailsPrint listonly
  184. SetShellVarContext current
  185. CreateShortCut "$DESKTOP\${APPNAMESRT}.lnk" "$INSTDIR\${APPNAME}.exe"
  186. SectionEnd
  187. ; Section "开始菜单" ShortcutsPrograms
  188. ; SectionIn 1 2
  189. ; SetDetailsPrint textonly
  190. ; DetailPrint "正在创建桌开始菜单目录..."
  191. ; SetDetailsPrint listonly
  192. ; SetShellVarContext current
  193. ; CreateDirectory "$SMPROGRAMS\${PRODUCT_NAME}"
  194. ; CreateShortCut "$SMPROGRAMS\${PRODUCT_NAME}\${APPNAME}.lnk" "$INSTDIR\${APPNAME}.exe"
  195. ; CreateShortCut "$SMPROGRAMS\${PRODUCT_NAME}\卸载${APPNAME}.lnk" "$INSTDIR\uninst.exe"
  196. ; SectionEnd
  197. SectionGroupEnd
  198. ; Section "添加到系统右键菜单" AddSystemContextMenu
  199. ; SectionIn 1 2
  200. ; SetDetailsPrint textonly
  201. ; DetailPrint "正在添加系统右键菜单..."
  202. ; SetDetailsPrint listonly
  203. ; WriteRegStr HKCR "*\shell\${APPNAME}" "" "使用${PRODUCT_NAME}编辑"
  204. ; WriteRegStr HKCR "*\shell\${APPNAME}\command" "" `"$INSTDIR\${APPNAME}.exe" "%1"`
  205. ; SectionEnd
  206. ; Section "替换系统记事本程序" ReplaceSystemNotepad
  207. ; SectionIn 2
  208. ; SetDetailsPrint textonly
  209. ; DetailPrint "正在替换系统记事本程序..."
  210. ; SetDetailsPrint listonly
  211. ; ${If} ${RunningX64}
  212. ; SetRegView 64
  213. ; WriteRegStr HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\notepad.exe" "Debugger" `"$INSTDIR\${APPNAME}.exe" "/z"`
  214. ; SetRegView lastused
  215. ; ${Else}
  216. ; SetRegView 32
  217. ; WriteRegStr HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\notepad.exe" "Debugger" `"$INSTDIR\${APPNAME}.exe" "/z"`
  218. ; SetRegView lastused
  219. ; ${EndIf}
  220. ; SectionEnd
  221. Section -Post
  222. SetDetailsPrint textonly
  223. DetailPrint "正在注册文件..."
  224. SetDetailsPrint listonly
  225. ${If} ${RunningX64}
  226. SetRegView 64
  227. !insertmacro AddUninstReg
  228. SetRegView lastused
  229. ${Else}
  230. SetRegView 32
  231. !insertmacro AddUninstReg
  232. SetRegView lastused
  233. ${EndIf}
  234. # 刷新图标关联
  235. System::Call `shell32::SHChangeNotify(i 0x08000000, i 0, i 0, i 0)`
  236. SectionEnd
  237. /************************
  238. * 安装回调函数
  239. ************************/
  240. Function .onInit
  241. # 初始化插件目录
  242. InitPluginsDir
  243. File "/ONAME=$PluginsDIR\Install.ico" ".\Resource\Install.ico"
  244. File "/ONAME=$PluginsDIR\nsis3-grey.bmp" ".\Resource\nsis3-grey.bmp"
  245. # 系统版本位数检测
  246. ${If} ${RunningX64}
  247. StrCpy $BIT "64"
  248. StrCpy $BITSUFFIX "(64-bit)"
  249. ${Else}
  250. StrCpy $BIT ""
  251. StrCpy $BITSUFFIX ""
  252. ${EndIf}
  253. # 创建互斥防止重复运行
  254. System::Call `kernel32::CreateMutex(i 0, i 0, t "${PRODUCT_NAME}_installer") i .r1 ?e`
  255. Pop $R0
  256. StrCmp $R0 0 +3
  257. MessageBox MB_OK|MB_ICONEXCLAMATION "安装程序已经运行!"
  258. Abort
  259. # 旧版本检测及卸载
  260. SetRegView 64
  261. ClearErrors
  262. ReadRegStr $R0 HKLM "${PRODUCT_KEY_UNINST}" "UninstallString"
  263. ${Unless} ${Errors}
  264. ReadRegStr $R1 HKLM "${PRODUCT_KEY_UNINST}" "DisplayVersion"
  265. SetRegView lastused
  266. Goto Uninst
  267. ${EndUnless}
  268. SetRegView 32
  269. ClearErrors
  270. ReadRegStr $R0 HKLM "${PRODUCT_KEY_UNINST}" "UninstallString"
  271. ${Unless} ${Errors}
  272. ReadRegStr $R1 HKLM "${PRODUCT_KEY_UNINST}" "DisplayVersion"
  273. SetRegView lastused
  274. Uninst:
  275. ${AndUnless} ${Cmd} `MessageBox MB_YESNO|MB_ICONQUESTION "检测到本机已经安装了 ${APPNAME} v$R1 $\n$\n是否卸载已安装的版本?" /SD IDYES IDNO`
  276. System::Call "*(&t${NSIS_MAX_STRLEN}R0)p.r0"
  277. System::Call "shlwapi::PathParseIconLocation(pr0)"
  278. System::Call "shlwapi::PathRemoveFileSpec(pr0)"
  279. System::Call "*$0(&t${NSIS_MAX_STRLEN}.R2)"
  280. System::Free $0
  281. ${AndUnless} $R2 == ""
  282. ExecWait `"$R0" /S _?=$R2` $0
  283. ${EndUnless}
  284. FunctionEnd
  285. Function OnDirPageshow # 安装目录设置
  286. SetRegView 64
  287. ReadRegStr $0 HKLM "${PRODUCT_KEY_APPDIR}" ""
  288. SetRegView lastused
  289. ${If} $0 == ""
  290. SetRegView 32
  291. ReadRegStr $0 HKLM "${PRODUCT_KEY_APPDIR}" ""
  292. SetRegView lastused
  293. ${ElseIf} $0 != ""
  294. FindWindow $R0 "#32770" "" $HWNDPARENT
  295. # 禁用浏览按钮
  296. GetDlgItem $0 $R0 1001
  297. EnableWindow $0 0
  298. # 禁用编辑的目录
  299. GetDlgItem $0 $R0 1019
  300. EnableWindow $0 0
  301. GetDlgItem $0 $R0 1006
  302. SendMessage $0 ${WM_SETTEXT} 0 "STR:已经检测到您的计算机上安装了${PRODUCT_NAME},现在进行的覆盖安装不能更改安装目录。如果您需要更改安装目录,请先卸载已经安装的版本之后再运行此安装程序!"
  303. ${EndIf}
  304. FunctionEnd
  305. /************************
  306. * 区段组件描述
  307. ************************/
  308. !insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
  309. !insertmacro MUI_DESCRIPTION_TEXT ${CoreFiles} "安装 ${PRODUCT_NAME}"
  310. !insertmacro MUI_DESCRIPTION_TEXT ${Shortcuts} "创建快捷方式"
  311. !insertmacro MUI_DESCRIPTION_TEXT ${ShortcutsDesktop} "创建桌面快捷方式"
  312. ;!insertmacro MUI_DESCRIPTION_TEXT ${ShortcutsPrograms} "创建开始菜单程序组快捷方式"
  313. ; !insertmacro MUI_DESCRIPTION_TEXT ${AddSystemContextMenu} "将 ${PRODUCT_NAME} 添加到系统右键菜单"
  314. ; !insertmacro MUI_DESCRIPTION_TEXT ${ReplaceSystemNotepad} "用 ${PRODUCT_NAME} 替换系统记事本程序"
  315. !insertmacro MUI_FUNCTION_DESCRIPTION_END
  316. /************************
  317. * 卸载 Section 段
  318. ************************/
  319. Section Uninstall
  320. SetDetailsPrint textonly
  321. DetailPrint "正在卸载${PRODUCT_NAME}..."
  322. SetDetailsPrint listonly
  323. # 进程清理
  324. !insertmacro ProcessCleanup
  325. Delete "$INSTDIR\*.*"
  326. # 删除安装文件
  327. Delete "$INSTDIR\${APPNAME}.exe"
  328. Delete "$INSTDIR\${APPNAME}.ini"
  329. Delete "$INSTDIR\uninst.exe"
  330. RMDir /r "$INSTDIR"
  331. RMDir "$INSTDIR"
  332. # 删除快捷方式
  333. SetShellVarContext current
  334. Delete "$DESKTOP\${APPNAMESRT}.lnk"
  335. SetShellVarContext current
  336. RMDir /r "$SMPROGRAMS\${PRODUCT_NAME}"
  337. RMDir /r "$PROFILE\naiyou"
  338. # 删除注册表
  339. SetRegView 64
  340. DeleteRegKey HKLM "${PRODUCT_KEY_APPDIR}"
  341. DeleteRegKey HKLM "${PRODUCT_KEY_UNINST}"
  342. DeleteRegKey HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\notepad.exe"
  343. SetRegView lastused
  344. SetRegView 32
  345. DeleteRegKey HKLM "${PRODUCT_KEY_APPDIR}"
  346. DeleteRegKey HKLM "${PRODUCT_KEY_UNINST}"
  347. DeleteRegKey HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\notepad.exe"
  348. SetRegView lastused
  349. DeleteRegKey HKCR "*\shell\${APPNAME}"
  350. # 刷新图标关联
  351. System::Call `shell32::SHChangeNotify(i 0x08000000, i 0, i 0, i 0)`
  352. SetAutoClose true
  353. SectionEnd
  354. /************************
  355. * 卸载回调函数
  356. ************************/
  357. Function un.onInit
  358. # 初始化插件目录
  359. InitPluginsDir
  360. # 创建互斥防止重复运行
  361. System::Call `kernel32::CreateMutex(i0,i0,t"${PRODUCT_NAME}_uninstaller")i.r1?e`
  362. Pop $R0
  363. StrCmp $R0 0 +3
  364. MessageBox MB_OK|MB_ICONEXCLAMATION "卸载程序已经运行!"
  365. Abort
  366. FunctionEnd