<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<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'>BootCampUpdate64.msp</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>

  // Including MinVer and MaxVer
  var BootCampServicesMinVer = "3.1.3";
  var BootCampServicesMaxVer = "3.1.3";
  var BootcampRegPath = "SOFTWARE\\Apple Inc.\\Boot Camp";
  var UpdateKey = "PatchVersion";

// 32bit Window OS
//  var TargetOS = "32";
//  var ProductId = "{B56ACF7B-D7B5-442B-8E1D-6B41347D88B2}";

// 64Bit Window OS
var TargetOS = "64";
var ProductId = "{B2B7054B-EC2E-4E96-8666-FD6ED77678B2}";

  function Check()
  {
      //    log("Bootcamp testing start ");
      if (!CheckOs(TargetOS))
      return false;

      if(!productInVersionRange(ProductId, BootCampServicesMinVer, BootCampServicesMaxVer))
      {
        // Not in target version, don't show update
        return false;
      }

      if(IsPatchAlreadyInstalled())
         return false;

      //    log("Bootcamp testing end need update ");
      return true;
  }

  function IsPatchAlreadyInstalled()
  {
      var SystemVersion = ASURegistryQueryStringValue("HKEY_LOCAL_MACHINE", BootcampRegPath, UpdateKey);

      //log("System Version = " + SystemVersion);

      if (SystemVersion == "3.1.3")
          return true;

      return false;
  }

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];
          
          // XP - Bootcamp only support 32 bit
          // always to present on 32 bit package.
          if(OsMajor == "5")
          {    
              if(OsMinor == "1")
              {
                  log("Found XP.");
                  return true;
              }
          }    
          else
          { 
              // OSArchitecture only supports on Vista and later
              var OsArch = WMIGetProperty(0, "OSArchitecture");

              // 32 bit or 64 OS
              if(OsArch.substring(0,2) == OsString)
              {
                  log("Found " + OsString + " bit OS.");
                  return true;
              }
          }
      } // for
    }  // try
  catch (e)
  {
	log("An exception occurred. CheckOs failed.");
	log("Error: " + e.message);
  }
  
  return false;
}

function productInVersionRange(productId, minVersion, maxVersion)
{
    var i = 0;
    var productIndex;
    
    do
    {
        productIndex = system.ASUEnumerateProducts(i++);
        if (!productIndex) 
            break;
        
        var foundName = system.ASUGetProductInfo(productIndex,"ProductName");
        
        system.log("found product: " + foundName);
        system.log("product Id : " + productIndex);
        
        if (productIndex == productId)
        {
            var foundVersion = system.ASUGetProductInfo(productIndex,"VersionString");
            system.log("version of " + foundName + " is: " + foundVersion);
            return(versionInRange(foundVersion, minVersion, maxVersion));
        }
    
    } while(productIndex);

    
    // they do not already have it, but should get it
    if(minVersion == "0.0.0.0.0")
    {
        return true;
    }
    
    // otherwise, we require a minimum version
    
    return false;
}

function versionInRange(testVersion, minVersion, maxVersion)
{
    
    if ((-1 != compareVersionStrings(testVersion, minVersion)) &amp;&amp; 
        (1 != compareVersionStrings(testVersion, maxVersion)))
        return true;
    else
        return false;
    
}

function compareVersionStrings(string1, string2)
{
    var parts1 = string1.split(".");
    var parts2 = string2.split(".");
    
    
    while(parts1.length &lt; parts2.length)
        parts1[parts1.length] = "0";
        
    while(parts2.length &lt; parts1.length)
        parts2[parts2.length] = "0";
        
    for( var i in parts1 )
    {
        var sub1 = 1*parts1[i];
        var sub2 = 1*parts2[i];
    
        if( sub1 != sub2 )
        {
            if( sub1 > sub2 )
                return 1;
            else
                return -1;
        }
    }
    
    return 0;
}

</script>
    <localization>
        <strings language="English"><![CDATA["SU_VERS" = "3.1";
"SU_TITLE" = "Boot Camp Update for 2010 13-inch MacBook Pro";
"SU_SERVERCOMMENT" = "For Windows";

"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 applies to the 2010 13-inch MacBook Pro running Windows operating systems.  It addresses an issue that causes the Boot Camp Control Panel applet to display an error when the brightness tab is selected and an issue that results in no headphone sound.</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>