You are here

What launcher to look at?

14 posts / 0 new
Last post
Devo
Offline
Last seen: 4 months 2 weeks ago
Joined: 2007-09-04 14:55
What launcher to look at?

Does anybody know what launcher to look at if there is data in C:\Documents and Settings\[username]\Local Settings\Application Data?

Or what variable to use? I'm writing a launcher for an app that stores data there and in the registry.

Thanks

OliverK
OliverK's picture
Offline
Last seen: 1 year 7 months ago
Developer
Joined: 2007-03-27 15:21
ATanks would handle the app

ATanks would handle the app data. Something like VTi will handle the registry. I don't know of any off the top of my head that deal with both.

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

Devo
Offline
Last seen: 4 months 2 weeks ago
Joined: 2007-09-04 14:55
Unfortunately this isn't what

Unfortunately this isn't what I was looking for. This deals with files that are in the ./App/atanks folder. I need to move files that are located in C:/Documents and Settings/[username]/Local Settings/Application Data. I to use "$USERPROFILE/Local Settings/Application Data" but I get an error when I'm compiling the script and the files are not moved.

OliverK
OliverK's picture
Offline
Last seen: 1 year 7 months ago
Developer
Joined: 2007-03-27 15:21
StrCyp $0
StrCyp $0 $DATADIRECTORY
System::Call 'Kernel32::SetEnvironmentVariableA(t, t) i("APPDATA", "$0").r0'

Use APPDATA to deal with files in %Application Data% and PROFILE for things in the profile folder.

Post a copy of the script and the error (in PRE tags :D) and I'll see I can see.

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

Devo
Offline
Last seen: 4 months 2 weeks ago
Joined: 2007-09-04 14:55
The problem is the APPDATA

The problem is the APPDATA variable refers to C:/Documents and Settings/[username]/Appication Data, which is the wrong folder.

I've posted my code below. I'm sure there's a better way to do this, but I'm not really good at writing launchers. Make any changes you think are necessary, but please let me know what they are so I can learn from my mistakes.

;Copyright (C) 2004-2008 John T. Haller

;Website: http://PortableApps.com/Development/test

;This software is OSI Certified Open Source Software.
;OSI Certified is a certification mark of the Open Source Initiative.

;This program is free software; you can redistribute it and/or
;modify it under the terms of the GNU General Public License
;as published by the Free Software Foundation; either version 2
;of the License, or (at your option) any later version.

;This program is distributed in the hope that it will be useful,
;but WITHOUT ANY WARRANTY; without even the implied warranty of
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;GNU General Public License for more details.

;You should have received a copy of the GNU General Public License
;along with this program; if not, write to the Free Software
;Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

!define PORTABLEAPPNAME "MediaMonkey Portable"
!define NAME "MediaMonkeyPortable"
!define APPNAME "MediaMonkey"
!define VER "3.0.6.1190"
!define WEBSITE "PortableApps.com/Development/test"
!define DEFAULTEXE "MediaMonkey.exe"
!define DEFAULTAPPDIR "MediaMonkey"
!define DEFAULTSETTINGSPATH "settings"

;=== Program Details
Name "${PORTABLEAPPNAME}"
OutFile "..\..\${NAME}.exe"
Caption "${PORTABLEAPPNAME} | PortableApps.com"
VIProductVersion "${VER}"
VIAddVersionKey ProductName "${PORTABLEAPPNAME}"
VIAddVersionKey Comments "Allows ${APPNAME} to be run from a removable drive.  For additional details, visit ${WEBSITE}"
VIAddVersionKey CompanyName "PortableApps.com"
VIAddVersionKey LegalCopyright "John T. Haller"
VIAddVersionKey FileDescription "${PORTABLEAPPNAME}"
VIAddVersionKey FileVersion "${VER}"
VIAddVersionKey ProductVersion "${VER}"
VIAddVersionKey InternalName "${PORTABLEAPPNAME}"
VIAddVersionKey LegalTrademarks "PortableApps.com is a Trademark of Rare Ideas, LLC."
VIAddVersionKey OriginalFilename "${NAME}.exe"
;VIAddVersionKey PrivateBuild ""
;VIAddVersionKey SpecialBuild ""

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

; Best Compression
SetCompress Auto
SetCompressor /SOLID lzma
SetCompressorDictSize 32
SetDatablockOptimize On

;=== Include
!include "Registry.nsh"
!include "GetParameters.nsh"
!include "MUI.nsh"

;=== Program Icon
Icon "..\..\App\AppInfo\appicon.ico"

;=== Icon & Stye ===
!define MUI_ICON "..\..\App\AppInfo\appicon.ico"

;=== Languages
!insertmacro MUI_LANGUAGE "English"

LangString LauncherFileNotFound ${LANG_ENGLISH} "${PORTABLEAPPNAME} cannot be started. You may wish to re-install to fix this issue. (ERROR: $MISSINGFILEORPATH could not be found)"
LangString LauncherAlreadyRunning ${LANG_ENGLISH} "Another instance of ${APPNAME} is already running. Please close other instances of ${APPNAME} before launching ${PORTABLEAPPNAME}."
LangString LauncherAskCopyLocal ${LANG_ENGLISH} "${PORTABLEAPPNAME} appears to be running from a location that is read-only. Would you like to temporarily copy it to the local hard drive and run it from there?$\n$\nPrivacy Note: If you say Yes, your personal data within ${PORTABLEAPPNAME} will be temporarily copied to a local drive. Although this copy of your data will be deleted when you close ${PORTABLEAPPNAME}, it may be possible for someone else to access your data later."
LangString LauncherNoReadOnly ${LANG_ENGLISH} "${PORTABLEAPPNAME} can not run directly from a read-only location and will now close."

Var PROGRAMDIRECTORY
Var SETTINGSDIRECTORY
Var ADDITIONALPARAMETERS
Var EXECSTRING
Var PROGRAMEXECUTABLE
Var INIPATH
Var DISABLESPLASHSCREEN
Var ISDEFAULTDIRECTORY
Var SECONDARYLAUNCH
Var FAILEDTORESTOREKEY
Var MISSINGFILEORPATH
Var USERPROFILE

