You are here

how can I redirect files using nsis [SOLVED]

32 posts / 0 new
Last post
denash
Offline
Last seen: 14 years 6 months ago
Joined: 2007-04-08 12:14
how can I redirect files using nsis [SOLVED]

Could anyone please tell me how to redirect
"C:\Documents and Settings\HOME PC\Application Data\Artweaver" using nsis? because I want those settings to be stored in the "Data" directory of the app, which I am trying to make portable.

thx in advance

edit: because subject was not very clear

Edit 2: I am trying to make my question clearer: how does a portable app handle the program which writes to "application data"? and how does it delete them and then get them to the "data" directory on the USB or so? could someone please show me the code?

digitxp
digitxp's picture
Offline
Last seen: 12 years 6 months ago
Joined: 2007-11-03 18:33
Depends

You'll have to be very advanced to redirect.
I just do copyfiles then delete (rename doesn't work between drives).
And Backup, also.

Insert original signature here with Greasemonkey Script.

denash
Offline
Last seen: 14 years 6 months ago
Joined: 2007-04-08 12:14
which part of the program

which part of the program launchers does that??? could you please show me the code?

digitxp
digitxp's picture
Offline
Last seen: 12 years 6 months ago
Joined: 2007-11-03 18:33
Sure

This goes after CheckForSettings:

Backup:
     Rename "$APPDATA\appnamefolder" "$APPDATA\appnamefolderbackupbyappnameportable"
MoveSettings:
     CreateDirectory "$APPDATA\appnamefolder"
     CopyFiles /SILENT "$SETTINGSDIRECTORY\appnamefolder\*.*" "$APPDATA\appnamefolder"
Delete "$SETTINGSDIRECTORY\appnamefolder\*.*"

And before LaunchAndExit:

CopyFiles /SILENT "$APPDATA\appnamefolder\*.*" "$SETTINGSDIRECTORY\appnamefolder"
RMDIR /r "$APPDATA\appnamefolder"
IfFileExists "$APPDATA\appnamefolderbackupbyappnameportable" +1 TheEnd
Rename "$APPDATA\appnamefolderbackupbyappnameportable" "$APPDATA\appnamefolder"

Just remember to fix appname and appnamefolder with the name of the base 'List of Instructions' :P.

Insert original signature here with Greasemonkey Script.

denash
Offline
Last seen: 14 years 6 months ago
Joined: 2007-04-08 12:14
what I am I doing wrong?

It still does not redirect, I hope you can help me to find the mistake:


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

;Website: http://PortableApps.com/ArtweaverPortable

;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 "Artweaver Portable"
!define NAME "ArtweaverPortable"
!define APPNAME "Artweaver"
!define VER "1.5.5.0"
!define WEBSITE "PortableApps.com/ArtweaverPortable"
!define DEFAULTEXE "Artweaver.exe"
!define DEFAULTAPPDIR "Artweaver"
!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

	Backup:
     		Rename "$APPDATA\appnamefolder"   "$APPDATA\ArtweaverbackupbyArtweaverportable"
		MoveSettings:
     		CreateDirectory "$APPDATA\Artweaver"
     		CopyFiles /SILENT "$SETTINGSDIRECTORY\Artweaver\*.*" "$APPDATA\Artweaver"
		Delete "$SETTINGSDIRECTORY\Artweaver\*.*"

	
	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} "HKU\S-1-5-21-3980898223-2580436373-2252194214-1005\Software\Artweaver-BackupByArtweaverPortable" $R0
		StrCmp $R0 "0" RestoreTheKey
		${registry::KeyExists} "HKU\S-1-5-21-3980898223-2580436373-2252194214-1005\Software\Artweaver" $R0
		StrCmp $R0 "-1" RestoreTheKey
		${registry::MoveKey} "HKU\S-1-5-21-3980898223-2580436373-2252194214-1005\Software\Artweaver" "HKU\S-1-5-21-3980898223-2580436373-2252194214-1005\Software\Artweaver-BackupByArtweaverPortable" $R0
		Sleep 100
		
	RestoreTheKey:
		IfFileExists "$SETTINGSDIRECTORY\Artweaver_portable.reg" "" LaunchNow
	
		IfFileExists "$WINDIR\system32\reg.exe" "" RestoreTheKey9x
			nsExec::ExecToStack `"$WINDIR\system32\reg.exe" import "$SETTINGSDIRECTORY\Artweaver_portable.reg"`
			Pop $R0
			StrCmp $R0 '0' LaunchNow ;successfully restored key

	RestoreTheKey9x:
		${registry::RestoreKey} "$SETTINGSDIRECTORY\Artweaver_portable.reg" $R0
		StrCmp $R0 '0' LaunchNow ;successfully restored key
		StrCpy $FAILEDTORESTOREKEY "true"
	
	LaunchNow:
		Sleep 100
		ExecWait $EXECSTRING
		
	CheckRunning:
		Sleep 1000
		FindProcDLL::FindProc "${DEFAULTEXE}"                  
		StrCmp $R0 "1" CheckRunning
		
		StrCmp $FAILEDTORESTOREKEY "true" SetOriginalKeyBack
		${registry::SaveKey} "HKU\S-1-5-21-3980898223-2580436373-2252194214-1005\Software\Artweaver" "$SETTINGSDIRECTORY\Artweaver_portable.reg" "" $0
		Sleep 100
	
	SetOriginalKeyBack:
		${registry::DeleteKey} "HKU\S-1-5-21-3980898223-2580436373-2252194214-1005\Software\Artweaver" $R0
		Sleep 100
		${registry::KeyExists} "HKU\S-1-5-21-3980898223-2580436373-2252194214-1005\Software\Artweaver-BackupByArtweaverPortable" $R0
		StrCmp $R0 "-1" TheEnd
		${registry::MoveKey} "HKU\S-1-5-21-3980898223-2580436373-2252194214-1005\Software\Artweaver-BackupByArtweaverPortable" "HKU\S-1-5-21-3980898223-2580436373-2252194214-1005\Software\Artweaver" $R0
		Sleep 100
		Goto TheEnd

		
		CopyFiles /SILENT "$APPDATA\Artweaver\*.*" "$SETTINGSDIRECTORY\Artweaver"
		RMDIR /r "$APPDATA\Artweaver"
		IfFileExists "$APPDATA\ArtweaverbackupbyArtweaverportable" +1 TheEnd
		Rename "$APPDATA\ArtweaverbackupbyArtweaverportable" "$APPDATA\Artweaverfolder"


		
	LaunchAndExit:
		Exec $EXECSTRING
	
	TheEnd:
		${registry::Unload}
		newadvsplash::stop /WAIT
