Var bolCustomCreatedLegacy

!macro CustomCodePreInstall
	System::Call kernel32::GetCurrentProcess()i.s
	System::Call kernel32::IsWow64Process(is,*i.r0)
	ReadRegStr $1 HKLM "Software\Microsoft\Windows NT\CurrentVersion" "CurrentBuild"
	
	${If} $1 < 7600 ;Windows XP/Vista
	${OrIf} $0 == 0 ;or 32-bit
		ReadINIStr $0 "$INSTDIR\App\AppInfo\appinfo.ini" "Version" "PackageVersion"
		${VersionCompare} $0 "5.10.0.0" $R0
		${If} $R0 = 2
			${GetParent} $INSTDIR $1
			${IfNot} ${FileExists} "$1\RawTherapeePortableLegacy32bit\*.*"
				${GetParent} $INSTDIR $1
				CreateDirectory "$1\RawTherapeePortableLegacy32bit"
				CreateDirectory "$1\RawTherapeePortableLegacy32bit\App"
				CreateDirectory "$1\RawTherapeePortableLegacy32bit\App\AppInfo"
				CreateDirectory "$1\RawTherapeePortableLegacy32bit\App\DefaultData"
				CreateDirectory "$1\RawTherapeePortableLegacy32bit\Data"
				CreateDirectory "$1\RawTherapeePortableLegacy32bit\Other"
				CreateDirectory "$1\RawTherapeePortableLegacy32bit\App\RawTherapee"
				CopyFiles /SILENT /FILESONLY "$INSTDIR\*.*" "$1\RawTherapeePortableLegacy32bit"
				CopyFiles /SILENT "$INSTDIR\App\AppInfo\*.*" "$1\RawTherapeePortableLegacy32bit\App\AppInfo"
				CopyFiles /SILENT "$INSTDIR\App\DefaultData\*.*" "$1\RawTherapeePortableLegacy32bit\App\DefaultData"
				Rename "$INSTDIR\App\RawTherapee\x86" "$1\RawTherapeePortableLegacy32bit\App\RawTherapee\x86"
				CopyFiles /SILENT "$INSTDIR\Data\*.*" "$1\RawTherapeePortableLegacy32bit\Data"
				CopyFiles /SILENT "$INSTDIR\Other\*.*" "$1\RawTherapeePortableLegacy32bit\Other"
				StrCpy $bolCustomCreatedLegacy true
			${EndIf}	
		${EndIf}
	${EndIf}
!macroend

!macro CustomCodePostInstall
	${If} $bolCustomCreatedLegacy == true
		${GetParent} $INSTDIR $1
		CopyFiles /SILENT "$INSTDIR\App\readme.txt" "$1\RawTherapeePortableLegacy32bit\App"
		Delete "$1\RawTherapeePortableLegacy32bit\RawTherapeePortable.exe"
		Delete "$1\RawTherapeePortableLegacy32bit\App\AppInfo\appinfo.ini"
		Delete "$1\RawTherapeePortableLegacy32bit\App\AppInfo\Launcher\custom.nsh"
		Delete "$1\RawTherapeePortableLegacy32bit\App\AppInfo\Launcher\RawTherapeePortable.ini"
		CopyFiles /SILENT "$INSTDIR\Other\Source\Legacy\RawTherapeePortableLegacy32bit.exe" "$1\RawTherapeePortableLegacy32bit"
		CopyFiles /SILENT "$INSTDIR\Other\Source\Legacy\RawTherapeePortableLegacy32bit.ini" "$1\RawTherapeePortableLegacy32bit\App\AppInfo\Launcher"
		CopyFiles /SILENT "$INSTDIR\Other\Source\Legacy\custom.nsh" "$1\RawTherapeePortableLegacy32bit\App\AppInfo\Launcher"
		CopyFiles /SILENT "$INSTDIR\Other\Source\Legacy\appinfo.ini" "$1\RawTherapeePortableLegacy32bit\App\AppInfo"
		${If} ${FileExists} "$1\RawTherapeePortableLegacy32bit\Data\settings\RawTherapeePortableSettings.ini"
			Rename "$1\RawTherapeePortableLegacy32bit\Data\settings\RawTherapeePortableSettings.ini" "$1\RawTherapeePortableLegacy32bit\Data\settings\RawTherapeePortableLegacy32bitSettings.ini"
			ReadINIStr $0 "$1\RawTherapeePortableLegacy32bit\Data\settings\RawTherapeePortableLegacy32bitSettings.ini" "RawTherapeePortableSettings" "LastDrive"
			WriteINIStr "$1\RawTherapeePortableLegacy32bit\Data\settings\RawTherapeePortableLegacy32bitSettings.ini" "RawTherapeePortableLegacy32bitSettings" "LastDrive" "$0"
			ReadINIStr $0 "$1\RawTherapeePortableLegacy32bit\Data\settings\RawTherapeePortableLegacy32bitSettings.ini" "RawTherapeePortableSettings" "LastDirectory"
			WriteINIStr "$1\RawTherapeePortableLegacy32bit\Data\settings\RawTherapeePortableLegacy32bitSettings.ini" "RawTherapeePortableLegacy32bitSettings" "LastDirectory" "$0"
			DeleteINISec "$1\RawTherapeePortableLegacy32bit\Data\settings\RawTherapeePortableLegacy32bitSettings.ini" "RawTherapeePortableSettings"
		${EndIf}
	${EndIf}
!macroend
