Var bolCustomCreatedLegacy

!macro CustomCodePreInstall
	${If} ${FileExists} "$INSTDIR\Data\settings\config\*.*"
	${AndIfNot} ${FileExists} "$INSTDIR\Data\library\*.*"
		CreateDirectory "$INSTDIR\Data\library"
	${EndIf}
	
	System::Call kernel32::GetCurrentProcess()i.s
	System::Call kernel32::IsWow64Process(is,*i.r0)
	
	${If} $0 == 0 ;32-bit
		ReadINIStr $0 "$INSTDIR\App\AppInfo\appinfo.ini" "Version" "PackageVersion"
		${VersionCompare} $0 "2.13.0.0" $R0
		${If} $R0 = 2
			${GetParent} $INSTDIR $1
			${IfNot} ${FileExists} "$1\CppcheckPortableLegacy32bit\*.*"
				${GetParent} $INSTDIR $1
				CreateDirectory "$1\CppcheckPortableLegacy32bit"
				CreateDirectory "$1\CppcheckPortableLegacy32bit\App"
				CreateDirectory "$1\CppcheckPortableLegacy32bit\App\AppInfo"
				CreateDirectory "$1\CppcheckPortableLegacy32bit\App\DefaultData"
				CreateDirectory "$1\CppcheckPortableLegacy32bit\Data"
				CreateDirectory "$1\CppcheckPortableLegacy32bit\Other"
				CopyFiles /SILENT /FILESONLY "$INSTDIR\*.*" "$1\CppcheckPortableLegacy32bit"
				CopyFiles /SILENT "$INSTDIR\App\readme.txt" "$1\CppcheckPortableLegacy32bit\App"
				CopyFiles /SILENT "$INSTDIR\App\AppInfo\*.*" "$1\CppcheckPortableLegacy32bit\App\AppInfo"
				CopyFiles /SILENT "$INSTDIR\App\DefaultData\*.*" "$1\CppcheckPortableLegacy32bit\App\DefaultData"
				Rename "$INSTDIR\App\Cppcheck" "$1\CppcheckPortableLegacy32bit\App\Cppcheck"
				CopyFiles /SILENT "$INSTDIR\Data\*.*" "$1\CppcheckPortableLegacy32bit\Data"
				CopyFiles /SILENT "$INSTDIR\Other\*.*" "$1\CppcheckPortableLegacy32bit\Other"
				StrCpy $bolCustomCreatedLegacy true
			${EndIf}	
		${EndIf}
	${EndIf}
!macroend

!macro CustomCodePostInstall
	${If} $bolCustomCreatedLegacy == true
		${GetParent} $INSTDIR $1
		Delete "$1\CppcheckPortableLegacy32bit\CppcheckPortable.exe"
		Delete "$1\CppcheckPortableLegacy32bit\App\AppInfo\appinfo.ini"
		Delete "$1\CppcheckPortableLegacy32bit\App\AppInfo\Launcher\custom.nsh"
		Delete "$1\CppcheckPortableLegacy32bit\App\AppInfo\Launcher\Splash.jpg"
		Delete "$1\CppcheckPortableLegacy32bit\App\AppInfo\Launcher\CppcheckPortable.ini"
		CopyFiles /SILENT "$INSTDIR\Other\Source\Legacy\CppcheckPortableLegacy32bit.exe" "$1\CppcheckPortableLegacy32bit"
		CopyFiles /SILENT "$INSTDIR\Other\Source\Legacy\CppcheckPortableLegacy32bit.ini" "$1\CppcheckPortableLegacy32bit\App\AppInfo\Launcher"
		CopyFiles /SILENT "$INSTDIR\Other\Source\Legacy\custom.nsh" "$1\CppcheckPortableLegacy32bit\App\AppInfo\Launcher"
		CopyFiles /SILENT "$INSTDIR\App\AppInfo\Launcher\Splash.jpg" "$1\CppcheckPortableLegacy32bit\App\AppInfo\Launcher"
		CopyFiles /SILENT "$INSTDIR\Other\Source\Legacy\appinfo.ini" "$1\CppcheckPortableLegacy32bit\App\AppInfo"
	${EndIf}
!macroend