SectionEnd

Thx for your help Smile

digitxp
digitxp's picture
Offline
Last seen: 12 years 6 months ago
Joined: 2007-11-03 18:33
You used Regshot

Instead of HKU\{blablabla1234567}\software\blabla, you do HKCU\software\blabla ;).
And change the copyrights to PortableApps.com and Contributors in the !define
I can't figure it out yet :P.

Insert original signature here with Greasemonkey Script.

denash
Offline
Last seen: 14 years 6 months ago
Joined: 2007-04-08 12:14
Once the launcher EXE is

Once the launcher EXE is created, this is what is written at the end of the compiling process

2 warnings:
label "Backup" not used
label "MoveSettings" not used

For some reason it is ignoring the code you gave me Sad

tipra.wicked
tipra.wicked's picture
Offline
Last seen: 13 years 8 months ago
Joined: 2007-08-31 05:27
it just means that you

it just means that you created two labels Backup and MoveSettings but have not used the GOTO statement to jump to them

denash
Offline
Last seen: 14 years 6 months ago
Joined: 2007-04-08 12:14
ok I have used the GOTO

ok I have used the GOTO statement but still it does not redirect those files Sad

the code now



!define PORTABLEAPPNAME "Artweaver Portable"
!define NAME "ArtweaverPortable"
!define APPNAME "Artweaver"
!define VER "1.5.5.0"
!define WEBSITE "PortableApps.com/ArtweaverPortable"
!define DEFAULTEXE "Artweaver.exe"
!define DEFAULTAPPDIR "Artweaver"
!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 "PortableApps.com and Contributors"
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 Backup

	Backup:
     		Rename "$APPDATA\appnamefolder" "$APPDATA\ArtweaverbackupbyArtweaverportable"
		Goto MoveSettings

	MoveSettings:
     		CreateDirectory "$APPDATA\Artweaver"
     		CopyFiles /SILENT "$SETTINGSDIRECTORY\Artweaver\*.*" "$APPDATA\Artweaver"
		Delete "$SETTINGSDIRECTORY\Artweaver\*.*"
		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} "HKCU\Software\Artweaver-BackupByArtweaverPortable" $R0
		StrCmp $R0 "0" RestoreTheKey
		${registry::KeyExists} "HKCU\Software\Artweaver" $R0
		StrCmp $R0 "-1" RestoreTheKey
		${registry::MoveKey} "HKCU\Software\Artweaver" "HKCU\Software\Artweaver-BackupByArtweaverPortable" $R0
		Sleep 100
		
	RestoreTheKey:
		IfFileExists "$SETTINGSDIRECTORY\Artweaver_portable.reg" "" LaunchNow
	
		IfFileExists "$WINDIR\system32\reg.exe" "" RestoreTheKey9x
			nsExec::ExecToStack `"$WINDIR\system32\reg.exe" import "$SETTINGSDIRECTORY\Artweaver_portable.reg"`
			Pop $R0
			StrCmp $R0 '0' LaunchNow ;successfully restored key

	RestoreTheKey9x:
		${registry::RestoreKey} "$SETTINGSDIRECTORY\Artweaver_portable.reg" $R0
		StrCmp $R0 '0' LaunchNow ;successfully restored key
		StrCpy $FAILEDTORESTOREKEY "true"
	
	LaunchNow:
		Sleep 100
		ExecWait $EXECSTRING
		
	CheckRunning:
		Sleep 1000
		FindProcDLL::FindProc "${DEFAULTEXE}"                  
		StrCmp $R0 "1" CheckRunning
		
		StrCmp $FAILEDTORESTOREKEY "true" SetOriginalKeyBack
		${registry::SaveKey} "HKCU\Software\Artweaver" "$SETTINGSDIRECTORY\Artweaver_portable.reg" "" $0
		Sleep 100
	
	SetOriginalKeyBack:
		${registry::DeleteKey} "HKCU\Software\Artweaver" $R0
		Sleep 100
		${registry::KeyExists} "HKCU\Software\Artweaver-BackupByArtweaverPortable" $R0
		StrCmp $R0 "-1" TheEnd
		${registry::MoveKey} "HKCU\Software\Artweaver-BackupByArtweaverPortable" "HKCU\Software\Artweaver" $R0
		CopyFiles /SILENT "$APPDATA\Artweaver\*.*" "$SETTINGSDIRECTORY\Artweaver"
		RMDIR /r "$APPDATA\Artweaver"
		IfFileExists "$APPDATA\ArtweaverbackupbyArtweaverportable" +1 TheEnd
		Rename "$APPDATA\ArtweaverbackupbyArtweaverportable" "$APPDATA\Artweaverfolder"
		Goto TheEnd	
		Sleep 100
			
	LaunchAndExit:
		Exec $EXECSTRING
	
	TheEnd:
		${registry::Unload}
		newadvsplash::stop /WAIT
