diff options
Diffstat (limited to 'build.nsi')
| -rw-r--r-- | build.nsi | 1020 |
1 files changed, 684 insertions, 336 deletions
@@ -1,391 +1,739 @@ -;yacy.nsi -; ---------------------------------------- -;(C) 2004-2006 by Alexander Schier -;(C) 2008-2010 by David Wieditz -;(C) 2011 by Rene Kluge -;(C) 2018 by luccioman; https://github.com/luccioman -/*---------------------------------------- -MANUALS -http://nsis.sourceforge.net/Docs/ -http://nsis.sourceforge.net/Docs/Modern%20UI%202/Readme.html ----------------------------------------- -COMMAND LINE OPTIONS (case sensitive): -/S - silent install/uninstall -/D="C:\yacy" - installation folder -----------------------------------------*/ - -; ---------------------------------------- -; MODERN UI +; YaCy Windows Installer (NSIS) !include MUI2.nsh !include x64.nsh !include FileFunc.nsh -!include WinVer.nsh - -; ---------------------------------------- -; GENERAL - -;Unicode true +!include LogicLib.nsh +!include WordFunc.nsh +!include WinMessages.nsh + +!ifndef WS_SIZEBOX +!define WS_SIZEBOX 0x00040000 +!endif +!ifndef WS_MAXIMIZEBOX +!define WS_MAXIMIZEBOX 0x00010000 +!endif +!ifndef GWL_STYLE +!define GWL_STYLE -16 +!endif + +!ifndef SWP_NOMOVE +!define SWP_NOMOVE 0x0002 +!endif +!ifndef SWP_NOSIZE +!define SWP_NOSIZE 0x0001 +!endif +!ifndef SWP_NOZORDER +!define SWP_NOZORDER 0x0004 +!endif +!ifndef SWP_FRAMECHANGED +!define SWP_FRAMECHANGED 0x0020 +!endif VIProductVersion "@REPL_VERSION@.0.0" VIAddVersionKey "ProductName" "YaCy" VIAddVersionKey "LegalCopyright" "YaCy" VIAddVersionKey "FileVersion" "@REPL_VERSION@" VIAddVersionKey "FileDescription" "YaCy" -VIAddVersionKey "OriginalFilename" "yacy_v@REPL_VERSION@_@REPL_REPVERDATE@@REPL_REPVERTIME@_@REPL_REPVERHASH@.exe" +VIAddVersionKey "OriginalFilename" "@REPL_RELEASESTUB@.exe" Name "YaCy @REPL_VERSION@" -OutFile "RELEASE\WINDOWS\yacy_v@REPL_VERSION@_@REPL_REPVERDATE@@REPL_REPVERTIME@_@REPL_REPVERHASH@.exe" - -;default installation folder -InstallDir "$PROFILE\YaCy" -InstallDirRegKey HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\YaCy" "UninstallString" +OutFile "@REPL_RELEASE_WINDOWS_ABS@/@REPL_RELEASESTUB@.exe" -;recommend free space in GB for YaCy -!define RecommendSpace "4" - -; commands for firewall config, see http://support.microsoft.com/kb/947709/en-us -!define WinXPAddFwRulePort 'netsh firewall add portopening TCP 8090 name="YaCy"' -!define WinXPDelFwRulePort 'netsh firewall del portopening TCP 8090' -!define WinVistaAddFwRulePort 'netsh advfirewall firewall add rule name="YaCy" dir=in action=allow enable=yes protocol=TCP localport=8090' -!define WinVistaDelFwRulePort 'netsh advfirewall firewall del rule name="YaCy"' -var WinAddFwRulePort -var WinDelFwRulePort - -;requested execution level on Vista / 7 -RequestExecutionLevel admin +InstallDir "$LOCALAPPDATA\Programs\YaCy" +InstallDirRegKey HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\YaCy" "InstallLocation" +RequestExecutionLevel user SetCompressor /SOLID LZMA -!insertmacro MUI_RESERVEFILE_LANGDLL ;loads faster - -; ---------------------------------------- -; GENERAL APPEARANCE +!insertmacro MUI_RESERVEFILE_LANGDLL -;BrandingText "yacy.net" - -!define MUI_ICON "RELEASE\MAIN\addon\YaCy.ico" +!define MUI_ICON "@REPL_RELEASE_MAIN_ABS@/addon/YaCy.ico" !define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\orange-uninstall.ico" +!define MUI_ABORTWARNING -!define MUI_WELCOMEFINISHPAGE_BITMAP "RELEASE\MAIN\addon\installer\network.bmp" - -!define MUI_HEADERIMAGE -!define MUI_HEADERIMAGE_BITMAP "RELEASE\MAIN\addon\installer\logo.bmp" -!define MUI_HEADERIMAGE_BITMAP_NOSTRETCH - -!define MUI_ABORTWARNING ;display warning before aborting installation +!define MUI_CUSTOMFUNCTION_GUIINIT YaCyGuiInit -; ---------------------------------------- -; INSTALLER PAGES - -!define MUI_PAGE_CUSTOMFUNCTION_SHOW MyWelcomeShowCallback !insertmacro MUI_PAGE_WELCOME - -Function MyWelcomeShowCallback - SendMessage $mui.WelcomePage.Text ${WM_SETTEXT} 0 "STR:$(MUI_TEXT_WELCOME_INFO_TEXT)$\r$\n$\r$\nThe YaCy project needs a maintainer for this installer!$\r$\nSee github.com/yacy/yacy_search_server/labels/Windows" -FunctionEnd - -!insertmacro MUI_PAGE_LICENSE gpl.txt - -!define MUI_COMPONENTSPAGE_NODESC -!insertmacro MUI_PAGE_COMPONENTS -ComponentText "YaCy v@REPL_VERSION@" - -!define MUI_PAGE_CUSTOMFUNCTION_LEAVE CheckDriveSpace +!insertmacro MUI_PAGE_LICENSE "@REPL_ROOT_ABS@/gpl.txt" !insertmacro MUI_PAGE_DIRECTORY - !insertmacro MUI_PAGE_INSTFILES - -!define MUI_PAGE_CUSTOMFUNCTION_SHOW SHOW_PageFinish_custom -!define MUI_FINISHPAGE_SHOWREADME https://www.youtube.com/yacy_tutorials -!define MUI_FINISHPAGE_SHOWREADME_TEXT $(finishPage) +!define MUI_FINISHPAGE_SHOWREADME "$TEMP\\yacy-installer.log" +!define MUI_FINISHPAGE_SHOWREADME_TEXT "Open installer log" +!define MUI_FINISHPAGE_SHOWREADME_NOTCHECKED !insertmacro MUI_PAGE_FINISH -; ---------------------------------------- -; UNINSTALLER PAGES - !insertmacro MUI_UNPAGE_CONFIRM - !insertmacro MUI_UNPAGE_INSTFILES -; ---------------------------------------- -; LANGUAGES - !insertmacro MUI_LANGUAGE "English" -!insertmacro MUI_LANGUAGE "French" -!insertmacro MUI_LANGUAGE "German" - -LangString stillRunning ${LANG_ENGLISH} "YaCy is still active. Please stop YaCy first." -LangString keepData 0 "Do you want to keep the data?" -LangString finishPage 0 "Show how to configure the Windows Firewall for YaCy." -LangString yacyNoHd 0 "YaCy should be installed on a hard disk. Continue with selected folder?" -LangString yacyNeedSpace 0 "We recommend ${RecommendSpace} GB free space for YaCy. There are only $TempDriveFree GB left. Continue anyway?" -LangString yacyNeedOs 0 "Please run Windows 2000 or better (e.g. Windows XP, Vista or Windows 7) for YaCy." -LangString yacyNoJavaFoundOpenBrowser ${LANG_ENGLISH} "Java 8 has not been found in the Windows registry!$\r$\n(Key: SOFTWARE\JavaSoft\Java Runtime Environment)$\r$\nOpen download location (adoptium.net) in Browser?" -LangString yacyNoJavaFoundContinue ${LANG_ENGLISH} "Click Retry to check again for installed Java version!" - -LangString stillRunning ${LANG_FRENCH} "YaCy is still active. Please stop YaCy first." -LangString keepData 0 "Do you want to keep the data?" -LangString finishPage 0 "Show how to configure the Windows Firewall for YaCy." -LangString yacyNoHd 0 "YaCy should be installed on a hard disk. Continue with selected folder?" -LangString yacyNeedSpace 0 "We recommend ${RecommendSpace} GB free space for YaCy. There are only $TempDriveFree GB left. Continue anyway?" -LangString yacyNeedOs 0 "Please run Windows 2000 or better (e.g. Windows XP, Vista or Windows 7) for YaCy." -LangString yacyNoJavaFoundOpenBrowser 0 "Java 8 has not been found in the Windows registry!$\r$\n(Key: SOFTWARE\JavaSoft\Java Runtime Environment)$\r$\nOpen download location (adoptium.net) in Browser?" -LangString yacyNoJavaFoundContinue 0 "Click Retry to check again for installed Java version!" - -LangString stillRunning ${LANG_GERMAN} "YaCy ist noch aktiv. Bitte beenden Sie YaCy." -LangString keepData 0 "Möchten Sie die Daten behalten?" -LangString finishPage 0 "Zeige die Windows Firewall Konfiguration fuer YaCy." -LangString yacyNoHd 0 "YaCy sollte auf einer Festplatte installiert werden. Soll der gewählte Ordner trotzdem verwendet werden?" -LangString yacyNeedSpace 0 "Wir empfehlen ${RecommendSpace} GB für YaCy. Es sind noch $TempDriveFree GB frei. Trotzdem fortfahren?" -LangString yacyNeedOs 0 "YaCy benoetigt Windows 2000 oder besser (z.B. Windows XP, Vista oder Windows 7)." -LangString yacyNoJavaFoundOpenBrowser 0 "Java 8 wurde in der Windows registry nicht gefunden!$\r$\n(Key: SOFTWARE\JavaSoft\Java Runtime Environment)$\r$\nDie Downloadseite (adoptium.net) im Browser öffnen?" -LangString yacyNoJavaFoundContinue 0 "Wähle Wiederholen, um erneut zu versuchen, Java zu finden!" - -; ---------------------------------------- -; INSTALLABLE MODULES - -;InstType "Normal" - -Section "check Java 8 installed" Sec_Java_id - SectionIn 1 RO - SetShellVarContext current - - ; init of JRE section - ; detect JRE first - var /global InstalledJREVersion - ${If} ${RunningX64} - SetRegView 64 - ${EndIf} - Retry: - ReadRegStr $InstalledJREVersion HKLM "SOFTWARE\JavaSoft\Java Runtime Environment" "CurrentVersion" - - ${If} $InstalledJREVersion != "11" - MessageBox MB_ICONEXCLAMATION|MB_YESNO "$(yacyNoJavaFoundOpenBrowser)" IDNO ContinueWithoutJava - ExecShell open "https://adoptium.net/de/temurin/releases/?version=8" - - MessageBox MB_ICONEXCLAMATION|MB_ABORTRETRYIGNORE "$(yacyNoJavaFoundContinue)" IDIGNORE ContinueWithoutJava IDRETRY Retry - Abort - ${EndIf} - ContinueWithoutJava: -SectionEnd - -Section "YaCy" - SectionIn 1 RO - SetShellVarContext current ; use system variables (folders) for current user - RMDir /r "$INSTDIR\lib" ;remove old libraries in case of update - RMDir /r "$SMPROGRAMS\YaCy" ;clear old shortcuts - Delete "$QUICKLAUNCH\YaCy-Search.lnk" ;old - Delete "$DESKTOP\YaCy-Search.lnk" ;old - Delete "$SMSTARTUP\start YaCy (no console).lnk" ;old - - SetOutPath $INSTDIR - ;set noindex attribute for windows indexing service - nsExec::Exec 'attrib +I "$INSTDIR"' - nsExec::Exec 'attrib +I "$INSTDIR\*" /S /D' - - File /r /x *.sh "RELEASE\MAIN\*" - - WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\YaCy" "DisplayName" "YaCy" - WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\YaCy" "UninstallString" '"$INSTDIR\uninstall.exe"' - WriteUninstaller "uninstall.exe" -SectionEnd - -Section "Start Menu Group" - SectionIn 1 - SetShellVarContext current - CreateDirectory "$SMPROGRAMS\YaCy" - CreateShortCut "$SMPROGRAMS\YaCy\YaCy.lnk" "$INSTDIR\startYACY.bat" "" "$INSTDIR\addon\YaCy.ico" "" SW_SHOWMINIMIZED - CreateShortCut "$SMPROGRAMS\YaCy\Readme.lnk" "$INSTDIR\readme.txt" - CreateShortCut "$SMPROGRAMS\YaCy\Uninstall.lnk" "$INSTDIR\Uninstall.exe" -SectionEnd -Section "Desktop Icon" - SectionIn 1 - SetShellVarContext current - CreateShortCut "$DESKTOP\YaCy.lnk" "$INSTDIR\startYACY.bat" "" "$INSTDIR\addon\YaCy.ico" "" SW_SHOWMINIMIZED +LangString javaMissing 0 "Java 11 or newer is required to run YaCy. Download and install the latest Temurin JRE now?" +LangString javaDownloadFail 0 "Java download failed. Please install Java 11+ manually." +LangString javaInstallFail 0 "Java 11+ was not found after installation. YaCy may not start until Java is installed." +LangString keepData 0 "Remove YaCy user data as well?" + +Var JavaVersion +Var JavaMajor +Var JavaFound +Var JavaInstallerUrl +Var JavaInstallerPath +Var DataDir +Var LogFile +Var JavaHome + +Section "YaCy" Sec_YaCy + SetDetailsView show + Push "Installer log: $LogFile" + Call LogLine + Call EnsureJava + SetShellVarContext current + + SetOutPath $INSTDIR + RMDir /r "$INSTDIR\lib" + RMDir /r "$SMPROGRAMS\YaCy" + Delete "$DESKTOP\YaCy.lnk" + + File /r /x *.sh "@REPL_RELEASE_MAIN_ABS@/*" + + WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\YaCy" "DisplayName" "YaCy" + WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\YaCy" "InstallLocation" "$INSTDIR" + WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\YaCy" "UninstallString" '"$INSTDIR\uninstall.exe"' + WriteRegStr HKCU "Software\YaCy" "DataDir" "$LOCALAPPDATA\YaCy" + WriteUninstaller "$INSTDIR\uninstall.exe" + + CreateDirectory "$SMPROGRAMS\YaCy" + CreateShortCut "$SMPROGRAMS\YaCy\YaCy.lnk" "$INSTDIR\startYACY.bat" "" "$INSTDIR\addon\YaCy.ico" "" SW_SHOWMINIMIZED + CreateShortCut "$SMPROGRAMS\YaCy\Readme.lnk" "$INSTDIR\readme.txt" + CreateShortCut "$SMPROGRAMS\YaCy\Uninstall.lnk" "$INSTDIR\uninstall.exe" + CreateShortCut "$DESKTOP\YaCy.lnk" "$INSTDIR\startYACY.bat" "" "$INSTDIR\addon\YaCy.ico" "" SW_SHOWMINIMIZED SectionEnd -Section "Configure Firewall" Sec_Firewall_id - SectionIn 1 - SetShellVarContext current - call OpenFirewall -SectionEnd - -/* -Section "YaCy in Startup" - SetShellVarContext current - CreateShortCut "$SMSTARTUP\YaCy.lnk" "$INSTDIR\startYACY.bat" "" "$INSTDIR\addon\YaCy.ico" "" SW_SHOWMINIMIZED -SectionEnd -*/ - -; ---------------------------------------- -; UNINSTALLER - Section "Uninstall" - ClearErrors - Delete "$INSTDIR\DATA\yacy.running" - IfErrors 0 uninstall - MessageBox MB_ICONSTOP "$(stillRunning)" /SD IDOK - Goto nouninstall - - uninstall: - Call un.CloseFirewall - SetShellVarContext current - - RMDir /r "$INSTDIR\addon" - RMDir /r "$INSTDIR\bin" - RMDir /r "$INSTDIR\classes" - RMDir /r "$INSTDIR\defaults" - RMDir /r "$INSTDIR\htroot" - RMDir /r "$INSTDIR\langstats" - RMDir /r "$INSTDIR\lib" - RMDir /r "$INSTDIR\libbuild" - RMDir /r "$INSTDIR\libx" - RMDir /r "$INSTDIR\locales" - RMDir /r "$INSTDIR\ranking" - RMDir /r "$INSTDIR\skins" - RMDir /r "$INSTDIR\source" - Delete "$INSTDIR\*.*" - - MessageBox MB_YESNO|MB_ICONQUESTION "$(keepData)" /SD IDYES IDYES keepdata - - ;delete all - RMDir /r "$INSTDIR" - - ;or jump to this - keepdata: - RMDir /r "$SMPROGRAMS\YaCy" - Delete "$DESKTOP\YaCy.lnk" - Delete "$SMSTARTUP\YaCy.lnk" - - DeleteRegKey HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\YaCy" - nouninstall: + SetShellVarContext current + + RMDir /r "$INSTDIR\addon" + RMDir /r "$INSTDIR\bin" + RMDir /r "$INSTDIR\classes" + RMDir /r "$INSTDIR\defaults" + RMDir /r "$INSTDIR\htroot" + RMDir /r "$INSTDIR\langstats" + RMDir /r "$INSTDIR\langdetect" + RMDir /r "$INSTDIR\lib" + RMDir /r "$INSTDIR\libbuild" + RMDir /r "$INSTDIR\libx" + RMDir /r "$INSTDIR\locales" + RMDir /r "$INSTDIR\ranking" + RMDir /r "$INSTDIR\skins" + RMDir /r "$INSTDIR\source" + Delete "$INSTDIR\*.*" + + RMDir /r "$SMPROGRAMS\YaCy" + Delete "$DESKTOP\YaCy.lnk" + + ReadRegStr $DataDir HKCU "Software\YaCy" "DataDir" + ${If} $DataDir == "" + StrCpy $DataDir "$LOCALAPPDATA\YaCy" + ${EndIf} + MessageBox MB_YESNO|MB_ICONQUESTION "$(keepData)" IDYES RemoveData + Goto SkipRemoveData + RemoveData: + RMDir /r "$DataDir" + SkipRemoveData: + + DeleteRegKey HKCU "Software\YaCy" + DeleteRegKey HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\YaCy" SectionEnd -; ---------------------------------------- -; FUNCTIONS - -Function .onInit - ; check Windows-Version, need Win 2000 or higher - ${If} ${AtMostWinME} - MessageBox MB_ICONSTOP "$(yacyNeedOs)" - Abort - ${EndIf} - - ; init of Firewall section, only valid for WindowsXP SP2/SP3 and Vista/Win 7 with Admin - var /global FirewallServiceStart - IntOp $FirewallServiceStart 3 + 0 - - ${If} ${IsWinVista} - ${OrIf} ${IsWin7} - StrCpy $WinAddFwRulePort '${WinVistaAddFwRulePort}' - StrCpy $WinDelFwRulePort '${WinVistaDelFwRulePort}' - ReadRegDWORD $FirewallServiceStart HKLM "SYSTEM\CurrentControlSet\services\MpsSvc" "Start" - ${EndIf} - - ${If} ${IsWinXP} - ${AndIf} ${AtLeastServicePack} 2 - StrCpy $WinAddFwRulePort '${WinXPAddFwRulePort}' - StrCpy $WinDelFwRulePort '${WinXPDelFwRulePort}' - ReadRegDWORD $FirewallServiceStart HKLM "SYSTEM\CurrentControlSet\services\SharedAccess" "Start" - ${EndIf} - - ;need Admin for firewall-config - ${IfNot} $0 = "Admin" - IntOp $FirewallServiceStart 3 + 0 - ${EndIf} - - ; hide and deselect Firewall if no proper configuration - ${If} $FirewallServiceStart > 2 - SectionSetText ${Sec_Firewall_id} "" - SectionSetFlags ${Sec_Firewall_id} 0 - ${EndIf} +Function EnsureJava + Push "Java detection: starting" + Call LogLine + Call GetJavaVersion + Push "Java detection: found=$JavaFound version='$JavaVersion' major=$JavaMajor" + Call LogLine + StrCmp $JavaFound "1" JavaOk JavaMissing + JavaMissing: + Push "Java detection: no Java found" + Call LogLine + MessageBox MB_ICONEXCLAMATION|MB_YESNO "$(javaMissing)" IDYES JavaDownload IDNO JavaContinue + Goto JavaContinue + JavaOk: + Push "Java detection: OK" + Call LogLine + Goto JavaContinue + + JavaDownload: + Push "Java install: downloading Temurin JRE" + Call LogLine + Call DownloadJava + Push "Java install: download/install finished, re-checking" + Call LogLine + Call GetJavaVersion + Push "Java detection (post-install): found=$JavaFound version='$JavaVersion' major=$JavaMajor" + Call LogLine + StrCmp $JavaFound "1" 0 JavaStillLow + JavaStillLow: + MessageBox MB_ICONEXCLAMATION "$(javaInstallFail)" + JavaContinue: FunctionEnd -Function CheckDriveSpace - var /global RootFolder - var /global TempDriveFree - var /global RootFolderType - - ; if "\\Folder" it's a Network-Folder - StrCpy $RootFolder $InstDir 2 - StrCmp $RootFolder "\\" NetworkFolder Driveletter +Function GetJavaVersion + StrCpy $JavaVersion "" + StrCpy $JavaMajor "0" + StrCpy $JavaFound "0" + + ${If} ${RunningX64} + SetRegView 64 + Push "Java detection: registry view 64" + Call LogLine + Call FindJavaVersionKeys + SetRegView 32 + Push "Java detection: registry view 32" + Call LogLine + Call FindJavaVersionKeys + ${Else} + Push "Java detection: registry view default" + Call LogLine + Call FindJavaVersionKeys + ${EndIf} + + Push "Java detection: registry done, found=$JavaFound version='$JavaVersion' major=$JavaMajor" + Call LogLine + Call FindJavaFromEnv + Call FindJavaFromProgramFiles + Call FindJavaFromPath + ${If} $JavaFound == "1" + ${If} $JavaMajor == "0" + StrCpy $JavaMajor "11" + Push "Java detection: version unknown, assuming >=11" + Call LogLine + ${EndIf} + ${EndIf} + Push "Java detection: PATH/env/fs check done, found=$JavaFound version='$JavaVersion' major=$JavaMajor" + Call LogLine +FunctionEnd - Networkfolder: - ; prepare String for DriveSpace - ${GetRoot} $RootFolder $InstDir - goto NoHDD +Function FindJavaVersionKeys + Push "SOFTWARE\JavaSoft\Java Runtime Environment" + Call FindJavaVersionInKeyHKLM + Push "SOFTWARE\JavaSoft\JDK" + Call FindJavaVersionInKeyHKLM + Push "SOFTWARE\Eclipse Adoptium\JRE" + Call FindJavaVersionInKeyHKLM + Push "SOFTWARE\Eclipse Adoptium\JDK" + Call FindJavaVersionInKeyHKLM + Push "SOFTWARE\Adoptium\JRE" + Call FindJavaVersionInKeyHKLM + Push "SOFTWARE\Adoptium\JDK" + Call FindJavaVersionInKeyHKLM + Push "SOFTWARE\Microsoft\JDK" + Call FindJavaVersionInKeyHKLM + Push "SOFTWARE\Microsoft\JRE" + Call FindJavaVersionInKeyHKLM + + Push "SOFTWARE\JavaSoft\Java Runtime Environment" + Call FindJavaVersionInKeyHKCU + Push "SOFTWARE\JavaSoft\JDK" + Call FindJavaVersionInKeyHKCU + Push "SOFTWARE\Eclipse Adoptium\JRE" + Call FindJavaVersionInKeyHKCU + Push "SOFTWARE\Eclipse Adoptium\JDK" + Call FindJavaVersionInKeyHKCU + Push "SOFTWARE\Adoptium\JRE" + Call FindJavaVersionInKeyHKCU + Push "SOFTWARE\Adoptium\JDK" + Call FindJavaVersionInKeyHKCU + Push "SOFTWARE\Microsoft\JDK" + Call FindJavaVersionInKeyHKCU + Push "SOFTWARE\Microsoft\JRE" + Call FindJavaVersionInKeyHKCU +FunctionEnd - ; now check drive-letters - Driveletter: - StrCpy $RootFolder $InstDir 3 +Function FindJavaVersionInKeyHKLM + Exch $1 + Push "Java detection: HKLM\\$1" + Call LogLine + Push $2 + Push $3 + Push $4 + Push $5 + Push $6 + Push $7 + Push $8 + + StrCpy $2 "" + ReadRegStr $2 HKLM "$1" "CurrentVersion" + ${If} $2 != "" + ReadRegStr $3 HKLM "$1\\$2" "JavaHome" + Push "Java detection: HKLM\\$1 CurrentVersion=$2 JavaHome='$3'" + Call LogLine + ${If} $3 != "" + IfFileExists "$3\\bin\\java.exe" 0 CheckEnum + Push "Java detection: java.exe found at $3\\bin\\java.exe" + Call LogLine + StrCpy $JavaFound "1" + Push $2 + Call GetJavaMajor + Pop $6 + IntCmp $6 $JavaMajor NoUpdate NoUpdate UpdateMajor + NoUpdate: + Goto DoneCompare + UpdateMajor: + StrCpy $JavaMajor $6 + StrCpy $JavaVersion $2 + DoneCompare: + Goto DoneHKLM + ${EndIf} + ${EndIf} + + CheckEnum: + StrCpy $3 0 + StrCpy $4 "" + EnumLoop: + EnumRegKey $5 HKLM "$1" $3 + ${If} $5 == "" + Goto EnumDone + ${EndIf} + ReadRegStr $7 HKLM "$1\\$5" "JavaHome" + ${If} $7 != "" + Push "Java detection: HKLM\\$1\\$5 JavaHome='$7'" + Call LogLine + IfFileExists "$7\\bin\\java.exe" 0 EnumNext + ${If} $4 == "" + StrCpy $4 $5 + ${Else} + StrCpy $8 "" + ${VersionCompare} $5 $4 $8 + ${If} $8 == "1" + StrCpy $4 $5 + ${EndIf} + ${EndIf} + ${EndIf} + EnumNext: + IntOp $3 $3 + 1 + Goto EnumLoop + EnumDone: + StrCpy $2 $4 + ${If} $2 != "" + StrCpy $JavaFound "1" + Push $2 + Call GetJavaMajor + Pop $6 + IntCmp $6 $JavaMajor NoUpdateEnum NoUpdateEnum UpdateMajorEnum + NoUpdateEnum: + Goto DoneHKLM + UpdateMajorEnum: + StrCpy $JavaMajor $6 + StrCpy $JavaVersion $2 + ${EndIf} + DoneHKLM: + + Pop $8 + Pop $7 + Pop $6 + Pop $5 + Pop $4 + Pop $3 + Pop $2 + Pop $1 +FunctionEnd - ; prepare for {GetDrives-Loop} - StrCpy $RootFolderType "invalid" - ${GetDrives} "ALL" "CheckDriveType" +Function FindJavaVersionInKeyHKCU + Exch $1 + Push "Java detection: HKCU\\$1" + Call LogLine + Push $2 + Push $3 + Push $4 + Push $5 + Push $6 + Push $7 + Push $8 + + StrCpy $2 "" + ReadRegStr $2 HKCU "$1" "CurrentVersion" + ${If} $2 != "" + ReadRegStr $3 HKCU "$1\\$2" "JavaHome" + Push "Java detection: HKCU\\$1 CurrentVersion=$2 JavaHome='$3'" + Call LogLine + ${If} $3 != "" + IfFileExists "$3\\bin\\java.exe" 0 CheckEnumCU + Push "Java detection: java.exe found at $3\\bin\\java.exe" + Call LogLine + StrCpy $JavaFound "1" + Push $2 + Call GetJavaMajor + Pop $6 + IntCmp $6 $JavaMajor NoUpdate NoUpdate UpdateMajor + NoUpdate: + Goto DoneCompare + UpdateMajor: + StrCpy $JavaMajor $6 + StrCpy $JavaVersion $2 + DoneCompare: + Goto DoneHKCU + ${EndIf} + ${EndIf} + + CheckEnumCU: + StrCpy $3 0 + StrCpy $4 "" + EnumLoopCU: + EnumRegKey $5 HKCU "$1" $3 + ${If} $5 == "" + Goto EnumDoneCU + ${EndIf} + ReadRegStr $7 HKCU "$1\\$5" "JavaHome" + ${If} $7 != "" + Push "Java detection: HKCU\\$1\\$5 JavaHome='$7'" + Call LogLine + IfFileExists "$7\\bin\\java.exe" 0 EnumNextCU + ${If} $4 == "" + StrCpy $4 $5 + ${Else} + StrCpy $8 "" + ${VersionCompare} $5 $4 $8 + ${If} $8 == "1" + StrCpy $4 $5 + ${EndIf} + ${EndIf} + ${EndIf} + EnumNextCU: + IntOp $3 $3 + 1 + Goto EnumLoopCU + EnumDoneCU: + StrCpy $2 $4 + ${If} $2 != "" + StrCpy $JavaFound "1" + Push $2 + Call GetJavaMajor + Pop $6 + IntCmp $6 $JavaMajor NoUpdateEnum NoUpdateEnum UpdateMajorEnum + NoUpdateEnum: + Goto DoneHKCU + UpdateMajorEnum: + StrCpy $JavaMajor $6 + StrCpy $JavaVersion $2 + ${EndIf} + DoneHKCU: + + Pop $8 + Pop $7 + Pop $6 + Pop $5 + Pop $4 + Pop $3 + Pop $2 + Pop $1 +FunctionEnd - ; jump if error - StrCmp $RootFolderType "invalid" CheckSpace +Function LogLine + Exch $0 + Push $1 + FileOpen $1 $LogFile a + FileWrite $1 "$0$\r$\n" + FileClose $1 + DetailPrint "$0" + Pop $1 + Pop $0 +FunctionEnd - ; jump if HDD - StrCmp $RootFolderType "HDD" CheckSpace +Function .onInit + StrCpy $LogFile "$TEMP\\yacy-installer.log" + Delete $LogFile +FunctionEnd - NoHDD: - ; stay on folder-selection if user wants to give another folder, else check free space - MessageBox MB_ICONEXCLAMATION|MB_YESNO "$(yacyNoHd)" IDYES NextPage - Abort +Function YaCyGuiInit + ${If} ${RunningX64} + System::Call 'user32::GetWindowLongPtr(p $HWNDPARENT, i ${GWL_STYLE}) p .r0' + IntOp $0 $0 | ${WS_SIZEBOX} + IntOp $0 $0 | ${WS_MAXIMIZEBOX} + System::Call 'user32::SetWindowLongPtr(p $HWNDPARENT, i ${GWL_STYLE}, p r0)' + ${Else} + System::Call 'user32::GetWindowLong(p $HWNDPARENT, i ${GWL_STYLE}) i .r0' + IntOp $0 $0 | ${WS_SIZEBOX} + IntOp $0 $0 | ${WS_MAXIMIZEBOX} + System::Call 'user32::SetWindowLong(p $HWNDPARENT, i ${GWL_STYLE}, i r0)' + ${EndIf} + System::Call 'user32::SetWindowPos(p $HWNDPARENT, p 0, i 0, i 0, i 0, i 0, i ${SWP_NOMOVE}|${SWP_NOSIZE}|${SWP_NOZORDER}|${SWP_FRAMECHANGED})' +FunctionEnd - CheckSpace: +Function FindJavaFromPath + Push $0 + Push $1 + Push $2 + + nsExec::ExecToStack 'cmd /c java -version 2^>^&1' + Pop $0 + Pop $1 + Push "Java detection: java -version exit=$0" + Call LogLine + Push "Java detection: java -version output=$1" + Call LogLine + ${If} $0 == "0" + StrCpy $JavaFound "1" + Push $1 + Call FindFirstInt + Pop $2 + IntCmp $2 $JavaMajor PathNoUpdate PathNoUpdate PathUpdate + PathNoUpdate: + Goto PathDone + PathUpdate: + StrCpy $JavaMajor $2 + StrCpy $JavaVersion $2 + PathDone: + ${EndIf} + + Pop $2 + Pop $1 + Pop $0 +FunctionEnd - ClearErrors - ${DriveSpace} $RootFolder "/D=F /S=G" $TempDriveFree - ; if DriveSpace fails for any reason -> jump ahead - IfErrors NextPage +Function FindJavaFromEnv + ReadEnvStr $JavaHome "JAVA_HOME" + ${If} $JavaHome != "" + Push "Java detection: JAVA_HOME=$JavaHome" + Call LogLine + IfFileExists "$JavaHome\\bin\\java.exe" 0 JavaHomeDone + Push "$JavaHome\\bin\\java.exe" + Call TryJavaExe + ${EndIf} + JavaHomeDone: + ReadEnvStr $JavaHome "JDK_HOME" + ${If} $JavaHome != "" + Push "Java detection: JDK_HOME=$JavaHome" + Call LogLine + IfFileExists "$JavaHome\\bin\\java.exe" 0 JdkHomeDone + Push "$JavaHome\\bin\\java.exe" + Call TryJavaExe + ${EndIf} + JdkHomeDone: +FunctionEnd - ${If} $TempDriveFree < ${RecommendSpace} - MessageBox MB_ICONEXCLAMATION|MB_YESNO "$(yacyNeedSpace)" IDYES NextPage - Abort - ${EndIf} +Function FindJavaFromProgramFiles + Push "$PROGRAMFILES64\\Java" + Call ScanJavaDir + Push "$PROGRAMFILES\\Java" + Call ScanJavaDir + Push "$PROGRAMFILES64\\Eclipse Adoptium" + Call ScanJavaDir + Push "$PROGRAMFILES\\Eclipse Adoptium" + Call ScanJavaDir + Push "$PROGRAMFILES64\\Adoptium" + Call ScanJavaDir + Push "$PROGRAMFILES\\Adoptium" + Call ScanJavaDir +FunctionEnd - NextPage: +Function ScanJavaDir + Exch $0 + Push $1 + Push $2 + Push $3 + + IfFileExists "$0\\*" 0 ScanDone + FindFirst $1 $2 "$0\\*" + ScanLoop: + StrCmp $2 "" ScanDone + IfFileExists "$0\\$2\\bin\\java.exe" 0 ScanNext + Push "$0\\$2\\bin\\java.exe" + Call TryJavaExe + ScanNext: + FindNext $1 $2 + Goto ScanLoop + ScanDone: + FindClose $1 + Pop $3 + Pop $2 + Pop $1 + Pop $0 FunctionEnd -Function CheckDriveType -; based on http://nsis.sourceforge.net/GetDrives - ${If} $9 == $RootFolder - StrCpy $RootFolderType $8 - StrCpy $0 StopGetDrives - ${EndIf} - Push $0 +Function TryJavaExe + Exch $0 + Push $1 + Push $2 + Push $3 + + StrCpy $1 'cmd /c ""$0" -version 2^>^&1"' + nsExec::ExecToStack $1 + Pop $2 + Pop $3 + ${If} $2 == "0" + StrCpy $JavaFound "1" + Push $3 + Call FindFirstInt + Pop $1 + IntCmp $1 $JavaMajor 0 0 TryUpdate + Goto TryDone + TryUpdate: + StrCpy $JavaMajor $1 + StrCpy $JavaVersion $1 + TryDone: + ${EndIf} + + Pop $3 + Pop $2 + Pop $1 + Pop $0 FunctionEnd -Function OpenFirewall - var /global ExecErrorCode - ; run netsh - nsExec::ExecToStack '$WinAddFwRulePort' - pop $ExecErrorCode - ; if run without error register for uninstall and clear finish page - ${If} $ExecErrorCode = "0" - WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\YaCy" "DelFwRulePort" '$WinDelFwRulePort' - IntOp $FirewallServiceStart 0 + 0 - ${Else} - IntOp $FirewallServiceStart 3 + 0 - ${EndIf} +Function GetJavaMajor + Exch $0 + Push $1 + Push $2 + Push $3 + Push $4 + + StrCpy $1 $0 2 + ${If} $1 == "1." + StrCpy $0 $0 "" 2 + ${EndIf} + + StrCpy $1 "" + StrLen $2 $0 + StrCpy $3 0 + LoopDigits: + IntCmp $3 $2 DoneDigits DoneDigits + StrCpy $4 $0 1 $3 + ${If} $4 >= "0" + ${AndIf} $4 <= "9" + StrCpy $1 "$1$4" + IntOp $3 $3 + 1 + Goto LoopDigits + ${Else} + Goto DoneDigits + ${EndIf} + DoneDigits: + ${If} $1 == "" + StrCpy $1 "0" + ${EndIf} + + StrCpy $0 $1 + Pop $4 + Pop $3 + Pop $2 + Pop $1 + Exch $0 FunctionEnd -Function SHOW_PageFinish_custom - ; hide and disable firewall info from wiki if firewall is open - ${If} $FirewallServiceStart = 0 - SendMessage $mui.FinishPage.ShowReadme ${BM_SETCHECK} 0 0 - ShowWindow $mui.FinishPage.ShowReadme ${SW_HIDE} - ${EndIf} +Function FindFirstInt + Exch $0 + Push $1 + Push $2 + Push $3 + Push $4 + Push $5 + + StrLen $1 $0 + StrCpy $2 0 + StrCpy $3 "" + StrCpy $4 0 + FindLoop: + IntCmp $2 $1 FindDone FindDone + StrCpy $5 $0 1 $2 + ${If} $4 == 0 + ${If} $5 >= "0" + ${AndIf} $5 <= "9" + StrCpy $4 1 + StrCpy $3 "$3$5" + ${EndIf} + ${Else} + ${If} $5 >= "0" + ${AndIf} $5 <= "9" + StrCpy $3 "$3$5" + ${Else} + Goto FindDone + ${EndIf} + ${EndIf} + IntOp $2 $2 + 1 + Goto FindLoop + FindDone: + ${If} $3 == "" + StrCpy $3 "0" + ${EndIf} + + StrCpy $0 $3 + Pop $5 + Pop $4 + Pop $3 + Pop $2 + Pop $1 + Exch $0 FunctionEnd -Function un.CloseFirewall - ; get string for closing port from registy - ReadRegStr '$WinDelFwRulePort' HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\YaCy" "DelFwRulePort" - ; if found > run netsh to close port - ${IfNot} '$WinDelFwRulePort' == '' - nsExec::ExecToStack '$WinDelFwRulePort' - ${EndIf} +Function DownloadJava + ${If} ${RunningX64} + StrCpy $JavaInstallerUrl "https://github.com/adoptium/temurin25-binaries/releases/download/jdk-25%2B36/OpenJDK25U-jdk_x64_windows_hotspot_25_36.msi" + StrCpy $JavaInstallerPath "$TEMP\\temurin-jdk-25-x64.msi" + ${Else} + MessageBox MB_ICONEXCLAMATION "This installer only supports 64-bit Windows." + Abort + ${EndIf} + + Push "Java install: download URL=$JavaInstallerUrl" + Call LogLine + Push "Java install: download path=$JavaInstallerPath" + Call LogLine + + Push "Java install: using PowerShell downloader (HTTPS)" + Call LogLine + StrCpy $2 "$TEMP\\yacy-download.ps1" + StrCpy $3 "$TEMP\\yacy-download.done" + StrCpy $4 "$TEMP\\yacy-download.err" + Delete $3 + Delete $4 + FileOpen $1 $2 w + FileWrite $1 "try {$\r$\n" + FileWrite $1 " [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12$\r$\n" + FileWrite $1 " $$wc = New-Object System.Net.WebClient$\r$\n" + FileWrite $1 " $$wc.DownloadFile('$JavaInstallerUrl', '$JavaInstallerPath')$\r$\n" + FileWrite $1 " 'OK' | Out-File -FilePath '$3' -Encoding ASCII$\r$\n" + FileWrite $1 "} catch { $\r$\n" + FileWrite $1 " $$_.Exception.Message | Out-File -FilePath '$4' -Encoding ASCII$\r$\n" + FileWrite $1 " exit 1$\r$\n" + FileWrite $1 "}$\r$\n" + FileClose $1 + Exec '"$SYSDIR\\WindowsPowerShell\\v1.0\\powershell.exe" -NoProfile -ExecutionPolicy Bypass -WindowStyle Hidden -File "$2"' + + StrCpy $5 0 + StrCpy $8 -1 + PowerLoop: + IfFileExists "$3" PowerDone + IfFileExists "$4" PowerError + IfFileExists "$JavaInstallerPath" 0 PowerWait + FileOpen $1 "$JavaInstallerPath" r + FileSeek $1 0 END $6 + FileClose $1 + IntOp $7 $6 / 1048576 + IntCmp $7 $8 PowerWait PowerWait PowerPrint + PowerPrint: + StrCpy $8 $7 + Push "Java install: downloaded ~$7 MB..." + Call LogLine + PowerWait: + Sleep 2000 + IntOp $5 $5 + 2 + IntCmp $5 1200 PowerTimeout PowerLoop PowerLoop + PowerTimeout: + Push "Java install: PowerShell download timeout" + Call LogLine + MessageBox MB_ICONEXCLAMATION "$(javaDownloadFail)$\r$\n$JavaInstallerUrl" + Delete $2 + Delete $3 + Delete $4 + Return + PowerError: + Push "Java install: PowerShell download failed" + Call LogLine + MessageBox MB_ICONEXCLAMATION "$(javaDownloadFail)$\r$\n$JavaInstallerUrl" + Delete $2 + Delete $3 + Delete $4 + Return + PowerDone: + Delete $2 + Delete $3 + Delete $4 + + ExecWait '"msiexec" /i "$JavaInstallerPath" /passive /norestart' FunctionEnd |
