; Script generated by the HM NIS Edit Script Wizard.

; HM NIS Edit Wizard helper defines
!define PRODUCT_NAME "scbc application"
!define PRODUCT_VERSION "2.0.1.6"
!define PRODUCT_PUBLISHER "tcl company, Inc."
!define PRODUCT_WEB_SITE "http://www.tcl.com"
!define PRODUCT_DIR_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\TCL Tools.exe"
!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
!define PRODUCT_UNINST_ROOT_KEY "HKLM"

Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
OutFile "Setup${PRODUCT_VERSION}.exe"
LoadLanguageFile "${NSISDIR}\Contrib\Language files\English.nlf"
LoadLanguageFile "${NSISDIR}\Contrib\Language files\SimpChinese.nlf"
InstallDir "$PROGRAMFILES\scbc application"
Icon "${NSISDIR}\Contrib\Graphics\Icons\orange-install.ico"
UninstallIcon "${NSISDIR}\Contrib\Graphics\Icons\orange-uninstall.ico"
InstallDirRegKey HKLM "${PRODUCT_DIR_REGKEY}" ""
DirText "安装程序将安装 $(^Name) 在下列文件夹。$\r$\n$\r$\n要安装在不同文件夹，单击 [浏览] 并选择其他文件夹。"
LicenseText "如果你接受所有协议条款，选择 [我愿意] 继续。你必须接受协议才能安装 $(^Name)。."
LicenseData "Licence.txt"
ShowInstDetails show
ShowUnInstDetails show


; 安装VC环境
Function InstallVC
   Push $R0
   ClearErrors
   ;FF66E9F6-83E7-3A3E-AF14-8DE9A809A6A4 Visual C++ 2008 runtime files VC 9.0 (x86)
   ;9A25302D-30C0-39D9-BD6F-21E6EC160475 Visual C++ 2008 SP1 runtime files VC 9.0 SP1 (x86) 
   ;f50edb7e-c25e-47b4-bc4f-7ec4a4d256b1 Visual C++ 2017 runtime files VC 9.0 SP1 (x86) 
   ;ad831ec0-6a55-427f-b75b-341c827ce380 Visual C++ ??? runtime files VC 9.0 SP1 (x86)
   ; vs2008
   ;ReadRegDword $R0 HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{9A25302D-30C0-39D9-BD6F-21E6EC160475}" "Version"
   ; vs2017
   ;ReadRegDword $R0 HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{ad831ec0-6a55-427f-b75b-341c827ce380}" "Version"
   ; vs2019
   ReadRegDword $R0 HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{5bfc1380-fd35-4b85-9715-7351535d077e}" "Version"

   ; 检测含有vc的注册表信息是否存在
   IfErrors 0 VSRedistInstalled
   Exec "$INSTDIR\vcredist_x86.exe /q"   ;若不存在，执行静默安装
   StrCpy $R0 "-1" 
   ; MessageBox MB_OK  $R0 

VSRedistInstalled:
   ; MessageBox MB_OK  "已安装" 
   Exch $R0
 ; Delete "$INSTDIR\vcredist_x86." 
FunctionEnd

Function .onInit
FunctionEnd

Section "MainSection" SEC01
  SetOutPath "$INSTDIR"
  ;覆盖旧文件;
  SetOverwrite ifnewer
  File "..\..\..\..\bin\TCL Copy Tool\TCL Copy Tool.exe"
  File "lib\Log4C.dll"
  File "lib\libcurl.dll"
  File "lib\libeay32.dll"
  File "lib\ssleay32.dll"
  File "lib\zlibwapi.dll"
  File "log4crc.xml"
  File "vcredist_x86.exe"
  Delete "$INSTDIR\TCL Tools.exe"
  CreateDirectory "$SMPROGRAMS\scbc application"
  CreateShortCut "$SMPROGRAMS\scbc application\scbc application.lnk" "$INSTDIR\TCL Copy Tool.exe"
  CreateShortCut "$DESKTOP\scbc application.lnk" "$INSTDIR\TCL Copy Tool.exe"
  File "..\..\..\..\bin\rename\rename.exe"
  ;不覆盖config.ini配置文件;
  SetOverwrite off
  File "TCL Copy Tool\config.json"
  SetOutPath "$INSTDIR\log"
  SetOutPath "$INSTDIR\db"
  SetOutPath "$INSTDIR\DataDir"
  SetOutPath "$INSTDIR\DataDir\WB"
  SetOutPath "$INSTDIR\DataDir\CIKEY"
  SetOutPath "$INSTDIR\DataDir\DeviceID"
  SetOutPath "$INSTDIR\DataDir\ESN"
  SetOutPath "$INSTDIR\DataDir\HDCPKEY"
  SetOutPath "$INSTDIR\DataDir\HDCPKEY22"
  SetOutPath "$INSTDIR\DataDir\MAC"
  SetOutPath "$INSTDIR\DataDir\Widevine"
  SetOutPath "$INSTDIR\DataDir\WiDi"
  ;安装VC环境
  Call InstallVC
SectionEnd

Section -AdditionalIcons
  WriteIniStr "$INSTDIR\${PRODUCT_NAME}.url" "InternetShortcut" "URL" "${PRODUCT_WEB_SITE}"
  CreateShortCut "$SMPROGRAMS\scbc application\Website.lnk" "$INSTDIR\${PRODUCT_NAME}.url"
  CreateShortCut "$SMPROGRAMS\scbc application\Uninstall.lnk" "$INSTDIR\uninst.exe"
SectionEnd

Section -Post
  WriteUninstaller "$INSTDIR\uninst.exe"
  WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "" "$INSTDIR\TCL Copy Tool.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\TCL Tools.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 un.onUninstSuccess
  HideWindow
  MessageBox MB_ICONINFORMATION|MB_OK "$(^Name) 已成功地从你的计算机移除。"
FunctionEnd

Function un.onInit
  MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "你确实要完全移除 $(^Name) ，其及所有的组件？" IDYES +2
  Abort
FunctionEnd

Section Uninstall
  Delete "$INSTDIR\${PRODUCT_NAME}.url"
  Delete "$INSTDIR\uninst.exe"
  Delete "$INSTDIR\rename.exe"
  Delete "$INSTDIR\TCL Copy Tool.exe"
  Delete "$INSTDIR\config.json"
  Delete "$INSTDIR\Log4C.dll"

  Delete "$SMPROGRAMS\scbc application\Uninstall.lnk"
  Delete "$SMPROGRAMS\scbc application\Website.lnk"
  Delete "$DESKTOP\scbc application.lnk"
  Delete "$SMPROGRAMS\scbc application\scbc application.lnk"

  RMDir "$SMPROGRAMS\scbc application"
  RMDir "$INSTDIR"

  DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
  DeleteRegKey HKLM "${PRODUCT_DIR_REGKEY}"
  SetAutoClose true
SectionEnd