SectionEnd
tipra.wicked
tipra.wicked's picture
Offline
Last seen: 13 years 8 months ago
Joined: 2007-08-31 05:27
first of all you dont need

first of all you dont need Goto Backup and Goto MoveSettings as the labels are just next to the statements you can delete both the label and the statements.

i once made one application portable which wrote to the application data folder
what i did was let the application write all its settings to $APPDATA then when the program exits copy all the files form $APPDATA to $EXEDIR\DATA (

powerjuce
powerjuce's picture
Offline
Last seen: 13 years 1 month ago
Developer
Joined: 2007-09-20 21:34
use this...
Var SETTINGSDIRECTORY
StrCpy $SETTINGSDIRECTORY "$EXEDIR\Data"
System::Call 'Kernel32::SetEnvironmentVariableA(t, t) i("APPDATA", "$SETTINGSDIRECTORY").r0'

This will make the APPDATA(Application Data) folder be your $EXEDIR\Data folder.
Now for the ArtWeaver App, all the files that are usually written to the APPDATA folder will be written to the $EXEDIR\Data folder

I hope that helps

Please search before posting. ~Thanks

denash
Offline
Last seen: 14 years 6 months ago
Joined: 2007-04-08 12:14
These are the files I want

These are the files I want the programm to redirect, I hinbk there is where my problem lies:

C:\Documents and Settings\HOME PC\Application Data\Artweaver\0.4\Brush Settings Cache
C:\Documents and Settings\HOME PC\Application Data\Artweaver\0.4\Plug-In Cache
C:\Documents and Settings\HOME PC\Application Data\Artweaver\0.4\Preview Image Cache
C:\Documents and Settings\HOME PC\Application Data\Artweaver\0.4\Current Session
C:\Documents and Settings\HOME PC\Application Data\Artweaver\0.4\Color Sets.aco

I basically want to redirect the whole folder "artweaver" instead of the folder "0.4" which is where all the other files are located in.

(maybe this is why the codes didn't work??)

but my launcher is able to redirect the registry keys.

(my mean the same way as the other portable launcher do)

powerjuce
powerjuce's picture
Offline
Last seen: 13 years 1 month ago
Developer
Joined: 2007-09-20 21:34
my code will...

try it

Please search before posting. ~Thanks

denash
Offline
Last seen: 14 years 6 months ago
Joined: 2007-04-08 12:14
I tried your code and its

I tried your code and its the same, it does not redirect the files Sad

the code:


!define PORTABLEAPPNAME "Artweaver Portable"
!define NAME "ArtweaverPortable"
!define APPNAME "Artweaver"
!define VER "1.5.5.0"
!define WEBSITE "PortableApps.com/ArtweaverPortable"
!define DEFAULTEXE "Artweaver.exe"
!define DEFAULTAPPDIR "Artweaver"
!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 VarSETTINGSDIRECTORY
		
	VarSETTINGSDIRECTORY:
		StrCpy $SETTINGSDIRECTORY "$EXEDIR\Data"
		System::Call 'Kernel32::SetEnvironmentVariableA(t, t) i("APPDATA", "$SETTINGSDIRECTORY").r0'
		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} "HKCU\Software\Artweaver-BackupByArtweaverPortable" $R0
		StrCmp $R0 "0" RestoreTheKey
		${registry::KeyExists} "HKCU\Software\Artweaver" $R0
		StrCmp $R0 "-1" RestoreTheKey
		${registry::MoveKey} "HKCU\Software\Artweaver" "HKCU\Software\Artweaver-BackupByArtweaverPortable" $R0
		Sleep 100
		
	RestoreTheKey:
		IfFileExists "$SETTINGSDIRECTORY\Artweaver_portable.reg" "" LaunchNow
	
		IfFileExists "$WINDIR\system32\reg.exe" "" RestoreTheKey9x
			nsExec::ExecToStack `"$WINDIR\system32\reg.exe" import "$SETTINGSDIRECTORY\Artweaver_portable.reg"`
			Pop $R0
			StrCmp $R0 '0' LaunchNow ;successfully restored key

	RestoreTheKey9x:
		${registry::RestoreKey} "$SETTINGSDIRECTORY\Artweaver_portable.reg" $R0
		StrCmp $R0 '0' LaunchNow ;successfully restored key
		StrCpy $FAILEDTORESTOREKEY "true"
	
	LaunchNow:
		Sleep 100
		ExecWait $EXECSTRING
		
	CheckRunning:
		Sleep 1000
		FindProcDLL::FindProc "${DEFAULTEXE}"                  
		StrCmp $R0 "1" CheckRunning
		
		StrCmp $FAILEDTORESTOREKEY "true" SetOriginalKeyBack
		${registry::SaveKey} "HKCU\Software\Artweaver" "$SETTINGSDIRECTORY\Artweaver_portable.reg" "" $0
		Sleep 100
	
	SetOriginalKeyBack:
		${registry::DeleteKey} "HKCU\Software\Artweaver" $R0
		Sleep 100
		${registry::KeyExists} "HKCU\Software\Artweaver-BackupByArtweaverPortable" $R0
		StrCmp $R0 "-1" TheEnd
		${registry::MoveKey} "HKCU\Software\Artweaver-BackupByArtweaverPortable" "HKCU\Software\Artweaver" $R0
		Sleep 100
		CopyFiles /SILENT "$APPDATA\Artweaver\*.*" "$SETTINGSDIRECTORY\Artweaver"
		RMDIR /r "$APPDATA\Artweaver"
		IfFileExists "$APPDATA\ArtweaverbackupbyArtweaverportable" +1 TheEnd
		Rename "$APPDATA\ArtweaverbackupbyArtweaverportable" "$APPDATA\Artweaverfolder"
		Goto TheEnd

		
	LaunchAndExit:
		Exec $EXECSTRING
	
	TheEnd:
		${registry::Unload}
		newadvsplash::stop /WAIT
SectionEnd

EDIT: I think I misunderstood what your code should do,
should your code only delete the folder created in "application Data"
OR Should your code delete the "Application Data" and then move the files created in there to the data folder of the portableapp?

haustin
Offline
Last seen: 12 years 6 months ago
Joined: 2007-09-19 17:59
powerjuce is right

Actually, so is tipra.wicked:

first of all you dont need Goto Backup and Goto MoveSettings as the labels are just next to the statements you can delete both the label and the statements.

You have the following Goto and label right next to each other, and the label isn't called from anywhere else; they can both be deleted:

    GoTo VarSETTINGSDIRECTORY
		
VarSETTINGSDIRECTORY:

More importantly, however, powerjuce's code ended up in a place where it won't get executed unless the executable is not found in the default location ($EXEDIR\App\${DEFAULTAPPDIR}\${DEFAULTEXE}). The code should go right under the SettingsFound: label. Also, since you're using both the Data directory (to store %APPDATA%\Artweaver) and Data\settings (for the registry snapshot), I'd recommend you keep them separate. So, replace this:

StrCpy $SETTINGSDIRECTORY "$EXEDIR\Data"
System::Call 'Kernel32::SetEnvironmentVariableA(t, t) i("APPDATA", "$SETTINGSDIRECTORY").r0'

with this:

System::Call 'Kernel32::SetEnvironmentVariableA(t, t) i("APPDATA", "$EXEDIR\Data").r0'

You'll probably notice a spare Goto right above the SettingsFound: label. Smile If you're adventurous, you can delete the useless Goto but leave the label where it is.

Don't forget to remove your previous APPDATA logic:

CopyFiles /SILENT "$APPDATA\Artweaver\*.*" "$SETTINGSDIRECTORY\Artweaver"
RMDIR /r "$APPDATA\Artweaver"
IfFileExists "$APPDATA\ArtweaverbackupbyArtweaverportable" +1 TheEnd
Rename "$APPDATA\ArtweaverbackupbyArtweaverportable" "$APPDATA\Artweaverfolder"

BTW, for the above file-moving logic to work, there has to be a corresponding block of code to move it the other direction before launching the app. There shouldn't be a need to bother with it though -- powerjuce has you covered.

Hope this helps. -hea

<EDIT>
In case you were wondering, setting the %APPDATA% environment variable before launching the app tells it that's where it's supposed to store its stuff. That's why you don't have to worry about moving the files back and forth. If you already have an Artweaver profile in your APPDATA folder and you want to use it, simply use Explorer to drag it to the ArtweaverPortable\Data folder while the application isn't running.
</EDIT>

denash
Offline
Last seen: 14 years 6 months ago
Joined: 2007-04-08 12:14
so if I did it right, what

so if I did it right, what you told me to do, my code looks like this:


!define PORTABLEAPPNAME "Artweaver Portable"
!define NAME "ArtweaverPortable"
!define APPNAME "Artweaver"
!define VER "1.5.5.0"
!define WEBSITE "PortableApps.com/ArtweaverPortable"
!define DEFAULTEXE "Artweaver.exe"
!define DEFAULTAPPDIR "Artweaver"
!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:
		System::Call 'Kernel32::SetEnvironmentVariableA(t, t) i("APPDATA", "$EXEDIR\Data").r0'
		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} "HKCU\Software\Artweaver-BackupByArtweaverPortable" $R0
		StrCmp $R0 "0" RestoreTheKey
		${registry::KeyExists} "HKCU\Software\Artweaver" $R0
		StrCmp $R0 "-1" RestoreTheKey
		${registry::MoveKey} "HKCU\Software\Artweaver" "HKCU\Software\Artweaver-BackupByArtweaverPortable" $R0
		Sleep 100
		
	RestoreTheKey:
		IfFileExists "$SETTINGSDIRECTORY\Artweaver_portable.reg" "" LaunchNow
	
		IfFileExists "$WINDIR\system32\reg.exe" "" RestoreTheKey9x
			nsExec::ExecToStack `"$WINDIR\system32\reg.exe" import "$SETTINGSDIRECTORY\Artweaver_portable.reg"`
			Pop $R0
			StrCmp $R0 '0' LaunchNow ;successfully restored key

	RestoreTheKey9x:
		${registry::RestoreKey} "$SETTINGSDIRECTORY\Artweaver_portable.reg" $R0
		StrCmp $R0 '0' LaunchNow ;successfully restored key
		StrCpy $FAILEDTORESTOREKEY "true"
	
	LaunchNow:
		Sleep 100
		ExecWait $EXECSTRING
		
	CheckRunning:
		Sleep 1000
		FindProcDLL::FindProc "${DEFAULTEXE}"                  
		StrCmp $R0 "1" CheckRunning
		
		StrCmp $FAILEDTORESTOREKEY "true" SetOriginalKeyBack
		${registry::SaveKey} "HKCU\Software\Artweaver" "$SETTINGSDIRECTORY\Artweaver_portable.reg" "" $0
		Sleep 100
	
	SetOriginalKeyBack:
		${registry::DeleteKey} "HKCU\Software\Artweaver" $R0
		Sleep 100
		${registry::KeyExists} "HKCU\Software\Artweaver-BackupByArtweaverPortable" $R0
		StrCmp $R0 "-1" TheEnd
		${registry::MoveKey} "HKCU\Software\Artweaver-BackupByArtweaverPortable" "HKCU\Software\Artweaver" $R0
		CopyFiles /SILENT "$APPDATA\Artweaver\*.*" "$SETTINGSDIRECTORY\Artweaver"
		RMDIR /r "$APPDATA\Artweaver"
		IfFileExists "$APPDATA\ArtweaverbackupbyArtweaverportable" +1 TheEnd
		Rename "$APPDATA\ArtweaverbackupbyArtweaverportable" "$APPDATA\Artweaverfolder"
		Sleep 100

		
	LaunchAndExit:
		Exec $EXECSTRING
	
	TheEnd:
		${registry::Unload}
		newadvsplash::stop /WAIT
