Var bolCustomCreatedLegacy

!macro CustomCodePreInstall
	ReadRegStr $1 HKLM "Software\Microsoft\Windows NT\CurrentVersion" "CurrentBuild"
	
	${If} $1 < 10000 ;Windows 7/8
		ReadINIStr $0 "$INSTDIR\App\AppInfo\appinfo.ini" "Version" "PackageVersion"
		${VersionCompare} $0 "8.0.0.0" $R0
		${If} $R0 = 2
			${GetParent} $INSTDIR $1
			${IfNot} ${FileExists} "$1\CopyQPortableLegacyWin7\*.*"
				${GetParent} $INSTDIR $1
				CreateDirectory "$1\CopyQPortableLegacyWin7"
				CopyFiles /SILENT "$INSTDIR\*.*" "$1\CopyQPortableLegacyWin7"
				StrCpy $bolCustomCreatedLegacy true
				WriteINIStr "$1\CopyQPortableLegacyWin7\App\AppInfo\AppInfo.ini" "Format" "Version" "3.8"
				WriteINIStr "$1\CopyQPortableLegacyWin7\App\AppInfo\AppInfo.ini" "Details" "Name" "CopyQ Portable (Legacy Win7)"
				WriteINIStr "$1\CopyQPortableLegacyWin7\App\AppInfo\AppInfo.ini" "Details" "AppId" "CopyQPortableLegacyWin7"
				WriteINIStr "$1\CopyQPortableLegacyWin7\App\AppInfo\AppInfo.ini" "Dependencies" "Requires64bitOS" "yes"
				WriteINIStr "$1\CopyQPortableLegacyWin7\App\AppInfo\AppInfo.ini" "Control" "Start" "CopyQPortableLegacyWin7.exe"
				WriteINIStr "$1\CopyQPortableLegacyWin7\App\AppInfo\AppInfo.ini" "Control" "BaseAppID" "%BASELAUNCHERPATH%\App\CopyQ\copyq.exe"
			${EndIf}	
		${EndIf}
	${EndIf}
!macroend

!macro CustomCodePostInstall
	${If} $bolCustomCreatedLegacy == true
		${GetParent} $INSTDIR $1
		CopyFiles /SILENT "$INSTDIR\App\readme.txt" "$1\CopyQPortableLegacyWin7\App"
		Delete "$1\CopyQPortableLegacyWin7\CopyQPortable.exe"
		Rename "$1\CopyQPortableLegacyWin7\App\AppInfo\Launcher\CopyQPortable.ini" "$1\CopyQPortableLegacyWin7\App\AppInfo\Launcher\CopyQPortableLegacyWin7.ini"
		WriteINIStr "$1\CopyQPortableLegacyWin7\App\AppInfo\Launcher\CopyQPortableLegacyWin7.ini" "Launch" "MinOS" "7"
		CopyFiles /SILENT "$INSTDIR\Other\Source\Legacy\CopyQPortableLegacyWin7.exe" "$1\CopyQPortableLegacyWin7"
		${If} ${FileExists} "$1\CopyQPortableLegacyWin7\Data\settings\CopyQPortableSettings.ini"
			Rename "$1\CopyQPortableLegacyWin7\Data\settings\CopyQPortableSettings.ini" "$1\CopyQPortableLegacyWin7\Data\settings\CopyQPortableLegacyWin7Settings.ini"
			ReadINIStr $0 "$1\CopyQPortableLegacyWin7\Data\settings\CopyQPortableLegacyWin7Settings.ini" "CopyQPortableSettings" "LastDrive"
			WriteINIStr "$1\CopyQPortableLegacyWin7\Data\settings\CopyQPortableLegacyWin7Settings.ini" "CopyQPortableLegacyWin7Settings" "LastDrive" "$0"
			ReadINIStr $0 "$1\CopyQPortableLegacyWin7\Data\settings\CopyQPortableLegacyWin7Settings.ini" "CopyQPortableSettings" "LastDirectory"
			WriteINIStr "$1\CopyQPortableLegacyWin7\Data\settings\CopyQPortableLegacyWin7Settings.ini" "CopyQPortableLegacyWin7Settings" "LastDirectory" "$0"
			DeleteINISec "$1\CopyQPortableLegacyWin7\Data\settings\CopyQPortableLegacyWin7Settings.ini" "CopyQPortableSettings"
		${EndIf}
	${EndIf}
!macroend