Section "Main"
	;=== Check if already running
	System::Call 'kernel32::CreateMutexA(i 0, i 0, t "${NAME}2") i .r1 ?e'
	Pop $0
	StrCmp $0 0 CheckForINI
		StrCpy $SECONDARYLAUNCH "true"

	CheckForINI:
	;=== Find the INI file, if there is one
		IfFileExists "$EXEDIR\${NAME}.ini" "" NoINI
			StrCpy "$INIPATH" "$EXEDIR"
			Goto ReadINI

	ReadINI:
		;=== Read the parameters from the INI file
		ReadINIStr $0 "$INIPATH\${NAME}.ini" "${NAME}" "${APPNAME}Directory"
		StrCpy "$PROGRAMDIRECTORY" "$EXEDIR\$0"
		ReadINIStr $0 "$INIPATH\${NAME}.ini" "${NAME}" "SettingsDirectory"
		StrCpy "$SETTINGSDIRECTORY" "$EXEDIR\$0"

		;=== Check that the above required parameters are present
		IfErrors NoINI

		ReadINIStr $0 "$INIPATH\${NAME}.ini" "${NAME}" "AdditionalParameters"
		StrCpy "$ADDITIONALPARAMETERS" $0
		ReadINIStr $0 "$INIPATH\${NAME}.ini" "${NAME}" "${APPNAME}Executable"
		StrCpy "$PROGRAMEXECUTABLE" $0
		ReadINIStr $0 "$INIPATH\${NAME}.ini" "${NAME}" "DisableSplashScreen"
		StrCpy "$DISABLESPLASHSCREEN" $0

	;CleanUpAnyErrors:
		;=== Any missing unrequired INI entries will be an empty string, ignore associated errors
		ClearErrors

		;=== Correct PROGRAMEXECUTABLE if blank
		StrCmp $PROGRAMEXECUTABLE "" "" CheckForProgramINI
			StrCpy "$PROGRAMEXECUTABLE" "${DEFAULTEXE}"
			Goto CheckForProgramINI
			
	CheckForProgramINI:
		IfFileExists "$PROGRAMDIRECTORY\$PROGRAMEXECUTABLE" FoundProgramEXE NoProgramEXE

	NoINI:
		;=== No INI file, so we'll use the defaults
		StrCpy "$ADDITIONALPARAMETERS" ""
		StrCpy "$PROGRAMEXECUTABLE" "${DEFAULTEXE}"
		StrCpy "$DISABLESPLASHSCREEN" "false"

		IfFileExists "$EXEDIR\App\${DEFAULTAPPDIR}\${DEFAULTEXE}" "" NoProgramEXE
			StrCpy "$PROGRAMDIRECTORY" "$EXEDIR\App\${DEFAULTAPPDIR}"
			StrCpy "$SETTINGSDIRECTORY" "$EXEDIR\Data\${DEFAULTSETTINGSPATH}"
			StrCpy "$ISDEFAULTDIRECTORY" "true"
			GoTo FoundProgramEXE

	NoProgramEXE:
		;=== Program executable not where expected
		StrCpy $MISSINGFILEORPATH $PROGRAMEXECUTABLE
		MessageBox MB_OK|MB_ICONEXCLAMATION `$(LauncherFileNotFound)`
		Abort
		
	FoundProgramEXE:
		;=== Check if already running
		StrCmp $SECONDARYLAUNCH "true" CheckForSettings
		FindProcDLL::FindProc "$PROGRAMEXECUTABLE"                 
		StrCmp $R0 "1" WarnAnotherInstance CheckForSettings

	WarnAnotherInstance:
		MessageBox MB_OK|MB_ICONINFORMATION `$(LauncherAlreadyRunning)`
		Abort
	
	CheckForSettings:
		IfFileExists "$SETTINGSDIRECTORY\*.*" SettingsFound
		;=== No settings found
		StrCmp $ISDEFAULTDIRECTORY "true" CopyDefaultSettings
		CreateDirectory $SETTINGSDIRECTORY
		Goto SettingsFound
	
	CopyDefaultSettings:
		CreateDirectory "$EXEDIR\Data"
		CreateDirectory "$EXEDIR\Data\settings"
		CopyFiles /SILENT $EXEDIR\App\DefaultData\settings\*.* $EXEDIR\Data\settings
		Goto SettingsFound

	SettingsFound:
		StrCmp $DISABLESPLASHSCREEN "true" GetPassedParameters
			;=== Show the splash screen before processing the files
			InitPluginsDir
			File /oname=$PLUGINSDIR\splash.jpg "${NAME}.jpg"	
			newadvsplash::show /NOUNLOAD 1500 200 0 -1 /L $PLUGINSDIR\splash.jpg

	GetPassedParameters:
		;=== Get any passed parameters
		Call GetParameters
		Pop $0
		StrCmp "'$0'" "''" "" LaunchProgramParameters

		;=== No parameters
		StrCpy $EXECSTRING `"$PROGRAMDIRECTORY\$PROGRAMEXECUTABLE"`
		Goto AdditionalParameters

	LaunchProgramParameters:
		StrCpy $EXECSTRING `"$PROGRAMDIRECTORY\$PROGRAMEXECUTABLE" $0`

	AdditionalParameters:
		StrCmp $ADDITIONALPARAMETERS "" RegistryBackup

		;=== Additional Parameters
		StrCpy $EXECSTRING `$EXECSTRING $ADDITIONALPARAMETERS`

	RegistryBackup:
		StrCmp $SECONDARYLAUNCH "true" LaunchAndExit
		;=== Backup the registry
		${registry::KeyExists} "HKEY_CURRENT_USER\Software\MediaMonkey-BackupByMediaMonkeyPortable" $R0
		StrCmp $R0 "0" RestoreTheKey
		${registry::KeyExists} "HKEY_CURRENT_USER\Software\MediaMonkey" $R0
		StrCmp $R0 "-1" RestoreTheKey
		${registry::MoveKey} "HKEY_CURRENT_USER\Software\MediaMonkey" "HKEY_CURRENT_USER\Software\MediaMonkey-BackupByMediaMonkeyPortable" $R0
		Sleep 100
		
	RestoreTheKey:
		IfFileExists "$SETTINGSDIRECTORY\MediaMonkey.reg" "" DetermineLocalInstall
	
		IfFileExists "$WINDIR\system32\reg.exe" "" RestoreTheKey9x
			nsExec::ExecToStack `"$WINDIR\system32\reg.exe" import "$SETTINGSDIRECTORY\MediaMonkey.reg"`
			Pop $R0
			StrCmp $R0 '0' DetermineLocalInstall ;successfully restored key

	RestoreTheKey9x:
		${registry::RestoreKey} "$SETTINGSDIRECTORY\MediaMonkey.reg" $R0
		StrCmp $R0 '0' DetermineLocalInstall ;successfully restored key
		StrCpy $FAILEDTORESTOREKEY "true"
	
	DetermineLocalInstall:
	IfFileExists "$USERPROFILE\Local Settings\Application Data\MediaMonkey\*.m3u" MoveOriginalSettings LaunchNow
	
	MoveOriginalSettings:
		Rename "$USERPROFILE\Local Settings\Application Data\MediaMonkey" "$USERPROFILE\Local Settings\Application Data\MediaMonkey-BackupByMediaMonkeyPortable"
		Sleep 100
		CreateDirectory "$USERPROFILE\Local Settings\Application Data\MediaMonkey"
		CopyFiles /SILENT "$SETTINGSDIRECTORY\MediaMonkey\*.*" "$USERPROFILE\Local Settings\Application Data\MediaMonkey"
		Goto LaunchNow
	
	LaunchNow:
		Sleep 100
		ExecWait $EXECSTRING
		
	CheckRunning:
		Sleep 1000
		FindProcDLL::FindProc "${DEFAULTEXE}"                  
		StrCmp $R0 "1" CheckRunning
		
		StrCmp $FAILEDTORESTOREKEY "true" SetOriginalKeyBack
		${registry::SaveKey} "HKEY_CURRENT_USER\Software\MediaMonkey" "$SETTINGSDIRECTORY\MediaMonkey.reg" "" $0
		Sleep 100
	
	SetOriginalKeyBack:
		${registry::DeleteKey} "HKEY_CURRENT_USER\Software\MediaMonkey" $R0
		Sleep 100
		${registry::KeyExists} "HKEY_CURRENT_USER\Software\MediaMonkey-BackupByMediaMonkeyPortable" $R0
		StrCmp $R0 "-1" MoveSettingsBack
		${registry::MoveKey} "HKEY_CURRENT_USER\Software\MediaMonkey-BackupByMediaMonkeyPortable" "HKEY_CURRENT_USER\Software\MediaMonkey" $R0
		Sleep 100
		Goto MoveSettingsBack
	
	MoveSettingsBack:
		Rename "$USERPROFILE\Local Settings\Application Data\MediaMonkey" "$SETTINGSDIRECTORY\MediaMonkey"
		Sleep 100
		Rename "$USERPROFILE\Local Settings\Application Data\MediaMonkey-BackupByMediaMonkeyPortable" "$USERPROFILE\Local Settings\Application Data\MediaMonkey"
		Sleep 100
		Goto TheEnd
		
	LaunchAndExit:
		Exec $EXECSTRING
	
	TheEnd:
		${registry::Unload}
		newadvsplash::stop /WAIT
