setup.nsi 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. ; 该脚本使用 HM VNISEdit 脚本编辑器向导产生
  2. !include "StrFunc.nsh"
  3. ${StrRep}
  4. ; 安装程序初始定义常量
  5. !define PRODUCT_NAME "MOKA Factory Tools"
  6. !define PRODUCT_VERSION "3.0.6.0"
  7. !define PRODUCT_PUBLISHER "MOKA"
  8. !define PRODUCT_DIR_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\MOKA Factory Tools.exe"
  9. !define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
  10. !define PRODUCT_UNINST_ROOT_KEY "HKLM"
  11. SetCompressor lzma
  12. ; ------ MUI 现代界面定义 (1.67 版本以上兼容) ------
  13. !include "MUI.nsh"
  14. ; MUI 预定义常量
  15. !define MUI_ABORTWARNING
  16. !define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\modern-install.ico"
  17. !define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\modern-uninstall.ico"
  18. ;安装.net运行环境
  19. !define NETVersion "4.5.50709"
  20. !define NETPath "../Runtime\dotnetfx45_full_x86_x64.exe"
  21. !define NETInstaller "dotnetfx45_full_x86_x64.exe"
  22. Section "MS .NET Framework v${NETVersion}" SecFramework
  23. ReadRegStr $0 HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full" "Version"
  24. ${If} $0 == "4.5.50709"
  25. DetailPrint "Microsoft .NET Framework is already installed!"
  26. ${Else}
  27. File /oname=$TEMP\${NETInstaller} ${NETPath}
  28. DetailPrint "Starting Microsoft .NET Framework v${NETVersion} Setup..."
  29. ExecWait "$TEMP\${NETInstaller}"
  30. Return
  31. ${EndIf}
  32. SectionEnd
  33. ; 语言选择窗口常量设置
  34. !define MUI_LANGDLL_REGISTRY_ROOT "${PRODUCT_UNINST_ROOT_KEY}"
  35. !define MUI_LANGDLL_REGISTRY_KEY "${PRODUCT_UNINST_KEY}"
  36. !define MUI_LANGDLL_REGISTRY_VALUENAME "NSIS:Language"
  37. ; 欢迎页面
  38. !insertmacro MUI_PAGE_WELCOME
  39. ; 许可协议页面
  40. !insertmacro MUI_PAGE_LICENSE "../Licence.txt"
  41. ; 安装目录选择页面
  42. !insertmacro MUI_PAGE_DIRECTORY
  43. ; 安装过程页面
  44. !insertmacro MUI_PAGE_INSTFILES
  45. ; 安装完成页面
  46. !define MUI_FINISHPAGE_RUN "$INSTDIR\MOKA Factory Tools.exe"
  47. !insertmacro MUI_PAGE_FINISH
  48. ; 安装卸载过程页面
  49. !insertmacro MUI_UNPAGE_INSTFILES
  50. ; 安装界面包含的语言设置
  51. !insertmacro MUI_LANGUAGE "English"
  52. !insertmacro MUI_LANGUAGE "SimpChinese"
  53. ; 安装预释放文件
  54. !insertmacro MUI_RESERVEFILE_LANGDLL
  55. !insertmacro MUI_RESERVEFILE_INSTALLOPTIONS
  56. ; ------ MUI 现代界面定义结束 ------
  57. Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
  58. OutFile "Setup${PRODUCT_VERSION}.exe"
  59. InstallDir "$PROGRAMFILES\MOKA Factory Tools"
  60. InstallDirRegKey HKLM "${PRODUCT_UNINST_KEY}" "UninstallString"
  61. ShowInstDetails show
  62. ShowUnInstDetails show
  63. Section "MainSection" SEC01
  64. SetOutPath "$INSTDIR"
  65. SetOverwrite ifnewer
  66. File "../bin\Release\System.Data.SQLite.xml"
  67. CreateDirectory "$SMPROGRAMS\MOKA Factory Tools"
  68. CreateShortCut "$SMPROGRAMS\MOKA Factory Tools\MOKA Factory Tools.lnk" "$INSTDIR\MOKA Factory Tools.exe"
  69. CreateShortCut "$DESKTOP\MOKA Factory Tools.lnk" "$INSTDIR\MOKA Factory Tools.exe"
  70. Delete "$INSTDIR\Config.json"
  71. File "../bin\Release\System.Data.SQLite.dll"
  72. File "../bin\Release\MOKA Factory Tools.exe"
  73. File "../bin\Release\MOKA Factory Tools.exe.config"
  74. File "../bin\Release\Newtonsoft.Json.dll"
  75. File "../bin\Release\Devaof.DB.SQLite.dll"
  76. File "../bin\Release\Devaof.DB.SqlBuilder.dll"
  77. File "../bin\Release\CSkin.xml"
  78. File "../bin\Release\CSkin.dll"
  79. File "../bin\Release\Config.json"
  80. File "../Runtime\dotnetfx45_full_x86_x64.exe"
  81. SetOutPath "$INSTDIR\x86"
  82. File "../bin\Release\x86\*.*"
  83. SetOutPath "$INSTDIR\x64"
  84. File "../bin\Release\x64\*.*"
  85. SetOutPath "$INSTDIR\zh-CN"
  86. File "../bin\Release\zh-CN\*.*"
  87. SectionEnd
  88. Section -AdditionalIcons
  89. CreateShortCut "$SMPROGRAMS\MOKA Factory Tools\Uninstall.lnk" "$INSTDIR\uninst.exe"
  90. SectionEnd
  91. Section -Post
  92. WriteUninstaller "$INSTDIR\uninst.exe"
  93. WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "" "$INSTDIR\MOKA Factory Tools.exe"
  94. WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayName" "$(^Name)"
  95. WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "UninstallString" "$INSTDIR\uninst.exe"
  96. WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayIcon" "$INSTDIR\MOKA Factory Tools.exe"
  97. WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayVersion" "${PRODUCT_VERSION}"
  98. WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "Publisher" "${PRODUCT_PUBLISHER}"
  99. SectionEnd
  100. #-- 根据 NSIS 脚本编辑规则,所有 Function 区段必须放置在 Section 区段之后编写,以避免安装程序出现未可预知的问题。--#
  101. Function .onInit
  102. Call RemoveOld
  103. !insertmacro MUI_LANGDLL_DISPLAY
  104. FunctionEnd
  105. /******************************
  106. * 以下是安装程序的卸载部分 *
  107. ******************************/
  108. Section Uninstall
  109. Delete "$INSTDIR\uninst.exe"
  110. Delete "$INSTDIR\dotnetfx45_full_x86_x64.exe"
  111. Delete "$INSTDIR\Config.json"
  112. Delete "$INSTDIR\CSkin.dll"
  113. Delete "$INSTDIR\CSkin.xml"
  114. Delete "$INSTDIR\Devaof.DB.SqlBuilder.dll"
  115. Delete "$INSTDIR\Devaof.DB.SQLite.dll"
  116. Delete "$INSTDIR\Newtonsoft.Json.dll"
  117. Delete "$INSTDIR\MOKA Factory Tools.exe"
  118. Delete "$INSTDIR\MOKA Factory Tools.exe.config"
  119. Delete "$INSTDIR\MOKA Fartory Tools Server.exe"
  120. Delete "$INSTDIR\MOKA Fartory Tools Server.exe.config"
  121. Delete "$INSTDIR\System.Data.SQLite.dll"
  122. Delete "$INSTDIR\System.Data.SQLite.xml"
  123. Delete "$SMPROGRAMS\MOKA Factory Tools\Uninstall.lnk"
  124. Delete "$DESKTOP\MOKA Factory Tools.lnk"
  125. Delete "$SMPROGRAMS\MOKA Factory Tools\MOKA Factory Tools.lnk"
  126. Delete "$INSTDIR\*.*"
  127. RMDir "$SMPROGRAMS\MOKA Factory Tools"
  128. RMDir "$INSTDIR"
  129. DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
  130. DeleteRegKey HKLM "${PRODUCT_DIR_REGKEY}"
  131. SetAutoClose true
  132. SectionEnd
  133. #-- 根据 NSIS 脚本编辑规则,所有 Function 区段必须放置在 Section 区段之后编写,以避免安装程序出现未可预知的问题。--#
  134. Function un.onInit
  135. !insertmacro MUI_UNGETLANGUAGE
  136. MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "您确实要完全移除 $(^Name) ,及其所有的组件?" IDYES +2
  137. Abort
  138. FunctionEnd
  139. Function un.onUninstSuccess
  140. HideWindow
  141. MessageBox MB_ICONINFORMATION|MB_OK "$(^Name) 已成功地从您的计算机移除。"
  142. FunctionEnd
  143. Function RemoveOld
  144. # 获取注册表信息;
  145. ReadRegStr $0 HKLM "${UNINSTALL_KEY}\SCBC Factory Tools" "UninstallString"
  146. ${IF} $0 != ""
  147. MessageBox MB_ICONINFORMATION|MB_OK "检测到旧的安装包,将会移除。"
  148. ${StrRep} $R1 $0 "\uninst.exe" ""
  149. # 复制文件;
  150. CopyFiles "$R1\Config.json" "$INSTDIR\Config.json"
  151. CopyFiles "$R1\Error.db" "$INSTDIR\Error.db"
  152. CopyFiles "$R1\Keys" "$INSTDIR\Keys"
  153. CopyFiles "$R1\log" "$INSTDIR\log"
  154. CopyFiles "$R1\download" "$INSTDIR\download"
  155. # 删除程序及注册表信息;
  156. Delete "$R1\uninst.exe"
  157. Delete "$R1\CSkin.dll"
  158. Delete "$R1\CSkin.xml"
  159. Delete "$R1\Devaof.DB.SqlBuilder.dll"
  160. Delete "$R1\Devaof.DB.SQLite.dll"
  161. Delete "$R1\Newtonsoft.Json.dll"
  162. Delete "$R1\SCBC Factory Tools.exe"
  163. Delete "$R1\SCBC Factory Tools.exe.config"
  164. Delete "$R1\SCBC Fartory Tools Server.exe"
  165. Delete "$R1\SCBC Fartory Tools Server.exe.config"
  166. Delete "$R1\System.Data.SQLite.dll"
  167. Delete "$R1\System.Data.SQLite.xml"
  168. Delete "$SMPROGRAMS\SCBC Factory Tools\Uninstall.lnk"
  169. Delete "$DESKTOP\SCBC Factory Tools.lnk"
  170. Delete "$SMPROGRAMS\SCBC Factory Tools\SCBC Factory Tools.lnk"
  171. RMDir "$SMPROGRAMS\SCBC Factory Tools"
  172. DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\SCBC Factory Tools"
  173. DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\App Paths\SCBC Factory Tools.exe"
  174. ${ENDIF}
  175. FunctionEnd