jellyfin.nsi 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  1. ; Shows a lot of debug information while compiling
  2. ; This can be removed once stable.
  3. !verbose 4
  4. SetCompressor lzma
  5. ShowInstDetails show
  6. ShowUninstDetails show
  7. ;--------------------------------
  8. !define SF_USELECTED 0 ; used to check selected options status, rest are inherited from Sections.nsh
  9. !include "MUI2.nsh"
  10. !include "Sections.nsh"
  11. !include "LogicLib.nsh"
  12. !include "helpers\ShowError.nsh"
  13. ; Global variables that we'll use
  14. Var _JELLYFINVERSION_
  15. Var _JELLYFINDATADIR_
  16. Var _SETUPTYPE_
  17. Var _INSTALLSERVICE_
  18. Var _SERVICESTART_
  19. Var _SERVICEACCOUNTTYPE_
  20. Var _EXISTINGINSTALLATION_
  21. Var _EXISTINGSERVICE_
  22. Var _MAKESHORTCUTS_
  23. Var _FOLDEREXISTS_
  24. ;
  25. !ifdef x64
  26. !define ARCH "x64"
  27. !define NAMESUFFIX "(64 bit)"
  28. !define INSTALL_DIRECTORY "$PROGRAMFILES64\Jellyfin\Server"
  29. !endif
  30. !ifdef x84
  31. !define ARCH "x86"
  32. !define NAMESUFFIX "(32 bit)"
  33. !define INSTALL_DIRECTORY "$PROGRAMFILES32\Jellyfin\Server"
  34. !endif
  35. !ifndef ARCH
  36. !error "Set the Arch with /Dx86 or /Dx64"
  37. !endif
  38. ;--------------------------------
  39. !define REG_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\JellyfinServer" ;Registry to show up in Add/Remove Programs
  40. !define REG_CONFIG_KEY "Software\Jellyfin\Server" ;Registry to store all configuration
  41. !getdllversion "$%InstallLocation%\jellyfin.dll" ver_ ;Align installer version with jellyfin.dll version
  42. Name "Jellyfin Server ${ver_1}.${ver_2}.${ver_3} ${NAMESUFFIX}" ; This is referred in various header text labels
  43. OutFile "jellyfin_${ver_1}.${ver_2}.${ver_3}_windows-${ARCH}.exe" ; Naming convention jellyfin_{version}_windows-{arch].exe
  44. BrandingText "Jellyfin Server ${ver_1}.${ver_2}.${ver_3} Installer" ; This shows in just over the buttons
  45. ; installer attributes, these show up in details tab on installer properties
  46. VIProductVersion "${ver_1}.${ver_2}.${ver_3}.0" ; VIProductVersion format, should be X.X.X.X
  47. VIFileVersion "${ver_1}.${ver_2}.${ver_3}.0" ; VIFileVersion format, should be X.X.X.X
  48. VIAddVersionKey "ProductName" "Jellyfin Server"
  49. VIAddVersionKey "FileVersion" "${ver_1}.${ver_2}.${ver_3}.0"
  50. VIAddVersionKey "LegalCopyright" "(c) 2019 Jellyfin Contributors. Code released under the GNU General Public License"
  51. VIAddVersionKey "FileDescription" "Jellyfin Server: The Free Software Media System"
  52. ;TODO, check defaults
  53. InstallDir ${INSTALL_DIRECTORY} ;Default installation folder
  54. InstallDirRegKey HKLM "${REG_CONFIG_KEY}" "InstallFolder" ;Read the registry for install folder,
  55. RequestExecutionLevel admin ; ask it upfront for service control, and installing in priv folders
  56. CRCCheck on ; make sure the installer wasn't corrupted while downloading
  57. !define MUI_ABORTWARNING ;Prompts user in case of aborting install
  58. ; TODO: Replace with nice Jellyfin Icons
  59. !ifdef UXPATH
  60. !define MUI_ICON "${UXPATH}\branding\NSIS\modern-install.ico" ; Installer Icon
  61. !define MUI_UNICON "${UXPATH}\branding\NSIS\modern-uninstall.ico" ; Uninstaller Icon
  62. !define MUI_HEADERIMAGE
  63. !define MUI_HEADERIMAGE_BITMAP "${UXPATH}\branding\NSIS\installer-header.bmp"
  64. !define MUI_WELCOMEFINISHPAGE_BITMAP "${UXPATH}\branding\NSIS\installer-right.bmp"
  65. !define MUI_UNWELCOMEFINISHPAGE_BITMAP "${UXPATH}\branding\NSIS\installer-right.bmp"
  66. !endif
  67. ;--------------------------------
  68. ;Pages
  69. ; Welcome Page
  70. !define MUI_WELCOMEPAGE_TEXT "The installer will ask for details to install Jellyfin Server."
  71. !insertmacro MUI_PAGE_WELCOME
  72. ; License Page
  73. !insertmacro MUI_PAGE_LICENSE "$%InstallLocation%\LICENSE" ; picking up generic GPL
  74. ; Setup Type Page
  75. Page custom ShowSetupTypePage SetupTypePage_Config
  76. ; Components Page
  77. !define MUI_PAGE_CUSTOMFUNCTION_PRE HideComponentsPage
  78. !insertmacro MUI_PAGE_COMPONENTS
  79. !define MUI_PAGE_CUSTOMFUNCTION_PRE HideInstallDirectoryPage ; Controls when to hide / show
  80. !define MUI_DIRECTORYPAGE_TEXT_DESTINATION "Install folder" ; shows just above the folder selection dialog
  81. !insertmacro MUI_PAGE_DIRECTORY
  82. ; Data folder Page
  83. !define MUI_PAGE_CUSTOMFUNCTION_PRE HideDataDirectoryPage ; Controls when to hide / show
  84. !define MUI_PAGE_HEADER_TEXT "Choose Data Location"
  85. !define MUI_PAGE_HEADER_SUBTEXT "Choose the folder in which to install the Jellyfin Server data."
  86. !define MUI_DIRECTORYPAGE_TEXT_TOP "The installer will set the following folder for Jellyfin Server data. To install in a different folder, click Browse and select another folder. Please make sure the folder exists and is accessible. Click Next to continue."
  87. !define MUI_DIRECTORYPAGE_TEXT_DESTINATION "Data folder"
  88. !define MUI_DIRECTORYPAGE_VARIABLE $_JELLYFINDATADIR_
  89. !insertmacro MUI_PAGE_DIRECTORY
  90. ; Custom Dialogs
  91. !include "dialogs\setuptype.nsdinc"
  92. !include "dialogs\service-config.nsdinc"
  93. !include "dialogs\confirmation.nsdinc"
  94. ; Select service account type
  95. #!define MUI_PAGE_CUSTOMFUNCTION_PRE HideServiceConfigPage ; Controls when to hide / show (This does not work for Page, might need to go PageEx)
  96. #!define MUI_PAGE_CUSTOMFUNCTION_SHOW fnc_service_config_Show
  97. #!define MUI_PAGE_CUSTOMFUNCTION_LEAVE ServiceConfigPage_Config
  98. #!insertmacro MUI_PAGE_CUSTOM ServiceAccountType
  99. Page custom ShowServiceConfigPage ServiceConfigPage_Config
  100. ; Confirmation Page
  101. Page custom ShowConfirmationPage ; just letting the user know what they chose to install
  102. ; Actual Installion Page
  103. !insertmacro MUI_PAGE_INSTFILES
  104. !insertmacro MUI_UNPAGE_CONFIRM
  105. !insertmacro MUI_UNPAGE_INSTFILES
  106. #!insertmacro MUI_UNPAGE_FINISH
  107. ;--------------------------------
  108. ;Languages; Add more languages later here if needed
  109. !insertmacro MUI_LANGUAGE "English"
  110. ;--------------------------------
  111. ;Installer Sections
  112. Section "!Jellyfin Server (required)" InstallJellyfinServer
  113. SectionIn RO ; Mandatory section, isn't this the whole purpose to run the installer.
  114. StrCmp "$_EXISTINGINSTALLATION_" "Yes" RunUninstaller CarryOn ; Silently uninstall in case of previous installation
  115. RunUninstaller:
  116. DetailPrint "Looking for uninstaller at $INSTDIR"
  117. FindFirst $0 $1 "$INSTDIR\Uninstall.exe"
  118. FindClose $0
  119. StrCmp $1 "" CarryOn ; the registry key was there but uninstaller was not found
  120. DetailPrint "Silently running the uninstaller at $INSTDIR"
  121. ExecWait '"$INSTDIR\Uninstall.exe" /S _?=$INSTDIR' $0
  122. DetailPrint "Uninstall finished, $0"
  123. CarryOn:
  124. ${If} $_EXISTINGSERVICE_ == 'Yes'
  125. ExecWait '"$INSTDIR\nssm.exe" stop JellyfinServer' $0
  126. ${If} $0 <> 0
  127. MessageBox MB_OK|MB_ICONSTOP "Could not stop the Jellyfin Server service."
  128. Abort
  129. ${EndIf}
  130. DetailPrint "Stopped Jellyfin Server service, $0"
  131. ${EndIf}
  132. SetOutPath "$INSTDIR"
  133. File "/oname=icon.ico" "${UXPATH}\branding\NSIS\modern-install.ico"
  134. File /r $%InstallLocation%\*
  135. ; Write the InstallFolder, DataFolder, Network Service info into the registry for later use
  136. WriteRegExpandStr HKLM "${REG_CONFIG_KEY}" "InstallFolder" "$INSTDIR"
  137. WriteRegExpandStr HKLM "${REG_CONFIG_KEY}" "DataFolder" "$_JELLYFINDATADIR_"
  138. WriteRegStr HKLM "${REG_CONFIG_KEY}" "ServiceAccountType" "$_SERVICEACCOUNTTYPE_"
  139. !getdllversion "$%InstallLocation%\jellyfin.dll" ver_
  140. StrCpy $_JELLYFINVERSION_ "${ver_1}.${ver_2}.${ver_3}" ;
  141. ; Write the uninstall keys for Windows
  142. WriteRegStr HKLM "${REG_UNINST_KEY}" "DisplayName" "Jellyfin Server $_JELLYFINVERSION_ ${NAMESUFFIX}"
  143. WriteRegExpandStr HKLM "${REG_UNINST_KEY}" "UninstallString" '"$INSTDIR\Uninstall.exe"'
  144. WriteRegStr HKLM "${REG_UNINST_KEY}" "DisplayIcon" '"$INSTDIR\Uninstall.exe",0'
  145. WriteRegStr HKLM "${REG_UNINST_KEY}" "Publisher" "The Jellyfin Project"
  146. WriteRegStr HKLM "${REG_UNINST_KEY}" "URLInfoAbout" "https://jellyfin.org/"
  147. WriteRegStr HKLM "${REG_UNINST_KEY}" "DisplayVersion" "$_JELLYFINVERSION_"
  148. WriteRegDWORD HKLM "${REG_UNINST_KEY}" "NoModify" 1
  149. WriteRegDWORD HKLM "${REG_UNINST_KEY}" "NoRepair" 1
  150. ;Create uninstaller
  151. WriteUninstaller "$INSTDIR\Uninstall.exe"
  152. SectionEnd
  153. Section "Jellyfin Server Service" InstallService
  154. ${If} $_INSTALLSERVICE_ == "Yes" ; Only run this if we're going to install the service!
  155. ExecWait '"$INSTDIR\nssm.exe" statuscode JellyfinServer' $0
  156. DetailPrint "Jellyfin Server service statuscode, $0"
  157. ${If} $0 == 0
  158. InstallRetry:
  159. ExecWait '"$INSTDIR\nssm.exe" install JellyfinServer "$INSTDIR\jellyfin.exe" --service --datadir \"$_JELLYFINDATADIR_\"' $0
  160. ${If} $0 <> 0
  161. !insertmacro ShowError "Could not install the Jellyfin Server service." InstallRetry
  162. ${EndIf}
  163. DetailPrint "Jellyfin Server Service install, $0"
  164. ${Else}
  165. DetailPrint "Jellyfin Server Service exists, updating..."
  166. ConfigureApplicationRetry:
  167. ExecWait '"$INSTDIR\nssm.exe" set JellyfinServer Application "$INSTDIR\jellyfin.exe"' $0
  168. ${If} $0 <> 0
  169. !insertmacro ShowError "Could not configure the Jellyfin Server service." ConfigureApplicationRetry
  170. ${EndIf}
  171. DetailPrint "Jellyfin Server Service setting (Application), $0"
  172. ConfigureAppParametersRetry:
  173. ExecWait '"$INSTDIR\nssm.exe" set JellyfinServer AppParameters --service --datadir \"$_JELLYFINDATADIR_\"' $0
  174. ${If} $0 <> 0
  175. !insertmacro ShowError "Could not configure the Jellyfin Server service." ConfigureAppParametersRetry
  176. ${EndIf}
  177. DetailPrint "Jellyfin Server Service setting (AppParameters), $0"
  178. ${EndIf}
  179. Sleep 3000 ; Give time for Windows to catchup
  180. ConfigureStartRetry:
  181. ExecWait '"$INSTDIR\nssm.exe" set JellyfinServer Start SERVICE_DELAYED_AUTO_START' $0
  182. ${If} $0 <> 0
  183. !insertmacro ShowError "Could not configure the Jellyfin Server service." ConfigureStartRetry
  184. ${EndIf}
  185. DetailPrint "Jellyfin Server Service setting (Start), $0"
  186. ConfigureDescriptionRetry:
  187. ExecWait '"$INSTDIR\nssm.exe" set JellyfinServer Description "Jellyfin Server: The Free Software Media System"' $0
  188. ${If} $0 <> 0
  189. !insertmacro ShowError "Could not configure the Jellyfin Server service." ConfigureDescriptionRetry
  190. ${EndIf}
  191. DetailPrint "Jellyfin Server Service setting (Description), $0"
  192. ConfigureDisplayNameRetry:
  193. ExecWait '"$INSTDIR\nssm.exe" set JellyfinServer DisplayName "Jellyfin Server"' $0
  194. ${If} $0 <> 0
  195. !insertmacro ShowError "Could not configure the Jellyfin Server service." ConfigureDisplayNameRetry
  196. ${EndIf}
  197. DetailPrint "Jellyfin Server Service setting (DisplayName), $0"
  198. Sleep 3000
  199. ${If} $_SERVICEACCOUNTTYPE_ == "NetworkService" ; the default install using NSSM is Local System
  200. ConfigureNetworkServiceRetry:
  201. ExecWait '"$INSTDIR\nssm.exe" set JellyfinServer Objectname "Network Service"' $0
  202. ${If} $0 <> 0
  203. !insertmacro ShowError "Could not configure the Jellyfin Server service account." ConfigureNetworkServiceRetry
  204. ${EndIf}
  205. DetailPrint "Jellyfin Server service account change, $0"
  206. ${EndIf}
  207. Sleep 3000
  208. ConfigureDefaultAppExit:
  209. ExecWait '"$INSTDIR\nssm.exe" set JellyfinServer AppExit Default Exit' $0
  210. ${If} $0 <> 0
  211. !insertmacro ShowError "Could not configure the Jellyfin Server service app exit action." ConfigureDefaultAppExit
  212. ${EndIf}
  213. DetailPrint "Jellyfin Server service exit action set, $0"
  214. ${EndIf}
  215. SectionEnd
  216. Section "-start service" StartService
  217. ${If} $_SERVICESTART_ == "Yes"
  218. ${AndIf} $_INSTALLSERVICE_ == "Yes"
  219. StartRetry:
  220. ExecWait '"$INSTDIR\nssm.exe" start JellyfinServer' $0
  221. ${If} $0 <> 0
  222. !insertmacro ShowError "Could not start the Jellyfin Server service." StartRetry
  223. ${EndIf}
  224. DetailPrint "Jellyfin Server service start, $0"
  225. ${EndIf}
  226. SectionEnd
  227. Section "Create Shortcuts" CreateWinShortcuts
  228. ${If} $_MAKESHORTCUTS_ == "Yes"
  229. CreateDirectory "$SMPROGRAMS\Jellyfin Server"
  230. CreateShortCut "$SMPROGRAMS\Jellyfin Server\Jellyfin (View Console).lnk" "$INSTDIR\jellyfin.exe" "--datadir $\"$_JELLYFINDATADIR_$\"" "$INSTDIR\icon.ico" 0 SW_SHOWMAXIMIZED
  231. CreateShortCut "$SMPROGRAMS\Jellyfin Server\Jellyfin Tray App.lnk" "$INSTDIR\jellyfintray.exe" "" "$INSTDIR\icon.ico" 0
  232. ;CreateShortCut "$DESKTOP\Jellyfin Server.lnk" "$INSTDIR\jellyfin.exe" "--datadir $\"$_JELLYFINDATADIR_$\"" "$INSTDIR\icon.ico" 0 SW_SHOWMINIMIZED
  233. CreateShortCut "$DESKTOP\Jellyfin Server\Jellyfin Server.lnk" "$INSTDIR\jellyfintray.exe" "" "$INSTDIR\icon.ico" 0
  234. ${EndIf}
  235. SectionEnd
  236. ;--------------------------------
  237. ;Descriptions
  238. ;Language strings
  239. LangString DESC_InstallJellyfinServer ${LANG_ENGLISH} "Install Jellyfin Server"
  240. LangString DESC_InstallService ${LANG_ENGLISH} "Install As a Service"
  241. ;Assign language strings to sections
  242. !insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
  243. !insertmacro MUI_DESCRIPTION_TEXT ${InstallJellyfinServer} $(DESC_InstallJellyfinServer)
  244. !insertmacro MUI_DESCRIPTION_TEXT ${InstallService} $(DESC_InstallService)
  245. !insertmacro MUI_FUNCTION_DESCRIPTION_END
  246. ;--------------------------------
  247. ;Uninstaller Section
  248. Section "Uninstall"
  249. ReadRegStr $INSTDIR HKLM "${REG_CONFIG_KEY}" "InstallFolder" ; read the installation folder
  250. ReadRegStr $_JELLYFINDATADIR_ HKLM "${REG_CONFIG_KEY}" "DataFolder" ; read the data folder
  251. ReadRegStr $_SERVICEACCOUNTTYPE_ HKLM "${REG_CONFIG_KEY}" "ServiceAccountType" ; read the account name
  252. DetailPrint "Jellyfin Install location: $INSTDIR"
  253. DetailPrint "Jellyfin Data folder: $_JELLYFINDATADIR_"
  254. MessageBox MB_YESNO|MB_ICONINFORMATION "Do you want to retain the Jellyfin Server data folder? The media will not be touched. $\r$\nIf unsure choose YES." /SD IDYES IDYES PreserveData
  255. RMDir /r /REBOOTOK "$_JELLYFINDATADIR_"
  256. PreserveData:
  257. ExecWait '"$INSTDIR\nssm.exe" statuscode JellyfinServer' $0
  258. DetailPrint "Jellyfin Server service statuscode, $0"
  259. IntCmp $0 0 NoServiceUninstall ; service doesn't exist, may be run from desktop shortcut
  260. Sleep 3000 ; Give time for Windows to catchup
  261. UninstallStopRetry:
  262. ExecWait '"$INSTDIR\nssm.exe" stop JellyfinServer' $0
  263. ${If} $0 <> 0
  264. !insertmacro ShowError "Could not stop the Jellyfin Server service." UninstallStopRetry
  265. ${EndIf}
  266. DetailPrint "Stopped Jellyfin Server service, $0"
  267. UninstallRemoveRetry:
  268. ExecWait '"$INSTDIR\nssm.exe" remove JellyfinServer confirm' $0
  269. ${If} $0 <> 0
  270. !insertmacro ShowError "Could not remove the Jellyfin Server service." UninstallRemoveRetry
  271. ${EndIf}
  272. DetailPrint "Removed Jellyfin Server service, $0"
  273. Sleep 3000 ; Give time for Windows to catchup
  274. NoServiceUninstall: ; existing install was present but no service was detected. Remove shortcuts if account is set to none
  275. ${If} $_SERVICEACCOUNTTYPE_ == "None"
  276. RMDir /r "$SMPROGRAMS\Jellyfin Server"
  277. Delete "$DESKTOP\Jellyfin Server.lnk"
  278. DetailPrint "Removed old shortcuts..."
  279. ${EndIf}
  280. Delete "$INSTDIR\*.*"
  281. RMDir /r /REBOOTOK "$INSTDIR\jellyfin-web"
  282. Delete "$INSTDIR\Uninstall.exe"
  283. RMDir /r /REBOOTOK "$INSTDIR"
  284. DeleteRegKey HKLM "Software\Jellyfin"
  285. DeleteRegKey HKLM "${REG_UNINST_KEY}"
  286. SectionEnd
  287. Function .onInit
  288. ; Setting up defaults
  289. StrCpy $_INSTALLSERVICE_ "Yes"
  290. StrCpy $_SERVICESTART_ "Yes"
  291. StrCpy $_SERVICEACCOUNTTYPE_ "NetworkService"
  292. StrCpy $_EXISTINGINSTALLATION_ "No"
  293. StrCpy $_EXISTINGSERVICE_ "No"
  294. StrCpy $_MAKESHORTCUTS_ "No"
  295. SetShellVarContext current
  296. StrCpy $_JELLYFINDATADIR_ "$%ProgramData%\Jellyfin\Server"
  297. System::Call 'kernel32::CreateMutex(p 0, i 0, t "JellyfinServerMutex") p .r1 ?e'
  298. Pop $R0
  299. StrCmp $R0 0 +3
  300. !insertmacro ShowErrorFinal "The installer is already running."
  301. ;Detect if Jellyfin is already installed.
  302. ; In case it is installed, let the user choose either
  303. ; 1. Exit installer
  304. ; 2. Upgrade without messing with data
  305. ; 2a. Don't ask for any details, uninstall and install afresh with old settings
  306. ; Read Registry for previous installation
  307. ClearErrors
  308. ReadRegStr "$0" HKLM "${REG_CONFIG_KEY}" "InstallFolder"
  309. IfErrors NoExisitingInstall
  310. DetailPrint "Existing Jellyfin Server detected at: $0"
  311. StrCpy "$INSTDIR" "$0" ; set the location fro registry as new default
  312. StrCpy $_EXISTINGINSTALLATION_ "Yes" ; Set our flag to be used later
  313. SectionSetText ${InstallJellyfinServer} "Upgrade Jellyfin Server (required)" ; Change install text to "Upgrade"
  314. ; check if service was run using Network Service account
  315. ClearErrors
  316. ReadRegStr $_SERVICEACCOUNTTYPE_ HKLM "${REG_CONFIG_KEY}" "ServiceAccountType" ; in case of error _SERVICEACCOUNTTYPE_ will be NetworkService as default
  317. ClearErrors
  318. ReadRegStr $_JELLYFINDATADIR_ HKLM "${REG_CONFIG_KEY}" "DataFolder" ; in case of error, the default holds
  319. ; Hide sections which will not be needed in case of previous install
  320. ; SectionSetText ${InstallService} ""
  321. ; check if there is a service called Jellyfin, there should be
  322. ; hack : nssm statuscode Jellyfin will return non zero return code in case it exists
  323. ExecWait '"$INSTDIR\nssm.exe" statuscode JellyfinServer' $0
  324. DetailPrint "Jellyfin Server service statuscode, $0"
  325. IntCmp $0 0 NoService ; service doesn't exist, may be run from desktop shortcut
  326. ; if service was detected, set defaults going forward.
  327. StrCpy $_EXISTINGSERVICE_ "Yes"
  328. StrCpy $_INSTALLSERVICE_ "Yes"
  329. StrCpy $_SERVICESTART_ "Yes"
  330. StrCpy $_MAKESHORTCUTS_ "No"
  331. SectionSetText ${CreateWinShortcuts} ""
  332. NoService: ; existing install was present but no service was detected
  333. ${If} $_SERVICEACCOUNTTYPE_ == "None"
  334. StrCpy $_SETUPTYPE_ "Basic"
  335. StrCpy $_INSTALLSERVICE_ "No"
  336. StrCpy $_SERVICESTART_ "No"
  337. StrCpy $_MAKESHORTCUTS_ "Yes"
  338. ${EndIf}
  339. ; Let the user know that we'll upgrade and provide an option to quit.
  340. MessageBox MB_OKCANCEL|MB_ICONINFORMATION "Existing installation of Jellyfin Server was detected, it'll be upgraded, settings will be retained. \
  341. $\r$\nClick OK to proceed, Cancel to exit installer." /SD IDOK IDOK ProceedWithUpgrade
  342. Quit ; Quit if the user is not sure about upgrade
  343. ProceedWithUpgrade:
  344. NoExisitingInstall: ; by this time, the variables have been correctly set to reflect previous install details
  345. FunctionEnd
  346. Function HideInstallDirectoryPage
  347. ${If} $_EXISTINGINSTALLATION_ == "Yes" ; Existing installation detected, so don't ask for InstallFolder
  348. Abort
  349. ${EndIf}
  350. FunctionEnd
  351. Function HideDataDirectoryPage
  352. ${If} $_EXISTINGINSTALLATION_ == "Yes" ; Existing installation detected, so don't ask for InstallFolder
  353. Abort
  354. ${EndIf}
  355. FunctionEnd
  356. Function HideServiceConfigPage
  357. ${If} $_INSTALLSERVICE_ == "No" ; Not running as a service, don't ask for service type
  358. ${OrIf} $_EXISTINGINSTALLATION_ == "Yes" ; Existing installation detected, so don't ask for InstallFolder
  359. Abort
  360. ${EndIf}
  361. FunctionEnd
  362. Function HideConfirmationPage
  363. ${If} $_EXISTINGINSTALLATION_ == "Yes" ; Existing installation detected, so don't ask for InstallFolder
  364. Abort
  365. ${EndIf}
  366. FunctionEnd
  367. Function HideSetupTypePage
  368. ${If} $_EXISTINGINSTALLATION_ == "Yes" ; Existing installation detected, so don't ask for SetupType
  369. Abort
  370. ${EndIf}
  371. FunctionEnd
  372. Function HideComponentsPage
  373. ${If} $_SETUPTYPE_ == "Basic" ; Basic installation chosen, don't show components choice
  374. Abort
  375. ${EndIf}
  376. FunctionEnd
  377. ; Setup Type dialog show function
  378. Function ShowSetupTypePage
  379. Call HideSetupTypePage
  380. Call fnc_setuptype_Create
  381. nsDialogs::Show
  382. FunctionEnd
  383. ; Service Config dialog show function
  384. Function ShowServiceConfigPage
  385. Call HideServiceConfigPage
  386. Call fnc_service_config_Create
  387. nsDialogs::Show
  388. FunctionEnd
  389. ; Confirmation dialog show function
  390. Function ShowConfirmationPage
  391. Call HideConfirmationPage
  392. Call fnc_confirmation_Create
  393. nsDialogs::Show
  394. FunctionEnd
  395. ; Declare temp variables to read the options from the custom page.
  396. Var StartServiceAfterInstall
  397. Var UseNetworkServiceAccount
  398. Var UseLocalSystemAccount
  399. Var BasicInstall
  400. Function SetupTypePage_Config
  401. ${NSD_GetState} $hCtl_setuptype_BasicInstall $BasicInstall
  402. IfFileExists "$LOCALAPPDATA\Jellyfin" folderfound foldernotfound ; if the folder exists, use this, otherwise, go with new default
  403. folderfound:
  404. StrCpy $_FOLDEREXISTS_ "Yes"
  405. Goto InstallCheck
  406. foldernotfound:
  407. StrCpy $_FOLDEREXISTS_ "No"
  408. Goto InstallCheck
  409. InstallCheck:
  410. ${If} $BasicInstall == 1
  411. StrCpy $_SETUPTYPE_ "Basic"
  412. StrCpy $_INSTALLSERVICE_ "No"
  413. StrCpy $_SERVICESTART_ "No"
  414. StrCpy $_SERVICEACCOUNTTYPE_ "None"
  415. StrCpy $_MAKESHORTCUTS_ "Yes"
  416. ${If} $_FOLDEREXISTS_ == "Yes"
  417. StrCpy $_JELLYFINDATADIR_ "$LOCALAPPDATA\Jellyfin\"
  418. ${EndIf}
  419. ${Else}
  420. StrCpy $_SETUPTYPE_ "Advanced"
  421. StrCpy $_INSTALLSERVICE_ "Yes"
  422. StrCpy $_MAKESHORTCUTS_ "No"
  423. ${If} $_FOLDEREXISTS_ == "Yes"
  424. MessageBox MB_OKCANCEL|MB_ICONINFORMATION "An existing data folder was detected.\
  425. $\r$\nBasic Setup is highly recommended.\
  426. $\r$\nIf you proceed, you will need to set up Jellyfin again." IDOK GoAhead IDCANCEL GoBack
  427. GoBack:
  428. Abort
  429. ${EndIf}
  430. GoAhead:
  431. StrCpy $_JELLYFINDATADIR_ "$%ProgramData%\Jellyfin\Server"
  432. SectionSetText ${CreateWinShortcuts} ""
  433. ${EndIf}
  434. FunctionEnd
  435. Function ServiceConfigPage_Config
  436. ${NSD_GetState} $hCtl_service_config_StartServiceAfterInstall $StartServiceAfterInstall
  437. ${If} $StartServiceAfterInstall == 1
  438. StrCpy $_SERVICESTART_ "Yes"
  439. ${Else}
  440. StrCpy $_SERVICESTART_ "No"
  441. ${EndIf}
  442. ${NSD_GetState} $hCtl_service_config_UseNetworkServiceAccount $UseNetworkServiceAccount
  443. ${NSD_GetState} $hCtl_service_config_UseLocalSystemAccount $UseLocalSystemAccount
  444. ${If} $UseNetworkServiceAccount == 1
  445. StrCpy $_SERVICEACCOUNTTYPE_ "NetworkService"
  446. ${ElseIf} $UseLocalSystemAccount == 1
  447. StrCpy $_SERVICEACCOUNTTYPE_ "LocalSystem"
  448. ${Else}
  449. !insertmacro ShowErrorFinal "Service account type not properly configured."
  450. ${EndIf}
  451. FunctionEnd
  452. ; This function handles the choices during component selection
  453. Function .onSelChange
  454. ; If we are not installing service, we don't need to set the NetworkService account or StartService
  455. SectionGetFlags ${InstallService} $0
  456. ${If} $0 = ${SF_SELECTED}
  457. StrCpy $_INSTALLSERVICE_ "Yes"
  458. ${Else}
  459. StrCpy $_INSTALLSERVICE_ "No"
  460. StrCpy $_SERVICESTART_ "No"
  461. StrCpy $_SERVICEACCOUNTTYPE_ "None"
  462. ${EndIf}
  463. FunctionEnd
  464. Function .onInstSuccess
  465. #ExecShell "open" "http://localhost:8096"
  466. FunctionEnd