SectionEnd

This is the error I get:

1 warning:
  Variable "USERPROFILE" not referenced or never set, wasting memory!
OliverK
OliverK's picture
Offline
Last seen: 1 year 7 months ago
Developer
Joined: 2007-03-27 15:21
Try replacing USERPROFILE

Try replacing USERPROFILE with PROFILE
And then delete Var USERPROFILE

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

Devo
Offline
Last seen: 4 months 2 weeks ago
Joined: 2007-09-04 14:55
Works

This worked. I've been testing it and I'm pretty sure everything gets backed up and restored. Can you check through the code just to make sure it works right. I'm not exactly sure if everything will work properly all the time, or if there are better ways to do things.

;Copyright (C) 2004-2008 John T. Haller

;Website: http://PortableApps.com/Development/test

;This software is OSI Certified Open Source Software.
;OSI Certified is a certification mark of the Open Source Initiative.

;This program is free software; you can redistribute it and/or
;modify it under the terms of the GNU General Public License
;as published by the Free Software Foundation; either version 2
;of the License, or (at your option) any later version.

;This program is distributed in the hope that it will be useful,
;but WITHOUT ANY WARRANTY; without even the implied warranty of
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;GNU General Public License for more details.

;You should have received a copy of the GNU General Public License
;along with this program; if not, write to the Free Software
;Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

!define PORTABLEAPPNAME "MediaMonkey Portable"
!define NAME "MediaMonkeyPortable"
!define APPNAME "MediaMonkey"
!define VER "3.0.6.1190"
!define WEBSITE "PortableApps.com/Development/test"
!define DEFAULTEXE "MediaMonkey.exe"
!define DEFAULTAPPDIR "MediaMonkey"
!define DEFAULTSETTINGSPATH "settings"

;=== Program Details
Name "${PORTABLEAPPNAME}"
OutFile "..\..\${NAME}.exe"
Caption "${PORTABLEAPPNAME} | PortableApps.com"
VIProductVersion "${VER}"
VIAddVersionKey ProductName "${PORTABLEAPPNAME}"
VIAddVersionKey Comments "Allows ${APPNAME} to be run from a removable drive.  For additional details, visit ${WEBSITE}"
VIAddVersionKey CompanyName "PortableApps.com"
VIAddVersionKey LegalCopyright "John T. Haller"
VIAddVersionKey FileDescription "${PORTABLEAPPNAME}"
VIAddVersionKey FileVersion "${VER}"
VIAddVersionKey ProductVersion "${VER}"
VIAddVersionKey InternalName "${PORTABLEAPPNAME}"
VIAddVersionKey LegalTrademarks "PortableApps.com is a Trademark of Rare Ideas, LLC."
VIAddVersionKey OriginalFilename "${NAME}.exe"
;VIAddVersionKey PrivateBuild ""
;VIAddVersionKey SpecialBuild ""

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

