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 "5.2.2.0" $R0
		${If} $R0 = 2
			${GetParent} $INSTDIR $1
			${IfNot} ${FileExists} "$1\KVIrcPortableLegacy32bit\*.*"
				${GetParent} $INSTDIR $1
				CreateDirectory "$1\KVIrcPortableLegacy32bit"
				CopyFiles /SILENT "$INSTDIR\*.*" "$1\KVIrcPortableLegacy32bit"
				WriteINIStr "$1\KVIrcPortableLegacy32bit\App\AppInfo\AppInfo.ini" "Details" "AppID" "KVIrcPortableLegacy32bit"
				WriteINIStr "$1\KVIrcPortableLegacy32bit\App\AppInfo\AppInfo.ini" "Details" "Name" "KVIrc Portable (Legacy 32-bit)"
				StrCpy $bolCustomCreatedLegacy true
				WriteINIStr "$1\KVIrcPortableLegacy32bit\App\AppInfo\AppInfo.ini" "Control" "Start" "KVIrcPortableLegacy32bit.exe"
			${EndIf}	
		${EndIf}
	${EndIf}
!macroend

!macro CustomCodePostInstall
	${If} $bolCustomCreatedLegacy == true
		${GetParent} $INSTDIR $1
		Delete "$1\KVIrcPortableLegacy32bit\KVIrcPortable.exe"
		Delete "$1\KVIrcPortableLegacy32bit\App\AppInfo\Launcher\custom.nsh"
		Delete "$1\KVIrcPortableLegacy32bit\App\AppInfo\Launcher\KVIrcPortable.ini"
		CopyFiles /SILENT "$INSTDIR\Other\Source\Legacy\KVIrcPortableLegacy32bit.exe" "$1\KVIrcPortableLegacy32bit"
		CopyFiles /SILENT "$INSTDIR\Other\Source\Legacy\KVIrcPortableLegacy32bit.ini" "$1\KVIrcPortableLegacy32bit\App\AppInfo\Launcher"
		CopyFiles /SILENT "$INSTDIR\Other\Source\Legacy\custom.nsh" "$1\KVIrcPortableLegacy32bit\App\AppInfo\Launcher"
		${If} ${FileExists} "$1\KVIrcPortableLegacy32bit\Data\settings\KVIrcPortableSettings.ini"
			Rename "$1\KVIrcPortableLegacy32bit\Data\settings\KVIrcPortableSettings.ini" "$1\KVIrcPortableLegacy32bit\Data\settings\KVIrcPortableLegacy32bitSettings.ini"
			ReadINIStr $0 "$1\KVIrcPortableLegacy32bit\Data\settings\KVIrcPortableLegacy32bitSettings.ini" "KVIrcPortableSettings" "LastDrive"
			WriteINIStr "$1\KVIrcPortableLegacy32bit\Data\settings\KVIrcPortableLegacy32bitSettings.ini" "KVIrcPortableLegacy32bitSettings" "LastDrive" "$0"
			ReadINIStr $0 "$1\KVIrcPortableLegacy32bit\Data\settings\KVIrcPortableLegacy32bitSettings.ini" "KVIrcPortableSettings" "LastDirectory"
			WriteINIStr "$1\KVIrcPortableLegacy32bit\Data\settings\KVIrcPortableLegacy32bitSettings.ini" "KVIrcPortableLegacy32bitSettings" "LastDirectory" "$0"
			DeleteINISec "$1\KVIrcPortableLegacy32bit\Data\settings\KVIrcPortableLegacy32bitSettings.ini" "KVIrcPortableSettings"
		${EndIf}
	${EndIf}
!macroend
