${SegmentFile}

${Segment.OnInit}
	System::Call kernel32::GetCurrentProcess()i.s
	System::Call kernel32::IsWow64Process(is,*i.r0)
	ReadRegStr $2 HKLM "Software\Microsoft\Windows NT\CurrentVersion" "CurrentBuild"
	
	${If} $2 < 10000 ;Windows 7/8
	${OrIf} $0 == 0 ;or 32-bit 10
		StrCpy $AppName "KVIrc"
		${If} ${IsWin2000}
			StrCpy $1 2000
		${ElseIf} ${IsWinXP}
			StrCpy $1 XP
		${ElseIf} ${IsWin2003}
			StrCpy $1 2003
		${ElseIf} ${IsWinVista}
			StrCpy $1 Vista
		${ElseIf} ${IsWin2008}
			StrCpy $1 2008
		${ElseIf} ${IsWin7}
			StrCpy $1 7
		${ElseIf} ${IsWin2008R2}
			StrCpy $1 "2008 R2"
		${ElseIf} ${IsWin8}
			${If} $2 < 10000 ;Windows 7/8
				StrCpy $1 8
			${Else}
				StrCpy $1 "10 32-bit"
			${EndIf}
		${ElseIf} ${IsWin2012}
			StrCpy $1 2012
		${Else}
			StrCpy $1 "Pre-Win10"
		${EndIf}	
		StrCpy $0 "10 64-bit"
		MessageBox MB_OK|MB_ICONSTOP "$(LauncherIncompatibleMinOS)"
		Abort
	${EndIf}
!macroend

${SegmentPostPrimary}
	; Copied in and modified from PAL for Qt 5.0 - now using QtProject vs. Trolltech
	;
	; The Qt plugin cache and a few other things leave keys inside
	; HKCU\Software\QtProject\OrganizationDefaults\*\X:\...\dirname which need
	; to be cleared up. They're useless, they've got just values like foo.dll
	; with a version number in them, but they need removing. Due to the
	; directory-recursive key nature of them, we can just scrap the package
	; directory for each and then prune the tree as far up as it's empty.
	StrCpy $R0 1
	${Do}
		ClearErrors
		${ReadLauncherConfig} $0 QtKeysCleanup $R0
		${IfThen} ${Errors} ${|} ${ExitDo} ${|}
		StrCpy $1 Software\QtProject\OrganizationDefaults\$0\$AppDirectory
		DeleteRegKey HKCU $1
		${Do}
			${GetParent} $1 $1
			DeleteRegKey /ifempty HKCU $1
		${LoopUntil} $1 == "Software\QtProject"

		IntOp $R0 $R0 + 1
	${Loop}
	; We don't need to set $UsesRegistry to true, the registry plug-in hasn't
	; been used and unloading it is what UsesRegistry is for.
!macroend