; Best Compression
SetCompress Auto
SetCompressor /SOLID lzma
SetCompressorDictSize 32
SetDatablockOptimize On

;=== Include
!include "Registry.nsh"
!include "GetParameters.nsh"
!include "MUI.nsh"

;=== Program Icon
Icon "..\..\App\AppInfo\appicon.ico"

;=== Icon & Stye ===
!define MUI_ICON "..\..\App\AppInfo\appicon.ico"

;=== Languages
!insertmacro MUI_LANGUAGE "English"

LangString LauncherFileNotFound ${LANG_ENGLISH} "${PORTABLEAPPNAME} cannot be started. You may wish to re-install to fix this issue. (ERROR: $MISSINGFILEORPATH could not be found)"
LangString LauncherAlreadyRunning ${LANG_ENGLISH} "Another instance of ${APPNAME} is already running. Please close other instances of ${APPNAME} before launching ${PORTABLEAPPNAME}."
LangString LauncherAskCopyLocal ${LANG_ENGLISH} "${PORTABLEAPPNAME} appears to be running from a location that is read-only. Would you like to temporarily copy it to the local hard drive and run it from there?$\n$\nPrivacy Note: If you say Yes, your personal data within ${PORTABLEAPPNAME} will be temporarily copied to a local drive. Although this copy of your data will be deleted when you close ${PORTABLEAPPNAME}, it may be possible for someone else to access your data later."
LangString LauncherNoReadOnly ${LANG_ENGLISH} "${PORTABLEAPPNAME} can not run directly from a read-only location and will now close."

Var PROGRAMDIRECTORY
Var SETTINGSDIRECTORY
Var ADDITIONALPARAMETERS
Var EXECSTRING
Var PROGRAMEXECUTABLE
Var INIPATH
Var DISABLESPLASHSCREEN
Var ISDEFAULTDIRECTORY
Var SECONDARYLAUNCH
Var FAILEDTORESTOREKEY
Var MISSINGFILEORPATH

