Var bolCustomCreatedLegacy

!macro CustomCodePreInstall
	${If} ${FileExists} "$INSTDIR\App\AppInfo\appinfo.ini"
		ReadINIStr $0 "$INSTDIR\App\AppInfo\appinfo.ini" "Version" "PackageVersion"
		${VersionCompare} $0 "6.0.0.0" $R0
		${If} $R0 = 2
			${GetParent} $INSTDIR $1
			${IfNot} ${FileExists} "$1\ListaryClassicPortable\*.*"
				${GetParent} $INSTDIR $1
				CreateDirectory "$1\ListaryClassicPortable"
				CopyFiles /SILENT "$INSTDIR\*.*" "$1\ListaryClassicPortable"
				StrCpy $bolCustomCreatedLegacy true
			${EndIf}	
		${EndIf}
	${EndIf}
!macroend

!macro CustomCodePostInstall
	${If} $bolCustomCreatedLegacy == true
		${GetParent} $INSTDIR $1
		Delete "$1\ListaryClassicPortable\App\readme.txt"
		CopyFiles /SILENT "$INSTDIR\App\readme.txt" "$1\ListaryClassicPortable\App"
		Delete "$1\ListaryClassicPortable\ListaryPortable.exe"
		CopyFiles /SILENT "$INSTDIR\Other\Source\Legacy\ListaryClassicPortable.exe" "$1\ListaryClassicPortable"
		Delete "$1\ListaryClassicPortable\help.html"
		CopyFiles /SILENT "$INSTDIR\help.html" "$1\ListaryClassicPortable"
		Delete "$1\ListaryClassicPortable\App\AppInfo\Launcher\ListaryPortable.ini"
		CopyFiles /SILENT "$INSTDIR\Other\Source\Legacy\ListaryClassicPortable.ini" "$1\ListaryClassicPortable\App\AppInfo\Launcher"
		Delete "$1\ListaryClassicPortable\App\AppInfo\Launcher\custom.nsh"
		Delete "$1\ListaryClassicPortable\App\AppInfo\installer.ini"
		Delete "$1\ListaryClassicPortable\App\AppInfo\appinfo.ini"
		CopyFiles /SILENT "$INSTDIR\Other\Source\Legacy\appinfo.ini" "$1\ListaryClassicPortable\App\AppInfo"
		CopyFiles /SILENT "$INSTDIR\App\AppInfo\EULA.txt" "$1\ListaryClassicPortable\App\AppInfo"
		Delete "$1\ListaryClassicPortable\App\AppInfo\appico*.*"
		CopyFiles /SILENT "$INSTDIR\Other\Source\Legacy\appico*.*" "$1\ListaryClassicPortable\App\AppInfo"
		
		${If} ${FileExists} "$1\ListaryClassicPortable\Data\settings\ListaryPortableSettings.ini"
			Rename "$1\ListaryClassicPortable\Data\settings\ListaryPortableSettings.ini" "$1\ListaryClassicPortable\Data\settings\ListaryClassicPortableSettings.ini"
			ReadINIStr $0 "$1\ListaryClassicPortable\Data\settings\ListaryClassicPortableSettings.ini" "ListaryPortableSettings" "LastDrive"
			WriteINIStr "$1\ListaryClassicPortable\Data\settings\ListaryClassicPortableSettings.ini" "ListaryClassicPortableSettings" "LastDrive" "$0"
			ReadINIStr $0 "$1\ListaryClassicPortable\Data\settings\ListaryClassicPortableSettings.ini" "ListaryPortableSettings" "LastDirectory"
			WriteINIStr "$1\ListaryClassicPortable\Data\settings\ListaryClassicPortableSettings.ini" "ListaryClassicPortableSettings" "LastDirectory" "$0"
			DeleteINISec "$1\ListaryClassicPortable\Data\settings\ListaryClassicPortableSettings.ini" "ListaryPortableSettings"
		${EndIf}
	${EndIf}
!macroend
