jellyfin.nsi 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. ; Shows a lot of debug information while compiling
  2. ; This can be removed once stable.
  3. !verbose 4
  4. ;--------------------------------
  5. ;Include Modern UI
  6. !include "MUI2.nsh"
  7. Var _JELLYFINVERSION_
  8. ; Var _DEFAULTEMBYDATADIR_
  9. Var _JELLYFINDATADIR_
  10. Var _SERVICEINSTALLED_
  11. Var _EXISTINGINSTALLATION_
  12. Var _EXISTINGSERVICE_
  13. ;--------------------------------
  14. ;General
  15. ; Align installer version with jellyfin.dll version
  16. !getdllversion "$%InstallLocation%\jellyfin.dll" ver_
  17. !echo "jellyfin.dll version is ${ver_1}.${ver_2}.${ver_3}.${ver_4}" ;!echo will print it while building
  18. Name "Jellyfin ${ver_1}.${ver_2}.${ver_3}.${ver_4}"
  19. OutFile "Jellyfin.Installer.${ver_1}.${ver_2}.${ver_3}.${ver_4}.exe"
  20. BrandingText "Jellyfin ${ver_1}.${ver_2}.${ver_3}.${ver_4} Installer"
  21. ; installer attributes
  22. VIProductVersion "${ver_1}.${ver_2}.${ver_3}.${ver_4}"
  23. VIFileVersion "${ver_1}.${ver_2}.${ver_3}.${ver_4}"
  24. VIAddVersionKey "ProductName" "Jellyfin"
  25. VIAddVersionKey "FileVersion" "${ver_1}.${ver_2}.${ver_3}.${ver_4}"
  26. VIAddVersionKey "LegalCopyright" "Jellyfin, Free Software Media System"
  27. VIAddVersionKey "FileDescription" "Jellyfin, Free Software Media System"
  28. ;Default installation folder
  29. InstallDir "$APPDATA\Jellyfin"
  30. ;Get installation folder from registry if available
  31. InstallDirRegKey HKLM "Software\Jellyfin" "InstallLocation"
  32. ;Request application privileges for service installation
  33. RequestExecutionLevel admin
  34. CRCCheck on
  35. !define MUI_ABORTWARNING
  36. ;--------------------------------
  37. ;Pages
  38. !insertmacro MUI_PAGE_LICENSE "$%InstallLocation%\LICENSE"
  39. !insertmacro MUI_PAGE_COMPONENTS
  40. !define MUI_PAGE_CUSTOMFUNCTION_PRE HideDirectoryPage
  41. !insertmacro MUI_PAGE_DIRECTORY
  42. ; Custom Directory page to ask for Emby Library location in case its needed
  43. ; Commented for now to avoid showing this.
  44. ; This can be uncommented in case Emby Migration is planned later
  45. ; !define MUI_PAGE_HEADER_TEXT "Emby Library locaton"
  46. ; !define MUI_PAGE_HEADER_SUBTEXT ""
  47. ; !define MUI_DIRECTORYPAGE_TEXT_TOP "Please select the folder where Emby library is present. This will have Enby folders like config, cache, data, metadata, etc."
  48. ; !define MUI_DIRECTORYPAGE_TEXT_DESTINATION "Emby Library location"
  49. ; !define MUI_PAGE_CUSTOMFUNCTION_PRE ShowEmbyLibraryPage
  50. ; !define MUI_DIRECTORYPAGE_VARIABLE $_DEFAULTEMBYDATADIR_
  51. ; !insertmacro MUI_PAGE_DIRECTORY
  52. !insertmacro MUI_PAGE_INSTFILES
  53. !insertmacro MUI_UNPAGE_CONFIRM
  54. !insertmacro MUI_UNPAGE_INSTFILES
  55. ;--------------------------------
  56. ;Languages
  57. !insertmacro MUI_LANGUAGE "English"
  58. ;--------------------------------
  59. ;Installer Sections
  60. Section "Install Jellyfin (required)" InstallJellyfin
  61. StrCmp $_EXISTINGINSTALLATION_ "YES" CheckService CarryOn
  62. CheckService:
  63. StrCmp $_EXISTINGSERVICE_ "YES" StopService ExistingInstallButNotService
  64. StopService: ; we stop the service to copy files in use
  65. ExecWait '"$INSTDIR\nssm.exe" stop Jellyfin' $0
  66. DetailPrint "Jellyfin service stop, $0"
  67. ExistingInstallButNotService:
  68. ;TODO, find a way to kill the process in case it was started as standalone
  69. MessageBox MB_OK|MB_ICONINFORMATION "Please stop Jellyfin manually before proceeding further."
  70. CarryOn:
  71. SetOutPath "$INSTDIR"
  72. SetShellVarContext current
  73. StrCpy $_JELLYFINDATADIR_ "$LOCALAPPDATA\jellyfin\"
  74. ; Pack all the files that were just compiled
  75. File /r $%InstallLocation%\*
  76. ; Write the installation path into the registry
  77. WriteRegStr HKLM "Software\Jellyfin" "InstallLocation" "$INSTDIR"
  78. ; Write the uninstall keys for Windows
  79. WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Jellyfin" "DisplayName" "Jellyfin $_JELLYFINVERSION_"
  80. WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Jellyfin" "UninstallString" '"$INSTDIR\Uninstall.exe"'
  81. WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Jellyfin" "DisplayIcon" '"$INSTDIR\Jellyfin.exe",0'
  82. WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Jellyfin" "Publisher" "The Jellyfin project"
  83. WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Jellyfin" "URLInfoAbout" "https://jellyfin.github.io/"
  84. WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Jellyfin" "DisplayVersion" "$_JELLYFINVERSION_"
  85. WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Jellyfin" "NoModify" 1
  86. WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Jellyfin" "NoRepair" 1
  87. ;Create uninstaller
  88. WriteUninstaller "$INSTDIR\Uninstall.exe"
  89. SectionEnd
  90. Section /o "Jellyfin desktop shortcut" DesktopShortcut
  91. SetShellVarContext current
  92. DetailPrint "Creating desktop shortcut"
  93. CreateShortCut "$DESKTOP\Jellyfin.lnk" "$INSTDIR\jellyfin.exe"
  94. SectionEnd
  95. Section /o "Jellyfin Service" InstallService
  96. ExecWait '"$INSTDIR\nssm.exe" install Jellyfin "$INSTDIR\jellyfin.exe" --datadir "$_JELLYFINDATADIR_"' $0
  97. DetailPrint "Jellyfin Service install, $0"
  98. Sleep 3000
  99. ExecWait '"$INSTDIR\nssm.exe" set Jellyfin Start SERVICE_DELAYED_AUTO_START' $0
  100. DetailPrint "Jellyfin Service setting, $0"
  101. StrCpy $_SERVICEINSTALLED_ "YES"
  102. SectionEnd
  103. Section /o "Start Jellyfin after installation" LaunchJellyfin
  104. ; either start the service or launch jellyfin standalone
  105. StrCmp $_SERVICEINSTALLED_ "YES" ServiceStart Standalone
  106. ServiceStart:
  107. ExecWait '"$INSTDIR\nssm.exe" start Jellyfin' $0
  108. DetailPrint "Jellyfin service start, $0"
  109. Return
  110. Standalone:
  111. ExecWait '"$INSTDIR\jellyfin.exe"' $0
  112. DetailPrint "$INSTDIR\jellyfin.exe start, $0"
  113. Return
  114. SectionEnd
  115. ; This can be uncommented in case Emby Migration is planned later
  116. ;Section /o "Migrate Emby Library" MigrateEmbyLibrary
  117. ; DetailPrint "Migrating Emby Library"
  118. ; CopyFiles $_DEFAULTEMBYDATADIR_/config $_JELLYFINDATADIR_
  119. ; CopyFiles $_DEFAULTEMBYDATADIR_/cache $_JELLYFINDATADIR_
  120. ; CopyFiles $_DEFAULTEMBYDATADIR_/data $_JELLYFINDATADIR_
  121. ; CopyFiles $_DEFAULTEMBYDATADIR_/metadata $_JELLYFINDATADIR_
  122. ; CopyFiles $_DEFAULTEMBYDATADIR_/root $_JELLYFINDATADIR_
  123. ;SectionEnd
  124. ;--------------------------------
  125. ;Descriptions
  126. ;Language strings
  127. LangString DESC_InstallJellyfin ${LANG_ENGLISH} "Install Jellyfin"
  128. LangString DESC_InstallService ${LANG_ENGLISH} "Install As a Service"
  129. LangString DESC_DesktopShortcut ${LANG_ENGLISH} "Create a desktop shortcut"
  130. LangString DESC_LaunchJellyfin ${LANG_ENGLISH} "Start Jellyfin after Install"
  131. ; LangString DESC_MigrateEmbyLibrary ${LANG_ENGLISH} "Migrate existing Emby Library"
  132. ;Assign language strings to sections
  133. !insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
  134. !insertmacro MUI_DESCRIPTION_TEXT ${InstallJellyfin} $(DESC_InstallJellyfin)
  135. !insertmacro MUI_DESCRIPTION_TEXT ${DesktopShortcut} $(DESC_DesktopShortcut)
  136. !insertmacro MUI_DESCRIPTION_TEXT ${InstallService} $(DESC_InstallService)
  137. !insertmacro MUI_DESCRIPTION_TEXT ${LaunchJellyfin} $(DESC_LaunchJellyfin)
  138. ; !insertmacro MUI_DESCRIPTION_TEXT ${MigrateEmbyLibrary} $(DESC_MigrateEmbyLibrary)
  139. !insertmacro MUI_FUNCTION_DESCRIPTION_END
  140. ;--------------------------------
  141. ;Uninstaller Section
  142. Section "Uninstall"
  143. SetShellVarContext current
  144. StrCpy $_JELLYFINDATADIR_ "$LOCALAPPDATA\jellyfin\"
  145. ; Currently we try to stop & remove a running service even if it doesn't exist
  146. ; not really sure about nssm statuscode detection method
  147. ; nothing to loose with brute force stop & remove method
  148. ExecWait '"$INSTDIR\nssm.exe" stop Jellyfin' $0
  149. DetailPrint "Jellyfin service stop, $0"
  150. ExecWait '"$INSTDIR\nssm.exe" remove Jellyfin confirm' $0
  151. DetailPrint "Jellyfin Service remove, $0"
  152. Delete "$INSTDIR\Uninstall.exe"
  153. ;TODO
  154. ; stop running instance gracefully, in case its running, the /REBOOTOK flag will delete it on reboot.
  155. RMDir /r /REBOOTOK "$INSTDIR" ;
  156. MessageBox MB_YESNO|MB_ICONINFORMATION "Do you want to retain Jellyfin settings ? The media will not be touched in any case." /SD IDYES IDYES PreserveData
  157. RMDir /r /REBOOTOK "$_JELLYFINDATADIR_"
  158. PreserveData:
  159. DeleteRegKey HKLM "Software\Jellyfin"
  160. DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Jellyfin"
  161. Delete "$DESKTOP\Jellyfin.lnk"
  162. SectionEnd
  163. Function .onInit
  164. StrCpy $_EXISTINGINSTALLATION_ "NO"
  165. StrCpy $_EXISTINGSERVICE_ "NO"
  166. ;Detect if Jellyfin is already installed.
  167. ; In case it is installed, let the user choose either
  168. ; 1. Exit installer
  169. ; 2. Upgrade without messing with data
  170. ; 2a. Don't ask for any installation folder
  171. ; 2b. If there is a service, don't ask for service installation or launch
  172. ; 2c. If no service, ask for autolaunch, and start as standalone
  173. ; Read Registry for installation
  174. ClearErrors
  175. ReadRegStr "$0" HKLM "Software\Jellyfin" "InstallLocation"
  176. IfErrors NoExisitingInstall
  177. DetailPrint "Existing Jellyfin detected at: $0"
  178. StrCpy "$INSTDIR" "$0"
  179. StrCpy $_EXISTINGINSTALLATION_ "YES"
  180. SectionSetText ${InstallJellyfin} "Upgrade Jellyfin" ; Change install text to "Upgrade"
  181. ; check if there is a service called Jellyfin
  182. ; hack : nssm statuscode Jellyfin will return non zero return code in case it exists
  183. ExecWait '"$INSTDIR\nssm.exe" statuscode Jellyfin' $0
  184. DetailPrint "Jellyfin service statuscode, $0"
  185. IntCmp $0 0 NoService ; service doesn't exist
  186. StrCpy $_EXISTINGSERVICE_ "YES"
  187. SectionSetText ${InstallService} "" ; hide service install option if old install was a service
  188. SectionSetText ${LaunchJellyfin} "" ; hide service start option if old install was a service
  189. SectionSetText ${DesktopShortcut} "" ; hide desktop shortcut option too
  190. NoService:
  191. ; if detected, let the user know that we'll upgrade and its ok to quit
  192. MessageBox MB_OKCANCEL|MB_ICONINFORMATION "Existing installation of Jellyfin was detected, it'll be upgraded, settings will be retained" /SD IDOK IDOK Proceed
  193. Quit ; Quit if the user is not sure about upgrade
  194. Proceed:
  195. NoExisitingInstall:
  196. SetShellVarContext all
  197. ; Align installer version with jellyfin.dll version
  198. !getdllversion "$%InstallLocation%\jellyfin.dll" ver_
  199. StrCpy $_JELLYFINVERSION_ "${ver_1}.${ver_2}.${ver_3}.${ver_4}"
  200. SetShellVarContext current
  201. StrCpy $_JELLYFINDATADIR_ "$LOCALAPPDATA\jellyfin\"
  202. DetailPrint "_JELLYFINDATADIR_ : $_JELLYFINDATADIR_"
  203. StrCpy $_SERVICEINSTALLED_ "NO"
  204. SectionSetFlags ${InstallJellyfin} 17 ; this makes the InstallJellyfin section mandatory
  205. FunctionEnd
  206. Function HideDirectoryPage
  207. StrCmp $_EXISTINGINSTALLATION_ "NO" show
  208. Abort ; Dont show folder selection if just upgrading
  209. show:
  210. FunctionEnd
  211. ; This can be uncommented in case Emby Migration is planned later
  212. ;Function ShowEmbyLibraryPage
  213. ; SectionGetFlags ${MigrateEmbyLibrary} $R0
  214. ; IntOp $R0 $R0 & ${SF_SELECTED}
  215. ; IntCmp $R0 ${SF_SELECTED} show
  216. ; Abort ; Dont show the Emby folder selection window if Emby migrartion is not selected
  217. ; show:
  218. ;FunctionEnd