SectionEnd

this does delete the files created from "application data"
I am getting interested and would like to know how does firefox redirect its files to "data/profile" then?, because I think that wopuld solve my problem

digitxp
digitxp's picture
Offline
Last seen: 12 years 6 months ago
Joined: 2007-11-03 18:33
Hmm...

I think it uses a command line parameter at FF. Not Sure.

Insert original signature here with Greasemonkey Script.

powerjuce
powerjuce's picture
Offline
Last seen: 13 years 1 month ago
Developer
Joined: 2007-09-20 21:34
yea

firefox takes a parameter called -profile

in the launcher that is wat john uses to redirect the profile

Please search before posting. ~Thanks

haustin
Offline
Last seen: 12 years 6 months ago
Joined: 2007-09-19 17:59
Well, actually,

I seem to recall saying something along the lines of ...

Don't forget to remove your previous APPDATA logic:

CopyFiles /SILENT "$APPDATA\Artweaver\*.*" "$SETTINGSDIRECTORY\Artweaver"
RMDIR /r "$APPDATA\Artweaver"
IfFileExists "$APPDATA\ArtweaverbackupbyArtweaverportable" +1 TheEnd
Rename "$APPDATA\ArtweaverbackupbyArtweaverportable" "$APPDATA\Artweaverfolder"

