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
		${If} ${FileExists} "$INSTDIR\Data\settings.ini"
			ReadINIStr $0 "$INSTDIR\App\AppInfo\appinfo.ini" "Version" "PackageVersion"
			${VersionCompare} $0 "2.5.1.0" $R0
			${If} $R0 = 2
				${GetParent} $INSTDIR $1
				${IfNot} ${FileExists} "$1\CaesiumPortableLegacyx86\*.*"
					${GetParent} $INSTDIR $1
					CreateDirectory "$1\CaesiumPortableLegacyx86"
					CreateDirectory "$1\CaesiumPortableLegacyx86\App"
					CreateDirectory "$1\CaesiumPortableLegacyx86\App\AppInfo"
					CreateDirectory "$1\CaesiumPortableLegacyx86\App\DefaultData"
					CreateDirectory "$1\CaesiumPortableLegacyx86\Data"
					CreateDirectory "$1\CaesiumPortableLegacyx86\Other"
					CopyFiles /SILENT /FILESONLY "$INSTDIR\*.*" "$1\CaesiumPortableLegacyx86"
					CopyFiles /SILENT "$INSTDIR\App\AppInfo\*.*" "$1\CaesiumPortableLegacyx86\App\AppInfo"
					CopyFiles /SILENT "$INSTDIR\App\DefaultData\*.*" "$1\CaesiumPortableLegacyx86\App\DefaultData"
					${If} ${FileExists} "$INSTDIR\App\CaesiumLegacy\*.*"
						Rename "$INSTDIR\App\CaesiumLegacy" "$1\CaesiumPortableLegacyx86\App\Caesium"
					${Else}
						Rename "$INSTDIR\App\Caesium" "$1\CaesiumPortableLegacyx86\App\Caesium"
					${EndIf}
					CopyFiles /SILENT "$INSTDIR\App\readme.txt" "$1\CaesiumPortableLegacyx86\App"
					CopyFiles /SILENT "$INSTDIR\Data\*.*" "$1\CaesiumPortableLegacyx86\Data"
					CopyFiles /SILENT "$INSTDIR\Other\*.*" "$1\CaesiumPortableLegacyx86\Other"
					Rename "$1\CaesiumPortableLegacyx86\CaesiumPortable.ini" "$1\CaesiumPortableLegacyx86\CaesiumPortableLegacyx86.ini"
					StrCpy $bolCustomCreatedLegacy true
				${EndIf}	
			${EndIf}
		${EndIf}
	${EndIf}
!macroend

!macro CustomCodePostInstall
	${If} $bolCustomCreatedLegacy == true
		${GetParent} $INSTDIR $1
		Delete "$1\CaesiumPortableLegacyx86\CaesiumPortable.exe"
		Delete "$1\CaesiumPortableLegacyx86\App\AppInfo\*.ini"
		Delete "$1\CaesiumPortableLegacyx86\App\AppInfo\Launcher\*.*"
		Delete "$1\CaesiumPortableLegacyx86\App\DefaultData\settings\Caesium.reg"
		CopyFiles /SILENT "$INSTDIR\Other\Source\Legacy\CaesiumPortableLegacyx86.exe" "$1\CaesiumPortableLegacyx86"
		CopyFiles /SILENT "$INSTDIR\Other\Source\Legacy\CaesiumPortableLegacyx86.ini" "$1\CaesiumPortableLegacyx86\App\AppInfo\Launcher"
		CopyFiles /SILENT "$INSTDIR\Other\Source\Legacy\custom.nsh" "$1\CaesiumPortableLegacyx86\App\AppInfo\Launcher"
		CopyFiles /SILENT "$INSTDIR\Other\Source\Legacy\appinfo.ini" "$1\CaesiumPortableLegacyx86\App\AppInfo"
		CopyFiles /SILENT "$INSTDIR\Other\Source\Legacy\installer.ini" "$1\CaesiumPortableLegacyx86\App\AppInfo"
	${EndIf}
!macroend
