; Script generated by the HM NIS Edit Script Wizard. !searchparse /noerrors /file ..\..\lib\common\utils.py 'VERSION = ' VERSION ; HM NIS Edit Wizard helper defines !define PRODUCT_NAME "cabernet" !define PRODUCT_VERSION ${VERSION} !define PRODUCT_PUBLISHER "rocky4546" !define PRODUCT_WEB_SITE "https://github.com/cabernetwork/cabernet" !define PRODUCT_DIR_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\tvh_main.py" !define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" !define PRODUCT_UNINST_ROOT_KEY "HKLM" !define PRODUCT_STARTMENU_REGVAL "NSIS:StartMenuDir" ; MultiUser variables for single user and admin installs !define MULTIUSER_EXECUTIONLEVEL Highest !define MULTIUSER_INSTALLMODE_INSTDIR "${PRODUCT_NAME}" !define MULTIUSER_MUI !define MULTIUSER_INSTALLMODE_COMMANDLINE !define MULTIUSER_INSTALLMODE_FUNCTION onMultiUserModeChanged ; MUI 1.67 compatible ------ !addplugindir '.\Plugins\inetc\Plugins\x86-unicode' !include "MUI.nsh" !include "MultiUser.nsh" !include "MUI2.nsh" !include nsDialogs.nsh !include "TvhLib.nsh" ; MUI Settings !define MUI_ABORTWARNING !define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\modern-install.ico" !define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\modern-uninstall.ico" ; Welcome page !insertmacro MUI_PAGE_WELCOME ;!define MUI_PAGE_CUSTOMFUNCTION_PRE LicenseFiles !insertmacro MULTIUSER_PAGE_INSTALLMODE ; License page !insertmacro MUI_PAGE_LICENSE "../../LICENSE" ; Directory page !insertmacro MUI_PAGE_DIRECTORY ; get data folder Page custom DataFolderPage DataFolderPageLeave ; Components page !define MUI_PAGE_CUSTOMFUNCTION_PRE TestPython !insertmacro MUI_PAGE_COMPONENTS ; Start menu page var ICONS_GROUP !define MUI_STARTMENUPAGE_NODISABLE !define MUI_STARTMENUPAGE_DEFAULTFOLDER "${PRODUCT_NAME}" !define MUI_STARTMENUPAGE_REGISTRY_ROOT "${PRODUCT_UNINST_ROOT_KEY}" !define MUI_STARTMENUPAGE_REGISTRY_KEY "${PRODUCT_UNINST_KEY}" !define MUI_STARTMENUPAGE_REGISTRY_VALUENAME "${PRODUCT_STARTMENU_REGVAL}" !insertmacro MUI_PAGE_STARTMENU Application $ICONS_GROUP ; Instfiles page !insertmacro MUI_PAGE_INSTFILES ; Finish page !define MUI_FINISHPAGE_SHOWREADME "$INSTDIR\README.txt" !insertmacro MUI_PAGE_FINISH ; Uninstaller pages !insertmacro MUI_UNPAGE_INSTFILES ; Language files !insertmacro MUI_LANGUAGE "English" ; MUI end ------ Name "${PRODUCT_NAME}-${PRODUCT_VERSION}" OutFile "${PRODUCT_NAME}-${PRODUCT_VERSION}.exe" InstallDir "$PROGRAMFILES64\${PRODUCT_NAME}" InstallDirRegKey HKLM "${PRODUCT_DIR_REGKEY}" "" ShowInstDetails show ShowUnInstDetails show Section "Install Python3" SEC01 SetOutPath "$INSTDIR" SetOverwrite ifnewer inetc::get /BANNER "Python3 download in progress..." \ "https://www.python.org/ftp/python/3.9.5/python-3.9.5-amd64.exe" \ "$TEMP\python.exe" /END Pop $0 StrCmp $0 "OK" dlok MessageBox MB_OK|MB_ICONEXCLAMATION "ERROR::HTTP Download Error while trying to download Python, $\r$\n\ $0$\r$\n\ Click OK to abort installation" /SD IDOK Abort dlok: nsExec::ExecToStack $pythoninstall Pop $0 ;return value Pop $1 ; status text IntCmp $0 0 PythonDone MessageBox MB_OK "Python not installed status:$0, Aborting" Abort PythonDone: DELETE "$TEMP\python.exe" Call TestPythonSilent ${If} $pythonpath == "" MessageBox MB_OK "Please restart the installer to pick up the python installation, Aborting" Abort ${EndIf} SectionEnd Function ClearPythonInstallFlag SectionSetFlags ${SEC01} 0 # python install section FunctionEnd Section "MainSection" SEC02 SetOutPath "$INSTDIR" SetOverwrite ifnewer Call AddFiles Call UpdateConfig ; Shortcuts !insertmacro MUI_STARTMENU_WRITE_BEGIN Application CreateDirectory "$SMPROGRAMS\$ICONS_GROUP" SetOutPath "$INSTDIR" CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\cabernet.lnk" "$INSTDIR\tvh_main.py" SetOutPath "$INSTDIR" ; CreateShortCut "$DESKTOP\cabernet.lnk" "$INSTDIR\tvh_main.py" !insertmacro MUI_STARTMENU_WRITE_END SectionEnd Section "Windows Service" SEC03 SetOutPath "$INSTDIR" SetOverwrite ifnewer Call InstallService SectionEnd Section "Install FFMPEG" SEC04 SetOutPath "$INSTDIR" SetOverwrite ifnewer inetc::get /BANNER "FFMPEG download in progress..." \ "https://www.gyan.dev/ffmpeg/builds/ffmpeg-release-essentials.zip" \ "$TEMP\ffmpeg.zip" /END Pop $0 StrCmp $0 "OK" dlok MessageBox MB_OK|MB_ICONEXCLAMATION "ERROR::HTTP Download Error while trying to download FFMPEG, $\r$\n\ $0$\r$\n\ Click OK to abort installation" /SD IDOK Abort dlok: StrCpy $cmd 'powershell expand-archive \"$TEMP\ffmpeg.zip\" \"$TEMP\ffmpeg\"' nsExec::ExecToStack '$cmd' Pop $0 ;return value Pop $1 ; status text ;MessageBox MB_OK "FFMPEG Extract Status:$0 $1" StrCpy $subfolder "$TEMP\ffmpeg\ffmpeg*.*" Call GetSubfolder StrCmp $subfolder "" empty CopyFiles "$TEMP\ffmpeg\$subfolder\bin\*.exe" "$INSTDIR\ffmpeg\bin" CopyFiles "$TEMP\ffmpeg\$subfolder\LICENSE" "$INSTDIR\ffmpeg" CopyFiles "$TEMP\ffmpeg\$subfolder\README.txt" "$INSTDIR\ffmpeg" ; if subfolder is not found, then do nothing empty: DELETE "$TEMP\ffmpeg.zip" RMDIR /r "$TEMP\ffmpeg\*.*" RMDIR "$TEMP\ffmpeg" SetOutPath "$INSTDIR" SectionEnd Section -AdditionalIcons !insertmacro MUI_STARTMENU_WRITE_BEGIN Application WriteIniStr "$INSTDIR\${PRODUCT_NAME}.url" "InternetShortcut" "URL" "${PRODUCT_WEB_SITE}" CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\Website.lnk" "$INSTDIR\${PRODUCT_NAME}.url" CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\Uninstall.lnk" "$INSTDIR\uninst.exe" !insertmacro MUI_STARTMENU_WRITE_END SectionEnd Section -Post WriteUninstaller "$INSTDIR\uninst.exe" WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "" "$INSTDIR\main.py" 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\main.py" 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 ; Section descriptions !insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN !insertmacro MUI_DESCRIPTION_TEXT ${SEC01} "Installs python for all users. Required for the Windows Service" !insertmacro MUI_DESCRIPTION_TEXT ${SEC02} "Installs the base app" !insertmacro MUI_DESCRIPTION_TEXT ${SEC03} "Adds a Windows Service using nssm." !insertmacro MUI_DESCRIPTION_TEXT ${SEC04} "Installs ffmpeg in app folder. Currently required for most providers" !insertmacro MUI_FUNCTION_DESCRIPTION_END Function onMultiUserModeChanged ${If} $MultiUser.InstallMode == "CurrentUser" StrCpy $INSTDIR "$LocalAppdata\Programs\${MULTIUSER_INSTALLMODE_INSTDIR}" StrCpy $pythoninstall '$TEMP\python.exe InstallAllUsers=0 PrependPath=1' SectionSetFlags ${SEC03} 16 ${Else} StrCpy $INSTDIR "$PROGRAMFILES64\${PRODUCT_NAME}" StrCpy $pythoninstall '$TEMP\python.exe InstallAllUsers=1 PrependPath=1' SectionSetFlags ${SEC03} 1 ${EndIf} FunctionEnd Function .onInit StrCpy $DataFolder "C:\Windows\system32\config\systemprofile\Documents\cabernet" !insertmacro MULTIUSER_INIT SectionSetFlags ${SEC02} 17 # main section ;SectionSetFlags ${SEC04} 0 # ffmpeg section, able to select, but not selected SectionSetFlags ${SEC04} 1 # main section FunctionEnd Function un.onInit Var /GLOBAL remove_all !insertmacro MULTIUSER_UNINIT MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "Are you sure you want to completely remove $(^Name)?" IDYES +2 Abort MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "Do you want to remove all data and plugins?" IDYES true2 StrCpy $remove_all "0" Goto end2 true2: StrCpy $remove_all "1" end2: FunctionEnd Function un.onUninstSuccess HideWindow MessageBox MB_ICONINFORMATION|MB_OK "$(^Name) was successfully removed from your computer." FunctionEnd Section Uninstall !insertmacro MUI_STARTMENU_GETFOLDER "Application" $ICONS_GROUP ${If} $MultiUser.InstallMode != "CurrentUser" Call un.installService ${EndIf} ${If} $remove_all == "1" RMDIR /r "$INSTDIR\*.*" ${Else} #Delete Cabernet folders RMDIR /r "$INSTDIR\build" RMDIR /r "$INSTDIR\lib" RMDIR /r "$INSTDIR\plugins" #Delete Cabernet files Delete "$INSTDIR\CHANGE*.*" Delete "$INSTDIR\Dock*" Delete "$INSTDIR\LIC*" Delete "$INSTDIR\READ*.*" Delete "$INSTDIR\req*.*" Delete "$INSTDIR\tvh*.*" Delete "$INSTDIR\uninst.exe" Delete "$INSTDIR\${PRODUCT_NAME}.url" ${EndIf} Delete "$SMPROGRAMS\$ICONS_GROUP\Uninstall.lnk" Delete "$SMPROGRAMS\$ICONS_GROUP\Website.lnk" Delete "$DESKTOP\cabernet.lnk" Delete "$SMPROGRAMS\$ICONS_GROUP\cabernet.lnk" RMDir "$SMPROGRAMS\$ICONS_GROUP" ${If} $remove_all == "1" RMDir "$INSTDIR" ${EndIf} DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" DeleteRegKey HKLM "${PRODUCT_DIR_REGKEY}" SetAutoClose true SectionEnd ; git ignore ; verify git status