I haven't checked to see if Kernel32::SetEnvironmentVariableA automatically updates NSIS' local copy.

If [YES], the above code will move the configuration stuff that you just told Artweaver to save on your portable drive in its default subfolder (Data\ArtWeaver) to a different location (Data\Settings\ArtWeaver). (If that's where you wanted it, it's easier to set the APPDATA variable accordingly and avoid the costly copy-and-delete.) On the next launch of ArtWeaver, it won't find its stuff (because you moved it!) and will probably want to create a new profile again.

If [NOT], the code will move the old saved data from your PC's APPDATA directory to Data\Settings\ArtWeaver on your portable drive (still not where the APPDATA told the app it would be).

Either way, the last two lines check for and potentially rename a file/directory that isn't created or referenced elsewhere in the script. Probably doesn't hurt anything, but it's probably not very useful either.

Now, as far as Firefox and other portable-friendly apps go, some have command-line switches that tell them to store everything they normally would spread out all over your machine (APPDATA, registry, bogus folders under Program Files, etc.) under a single directory that you specify on the command-line. Some apps behave well for files, but leave crap in the regisrty; others automatically switch to an INI or REG file and leave the registry clean, but still leave their files scattered wherever they please. So, the "right" way to handle the app is to get it to be as helpful as it can be and then work around the areas the developers didn't handle.

