<?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' arguments='ASU'>AppleBcUpdate.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 BootCampServicesMinVer = "3.0.2";
    var BootCampServicesMaxVer = "5.1.9999";

    // If it is less than the version number, it needed to update
    var DeviceVersionPath = "SOFTWARE\\Apple Inc.\\Boot Camp\\Versions";
    var DeviceVersionKey = "AppleBTBCUpdate";
    var TargetedVersion ="6.0.6100.0";

    var isSupported = false;

    var TargetOS = "64";

    //Boot Camp 3.x x64 = "{B2B7054B-EC2E-4E96-8666-FD6ED77678B2}";
    //Boot Camp 4.x x64 = "{ADA3F9C8-A6D3-4FCF-BFBB-EAD69AC0884E}";
    //Boot Camp 5.x x64 = "{FA2B2C2A-EA41-495A-9308-60726125D562}";

    var ProductIDs = new Array("{FA2B2C2A-EA41-495A-9308-60726125D562}","{ADA3F9C8-A6D3-4FCF-BFBB-EAD69AC0884E}","{B2B7054B-EC2E-4E96-8666-FD6ED77678B2}");


    function Check()
    {


    if (!CheckOs(TargetOS))
    return false;

    if(!IsNeedDriverUpdate())
    {
    return false;
    }

    for(var i = 0; i &lt; ProductIDs.length; i++)
      {
        
        if(productInVersionRange(ProductIDs[i],BootCampServicesMinVer, BootCampServicesMaxVer))
        {
          //log("Could not find Boot Camp Services");
          isSupported = true;
          break;
        }
      }
    
      if (!isSupported)
         return false;

      return true;
    }

  function CheckOs( OsString )
  {
      try
      {


	        var os = OSArchitecture();
	        var PROCESSOR_ARCHITECTURE_IA64 = 6;
	        var PROCESSOR_ARCHITECTURE_AMD64 = 9;
	        if (os == PROCESSOR_ARCHITECTURE_IA64 || os == PROCESSOR_ARCHITECTURE_AMD64) 
          {

            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];

                if(OsMajor == "6")
                {
                    if(OsMinor == "1") 
                    {
                        log("Found Win7 or later");
                        return true;
                    }
                    else
                    {
                      log("No supported OS versions found")
                      return false;
                    }              
            
                }
                else
                {
                      log("No supported OS versions found")
                      return false;
                }
             }
         }
	  }
	  catch (e)
	  {
		  log("An exception occurred. CheckOs failed.");
		  log("Error: " + e.message);
	  }
    
      return false;
  }
  
  
  function IsNeedDriverUpdate()
  {
      var result;
      var SystemVersion = ASURegistryQueryStringValue("HKEY_LOCAL_MACHINE", DeviceVersionPath, DeviceVersionKey );

      log("System :" + SystemVersion );

      if (SystemVersion == TargetedVersion)
      {
        return false;
      }

      return true;
  }

    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 &gt; sub2 )
            return 1;
          else
            return -1;
        }
      }

      return 0;
    }


    function IsSystemModel(ModelString)
    {
      try
      {
        var count = 0;

        count = WMIExecQuery("SELECT * FROM Win32_ComputerSystem");
        // 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 SystemModel = WMIGetProperty(i, "Model");

          log("System Model : " + SystemModel);
          if( SystemModel ==  ModelString)
          {
            return true;
          }
        }
      }
      catch (e)
      {
        log("An exception occurred. IsSystemModel failed.");
        log("Error: " + e.message);
      }

      return false;

    }

  </script>
    <localization>
        <strings language="English"><![CDATA["SU_VERS" = "6.0";
"SU_TITLE" = "Bluetooth Update for Windows 7";
"SU_SERVERCOMMENT" = "For Windows 7 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 improves compatibility with Bluetooth devices.</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>