${SegmentFile}

Var bolCustomRegistryExists

${SegmentInit}
	${If} $Bits = 64
		${If} ${FileExists} "$EXEDIR\App\Speccy\dll64\cpuidsdk.dll"
			Rename "$EXEDIR\App\Speccy\cpuidsdk.dll" "$EXEDIR\App\Speccy\dll32\cpuidsdk.dll"
			Rename "$EXEDIR\App\Speccy\dll64\cpuidsdk.dll" "$EXEDIR\App\Speccy\cpuidsdk.dll"
		${EndIf}
	${Else}
		${If} ${FileExists} "$EXEDIR\App\Speccy\dll32\cpuidsdk.dll"
			Rename "$EXEDIR\App\Speccy\cpuidsdk.dll" "$EXEDIR\App\Speccy\dll64\cpuidsdk.dll"
			Rename "$EXEDIR\App\Speccy\dll32\cpuidsdk.dll" "$EXEDIR\App\Speccy\cpuidsdk.dll"
		${EndIf}
	${EndIf}
!macroend

${SegmentPrePrimary}
	StrCpy $bolCustomRegistryExists false
    ${If} $Bits == 64
		SetRegView 64
		ReadRegStr $0 HKLM "SOFTWARE\Piriform\Speccy" "GUID"
		${If} $0 != ""
			StrCpy $bolCustomRegistryExists true
		${EndIf}
		SetRegView 32
	${EndIf}
!macroend

${SegmentPostPrimary}
    ${If} $Bits == 64
	${AndIf} $bolCustomRegistryExists == false
		SetRegView 64
			DeleteRegKey HKLM "SOFTWARE\Piriform\Speccy"
			DeleteRegKey /ifempty HKLM "SOFTWARE\Piriform"
		SetRegView 32
	${EndIf}
!macroend