So, if an app writes to APPDATA and the registry, and has a /portable switch that makes it use INI files instead of the registry, you can probably close the deal by using the APPDATA trick that powerjuce showed you. If an app insists on using the registry, then you have to resort to backing up and restoring the keys that are needed by or clobbered during a run of your portable version.

In Firefox's case, its -profile switch handles both registry behavior and APPDATA, so it's actually very well-behaved. The problem then becomes that Firefox components are TOO aware of where their all-in-one profile directory is. The genius of John's launcher is that it cleans up all the internal URI references and config files whenever you bork them by moving your portable drive and getting assigned a different drive letter.

-hea

denash
Offline
Last seen: 14 years 6 months ago
Joined: 2007-04-08 12:14
I think I just leave it as

I think I just leave it as it is is, but thanks for all your suggestions, codes and help

THANK YOU! @all

David Dixon II
David Dixon II's picture
Offline
Last seen: 2 years 1 month ago
Developer
Joined: 2007-06-11 22:54
dude!

THANKS FOR THAT Smile TY TY TY TY TY TY TY TY TY TY TY TY
(ok im done ;))

Na na na, come on!

denash
Offline
Last seen: 14 years 6 months ago
Joined: 2007-04-08 12:14
Solution

!define PORTABLEAPPNAME "Artweaver Portable"
!define NAME "ArtweaverPortable"
!define APPNAME "Artweaver"
!define VER "1.5.5.0"
!define WEBSITE "PortableApps.com/ArtweaverPortable"
!define DEFAULTEXE "Artweaver.exe"
!define DEFAULTAPPDIR "Artweaver"
!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
		StrCpy $SETTINGSDIRECTORY "$EXEDIR\Data"
		System::Call 'Kernel32::SetEnvironmentVariableA(t, t) i("APPDATA", "$SETTINGSDIRECTORY").r0'
		GoTo SettingsFound
	
	CopyDefaultSettings:
		CreateDirectory "$EXEDIR\Data"
		CreateDirectory "$EXEDIR\Data\settings"
		CopyFiles /SILENT "$EXEDIR\App\DefaultData\settings\*.*" "$SETTINGSDIRECTORY"
		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} "HKCU\Software\Artweaver-BackupByArtweaverPortable" $R0
		StrCmp $R0 "0" RestoreTheKey
		${registry::KeyExists} "HKCU\Software\Artweaver" $R0
		StrCmp $R0 "-1" RestoreTheKey
		${registry::MoveKey} "HKCU\Software\Artweaver" "HKCU\Software\Artweaver-BackupByArtweaverPortable" $R0
		Sleep 100
		
	RestoreTheKey:
		IfFileExists "$SETTINGSDIRECTORY\Artweaver_portable.reg" "" LaunchNow
	
		IfFileExists "$WINDIR\system32\reg.exe" "" RestoreTheKey9x
			nsExec::ExecToStack `"$WINDIR\system32\reg.exe" import "$SETTINGSDIRECTORY\Artweaver_portable.reg"`
			Pop $R0
			StrCmp $R0 '0' LaunchNow ;successfully restored key

	RestoreTheKey9x:
		${registry::RestoreKey} "$SETTINGSDIRECTORY\Artweaver_portable.reg" $R0
		StrCmp $R0 '0' LaunchNow ;successfully restored key
		StrCpy $FAILEDTORESTOREKEY "true"
	
	LaunchNow:
		Sleep 100
		ExecWait $EXECSTRING
		
	CheckRunning:
		Sleep 1000
		FindProcDLL::FindProc "${DEFAULTEXE}"                  
		StrCmp $R0 "1" CheckRunning
		
		StrCmp $FAILEDTORESTOREKEY "true" SetOriginalKeyBack
		${registry::SaveKey} "HKCU\Software\Artweaver" "$SETTINGSDIRECTORY\Artweaver_portable.reg" "" $0
		Sleep 100
	
	SetOriginalKeyBack:
		${registry::DeleteKey} "HKCU\Software\Artweaver" $R0
		Sleep 100
		${registry::KeyExists} "HKCU\Software\Artweaver-BackupByArtweaverPortable" $R0
		StrCmp $R0 "-1" TheEnd
		${registry::MoveKey} "HKCU\Software\Artweaver-BackupByArtweaverPortable" "HKCU\Software\Artweaver" $R0
		CopyFiles /SILENT "$APPDATA\Artweaver\*.*" "$SETTINGSDIRECTORY"
		IfFileExists "$APPDATA\Artweaver-backupbyArtweaverportable" +1 
		Rename "$APPDATA\Artweaver-backupbyArtweaverportable" "$SETTINGSDIRECTORY"
		RMDIR /r "$APPDATA\Artweaver"
		Goto TheEnd

		
	LaunchAndExit:
		Exec $EXECSTRING
	
	TheEnd:
		${registry::Unload}
		newadvsplash::stop /WAIT
SectionEnd

I just replaced all "$SETTINGSDIRECTORY\Artweaver" which had something to do with moving setting "$SETTINGSDIRECTORY" thatt made the code work, because I think it didnt know where "\Artweaver" was located

