1 Star 0 Fork 311

丫头,咱们回家吧/常用工具

forked from Ricky/常用工具 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
setup.nsi 15.07 KB
一键复制 编辑 原始数据 按行查看 历史
Ricky 提交于 2024-03-29 10:37 . NSIS打包配置
; Script generated by the HM NIS Edit Script Wizard.
; HM NIS Edit Wizard helper defines
!define PRODUCT_NAME "体尺测定设备数据上报服务"
!define PRODUCT_VERSION "1.0.2"
!define PRODUCT_PUBLISHER "内蒙古好快科技有限公司"
!define PRODUCT_WEB_SITE "http://www.haokuai.cn"
!define PRODUCT_DIR_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\win-service.exe"
!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
!define PRODUCT_UNINST_ROOT_KEY "HKLM"
!define PRODUCT_SERVICE_NAME "tccdsjscService"
!define PRODUCT_SERVICE_DISPLAY_NAME "HK Tccdsjsc Service"
!define PRODUCT_SERVICE_DESC "体尺测定设备数据上传服务"
!define PRODUCT_FILE_VERSION "1.0.0.1"
BrandingText "内蒙古好快科技有限公司"
; ProgramData dir
Var PROGRAMDATA
; Device Config Dialog Variables
Var HWND_DEVICE_CONFIG_DIALOG
Var HWND_DEVICE_CONFIG_DIALOG_TEXT_CODE
Var HWND_DEVICE_CONFIG_DIALOG_TEXT_PASSWORD
Var HWND_DEVICE_CONFIG_DIALOG_TEXT_DOMAIN
Var HWND_DEVICE_CONFIG_DIALOG_TEXT_AREA
Var HWND_DEVICE_CONFIG_DIALOG_NEXT_BUTTON
; Data Config Dialog Variables
Var HWND_DATA_CONFIG_DIALOG
Var HWND_DATA_CONFIG_DIALOG_DIR_DATA
Var HWND_DATA_CONFIG_DIALOG_DIR_LOG
Var HWND_DATA_CONFIG_DIALOG_DIR_BACKUP
Var HWND_DATA_CONFIG_DIALOG_NEXT_BUTTON
; MUI 1.67 compatible ------
!include "MUI.nsh"
!include LogicLib.nsh
!include nsDialogs.nsh
; MUI Settings
!define MUI_ABORTWARNING
!define MUI_ICON "..\hk-icon.ico"
!define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\modern-uninstall.ico"
; Language Selection Dialog Settings
!define MUI_LANGDLL_REGISTRY_ROOT "${PRODUCT_UNINST_ROOT_KEY}"
!define MUI_LANGDLL_REGISTRY_KEY "${PRODUCT_UNINST_KEY}"
!define MUI_LANGDLL_REGISTRY_VALUENAME "NSIS:Language"
; Welcome page
!insertmacro MUI_PAGE_WELCOME
; DeviceConfig page
Page custom DeviceConfigPageInitFunc DeviceConfigPageLeaveFunc
; DataConfig page
Page custom DataConfigPageInitFunc DataConfigPageLeaveFunc
; Directory page
!insertmacro MUI_PAGE_DIRECTORY
; Instfiles page
!insertmacro MUI_PAGE_INSTFILES
; Finish page
!insertmacro MUI_PAGE_FINISH
; Uninstaller pages
!insertmacro MUI_UNPAGE_INSTFILES
; Language files
!insertmacro MUI_LANGUAGE "SimpChinese"
VIProductVersion "${PRODUCT_FILE_VERSION}"
VIAddVersionKey /LANG=2052 "ProductName" "体尺测定设备数据上报服务安装包"
VIAddVersionKey /LANG=2052 "Comments" "免费使用,不限分发。"
VIAddVersionKey /LANG=2052 "CompanyName" "内蒙古好快科技有限公司"
VIAddVersionKey /LANG=2052 "LegalTrademarks" "羊体尺测定设备"
VIAddVersionKey /LANG=2052 "LegalCopyright" "内蒙古好快科技有限公司"
VIAddVersionKey /LANG=2052 "FileDescription" "体尺测定设备数据上报服务安装包"
VIAddVersionKey /LANG=2052 "FileVersion" "${PRODUCT_FILE_VERSION}"
VIAddVersionKey /LANG=2052 "ProductVersion" "1.0.2"
; MUI end ------
Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
OutFile "setup-V${PRODUCT_FILE_VERSION}.exe"
InstallDir "$PROGRAMFILES\体尺测定设备数据上报服务"
InstallDirRegKey HKLM "${PRODUCT_DIR_REGKEY}" ""
ShowInstDetails show
ShowUnInstDetails show
Function .onInit
!insertmacro MUI_LANGDLL_DISPLAY
FunctionEnd
Function GetProgramDataDirFunc
System::Call 'Kernel32::GetEnvironmentVariable(t "ProgramData", t.r1, i ${NSIS_MAX_STRLEN})'
IfFileExists "$1\Tccdsjsc" +1 0
CreateDirectory "$1\Tccdsjsc"
StrCpy $PROGRAMDATA "$1\Tccdsjsc"
FunctionEnd
Function DeviceConfigPageInitFunc
Call GetProgramDataDirFunc
SendMessage $HWNDPARENT ${WM_SETTEXT} 0 "STR:设备信息配置"
!insertmacro MUI_HEADER_TEXT "配置设备信息" "设备编号及秘钥为随机生成,如果有需要可自行修改,已经安装过的无法再次修改,如需修改请联系开发者 "
nsDialogs::Create /NOUNLOAD 1018
Pop $HWND_DEVICE_CONFIG_DIALOG
${If} $HWND_DEVICE_CONFIG_DIALOG == error
Abort
${EndIf}
GetDlgItem $HWND_DEVICE_CONFIG_DIALOG_NEXT_BUTTON $HWNDPARENT 1
EnableWindow $HWND_DEVICE_CONFIG_DIALOG_NEXT_BUTTON 0
ReadINIStr $1 "$PROGRAMDATA\config.ini" "device" "devicecode"
ReadINIStr $2 "$PROGRAMDATA\config.ini" "device" "devicesecretkey"
ReadINIStr $3 "$PROGRAMDATA\config.ini" "http" "domain"
ReadINIStr $4 "$PROGRAMDATA\config.ini" "device" "devicearea"
StrCmp $1 "" 0 +4
Crypto::RNG
Pop $1
StrCpy $1 "$1" 16
StrCmp $2 "" 0 +4
Crypto::RNG
Pop $2
StrCpy $2 "$2" 16
StrCmp $3 "" 0 +1
StrCpy $3 "http://cloud.huamutech.cn"
${NSD_CreateGroupBox} 0 0 100% 30u "设备编号"
${NSD_CreateText} 2% 11u 96% 13u "$1"
Pop $HWND_DEVICE_CONFIG_DIALOG_TEXT_CODE
${NSD_OnChange} $HWND_DEVICE_CONFIG_DIALOG_TEXT_CODE CheckDeviceConfigDialogInputFields
${NSD_CreateGroupBox} 0 32u 100% 30u "设备秘钥"
${NSD_CreateText} 2% 43u 96% 13u "$2"
Pop $HWND_DEVICE_CONFIG_DIALOG_TEXT_PASSWORD
${NSD_OnChange} $HWND_DEVICE_CONFIG_DIALOG_TEXT_PASSWORD CheckDeviceConfigDialogInputFields
${NSD_CreateGroupBox} 0 64u 100% 30u "接口地址"
${NSD_CreateText} 2% 75u 96% 13u "$3"
Pop $HWND_DEVICE_CONFIG_DIALOG_TEXT_DOMAIN
${NSD_OnChange} $HWND_DEVICE_CONFIG_DIALOG_TEXT_DOMAIN CheckDeviceConfigDialogInputFields
${NSD_CreateGroupBox} 0 96u 100% 30u "所属地区"
${NSD_CreateText} 2% 107u 96% 13u "$4"
Pop $HWND_DEVICE_CONFIG_DIALOG_TEXT_AREA
${NSD_OnChange} $HWND_DEVICE_CONFIG_DIALOG_TEXT_AREA CheckDeviceConfigDialogInputFields
Call CheckDeviceConfigDialogInputFields
nsDialogs::Show
FunctionEnd
Function CheckDeviceConfigDialogInputFields
${NSD_GetText} $HWND_DEVICE_CONFIG_DIALOG_TEXT_CODE $R1
${NSD_GetText} $HWND_DEVICE_CONFIG_DIALOG_TEXT_PASSWORD $R2
${NSD_GetText} $HWND_DEVICE_CONFIG_DIALOG_TEXT_DOMAIN $R3
${NSD_GetText} $HWND_DEVICE_CONFIG_DIALOG_TEXT_AREA $R4
StrCmp $R1 "" +4 0
StrCmp $R2 "" +3 0
StrCmp $R3 "" +2 0
StrCmp $R4 "" 0 +2
Goto Disable
Goto Enable
Enable:
EnableWindow $HWND_DEVICE_CONFIG_DIALOG_NEXT_BUTTON 1
Return
Disable:
EnableWindow $HWND_DEVICE_CONFIG_DIALOG_NEXT_BUTTON 0
Return
FunctionEnd
Function DeviceConfigPageLeaveFunc
${NSD_GetText} $HWND_DEVICE_CONFIG_DIALOG_TEXT_CODE $R1
${NSD_GetText} $HWND_DEVICE_CONFIG_DIALOG_TEXT_PASSWORD $R2
${NSD_GetText} $HWND_DEVICE_CONFIG_DIALOG_TEXT_DOMAIN $R3
${NSD_GetText} $HWND_DEVICE_CONFIG_DIALOG_TEXT_AREA $R4
WriteIniStr "$PROGRAMDATA\config.ini" "device" "devicecode" "$R1"
WriteIniStr "$PROGRAMDATA\config.ini" "device" "devicesecretkey" "$R2"
WriteIniStr "$PROGRAMDATA\config.ini" "http" "domain" "$R3"
WriteIniStr "$PROGRAMDATA\config.ini" "device" "devicearea" "$R4"
FunctionEnd
Function DataConfigPageInitFunc
SendMessage $HWNDPARENT ${WM_SETTEXT} 0 "STR:数据目录配置"
!insertmacro MUI_HEADER_TEXT "选择数据目录" "选择体尺数据文件目录、数据上传日志目录、数据备份目录,数据备份目录建议选择C盘以外的磁盘 "
nsDialogs::Create /NOUNLOAD 1018
Pop $HWND_DATA_CONFIG_DIALOG
${If} $HWND_DATA_CONFIG_DIALOG == error
Abort
${EndIf}
GetDlgItem $HWND_DATA_CONFIG_DIALOG_NEXT_BUTTON $HWNDPARENT 1
EnableWindow $HWND_DATA_CONFIG_DIALOG_NEXT_BUTTON 0
ReadINIStr $1 "$PROGRAMDATA\config.ini" "device" "datapath"
ReadINIStr $2 "$PROGRAMDATA\config.ini" "device" "databackuppath"
ReadINIStr $3 "$PROGRAMDATA\config.ini" "service" "log"
${NSD_CreateGroupBox} 0 0 100% 30u "数据目录"
${NSD_CreateDirRequest} 2% 11u 80% 13u "$1"
Pop $HWND_DATA_CONFIG_DIALOG_DIR_DATA
${NSD_OnChange} $HWND_DATA_CONFIG_DIALOG_DIR_DATA CheckDataConfigDialogInputFields
${NSD_CreateBrowseButton} 83% 10u 15% 16u "浏览..."
Pop $R1
${NSD_OnClick} $R1 OnBrowseForDataDir
${NSD_CreateGroupBox} 0 32u 100% 30u "日志目录"
${NSD_CreateDirRequest} 2% 43u 80% 13u "$2"
Pop $HWND_DATA_CONFIG_DIALOG_DIR_LOG
${NSD_OnChange} $HWND_DATA_CONFIG_DIALOG_DIR_LOG CheckDataConfigDialogInputFields
${NSD_CreateBrowseButton} 83% 42u 15% 16u "浏览..."
Pop $R2
${NSD_OnClick} $R2 OnBrowseForLogDir
${NSD_CreateGroupBox} 0 64u 100% 30u "备份目录"
${NSD_CreateDirRequest} 2% 75u 80% 13u "$3"
Pop $HWND_DATA_CONFIG_DIALOG_DIR_BACKUP
${NSD_OnChange} $HWND_DATA_CONFIG_DIALOG_DIR_BACKUP CheckDataConfigDialogInputFields
${NSD_CreateBrowseButton} 83% 74u 15% 16u "浏览..."
Pop $R3
${NSD_OnClick} $R3 OnBrowseForBackUpDir
Call CheckDataConfigDialogInputFields
nsDialogs::Show
FunctionEnd
Function CheckDataConfigDialogInputFields
${NSD_GetText} $HWND_DATA_CONFIG_DIALOG_DIR_DATA $R1
${NSD_GetText} $HWND_DATA_CONFIG_DIALOG_DIR_LOG $R2
${NSD_GetText} $HWND_DATA_CONFIG_DIALOG_DIR_BACKUP $R3
StrCmp $R1 "" +3 0
StrCmp $R2 "" +2 0
StrCmp $R3 "" 0 +2
Goto Disable
Goto Enable
Enable:
EnableWindow $HWND_DATA_CONFIG_DIALOG_NEXT_BUTTON 1
Return
Disable:
EnableWindow $HWND_DATA_CONFIG_DIALOG_NEXT_BUTTON 0
Return
FunctionEnd
Function OnBrowseForDataDir
${NSD_GetText} $HWND_DATA_CONFIG_DIALOG_DIR_DATA $R0
nsDialogs::SelectFolderDialog /NOUNLOAD "选择数据目录,数据上传时需要读取数据文件" "$R0"
Pop $0
${If} $0 == error
${Else}
${NSD_SetText} $HWND_DATA_CONFIG_DIALOG_DIR_DATA $0
${EndIf}
FunctionEnd
Function OnBrowseForLogDir
${NSD_GetText} $HWND_DATA_CONFIG_DIALOG_DIR_LOG $R0
nsDialogs::SelectFolderDialog /NOUNLOAD "选择日志目录,用来存储数据上传服务产生的日志" "$R0"
Pop $0
${If} $0 == error
${Else}
${NSD_SetText} $HWND_DATA_CONFIG_DIALOG_DIR_LOG $0
${EndIf}
FunctionEnd
Function OnBrowseForBackUpDir
${NSD_GetText} $HWND_DATA_CONFIG_DIALOG_DIR_BACKUP $R0
nsDialogs::SelectFolderDialog /NOUNLOAD "选择备份目录,用来存储上传数据后备份的文件" "$R0"
Pop $0
${If} $0 == error
${Else}
${NSD_SetText} $HWND_DATA_CONFIG_DIALOG_DIR_BACKUP $0
${EndIf}
FunctionEnd
Function DataConfigPageLeaveFunc
${NSD_GetText} $HWND_DATA_CONFIG_DIALOG_DIR_DATA $R1
${NSD_GetText} $HWND_DATA_CONFIG_DIALOG_DIR_LOG $R2
${NSD_GetText} $HWND_DATA_CONFIG_DIALOG_DIR_BACKUP $R3
WriteIniStr "$PROGRAMDATA\config.ini" "device" "datapath" "$R1"
WriteIniStr "$PROGRAMDATA\config.ini" "device" "databackuppath" "$R2"
WriteIniStr "$PROGRAMDATA\config.ini" "service" "log" "$R3"
FunctionEnd
Section "MainSection" SEC01
SetOutPath "$INSTDIR"
SetOverwrite ifnewer
File "..\dist\win-service.exe"
CreateDirectory "$SMPROGRAMS\体尺测定设备数据上报服务"
Call InstallService
SectionEnd
Section -AdditionalIcons
WriteIniStr "$INSTDIR\${PRODUCT_NAME}.url" "InternetShortcut" "URL" "${PRODUCT_WEB_SITE}"
CreateShortCut "$SMPROGRAMS\体尺测定设备数据上报服务\Website.lnk" "$INSTDIR\${PRODUCT_NAME}.url"
CreateShortCut "$SMPROGRAMS\体尺测定设备数据上报服务\Uninstall.lnk" "$INSTDIR\uninst.exe"
SectionEnd
Section -Post
WriteUninstaller "$INSTDIR\uninst.exe"
WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "" "$INSTDIR\win-service.exe"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayName" "$(^Name)"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "UninstallString" "$INSTDIR\uninst.exe"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayIcon" "$INSTDIR\win-service.exe"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayVersion" "${PRODUCT_VERSION}"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "URLInfoAbout" "${PRODUCT_WEB_SITE}"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "Publisher" "${PRODUCT_PUBLISHER}"
SectionEnd
Function InstallService
SimpleSC::ExistsService "${PRODUCT_SERVICE_NAME}"
Pop $0
${If} $0 == 0
Push $0
SimpleSc::ServiceIsRunning "${PRODUCT_SERVICE_NAME}"
Pop $0
Pop $1
${If} $0 == 0
Push $0
${If} $1 == 1
DetailPrint "正在停止 ${PRODUCT_SERVICE_DESC} ..."
SimpleSC::StopService "${PRODUCT_SERVICE_NAME}" 1 30
Pop $0
${If} $0 != 0
Push $0
SimpleSC::GetErrorMessage
Pop $0
MessageBox MB_OK|MB_ICONSTOP "${PRODUCT_SERVICE_DESC}关闭失败($0)"
${Else}
DetailPrint "正在删除 ${PRODUCT_SERVICE_DESC} ..."
SimpleSC::RemoveService "${PRODUCT_SERVICE_NAME}"
${EndIf}
${ElseIf} $1 == 0
DetailPrint "正在删除 ${PRODUCT_SERVICE_DESC} ..."
SimpleSC::RemoveService "${PRODUCT_SERVICE_NAME}"
${EndIf}
${ElseIf} $0 != 0
Push $0
SimpleSC::GetErrorMessage
Pop $0
MessageBox MB_OK|MB_ICONSTOP "检测${PRODUCT_SERVICE_DESC}是否正在运行失败($0)"
${EndIf}
${EndIf}
DetailPrint "正在安装 ${PRODUCT_SERVICE_DESC} ..."
SimpleSC::InstallService "${PRODUCT_SERVICE_NAME}" "${PRODUCT_SERVICE_DISPLAY_NAME}" "16" "2" '"$INSTDIR\win-service.exe" Tccdsjsc' "" "" ""
Pop $0
${If} $0 != 0
Push $0
SimpleSC::GetErrorMessage
Pop $0
MessageBox MB_OK|MB_ICONSTOP "${PRODUCT_SERVICE_DESC}安装失败($0),请手动注册"
${Else}
SimpleSC::SetServiceDescription "${PRODUCT_SERVICE_NAME}" "${PRODUCT_SERVICE_DESC}"
${EndIf}
${If} $0 == 0
DetailPrint "正在启动 ${PRODUCT_SERVICE_DESC} ..."
SimpleSC::StartService "${PRODUCT_SERVICE_NAME}" "" 30
Pop $0
${If} $0 != 0
Push $0
SimpleSC::GetErrorMessage
Pop $0
MessageBox MB_OK|MB_ICONSTOP "${PRODUCT_SERVICE_DESC}启动失败($0)"
${EndIf}
${EndIf}
FunctionEnd
Function un.UninstallService
SimpleSC::ExistsService "${PRODUCT_SERVICE_NAME}"
Pop $0
${If} $0 == 0
Push $0
SimpleSc::ServiceIsRunning "${PRODUCT_SERVICE_NAME}"
Pop $0
Pop $1
${If} $0 == 0
Push $0
${If} $1 == 1
DetailPrint "正在停止 ${PRODUCT_SERVICE_DESC} ..."
SimpleSC::StopService "${PRODUCT_SERVICE_NAME}" 1 30
Pop $0
${If} $0 != 0
Push $0
SimpleSC::GetErrorMessage
Pop $0
MessageBox MB_OK|MB_ICONSTOP "${PRODUCT_SERVICE_DESC}服务关闭失败($0)"
${Else}
DetailPrint "正在删除 ${PRODUCT_SERVICE_DESC} ..."
SimpleSC::RemoveService "${PRODUCT_SERVICE_NAME}"
${EndIf}
${ElseIf} $1 == 0
DetailPrint "正在删除 ${PRODUCT_SERVICE_DESC} ..."
SimpleSC::RemoveService "${PRODUCT_SERVICE_NAME}"
${EndIf}
${ElseIf} $0 != 0
Push $0
SimpleSC::GetErrorMessage
Pop $0
MessageBox MB_OK|MB_ICONSTOP "检测${PRODUCT_SERVICE_DESC}是否正在运行失败($0)"
${EndIf}
${EndIf}
FunctionEnd
Function un.onUninstSuccess
HideWindow
MessageBox MB_ICONINFORMATION|MB_OK "$(^Name) 已成功地从你的计算机移除。"
FunctionEnd
Function un.onInit
!insertmacro MUI_UNGETLANGUAGE
MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "你确实要完全移除 $(^Name) ,其及所有的组件?" IDYES +2
Abort
FunctionEnd
Section Uninstall
Call un.UninstallService
Delete "$INSTDIR\${PRODUCT_NAME}.url"
Delete "$INSTDIR\uninst.exe"
Delete "$INSTDIR\win-service.exe"
Delete "$SMPROGRAMS\体尺测定设备数据上报服务\Uninstall.lnk"
Delete "$SMPROGRAMS\体尺测定设备数据上报服务\Website.lnk"
Delete "$DESKTOP\体尺测定设备数据上报服务.lnk"
Delete "$SMPROGRAMS\体尺测定设备数据上报服务\体尺测定设备数据上报服务.lnk"
RMDir "$SMPROGRAMS\体尺测定设备数据上报服务"
RMDir "$INSTDIR"
DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
DeleteRegKey HKLM "${PRODUCT_DIR_REGKEY}"
SetAutoClose true
SectionEnd
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/chbchenhongbin/common-tools.git
git@gitee.com:chbchenhongbin/common-tools.git
chbchenhongbin
common-tools
常用工具
master

搜索帮助