Section "Main"
	;=== Check if already running
	System::Call 'kernel32::CreateMutexA(i 0, i 0, t "${NAME}2") i .r1 ?e'
	Pop $0
	StrCmp $0 0 CheckForINI
		StrCpy $SECONDARYLAUNCH "true"

	CheckForINI:
	;=== Find the INI file, if there is one
		IfFileExists "$EXEDIR\${NAME}.ini" "" NoINI
			StrCpy "$INIPATH" "$EXEDIR"
			Goto ReadINI

	ReadINI:
		;=== Read the parameters from the INI file
		ReadINIStr $0 "$INIPATH\${NAME}.ini" "${NAME}" "${APPNAME}Directory"
		StrCpy "$PROGRAMDIRECTORY" "$EXEDIR\$0"
		ReadINIStr $0 "$INIPATH\${NAME}.ini" "${NAME}" "SettingsDirectory"
		StrCpy "$SETTINGSDIRECTORY" "$EXEDIR\$0"

		;=== Check that the above required parameters are present
		IfErrors NoINI

		ReadINIStr $0 "$INIPATH\${NAME}.ini" "${NAME}" "AdditionalParameters"
		StrCpy "$ADDITIONALPARAMETERS" $0
		ReadINIStr $0 "$INIPATH\${NAME}.ini" "${NAME}" "${APPNAME}Executable"
		StrCpy "$PROGRAMEXECUTABLE" $0
		ReadINIStr $0 "$INIPATH\${NAME}.ini" "${NAME}" "DisableSplashScreen"
		StrCpy "$DISABLESPLASHSCREEN" $0

	;CleanUpAnyErrors:
		;=== Any missing unrequired INI entries will be an empty string, ignore associated errors
		ClearErrors

		;=== Correct PROGRAMEXECUTABLE if blank
		StrCmp $PROGRAMEXECUTABLE "" "" CheckForProgramINI
			StrCpy "$PROGRAMEXECUTABLE" "${DEFAULTEXE}"
			Goto CheckForProgramINI
			
	CheckForProgramINI:
		IfFileExists "$PROGRAMDIRECTORY\$PROGRAMEXECUTABLE" FoundProgramEXE NoProgramEXE

	NoINI:
		;=== No INI file, so we'll use the defaults
		StrCpy "$ADDITIONALPARAMETERS" ""
		StrCpy "$PROGRAMEXECUTABLE" "${DEFAULTEXE}"
		StrCpy "$DISABLESPLASHSCREEN" "false"

		IfFileExists "$EXEDIR\App\${DEFAULTAPPDIR}\${DEFAULTEXE}" "" NoProgramEXE
			StrCpy "$PROGRAMDIRECTORY" "$EXEDIR\App\${DEFAULTAPPDIR}"
			StrCpy "$SETTINGSDIRECTORY" "$EXEDIR\Data\${DEFAULTSETTINGSPATH}"
			StrCpy "$ISDEFAULTDIRECTORY" "true"
			GoTo FoundProgramEXE

	NoProgramEXE:
		;=== Program executable not where expected
		StrCpy $MISSINGFILEORPATH $PROGRAMEXECUTABLE
		MessageBox MB_OK|MB_ICONEXCLAMATION `$(LauncherFileNotFound)`
		Abort
		
	FoundProgramEXE:
		;=== Check if already running
		StrCmp $SECONDARYLAUNCH "true" CheckForSettings
		FindProcDLL::FindProc "$PROGRAMEXECUTABLE"                 
		StrCmp $R0 "1" WarnAnotherInstance CheckForSettings

	WarnAnotherInstance:
		MessageBox MB_OK|MB_ICONINFORMATION `$(LauncherAlreadyRunning)`
		Abort
	
	CheckForSettings:
		IfFileExists "$SETTINGSDIRECTORY\*.*" SettingsFound
		;=== No settings found
		StrCmp $ISDEFAULTDIRECTORY "true" CopyDefaultSettings
		CreateDirectory $SETTINGSDIRECTORY
		Goto SettingsFound
	
	CopyDefaultSettings:
		CreateDirectory "$EXEDIR\Data"
		CreateDirectory "$EXEDIR\Data\settings"
		CopyFiles /SILENT $EXEDIR\App\DefaultData\settings\*.* $EXEDIR\Data\settings
		Goto SettingsFound

	SettingsFound:
		StrCmp $DISABLESPLASHSCREEN "true" GetPassedParameters
			;=== Show the splash screen before processing the files
			InitPluginsDir
			File /oname=$PLUGINSDIR\splash.jpg "${NAME}.jpg"	
			newadvsplash::show /NOUNLOAD 1500 200 0 -1 /L $PLUGINSDIR\splash.jpg

	GetPassedParameters:
		;=== Get any passed parameters
		Call GetParameters
		Pop $0
		StrCmp "'$0'" "''" "" LaunchProgramParameters

		;=== No parameters
		StrCpy $EXECSTRING `"$PROGRAMDIRECTORY\$PROGRAMEXECUTABLE"`
		Goto AdditionalParameters

	LaunchProgramParameters:
		StrCpy $EXECSTRING `"$PROGRAMDIRECTORY\$PROGRAMEXECUTABLE" $0`

	AdditionalParameters:
		StrCmp $ADDITIONALPARAMETERS "" RegistryBackup

		;=== Additional Parameters
		StrCpy $EXECSTRING `$EXECSTRING $ADDITIONALPARAMETERS`

	RegistryBackup:
		StrCmp $SECONDARYLAUNCH "true" LaunchAndExit
		;=== Backup the registry
		${registry::KeyExists} "HKEY_CURRENT_USER\Software\MediaMonkey-BackupByMediaMonkeyPortable" $R0
		StrCmp $R0 "0" RestoreTheKey
		${registry::KeyExists} "HKEY_CURRENT_USER\Software\MediaMonkey" $R0
		StrCmp $R0 "-1" RestoreTheKey
		${registry::MoveKey} "HKEY_CURRENT_USER\Software\MediaMonkey" "HKEY_CURRENT_USER\Software\MediaMonkey-BackupByMediaMonkeyPortable" $R0
		Sleep 100
		
	RestoreTheKey:
		IfFileExists "$SETTINGSDIRECTORY\MediaMonkey.reg" "" DetermineLocalInstall
	
		IfFileExists "$WINDIR\system32\reg.exe" "" RestoreTheKey9x
			nsExec::ExecToStack `"$WINDIR\system32\reg.exe" import "$SETTINGSDIRECTORY\MediaMonkey.reg"`
			Pop $R0
			StrCmp $R0 '0' DetermineLocalInstall ;successfully restored key

	RestoreTheKey9x:
		${registry::RestoreKey} "$SETTINGSDIRECTORY\MediaMonkey.reg" $R0
		StrCmp $R0 '0' DetermineLocalInstall ;successfully restored key
		StrCpy $FAILEDTORESTOREKEY "true"
	
	DetermineLocalInstall:
	IfFileExists "$PROFILE\Local Settings\Application Data\MediaMonkey\*.m3u" MoveOriginalSettings LaunchNow
	
	MoveOriginalSettings:
		Rename "$PROFILE\Local Settings\Application Data\MediaMonkey" "$PROFILE\Local Settings\Application Data\MediaMonkey-BackupByMediaMonkeyPortable"
		Sleep 100
		Goto LaunchNow
	
	LaunchNow:
		Rename "$SETTINGSDIRECTORY\MediaMonkey.ini" "$PROGRAMDIRECTORY\MediaMonkey.ini"
		CreateDirectory "$PROFILE\Local Settings\Application Data\MediaMonkey"
		CopyFiles /SILENT "$SETTINGSDIRECTORY\MediaMonkey\*.*" "$PROFILE\Local Settings\Application Data\MediaMonkey"
		Sleep 100
		ExecWait $EXECSTRING
		
	CheckRunning:
		Sleep 1000
		FindProcDLL::FindProc "${DEFAULTEXE}"                  
		StrCmp $R0 "1" CheckRunning
		
		StrCmp $FAILEDTORESTOREKEY "true" SetOriginalKeyBack
		${registry::SaveKey} "HKEY_CURRENT_USER\Software\MediaMonkey" "$SETTINGSDIRECTORY\MediaMonkey.reg" "" $0
		Sleep 100
	
	SetOriginalKeyBack:
		${registry::DeleteKey} "HKEY_CURRENT_USER\Software\MediaMonkey" $R0
		Sleep 100
		${registry::KeyExists} "HKEY_CURRENT_USER\Software\MediaMonkey-BackupByMediaMonkeyPortable" $R0
		StrCmp $R0 "-1" MoveSettingsBack
		${registry::MoveKey} "HKEY_CURRENT_USER\Software\MediaMonkey-BackupByMediaMonkeyPortable" "HKEY_CURRENT_USER\Software\MediaMonkey" $R0
		Sleep 100
		Goto MoveSettingsBack
	
	MoveSettingsBack:
		CopyFiles /SILENT "$PROFILE\Local Settings\Application Data\MediaMonkey\*.*" "$SETTINGSDIRECTORY\MediaMonkey"
		Sleep 100
		RMDir /r "$PROFILE\Local Settings\Application Data\MediaMonkey"
		Sleep 100
		Rename "$PROFILE\Local Settings\Application Data\MediaMonkey-BackupByMediaMonkeyPortable" "$PROFILE\Local Settings\Application Data\MediaMonkey"
		Sleep 100
		Rename "$PROGRAMDIRECTORY\MediaMonkey.ini" "$SETTINGSDIRECTORY\MediaMonkey.ini"
		Goto TheEnd
		
	LaunchAndExit:
		Exec $EXECSTRING
	
	TheEnd:
		${registry::Unload}
		newadvsplash::stop /WAIT
SectionEnd
Devo
Offline
Last seen: 4 months 2 weeks ago
Joined: 2007-09-04 14:55
Launcher won't work

