Var bolCustomCreatedLegacy

!macro CustomCodePreInstall
	System::Call kernel32::GetCurrentProcess()i.s
	System::Call kernel32::IsWow64Process(is,*i.r0)

	${If} $0 == 0 ;or 32-bit 10
		ReadINIStr $0 "$INSTDIR\App\AppInfo\appinfo.ini" "Version" "PackageVersion"
		${VersionCompare} $0 "1.37.1.0" $R0
		${If} $R0 = 2
			${GetParent} $INSTDIR $1
			${IfNot} ${FileExists} "$1\TheLegendOfEdgarPortableLegacy32bit\*.*"
				${GetParent} $INSTDIR $1
				CreateDirectory "$1\TheLegendOfEdgarPortableLegacy32bit"
				CopyFiles /SILENT "$INSTDIR\*.*" "$1\TheLegendOfEdgarPortableLegacy32bit"
				WriteINIStr "$1\TheLegendOfEdgarPortableLegacy32bit\App\AppInfo\AppInfo.ini" "Details" "AppID" "TheLegendOfEdgarPortableLegacy32bit"
				WriteINIStr "$1\TheLegendOfEdgarPortableLegacy32bit\App\AppInfo\AppInfo.ini" "Details" "Name" "The Legend of Edgar Portable (Legacy 32-bit)"
				WriteINIStr "$1\TheLegendOfEdgarPortableLegacy32bit\App\AppInfo\AppInfo.ini" "Details" "Description" "2D platform adventure game"
				StrCpy $bolCustomCreatedLegacy true
				WriteINIStr "$1\TheLegendOfEdgarPortableLegacy32bit\App\AppInfo\AppInfo.ini" "Control" "Start" "TheLegendOfEdgarPortableLegacy32bit.exe"
				WriteINIStr "$1\TheLegendOfEdgarPortableLegacy32bit\App\AppInfo\AppInfo.ini" "Format" "Version" "3.8"
			${EndIf}	
		${EndIf}
	${EndIf}
!macroend

!macro CustomCodePostInstall
	${If} $bolCustomCreatedLegacy == true
		${GetParent} $INSTDIR $1
		Delete "$1\TheLegendOfEdgarPortableLegacy32bit\TheLegendOfEdgarPortable.exe"
		Delete "$1\TheLegendOfEdgarPortableLegacy32bit\App\Readme.txt"
		CopyFiles /SILENT "$INSTDIR\App\Readme.txt" "$1\TheLegendOfEdgarPortableLegacy32bit\App"
		Delete "$1\TheLegendOfEdgarPortableLegacy32bit\help.html"
		CopyFiles /SILENT "$INSTDIR\help.html" "$1\TheLegendOfEdgarPortableLegacy32bit"
		CopyFiles /SILENT "$INSTDIR\Other\Source\Legacy\TheLegendOfEdgarPortableLegacy32bit.exe" "$1\TheLegendOfEdgarPortableLegacy32bit"
		Rename "$1\TheLegendOfEdgarPortableLegacy32bit\App\AppInfo\Launcher\TheLegendOfEdgarPortable.ini" "$1\TheLegendOfEdgarPortableLegacy32bit\App\AppInfo\Launcher\TheLegendOfEdgarPortableLegacy32bit.ini"
		${If} ${FileExists} "$1\TheLegendOfEdgarPortableLegacy32bit\Data\settings\TheLegendOfEdgarPortableSettings.ini"
			Rename "$1\TheLegendOfEdgarPortableLegacy32bit\Data\settings\TheLegendOfEdgarPortableSettings.ini" "$1\TheLegendOfEdgarPortableLegacy32bit\Data\settings\TheLegendOfEdgarPortableLegacy32bitSettings.ini"
			ReadINIStr $0 "$1\TheLegendOfEdgarPortableLegacy32bit\Data\settings\TheLegendOfEdgarPortableLegacy32bitSettings.ini" "TheLegendOfEdgarPortableSettings" "LastDrive"
			WriteINIStr "$1\TheLegendOfEdgarPortableLegacy32bit\Data\settings\TheLegendOfEdgarPortableLegacy32bitSettings.ini" "TheLegendOfEdgarPortableLegacy32bitSettings" "LastDrive" "$0"
			ReadINIStr $0 "$1\TheLegendOfEdgarPortableLegacy32bit\Data\settings\TheLegendOfEdgarPortableLegacy32bitSettings.ini" "TheLegendOfEdgarPortableSettings" "LastDirectory"
			WriteINIStr "$1\TheLegendOfEdgarPortableLegacy32bit\Data\settings\TheLegendOfEdgarPortableLegacy32bitSettings.ini" "TheLegendOfEdgarPortableLegacy32bitSettings" "LastDirectory" "$0"
			DeleteINISec "$1\TheLegendOfEdgarPortableLegacy32bit\Data\settings\TheLegendOfEdgarPortableLegacy32bitSettings.ini" "TheLegendOfEdgarPortableSettings"
		${EndIf}
	${EndIf}
!macroend
