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 < 10000 ;Windows 7/8
	${OrIf} $0 == 0 ;or 32-bit 10
		ReadINIStr $0 "$INSTDIR\App\AppInfo\appinfo.ini" "Version" "PackageVersion"
		${VersionCompare} $0 "1.8.6.0" $R0
		${If} $R0 = 2
			${GetParent} $INSTDIR $1
			${IfNot} ${FileExists} "$1\FocusWriterPortableLegacy32bit\*.*"
				CreateDirectory "$1\FocusWriterPortableLegacy32bit"
				CreateDirectory "$1\FocusWriterPortableLegacy32bit\App"
				CreateDirectory "$1\FocusWriterPortableLegacy32bit\App\AppInfo"
				CreateDirectory "$1\FocusWriterPortableLegacy32bit\App\DefaultData"
				CreateDirectory "$1\FocusWriterPortableLegacy32bit\Data"
				CreateDirectory "$1\FocusWriterPortableLegacy32bit\Other"
				CopyFiles /SILENT /FILESONLY "$INSTDIR\*.*" "$1\FocusWriterPortableLegacy32bit"
				CopyFiles /SILENT "$INSTDIR\App\AppInfo\*.*" "$1\FocusWriterPortableLegacy32bit\App\AppInfo"
				CopyFiles /SILENT "$INSTDIR\App\DefaultData\*.*" "$1\FocusWriterPortableLegacy32bit\App\DefaultData"
				${If} ${FileExists} "$INSTDIR\App\FocusWriter32\*.*"
					Rename "$INSTDIR\App\FocusWriter32" "$1\FocusWriterPortableLegacy32bit\App\FocusWriter"
				${Else}
					Rename "$INSTDIR\App\FocusWriter" "$1\FocusWriterPortableLegacy32bit\App\FocusWriter"
				${EndIf}
				CopyFiles /SILENT "$INSTDIR\Data\*.*" "$1\FocusWriterPortableLegacy32bit\Data"
				CopyFiles /SILENT "$INSTDIR\Other\*.*" "$1\FocusWriterPortableLegacy32bit\Other"
				WriteINIStr "$1\FocusWriterPortableLegacy32bit\App\AppInfo\AppInfo.ini" "Details" "AppID" "FocusWriterPortableLegacy32bit"
				WriteINIStr "$1\FocusWriterPortableLegacy32bit\App\AppInfo\AppInfo.ini" "Details" "Name" "FocusWriter Portable (Legacy 32-bit)"
				WriteINIStr "$1\FocusWriterPortableLegacy32bit\App\AppInfo\AppInfo.ini" "Version" "PackageVersion" "1.6.16.0"
				WriteINIStr "$1\FocusWriterPortableLegacy32bit\App\AppInfo\AppInfo.ini" "Version" "DisplayVersion" "1.6.16"
				StrCpy $bolCustomCreatedLegacy true
				WriteINIStr "$1\FocusWriterPortableLegacy32bit\App\AppInfo\AppInfo.ini" "Control" "Start" "FocusWriterPortableLegacy32bit.exe"
			${EndIf}	
		${EndIf}
	${EndIf}
!macroend

!macro CustomCodePostInstall
	${If} $bolCustomCreatedLegacy == true
		${GetParent} $INSTDIR $1
		Delete "$1\FocusWriterPortableLegacy32bit\FocusWriterPortable.exe"
		Delete "$1\FocusWriterPortableLegacy32bit\App\AppInfo\Launcher\custom.nsh"
		Delete "$1\FocusWriterPortableLegacy32bit\App\AppInfo\Launcher\FocusWriterPortable.ini"
		CopyFiles /SILENT "$INSTDIR\Other\Source\Legacy\FocusWriterPortableLegacy32bit.exe" "$1\FocusWriterPortableLegacy32bit"
		CopyFiles /SILENT "$INSTDIR\Other\Source\Legacy\FocusWriterPortableLegacy32bit.ini" "$1\FocusWriterPortableLegacy32bit\App\AppInfo\Launcher"
		CopyFiles /SILENT "$INSTDIR\Other\Source\Legacy\custom.nsh" "$1\FocusWriterPortableLegacy32bit\App\AppInfo\Launcher"
		Delete "$1\FocusWriterPortableLegacy32bit\help.html"
		CopyFiles /SILENT "$INSTDIR\help.html" "$1\FocusWriterPortableLegacy32bit"
		CopyFiles /SILENT "$INSTDIR\App\readme.txt" "$1\FocusWriterPortableLegacy32bit\App"
	${EndIf}
!macroend