I found an error with my launcher but I don't know how to fix it. Basically, on the very first run, if the MediaMonkeyPortable.ini is present in the root directory, the default settings are not copied to the settings folder. I've looked through the code, but I can't figure out what's wrong.

Below is the code for the ini

[MediaMonkeyPortable]
MediaMonkeyDirectory=App\MediaMonkey
SettingsDirectory=Data\settings
MediaMonkeyExecutable=MediaMonkey.exe
AdditionalParameters=
DisableSplashScreen=false

# The above options are explained in the included readme.txt
# This INI file is an example only and is not used unless it is placed as described in the included readme.txt

And this is the code for the launcher, if somebody could take a look at it I would greatly appreciate it.

;Copyright (C) 2004-2008 John T. Haller

;Website: http://PortableApps.com/Development/test

;This software is OSI Certified Open Source Software.
;OSI Certified is a certification mark of the Open Source Initiative.

;This program is free software; you can redistribute it and/or
;modify it under the terms of the GNU General Public License
;as published by the Free Software Foundation; either version 2
;of the License, or (at your option) any later version.

;This program is distributed in the hope that it will be useful,
;but WITHOUT ANY WARRANTY; without even the implied warranty of
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;GNU General Public License for more details.

;You should have received a copy of the GNU General Public License
;along with this program; if not, write to the Free Software
;Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

!define PORTABLEAPPNAME "MediaMonkey Portable"
!define NAME "MediaMonkeyPortable"
!define APPNAME "MediaMonkey"
!define VER "3.0.6.1190"
!define WEBSITE "PortableApps.com/Development/test"
!define DEFAULTEXE "MediaMonkey.exe"
!define DEFAULTAPPDIR "MediaMonkey"
!define DEFAULTSETTINGSPATH "settings"

;=== Program Details
Name "${PORTABLEAPPNAME}"
OutFile "..\..\${NAME}.exe"
Caption "${PORTABLEAPPNAME} | PortableApps.com"
VIProductVersion "${VER}"
VIAddVersionKey ProductName "${PORTABLEAPPNAME}"
VIAddVersionKey Comments "Allows ${APPNAME} to be run from a removable drive.  For additional details, visit ${WEBSITE}"
VIAddVersionKey CompanyName "PortableApps.com"
VIAddVersionKey LegalCopyright "John T. Haller"
VIAddVersionKey FileDescription "${PORTABLEAPPNAME}"
VIAddVersionKey FileVersion "${VER}"
VIAddVersionKey ProductVersion "${VER}"
VIAddVersionKey InternalName "${PORTABLEAPPNAME}"
VIAddVersionKey LegalTrademarks "PortableApps.com is a Trademark of Rare Ideas, LLC."
VIAddVersionKey OriginalFilename "${NAME}.exe"
;VIAddVersionKey PrivateBuild ""
;VIAddVersionKey SpecialBuild ""

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

; Best Compression
SetCompress Auto
SetCompressor /SOLID lzma
SetCompressorDictSize 32
SetDatablockOptimize On

;=== Include
!include "Registry.nsh"
!include "GetParameters.nsh"
!include "MUI.nsh"

;=== Program Icon
Icon "..\..\App\AppInfo\appicon.ico"

;=== Icon & Stye ===
!define MUI_ICON "..\..\App\AppInfo\appicon.ico"

;=== Languages
!insertmacro MUI_LANGUAGE "English"

LangString LauncherFileNotFound ${LANG_ENGLISH} "${PORTABLEAPPNAME} cannot be started. You may wish to re-install to fix this issue. (ERROR: $MISSINGFILEORPATH could not be found)"
LangString LauncherAlreadyRunning ${LANG_ENGLISH} "Another instance of ${APPNAME} is already running. Please close other instances of ${APPNAME} before launching ${PORTABLEAPPNAME}."
LangString LauncherAskCopyLocal ${LANG_ENGLISH} "${PORTABLEAPPNAME} appears to be running from a location that is read-only. Would you like to temporarily copy it to the local hard drive and run it from there?$\n$\nPrivacy Note: If you say Yes, your personal data within ${PORTABLEAPPNAME} will be temporarily copied to a local drive. Although this copy of your data will be deleted when you close ${PORTABLEAPPNAME}, it may be possible for someone else to access your data later."
LangString LauncherNoReadOnly ${LANG_ENGLISH} "${PORTABLEAPPNAME} can not run directly from a read-only location and will now close."

Var PROGRAMDIRECTORY
Var SETTINGSDIRECTORY
Var ADDITIONALPARAMETERS
Var EXECSTRING
Var PROGRAMEXECUTABLE
Var INIPATH
Var DISABLESPLASHSCREEN
Var ISDEFAULTDIRECTORY
Var SECONDARYLAUNCH
Var FAILEDTORESTOREKEY
Var MISSINGFILEORPATH

