!include WinVer.nsh

Var bolCustomCreatedLegacy

!macro CustomCodePreInstall
	System::Call kernel32::GetCurrentProcess()i.s
	System::Call kernel32::IsWow64Process(is,*i.r0)
	
	${If} ${IsWinXP}
	${OrIf} $0 == 0 ;or 32-bit
			ReadINIStr $0 "$INSTDIR\App\AppInfo\appinfo.ini" "Version" "PackageVersion"
			${VersionCompare} $0 "3.90.0.2" $R0
			${If} $R0 = 2
				${GetParent} $INSTDIR $1
				${IfNot} ${FileExists} "$1\FotoSketcherPortableLegacy32bit\*.*"
					${GetParent} $INSTDIR $1
					CreateDirectory "$1\FotoSketcherPortableLegacy32bit"
					CopyFiles /SILENT "$INSTDIR\*.*" "$1\FotoSketcherPortableLegacy32bit"
					WriteINIStr "$1\FotoSketcherPortableLegacy32bit\App\AppInfo\AppInfo.ini" "Details" "AppID" "FotoSketcherPortableLegacy32bit"
					WriteINIStr "$1\FotoSketcherPortableLegacy32bit\App\AppInfo\AppInfo.ini" "Details" "Name" "FotoSketcher Portable (Legacy 32-bit)"
					StrCpy $bolCustomCreatedLegacy true
					WriteINIStr "$1\FotoSketcherPortableLegacy32bit\App\AppInfo\AppInfo.ini" "Control" "Start" "FotoSketcherPortableLegacy32bit.exe"
				${EndIf}	
			${EndIf}
	${EndIf}
!macroend

!macro CustomCodePostInstall
	${If} $bolCustomCreatedLegacy == true
		${GetParent} $INSTDIR $1
		Delete "$1\FotoSketcherPortableLegacy32bit\FotoSketcherPortable.exe"
		Delete "$1\FotoSketcherPortableLegacy32bit\App\AppInfo\Launcher\FotoSketcherPortable.ini"
		CopyFiles /SILENT "$INSTDIR\Other\Source\Legacy\FotoSketcherPortableLegacy32bit.exe" "$1\FotoSketcherPortableLegacy32bit"
		CopyFiles /SILENT "$INSTDIR\Other\Source\Legacy\FotoSketcherPortableLegacy32bit.ini" "$1\FotoSketcherPortableLegacy32bit\App\AppInfo\Launcher"
		ReadINIStr $2 "$1\FotoSketcherPortableLegacy32bit\App\AppInfo\appinfo.ini" "Version" "PackageVersion"
		ReadINIStr $3 "$1\FotoSketcherPortableLegacy32bit\App\AppInfo\appinfo.ini" "Version" "DisplayVersion"
		Delete "$1\FotoSketcherPortableLegacy32bit\App\AppInfo\appinfo.ini"
		CopyFiles /SILENT "$INSTDIR\Other\Source\Legacy\appinfo.ini" "$1\FotoSketcherPortableLegacy32bit\App\AppInfo"
		${If} $2 == "3.90.0.0"
			StrCpy $2 "3.80.0.0"
			StrCpy $3 "3.80"
		${EndIf}
		WriteINIStr "$1\FotoSketcherPortableLegacy32bit\App\AppInfo\appinfo.ini" "Version" "PackageVersion" "$2"
		WriteINIStr "$1\FotoSketcherPortableLegacy32bit\App\AppInfo\appinfo.ini" "Version" "DisplayVersion" "$3"
		Delete "$1\FotoSketcherPortableLegacy32bit\App\AppInfo\EULA.txt"
		CopyFiles /SILENT "$INSTDIR\App\AppInfo\EULA.txt" "$1\FotoSketcherPortableLegacy32bit\App\AppInfo"
		Delete "$1\FotoSketcherPortableLegacy32bit\App\AppInfo\appico*.*"
		CopyFiles /SILENT "$INSTDIR\App\AppInfo\appico*.*" "$1\FotoSketcherPortableLegacy32bit\App\AppInfo"
		Delete "$1\FotoSketcherPortableLegacy32bit\help.html"
		CopyFiles /SILENT "$INSTDIR\help.html" "$1\FotoSketcherPortableLegacy32bit"
		CreateDirectory "$1\FotoSketcherPortableLegacy32bit\App\DefaultData"
		CopyFiles /SILENT "$INSTDIR\App\DefaultData\*.*" "$1\FotoSketcherPortableLegacy32bit\App\DefaultData"
		Delete "$1\FotoSketcherPortableLegacy32bit\App\Readme.txt"
		CopyFiles /SILENT "$INSTDIR\App\Readme.txt" "$1\FotoSketcherPortableLegacy32bit\App"
		Delete "$1\FotoSketcherPortableLegacy32bit\App\FotoSketcher\PortableFotoSketcher64.exe"
	${EndIf}
!macroend
