Get the new PortableApps.com Platform 10.0: Gorgeous themes, a full portable app store and advanced functionality
Announcing the World's Best Flash Drive: The PortableApps.com Companion | Did you see a malware warning on Friday?

Problem with Nsis launcher code.

radarman36's picture
radarman36 (Homepage) - November 20, 2009 - 4:06pm

Hi everyone,

I'm making a portable version of Geogebra, but I'm unable to do a launcher which checks without errors if Java is installed on the host PC, or on the USB drive.

I looked after many source scripts, but with no success, unfortunaltely =(
So, could anyone make a Function I'll include on my script, with this check ?(The global check 'll be the Java on the host, If found, launch the program, if not, check if Java is installed on the USB Drive. If found, launch too, and If not, abort.)

Thanks in advance guys Eye-wink


( categories: )

how bout you show us the

how bout you show us the source of your launcher.

Look at eclipse to see a well built implementation of jave

Too many lonely hearts in the real world
Too many bridges you can burn
Too many tables you can't turn
Don't wanna live my life in the real world

Already done...

I've already saw at the Eclipse portable launcher, but with no success.

If you want to see, here is my launcher (2 parts : main, and a .nsh file.

GeogebraPortable.nsi :

; PortableApps.com & Vince'
; NSIS with Registry.nsh in Include and Registry.dll, FindProcDLL.dll, KillProcDLL.dll in Plugins

; **************************************************************************
; === Define constants ===
; **************************************************************************
!define VER 		"3.2.0.0"	; version of launcher
!define APPNAME 	"Geogebra"	; complete name of program
!define APP 		"Geogebra"	; short name of program without space and accent  this one is used for the final executable an in the directory structure
!define APPEXE 		"GeoGebra.exe"	; main exe name
!define APPDIR 		"App\GeoGebra"	; main exe relative path
!define APPSWITCH 	""	; some default Parameters

; **************************************************************************
; === Best Compression ===
; **************************************************************************
SetCompressor /SOLID lzma
SetCompressorDictSize 32

; **************************************************************************
; === Includes ===
; **************************************************************************
!include "PortableApp.nsh" 

; **************************************************************************
; === Set basic information ===
; **************************************************************************
Name "${APPNAME} Portable"
OutFile "..\..\${APP}Portable.exe"
Icon "${APP}.ico"

; **************************************************************************
; === MultiLang ===
; **************************************************************************
Var LNG
Function MultiLang
StrCpy $LNG "English"
System::Call 'kernel32::GetUserDefaultLangID() i .r0'
StrCmp $0 "1033" 0 +2
StrCpy $LNG "English"
StrCmp $0 "1036" 0 +2
StrCpy $LNG "Francais"
ReadINIStr $0 "$EXEDIR\${APP}Portable.ini" "${APP}Portable" "UserDefaultLang"
StrCmp $0 "false" +3
WriteINIStr "$EXEDIR\${APP}Portable.ini" "${APP}Portable" "UserDefaultLang" "true"
WriteRegStr HKEY_LOCAL_MACHINE "SOFTWARE\MyProg" "Language" "$LNG"
FunctionEnd

; **************************************************************************
; === Other Actions ===
; **************************************************************************
Function Init

FunctionEnd

Function Close

FunctionEnd


; **************************************************************************
; ==== Running ====
; **************************************************************************
Section "Main"

	Call CheckStart
	
	Call Init
	Call MultiLang

		Call SplashLogo
		Call Launch

	Call Restore

SectionEnd

Function Restore

	Call Close

FunctionEnd

; **************************************************************************
; === Run Application ===
; **************************************************************************
Function Launch
SetOutPath "$EXEDIR\${APPDIR}"
${GetParameters} $0
ExecWait `"$EXEDIR\${APPDIR}\${APPEXE}"${APPSWITCH} $0`
WriteINIStr "$EXEDIR\Data\${APP}Portable.ini" "${APP}Portable" "GoodExit" "true"
FunctionEnd

Portableapp.nsh :

 ; **************************************************************************
; === Set version information ===
; **************************************************************************
Caption "${APPNAME} Portable"
VIProductVersion "${VER}"
VIAddVersionKey ProductName "${APPNAME} Portable"
VIAddVersionKey Comments "Allows ${APPNAME} to be run from a removable drive."
VIAddVersionKey CompanyName ""
VIAddVersionKey LegalCopyright ""
VIAddVersionKey FileDescription "${APPNAME} Portable"
VIAddVersionKey FileVersion "${VER}"
VIAddVersionKey ProductVersion "${VER}"
VIAddVersionKey InternalName "${APPNAME} Portable"
VIAddVersionKey LegalTrademarks ""
VIAddVersionKey OriginalFilename "${APP}Portable.exe"

; **************************************************************************
; === Includes ===
; **************************************************************************
!ifdef REGKEY1
!include "Registry.nsh"
!endif
!include TextFunc.nsh
!insertmacro GetParameters

; **************************************************************************
; === Runtime Switches ===
; **************************************************************************
WindowIcon Off
SilentInstall Silent
AutoCloseWindow True
RequestExecutionLevel user

; **************************************************************************
; ===Start ===
; **************************************************************************

Function CheckDirExe
	IfFileExists "$EXEDIR\${APPDIR}\${APPEXE}" +3
	MessageBox MB_OK|MB_ICONEXCLAMATION `${APPEXE} was not found in $EXEDIR\${APPDIR}`
	Abort
FunctionEnd

Function CheckRunExe
	ReadINIStr $0 "$EXEDIR\${APP}Portable.ini" "${APP}Portable" "AllowMultipleInstances"
	StrCmp $0 "" 0 +2
	WriteINIStr "$EXEDIR\${APP}Portable.ini" "${APP}Portable" "AllowMultipleInstances" "false"
	FindProcDLL::FindProc "${APPEXE}"
		Pop $R0
		StrCmp $R0 "1" 0 CheckRunEnd
	ReadINIStr $0 "$EXEDIR\${APP}Portable.ini" "${APP}Portable" "AllowMultipleInstances"
	StrCmp $0 "true" SecondLaunch
		MessageBox MB_OK|MB_ICONINFORMATION `Another ${APPNAME} is running. Close ${APPNAME} before running ${APPNAME} Portable.`
		Abort
SecondLaunch:
	SetOutPath "$EXEDIR\${APPDIR}"
	${GetParameters} $0
	Exec `"$EXEDIR\${APPDIR}\${APPEXE}"${APPSWITCH} $0`
	Abort
CheckRunEnd:
FunctionEnd

Function CheckRegWrite
!ifdef REGKEY1
ReadINIStr $0 "$EXEDIR\${APP}Portable.ini" "${APP}Portable" "CheckRegWrite"
StrCmp $0 "false" +8
WriteINIStr "$EXEDIR\${APP}Portable.ini" "${APP}Portable" "CheckRegWrite" "true"
	${registry::CreateKey} "HKEY_LOCAL_MACHINE\SOFTWARE\PortableAppRegistryTest" "$R7"
	StrCmp "$R7" "-1" "" +4
		MessageBox MB_OKCANCEL|MB_ICONQUESTION 'You are not allowed to write to the registry!!$\nContinue anyway?' IDOK +3 IDCANCEL 0
		${registry::Unload}
		Abort
	${registry::DeleteKey} "HKEY_LOCAL_MACHINE\SOFTWARE\PortableAppRegistryTest" "$R7"
!endif
FunctionEnd

Function CheckGoodExit
	ReadINIStr $0 "$EXEDIR\Data\${APP}Portable.ini" "${APP}Portable" "GoodExit"
	StrCmp $0 "false" 0 CheckExitEnd
	ReadINIStr $0 "$EXEDIR\${APP}Portable.ini" "${APP}Portable" "AllowMultipleInstances"
	StrCmp $0 "true" 0 +4
	FindProcDLL::FindProc "${APPEXE}"
		Pop $R0
		StrCmp $R0 "1" CheckExitEnd
	MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION `Last exit of ${APP}Portable did'nt restore settings.$\nWould you try to restore local and backup portable settings now?` IDOK RestoreNow IDCANCEL CheckExitEnd
	RestoreNow:
	Call Restore
	CheckExitEnd:
FunctionEnd

Function CheckStart
	Call CheckDirExe
	Call CheckRegWrite
	Call CheckRunExe
	Call CheckGoodExit
FunctionEnd

; **************************************************************************
; === Before Launching ===
; **************************************************************************
Function SplashLogo
	CreateDirectory "$EXEDIR\Data"
	ReadINIStr $0 "$EXEDIR\${APP}Portable.ini" "${APP}Portable" "DisableSplashScreen"
	StrCmp $0 "true" +6
	WriteINIStr "$EXEDIR\${APP}Portable.ini" "${APP}Portable" "DisableSplashScreen" "false"
	InitPluginsDir
	File /oname=$PLUGINSDIR\splash.bmp "${APP}Splash.bmp"
	newadvsplash::show /NOUNLOAD 1000 300 200 0xFF00FF /L $PLUGINSDIR\splash.bmp
	Pop $0
	WriteINIStr "$EXEDIR\Data\${APP}Portable.ini" "${APP}Portable" "LastDirectory" "$EXEDIR"
	WriteINIStr "$EXEDIR\Data\${APP}Portable.ini" "${APP}Portable" "GoodExit" "false"
	SetFileAttributes "$EXEDIR\Data\${APP}Portable.ini" HIDDEN
FunctionEnd

Eclipse?

I would think that one of Rab040ma's launcher would be a better base; he has a billion java apps on him.

Insert original signature here with Greasemonkey Script.

Thanks !

I've seen the code of the Frostwire launcher, and I achieved to make the launcher. I publish the package soon Eye-wink

Thank you dude !