Section "Main"
	;=== Check if already running
	System::Call 'kernel32::CreateMutexA(i 0, i 0, t "${NAME}2") i .r1 ?e'
	Pop $0
	StrCmp $0 0 CheckForINI
		StrCpy $SECONDARYLAUNCH "true"

	CheckForINI:
	;=== Find the INI file, if there is one
		IfFileExists "$EXEDIR\${NAME}.ini" "" NoINI
			StrCpy "$INIPATH" "$EXEDIR"
			Goto ReadINI

	ReadINI:
		;=== Read the parameters from the INI file
		ReadINIStr $0 "$INIPATH\${NAME}.ini" "${NAME}" "${APPNAME}Directory"
		StrCpy "$PROGRAMDIRECTORY" "$EXEDIR\$0"
		ReadINIStr $0 "$INIPATH\${NAME}.ini" "${NAME}" "SettingsDirectory"
		StrCpy "$SETTINGSDIRECTORY" "$EXEDIR\$0"

		;=== Check that the above required parameters are present
		IfErrors NoINI

		ReadINIStr $0 "$INIPATH\${NAME}.ini" "${NAME}" "AdditionalParameters"
		StrCpy "$ADDITIONALPARAMETERS" $0
		ReadINIStr $0 "$INIPATH\${NAME}.ini" "${NAME}" "${APPNAME}Executable"
		StrCpy "$PROGRAMEXECUTABLE" $0
		ReadINIStr $0 "$INIPATH\${NAME}.ini" "${NAME}" "DisableSplashScreen"
		StrCpy "$DISABLESPLASHSCREEN" $0

	;CleanUpAnyErrors:
		;=== Any missing unrequired INI entries will be an empty string, ignore associated errors
		ClearErrors

		;=== Correct PROGRAMEXECUTABLE if blank
		StrCmp $PROGRAMEXECUTABLE "" "" CheckForProgramINI
			StrCpy "$PROGRAMEXECUTABLE" "${DEFAULTEXE}"
			Goto CheckForProgramINI
			
	CheckForProgramINI:
		IfFileExists "$PROGRAMDIRECTORY\$PROGRAMEXECUTABLE" FoundProgramEXE NoProgramEXE

	NoINI:
		;=== No INI file, so we'll use the defaults
		StrCpy "$ADDITIONALPARAMETERS" ""
		StrCpy "$PROGRAMEXECUTABLE" "${DEFAULTEXE}"
		StrCpy "$DISABLESPLASHSCREEN" "false"

		IfFileExists "$EXEDIR\App\${DEFAULTAPPDIR}\${DEFAULTEXE}" "" NoProgramEXE
			StrCpy "$PROGRAMDIRECTORY" "$EXEDIR\App\${DEFAULTAPPDIR}"
			StrCpy "$SETTINGSDIRECTORY" "$EXEDIR\Data\${DEFAULTSETTINGSPATH}"
			StrCpy "$ISDEFAULTDIRECTORY" "true"
			GoTo FoundProgramEXE

	NoProgramEXE:
		;=== Program executable not where expected
		StrCpy $MISSINGFILEORPATH $PROGRAMEXECUTABLE
		MessageBox MB_OK|MB_ICONEXCLAMATION `$(LauncherFileNotFound)`
		Abort
		
	FoundProgramEXE:
		;=== Check if already running
		StrCmp $SECONDARYLAUNCH "true" CheckForSettings
		FindProcDLL::FindProc "$PROGRAMEXECUTABLE"                 
		StrCmp $R0 "1" WarnAnotherInstance CheckForSettings

	WarnAnotherInstance:
		MessageBox MB_OK|MB_ICONINFORMATION `$(LauncherAlreadyRunning)`
		Abort
	
	CheckForSettings:
		IfFileExists "$SETTINGSDIRECTORY\*.*" SettingsFound
		;=== No settings found
		StrCmp $ISDEFAULTDIRECTORY "true" CopyDefaultSettings
		CreateDirectory $SETTINGSDIRECTORY
		Goto SettingsFound
	
	CopyDefaultSettings:
		CreateDirectory "$EXEDIR\Data"
		CreateDirectory "$EXEDIR\Data\settings"
		CopyFiles /SILENT $EXEDIR\App\DefaultData\settings\*.* $EXEDIR\Data\settings
		Goto SettingsFound

	SettingsFound:
		StrCmp $DISABLESPLASHSCREEN "true" GetPassedParameters
			;=== Show the splash screen before processing the files
			InitPluginsDir
			File /oname=$PLUGINSDIR\splash.jpg "${NAME}.jpg"	
			newadvsplash::show /NOUNLOAD 1500 200 0 -1 /L $PLUGINSDIR\splash.jpg

	GetPassedParameters:
		;=== Get any passed parameters
		Call GetParameters
		Pop $0
		StrCmp "'$0'" "''" "" LaunchProgramParameters

		;=== No parameters
		StrCpy $EXECSTRING `"$PROGRAMDIRECTORY\$PROGRAMEXECUTABLE"`
		Goto AdditionalParameters

	LaunchProgramParameters:
		StrCpy $EXECSTRING `"$PROGRAMDIRECTORY\$PROGRAMEXECUTABLE" $0`

	AdditionalParameters:
		StrCmp $ADDITIONALPARAMETERS "" RegistryBackup

		;=== Additional Parameters
		StrCpy $EXECSTRING `$EXECSTRING $ADDITIONALPARAMETERS`

	RegistryBackup:
		StrCmp $SECONDARYLAUNCH "true" LaunchAndExit
		;=== Backup the registry
		${registry::KeyExists} "HKEY_CURRENT_USER\Software\MediaMonkey-BackupByMediaMonkeyPortable" $R0
		StrCmp $R0 "0" RestoreTheKey
		${registry::KeyExists} "HKEY_CURRENT_USER\Software\MediaMonkey" $R0
		StrCmp $R0 "-1" RestoreTheKey
		${registry::MoveKey} "HKEY_CURRENT_USER\Software\MediaMonkey" "HKEY_CURRENT_USER\Software\MediaMonkey-BackupByMediaMonkeyPortable" $R0
		Sleep 100
		
	RestoreTheKey:
		IfFileExists "$SETTINGSDIRECTORY\MediaMonkey.reg" "" DetermineLocalInstall
	
		IfFileExists "$WINDIR\system32\reg.exe" "" RestoreTheKey9x
			nsExec::ExecToStack `"$WINDIR\system32\reg.exe" import "$SETTINGSDIRECTORY\MediaMonkey.reg"`
			Pop $R0
			StrCmp $R0 '0' DetermineLocalInstall ;successfully restored key

	RestoreTheKey9x:
		${registry::RestoreKey} "$SETTINGSDIRECTORY\MediaMonkey.reg" $R0
		StrCmp $R0 '0' DetermineLocalInstall ;successfully restored key
		StrCpy $FAILEDTORESTOREKEY "true"
	
	DetermineLocalInstall:
	IfFileExists "$PROFILE\Local Settings\Application Data\MediaMonkey\*.m3u" MoveOriginalSettings LaunchNow
	
	MoveOriginalSettings:
		Rename "$PROFILE\Local Settings\Application Data\MediaMonkey" "$PROFILE\Local Settings\Application Data\MediaMonkey-BackupByMediaMonkeyPortable"
		Sleep 100
		Goto LaunchNow
	
	LaunchNow:
		CopyFiles /SILENT "$SETTINGSDIRECTORY\MediaMonkey.ini" "$PROGRAMDIRECTORY\MediaMonkey.ini"
		CopyFiles /SILENT "$SETTINGSDIRECTORY\MM.db" "$PROGRAMDIRECTORY\MM.db"
		CreateDirectory "$PROFILE\Local Settings\Application Data\MediaMonkey"
		CopyFiles /SILENT "$SETTINGSDIRECTORY\MediaMonkey\*.*" "$PROFILE\Local Settings\Application Data\MediaMonkey"
		Sleep 100
		ExecWait $EXECSTRING
		
	CheckRunning:
		Sleep 1000
		FindProcDLL::FindProc "${DEFAULTEXE}"                  
		StrCmp $R0 "1" CheckRunning
		
		StrCmp $FAILEDTORESTOREKEY "true" SetOriginalKeyBack
		${registry::SaveKey} "HKEY_CURRENT_USER\Software\MediaMonkey" "$SETTINGSDIRECTORY\MediaMonkey.reg" "" $0
		Sleep 100
	
	SetOriginalKeyBack:
		${registry::DeleteKey} "HKEY_CURRENT_USER\Software\MediaMonkey" $R0
		Sleep 100
		${registry::KeyExists} "HKEY_CURRENT_USER\Software\MediaMonkey-BackupByMediaMonkeyPortable" $R0
		StrCmp $R0 "-1" MoveSettingsBack
		${registry::MoveKey} "HKEY_CURRENT_USER\Software\MediaMonkey-BackupByMediaMonkeyPortable" "HKEY_CURRENT_USER\Software\MediaMonkey" $R0
		Sleep 100
		Goto MoveSettingsBack
	
	MoveSettingsBack:
		CopyFiles /SILENT "$PROFILE\Local Settings\Application Data\MediaMonkey\*.*" "$SETTINGSDIRECTORY\MediaMonkey"
		Sleep 100
		RMDir /r "$PROFILE\Local Settings\Application Data\MediaMonkey"
		Sleep 100
		Rename "$PROFILE\Local Settings\Application Data\MediaMonkey-BackupByMediaMonkeyPortable" "$PROFILE\Local Settings\Application Data\MediaMonkey"
		Sleep 100
		Delete "$SETTINGSDIRECTORY\MediaMonkey.ini"
		Rename "$PROGRAMDIRECTORY\MediaMonkey.ini" "$SETTINGSDIRECTORY\MediaMonkey.ini"
		Delete "$SETTINGSDIRECTORY\MM.db"
		Rename "$PROGRAMDIRECTORY\MM.db" "$SETTINGSDIRECTORY\MM.db"
		Goto TheEnd
		
	LaunchAndExit:
		Exec $EXECSTRING
	
	TheEnd:
		${registry::Unload}
		newadvsplash::stop /WAIT
