<?xml version="1.0" encoding="UTF-8"?>
<installer-gui-script minSpecVersion='1'>
    <platforms>
        <Windows arch="intel"/>
    </platforms>
    <choices-outline ui='SoftwareUpdate'>
        <line choice='su'/>
    </choices-outline>
    <choice id='su'>
        <pkg-ref id='auto' onConclusion='RequireRestart' arguments='ASU'>BootCamp_Update_2.2.exe</pkg-ref>
    </choice>
    <choice id='su' visible='Check()'/>
    <choice id='su' title='SU_TITLE' versStr='SU_VERS'/>
    <choice id='su' description='SU_DESCRIPTION' description-mime-type='text/html'/>
    

// 
<script>

var TargetOS = "Vista";
var OtherTargetOS = "Windows 7";
var productVersionLastRelease = "2.1";
var productVersionBase = "2.1";

function Check() 
{
	if(!IsWasuVersionSupportBootcamp())
        return false;

	if(!GotTargetedVersion("Boot Camp", productVersionBase, productVersionLastRelease))
        return false;
    
    // don't care about GUIDs, so don't check them
    
	// Check for Vista (32 bit and 64 bit) Gold and SP1, because we don't allow update on those versions...
	if (!CheckOS(TargetOS))
		return false;

	// Check for Windows 7, because we don't allow installations on Windows 7		
	if (!CheckOS(OtherTargetOS))
		return false;

    // Needs update
    return true;
} 

function IsWasuVersionSupportBootcamp()
{
//    log("Check ASU version " + AsuVersion);
    if(compareVersionStrings(AsuVersion, "2.1.0.97") != -1)
    {
        return true;
    }
        
    return false;
}


function GotTargetedVersion(productName, BaseVersion, LastReleaseVersion)
{ 
    var i = 0;
    var j = 0; 
    var productIndex; 
    
    do
    { 
        productIndex = system.ASUEnumerateProducts(i++); 
        var foundName = system.ASUGetProductInfo(productIndex,"ProductName"); 
        log("found product: " + foundName); 
        
		for (j = 0; j &lt; (foundName.length - productName.length + 1); j++)
        {
            if (foundName.substring(j, productName.length+j) == productName) 
            { 
                var foundVersion = system.ASUGetProductInfo(productIndex,"VersionString"); 
                log("version of " + foundName + " is: " + foundVersion);
                return(TargetedVersion(foundVersion, BaseVersion, LastReleaseVersion)); 
            } 
        }
    }
    while(productIndex); 
    
    return false; 
    
}

function TargetedVersion(testVersion, BaseVersion, LastReleaseVersion)
{ 
    if (compareVersionStrings(BaseVersion, testVersion) == 0) 
    {
//        log("Found Base version");
        return true; 
    }
    
    if (compareVersionStrings(LastReleaseVersion, testVersion) == 0) 
    {
//        log("Found Last Release version");
        return true; 
    }
    
//    log("Could not find version");
    return false; 
} 


function compareVersionStrings(string1, string2) 
{ 
    // Make sure allocate enough space for future version number
    tempString = "0000.0000.0000.0000";
    
    var parts1 = tempString.split("."); 
    var parts2 = tempString.split("."); 
    
    parts1 = string1.split("."); 
    parts2 = string2.split("."); 
    
    for( var i in parts1 ) 
    { 
        var sub1 = 1*parts1[i]; 
        var sub2 = 1*parts2[i]; 
        
//        log("i = " + i);
//        log("sub1 {" + sub1 + "}");
//        log("sub2 {" + sub2 + "}");
        
        if( sub1 != sub2 )
        { 
            if( sub1 > sub2 ) 
                return 1; 
            else 
                return -1; 
        } 
    } 
    return 0; 
}

function CheckOS( OsString )
{
	try
	{
		var count = 0;
        
		count = WMIExecQuery("SELECT * FROM Win32_OperatingSystem ");					
		// log("Found " + count + " records.");
		
		//  Now let us iterate through the list of objects
		//  found from the query.
		
		for (i = 0; i &lt; count; i++)
		{
            
            var TempString  = WindowsVersion();
            var OsVers = TempString.split(".");
            var OsMajor = OsVers[0];
            var OsMinor = OsVers[1];
            var OsSPLevel = OsVers[2];
            
//            log("OS Major : " + OsMajor + " Minor : " + OsMinor);

            // Windows 7 (both versions)
            if(OsString == "Windows 7")
                if(OsMajor == "6")
                    if(OsMinor == "1")
						return false;	// don't install
                    
            // XP bit
            if(OsString == "XP")
                if(OsMajor == "5")
                    if(OsMinor == "1")
                    {
//                        log("Found XP.");
                        return true;
                    }
            
            // Vista 32 AND 64 bit
            if(OsString == "Vista")
            {
                if(OsMajor == "6")
                {
                    if(OsMinor == "0")
                    {
//						log("Found Vista.");
						// So now we check for Gold or SP1, because we
						// don't support the update on them for 32 bit or 64 bit
						var OsSPLevel = WMIGetProperty(i, "ServicePackMajorVersion");
						if (OsSPLevel > 1)
						{
//							log("Found SP2 or better.");
							return true;	// okay to install
						}
						else
						{
//							log("Found Vista Gold or SP1.");
							return false;	// don't install
						}
                    }
				}
			}
		}
	}
	catch (e)
	{
		log("An exception occurred. CheckOs failed.");
		log("Error: " + e.message);
	}
    
    return true;
    
}

</script>
    <localization>
        <strings language="English"><![CDATA["SU_TITLE" = "Boot Camp Update";
"SU_VERS" = "2.2";
"SU_SERVERCOMMENT" = "For Windows systems";

"SU_DESCRIPTION"='<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <meta http-equiv="Content-Style-Type" content="text/css">
  <title></title>
  <meta name="Generator" content="Cocoa HTML Writer">
  <meta name="CocoaVersion" content="824.41">
  <style type="text/css">
    p.p1 {margin: 0.0px 0.0px 12.0px 0.0px; font: 12.0px Lucida Sans Unicode}
  </style>
</head>
<body>
<p class="p1">This update addresses bugs and improves compatibility with Microsoft Windows XP and Windows Vista running on a Mac computer using Boot Camp. It is highly recommended for all Boot Camp users.</p>
<p class="p1">For more information about this update, please visit this website: <a href="http://www.apple.com/support/bootcamp/">http://www.apple.com/support/bootcamp/</a></p>
</body>
</html>
';
]]></strings>
    </localization>
</installer-gui-script>