digitxp
digitxp's picture
Offline
Last seen: 12 years 6 months ago
Joined: 2007-11-03 18:33
Just don't forget to change the copyright in the Viversion

to PortableApps.com and Contributors.
And put back the comments in the front (GPL)

Insert original signature here with Greasemonkey Script.

denash
Offline
Last seen: 14 years 6 months ago
Joined: 2007-04-08 12:14
ok I will do that, thx

ok I will do that, thx

alpha1
alpha1's picture
Offline
Last seen: 8 years 10 months ago
Joined: 2007-07-08 20:02
How would you go about just

How would you go about just deleting a folder in ...when it closes?
C:\Documents and Settings\User\Application Data\Avidemux

Lead, Follow, or get out of the way.

denash
Offline
Last seen: 14 years 6 months ago
Joined: 2007-04-08 12:14
SetOriginalKeyBack: CopyFi
SetOriginalKeyBack:
		CopyFiles /SILENT "$APPDATA\Avidemux\*.*" "$SETTINGSDIRECTORY"
		IfFileExists "$APPDATA\Avidemux-backupbyPROGRAMMNAMEportable" +1 
		Rename "$APPDATA\Avidemux-backupbyPROGRAMMNAMEportable" "$SETTINGSDIRECTORY"
		RMDIR /r "$APPDATA\Avidemux"
		Goto TheEnd