SectionEnd
OliverK
OliverK's picture
Offline
Last seen: 1 year 7 months ago
Developer
Joined: 2007-03-27 15:21
CopyFiles /SILENT

CopyFiles /SILENT $EXEDIR\App\DefaultData\settings\*.* $EXEDIR\Data\settings
Goto SettingsFound

Try with
CopyFiles /SILENT $EXEDIR\App\DefaultData\settings\*.* $EXEDIR\Data\settings\*.*
Goto SettingsFound

Also, something is (logically) wrong here:
ReadINIStr $0 "$INIPATH\${NAME}.ini" "${NAME}" "SettingsDirectory"
StrCpy "$SETTINGSDIRECTORY" "$EXEDIR\$0"

Stuff a MessageBox in so you can see what value $SETTINGSDIRECTORY gets.

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

Devo
Offline
Last seen: 4 months 2 weeks ago
Joined: 2007-09-04 14:55
So, how do I put a message

So, how do I put a message box in? I've never done that before. I know it's probably a bad question, but I really appreciate you helping me with this.

OliverK
OliverK's picture
Offline
Last seen: 1 year 7 months ago
Developer
Joined: 2007-03-27 15:21
You can look at some of the

You can look at some of the code for the errors when the program is found, etc.
Here's what you would use:

	ReadINIStr $0 "$INIPATH\${NAME}.ini" "${NAME}" "AdditionalParameters"
		StrCpy "$ADDITIONALPARAMETERS" $0
		ReadINIStr $0 "$INIPATH\${NAME}.ini" "${NAME}" "${APPNAME}Executable"
		StrCpy "$PROGRAMEXECUTABLE" $0
		ReadINIStr $0 "$INIPATH\${NAME}.ini" "${NAME}" "DisableSplashScreen"
		StrCpy "$DISABLESPLASHSCREEN" $0
		
		MessageBox MB_OK|MB_ICONEXCLAMATION `$PROGRAMDIRECTORY | $SETTINGSDIRECTORY `
		Abort

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

Bart.S
Offline
Last seen: 2 weeks 11 hours ago
Developer
Joined: 2008-07-23 07:56
:P

Also, something is (logically) wrong here:
ReadINIStr $0 "$INIPATH\${NAME}.ini" "${NAME}" "SettingsDirectory"
StrCpy "$SETTINGSDIRECTORY" "$EXEDIR\$0"

Nope, that's correct.

OliverK
OliverK's picture
Offline
Last seen: 1 year 7 months ago
Developer
Joined: 2007-03-27 15:21
Logically, some of the code

Logically, some of the code is failing Blum
EDIT
Or it just could be that I'm failing, it handles it correctly, I just tested.

Try that *.* addition .. . .

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

Devo
Offline
Last seen: 4 months 2 weeks ago
Joined: 2007-09-04 14:55
Works now, should I post it.

I ended up putting in the code for the message box and the settings directory is correct in both instances. I changed various other things and thought I changed it back, but apparently I didn't because the launcher works perfectly in both cases. I'm thinking about posting it but I'm not sure anybody would be interested in it, what do you think?

Log in or register to post comments