${SegmentFile}

${SegmentInit}
	ReadRegStr $1 HKLM "Software\Microsoft\Windows NT\CurrentVersion" "CurrentBuild"
	System::Call kernel32::GetCurrentProcess()i.s
	System::Call kernel32::IsWow64Process(is,*i.r0)

	${If} $0 == 0 ;32-bit
	${OrIf} $1 < 10000 ;Win 7/8/8.1
		;Use Qt5 32-bit build on Win 7/8/8.1 and Win 10 32-bit
		${If} ${FileExists} "$EXEDIR\App\TransmissionLegacy"
			Rename "$EXEDIR\App\Transmission" "$EXEDIR\App\TransmissionModern"
			Rename "$EXEDIR\App\TransmissionLegacy" "$EXEDIR\App\Transmission"
		${EndIf}
	${Else}
		${If} ${FileExists} "$EXEDIR\App\TransmissionModern"
			Rename "$EXEDIR\App\Transmission" "$EXEDIR\App\TransmissionLegacy"
			Rename "$EXEDIR\App\TransmissionModern" "$EXEDIR\App\Transmission"
		${EndIf}
	${EndIf}
	

	ExpandEnvStrings $1 "%PortableApps.comDocuments%"
	${If} $1 == ""
	${OrIfNot} ${FileExists} "$1\*.*"
		${GetParent} $EXEDIR $3
		${GetParent} $3 $1
		${If} $1 == "" ;Be sure we didn't just GetParent on Root
			StrCpy $1 $3
		${EndIf}
		${If} ${FileExists} "$1\Documents\*.*"
			StrCpy $2 "$1\Documents"
		${Else}
			${GetRoot} $EXEDIR $1
			${If} ${FileExists} "$1\Documents\*.*"
				StrCpy $2 "$1\Documents"
			${Else}
				StrCpy $2 "$1"
			${EndIf}
		${EndIf}
		System::Call 'Kernel32::SetEnvironmentVariable(t, t) i("PortableApps.comDocuments", "$2").r0'
	${EndIf}
!macroend