At the end put this code in. (replace "PROGRAMMNAME" with your apps name) this will redirect those files to the "Data" directory of the portable app (if you are having the "Data" directory.

RMDIR/r "$APPDATA\Avidemux"

This will remoove that direcory of the computer when the launcher exits

(hope it helps) if you need anymore help could you please post the whole code?

alpha1
alpha1's picture
Offline
Last seen: 8 years 10 months ago
Joined: 2007-07-08 20:02
well with this i keep

well with this i keep getting an error or line 124:CopyFiles /SILENT "$APPDATA\avidemux\*.*" "$SETTINGSDIRECTORY"
In $APPDATA\avidemux there is a folder"custom" and "admlog.txt",folder is empty
do i need to set it to go delete each of those files, or the whole directory? they aren't needed to run or save
settings in avidemux so I don't really need to redirect so much as just delete $APPDATA\avidemux
is there s simpler code to do just that?

My code, based of Tennix!portable:

;Copyright (C) 2004-2008 John T. Haller
;Copyright (C) 2007-2008 Mike Fitzpatrick-Ruth

;Website: https://portableapps.com/AvidemuxPortable

;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 "Avidemux Portable"
!define APPNAME "Avidemux!"
!define NAME "AvidemuxPortable"
!define VER "1.5.7.0"
!define WEBSITE "PortableApps.com/AvidemuxPortable"
!define DEFAULTEXE "Avidemux.exe"
!define DEFAULTAPPDIR "Avidemux"

;=== 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 "PortableApps.com & Contributers"
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 "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 EXECSTRING
Var DISABLESPLASHSCREEN
Var MISSINGFILEORPATH


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

	CheckINI:
		ReadINIStr $DISABLESPLASHSCREEN "$EXEDIR\${NAME}.ini" "${NAME}" "DisableSplashScreen"
		ClearErrors

		IfFileExists "$EXEDIR\App\${DEFAULTAPPDIR}\${DEFAULTEXE}" FoundProgramEXE

	;NoProgramEXE:
		;=== Program executable not where expected
		StrCpy $MISSINGFILEORPATH $EXEDIR\App\${DEFAULTAPPDIR}\${DEFAULTEXE}
		MessageBox MB_OK|MB_ICONEXCLAMATION `$(LauncherFileNotFound)`
		Abort
		
	FoundProgramEXE:
		StrCmp $DISABLESPLASHSCREEN "true" CreateExecString
			;=== Show the splash screen while processing registry entries
			InitPluginsDir
			File /oname=$PLUGINSDIR\splash.jpg "${NAME}.jpg"
			newadvsplash::show /NOUNLOAD 1000 0 0 -1 /L $PLUGINSDIR\splash.jpg
	
	CreateExecString:
		StrCpy $EXECSTRING `"$EXEDIR\App\${DEFAULTAPPDIR}\${DEFAULTEXE}"`
	
	;LaunchNow:
		ExecWait $EXECSTRING
		
	CheckRunning:
		Sleep 1000
		FindProcDLL::FindProc "${DEFAULTEXE}"                  
		StrCmp $R0 "1" CheckRunning

	newadvsplash::stop /WAIT
	
SectionEnd
	SetOriginalKeyBack:
		CopyFiles /SILENT "$APPDATA\avidemux\*.*" "$SETTINGSDIRECTORY"
		IfFileExists "$APPDATA\Avidemux-backupbyavidemuxportable" +1 
		Rename "$APPDATA\Avidemux-backupbyavidemuxportable" "$SETTINGSDIRECTORY"
		RMDIR /r "$APPDATA\Avidemux"
		Goto TheEnd

thank you very much

Lead, Follow, or get out of the way.

denash
Offline
Last seen: 14 years 6 months ago
Joined: 2007-04-08 12:14
Try this

;Copyright (C) 2004-2008 John T. Haller
;Copyright (C) 2007-2008 Mike Fitzpatrick-Ruth

;Website: https://portableapps.com/AvidemuxPortable

;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 "Avidemux Portable"
!define APPNAME "Avidemux!"
!define NAME "AvidemuxPortable"
!define VER "1.5.7.0"
!define WEBSITE "PortableApps.com/AvidemuxPortable"
!define DEFAULTEXE "Avidemux.exe"
!define DEFAULTAPPDIR "Avidemux"

;=== 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 "PortableApps.com & Contributers"
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 "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 EXECSTRING
Var DISABLESPLASHSCREEN
Var MISSINGFILEORPATH


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

	CheckINI:
		ReadINIStr $DISABLESPLASHSCREEN "$EXEDIR\${NAME}.ini" "${NAME}" "DisableSplashScreen"
		ClearErrors

		IfFileExists "$EXEDIR\App\${DEFAULTAPPDIR}\${DEFAULTEXE}" FoundProgramEXE

	;NoProgramEXE:
		;=== Program executable not where expected
		StrCpy $MISSINGFILEORPATH $EXEDIR\App\${DEFAULTAPPDIR}\${DEFAULTEXE}
		MessageBox MB_OK|MB_ICONEXCLAMATION `$(LauncherFileNotFound)`
		Abort
		
	FoundProgramEXE:
		StrCmp $DISABLESPLASHSCREEN "true" CreateExecString
			;=== Show the splash screen while processing registry entries
			InitPluginsDir
			File /oname=$PLUGINSDIR\splash.jpg "${NAME}.jpg"
			newadvsplash::show /NOUNLOAD 1000 0 0 -1 /L $PLUGINSDIR\splash.jpg
	
	CreateExecString:
		StrCpy $EXECSTRING `"$EXEDIR\App\${DEFAULTAPPDIR}\${DEFAULTEXE}"`
	
	;LaunchNow:
		ExecWait $EXECSTRING
		
	CheckRunning:
		Sleep 1000
		FindProcDLL::FindProc "${DEFAULTEXE}"                  
		StrCmp $R0 "1" CheckRunning
	

	SetOriginalKeyBack:
		CopyFiles /SILENT "$APPDATA\avidemux\*.*" "$SETTINGSDIRECTORY"
		IfFileExists "$APPDATA\Avidemux-backupbyavidemuxportable" +1 
		Rename "$APPDATA\Avidemux-backupbyavidemuxportable" "$SETTINGSDIRECTORY"
		RMDIR /r "$APPDATA\Avidemux"
		Goto TheEnd
	
	LaunchAndExit:
		Exec $EXECSTRING
	
	TheEnd:
		newadvsplash::stop /WAIT

SectionEnd

The only mistake I found is that you delete the files after the "SecondEnd" Part which means The whole code ends there. (I Think)
You also don't have the "TheEnd" label but direct your label to it to.
Just copy and paste THIS code and try it. If it does not work, please post you code here again.

alpha1
alpha1's picture
Offline
Last seen: 8 years 10 months ago
Joined: 2007-07-08 20:02
i used you code exactly and

i used you code exactly and still got nothing
this is the error i get, it still compiles and runs but the $APPDATA doesn't disappear and nothing new in Data
in Avidemux
"4 warnings:
unknown variable/constant "SETTINGSDIRECTORY" detected, ignoring (C:\Documents and Settings\User\Desktop\AvidemuxPortable\Other\Source\AvidemuxPortable.nsi:123)
unknown variable/constant "SETTINGSDIRECTORY" detected, ignoring (C:\Documents and Settings\User\Desktop\AvidemuxPortable\Other\Source\AvidemuxPortable.nsi:125)
label "SetOriginalKeyBack" not used
label "LaunchAndExit" not used"
thanks again

Lead, Follow, or get out of the way.

Nathan9222
Nathan9222's picture
Offline
Last seen: 2 years 5 months ago
Developer
Joined: 2007-12-06 22:35
if you want......

if you want to know how to move something from $APPDATA look at opera portable that I released, I just used the "Rename" to move from $APPDATA to $SETTINGS because I do not know it environment variable. Oh yeah you can make it so that nothing gets deleted, just moved around. for example you can have appdata go to the DefaultData folder then to $SETTINGS folder and back to DefaultData and back to $APPDATA. I dont know if there is a function that will overwrite the whole folder and files inside, maybe it is CopyFiles /SILENT function.

An eye for an eye makes the whole world blind.
Mahatma Gandhi,
Indian political and spiritual leader (1869 - 1948)

alpha1
alpha1's picture
Offline
Last seen: 8 years 10 months ago
Joined: 2007-07-08 20:02
ok thanks, I'm going to do

ok thanks, I'm going to do that right now
I'll let you know how it goes

Lead, Follow, or get out of the way.

alpha1
alpha1's picture
Offline
Last seen: 8 years 10 months ago
Joined: 2007-07-08 20:02
stupid me

i figured out why nothing worked, a stupid mistake on my part
there is stuff under $APPDATA, but also , under docs and settings/user, and i was checking there the entire time, and not the $APPDATA folder
you code takes care of the $APPDATA folder, but how can i modify that to take care of Documents and Settings/User/Avidemux
i'm going to start a new post for this here, instead of hijacking this threat further

Lead, Follow, or get out of the way.

Log in or register to post comments