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
		${If} ${FileExists} "$INSTDIR\App\AppInfo\appinfo.ini"
			ReadINIStr $0 "$INSTDIR\App\AppInfo\appinfo.ini" "Version" "PackageVersion"
			${VersionCompare} $0 "5.0.4.10" $R0
			${If} $R0 = 2
				${GetParent} $INSTDIR $1
				${IfNot} ${FileExists} "$1\qBittorrentEnhancedPortableLegacyWin7\*.*"
					${GetParent} $INSTDIR $1
					CreateDirectory "$1\qBittorrentEnhancedPortableLegacyWin7"
					CopyFiles /SILENT "$INSTDIR\*.*" "$1\qBittorrentEnhancedPortableLegacyWin7"
					Rename "$1\qBittorrentEnhancedPortableLegacyWin7\qBittorrentEnhancedPortable.ini" "$1\qBittorrentEnhancedPortableLegacyWin7\qBittorrentEnhancedPortableLegacyWin7.ini"
					StrCpy $bolCustomCreatedLegacy true
					Rename "$1\qBittorrentEnhancedPortableLegacyWin7\Data\qBittorrentEnhancedPortableSettings.ini" "$1\qBittorrentEnhancedPortableLegacyWin7\Data\qBittorrentEnhancedPortableLegacyWin7Settings.ini"
				${EndIf}	
			${EndIf}
		${EndIf}
	${EndIf}
!macroend

!macro CustomCodePostInstall
	${If} $bolCustomCreatedLegacy == true
		${GetParent} $INSTDIR $1
		Delete "$1\qBittorrentEnhancedPortableLegacyWin7\qBittorrentEnhancedPortable.exe"
		Delete "$1\qBittorrentEnhancedPortableLegacyWin7\App\AppInfo\*.ini"
		Delete "$1\qBittorrentEnhancedPortableLegacyWin7\App\AppInfo\Launcher\*.*"
		CopyFiles /SILENT "$INSTDIR\Other\Source\Legacy\qBittorrentEnhancedPortableLegacyWin7.exe" "$1\qBittorrentEnhancedPortableLegacyWin7"
		CopyFiles /SILENT "$INSTDIR\Other\Source\Legacy\qBittorrentEnhancedPortableLegacyWin7.ini" "$1\qBittorrentEnhancedPortableLegacyWin7\App\AppInfo\Launcher"
		CopyFiles /SILENT "$INSTDIR\Other\Source\Legacy\custom.nsh" "$1\qBittorrentEnhancedPortableLegacyWin7\App\AppInfo\Launcher"
		CopyFiles /SILENT "$INSTDIR\Other\Source\Legacy\appinfo.ini" "$1\qBittorrentEnhancedPortableLegacyWin7\App\AppInfo"
		CopyFiles /SILENT "$INSTDIR\Other\Source\Legacy\installer.ini" "$1\qBittorrentEnhancedPortableLegacyWin7\App\AppInfo"
		${If} ${FileExists} "$1\qBittorrentEnhancedPortableLegacyWin7\Data\settings\qBittorrentEnhancedPortableSettings.ini"
			Rename "$1\qBittorrentEnhancedPortableLegacyWin7\Data\settings\qBittorrentEnhancedPortableSettings.ini" "$1\qBittorrentEnhancedPortableLegacyWin7\Data\settings\qBittorrentEnhancedPortableLegacyWin7Settings.ini"
			ReadINIStr $0 "$1\qBittorrentEnhancedPortableLegacyWin7\Data\settings\qBittorrentEnhancedPortableLegacyWin7Settings.ini" "qBittorrentEnhancedPortableSettings" "LastDrive"
			WriteINIStr "$1\qBittorrentEnhancedPortableLegacyWin7\Data\settings\qBittorrentEnhancedPortableLegacyWin7Settings.ini" "qBittorrentEnhancedPortableLegacyWin7Settings" "LastDrive" "$0"
			ReadINIStr $0 "$1\qBittorrentEnhancedPortableLegacyWin7\Data\settings\qBittorrentEnhancedPortableLegacyWin7Settings.ini" "qBittorrentEnhancedPortableSettings" "LastDirectory"
			WriteINIStr "$1\qBittorrentEnhancedPortableLegacyWin7\Data\settings\qBittorrentEnhancedPortableLegacyWin7Settings.ini" "qBittorrentEnhancedPortableLegacyWin7Settings" "LastDirectory" "$0"
			DeleteINISec "$1\qBittorrentEnhancedPortableLegacyWin7\Data\settings\qBittorrentEnhancedPortableLegacyWin7Settings.ini" "qBittorrentEnhancedPortableSettings"
		${EndIf}
	${EndIf}
!macroend
