<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<installer-gui-script minSpecVersion="1">
    <options customize="never"/>
    <options hostArchitectures="i386"/>
    <options rootVolumeOnly="true"/>
    <options type="firmware"/>
    <script>
var EntityToFind1	= "IOUSBDevice";
var vendorID		= 0x5AC;
var productIDArray	= [0x1105, 0x1106];
var versionArray	= [0x101, 0x105, 0x111];
var updatingVersion	= 0x120;

var EntityToFind2	= "AppleUSBDisplays";
var productIDArray1	= [0x9226];
var versionArray1	= [0x291, 0x293];
var updatingVersion1	= 0x298;
</script>
    <title>SU_TITLE</title>
    <installation-check script="installationCheck()"/>
    <script>
	
		function installationCheck()
		{		
			if( system.env.OS_INSTALL == 1 ){ return true; }
			
			if( system.compareVersions(system.version.ProductVersion, '10.8.2') &lt; 0 )
			{
				debuglog("OS below 10.8.2!");
				my.result.type = 'Fatal';
				my.result.message = system.localizedString('ERROR_LION_OS');
				return false;
			}			
		

			// Update requires Mac OS X 10.8.2 AND buildversion match for logical flow.
			if ((system.compareVersions(system.version.ProductVersion, '10.8.2') == 0) &amp;&amp; (!ValidMountainLion("/")))
				{
				        debuglog("OS = 10.8.2 but wrong buildversion!");
						my.result.message = system.localizedString('ERROR_MLION_OS');
				        my.result.type = 'Fatal';
				        return false;
				}
			
            if( doesAnyoneMatch("AudioFWCheck",EntityToFind1,vendorID,productIDArray,versionArray) ){ return true; }
            
			// check MLB firmware
            if( !doesAnyoneMatch2("MLBFWCheck",EntityToFind2,vendorID,productIDArray1,versionArray1) )
			{
				my.result.type = 'Fatal';
				my.result.message = system.localizedString('ERROR_INSTALL');
		        return false;
				debuglog("No eligible audio or MLB firmware found");
			}
			
			return true;
		}
		
		function ValidMountainLion(prefix) {
			var plist = system.files.plistAtPath(prefix + '/System/Library/CoreServices/SystemVersion.plist');
			if (!plist) {
				return false;
			}
			var plistKeyValue = plist['ProductBuildVersion'];
			if (!plistKeyValue) {
				return false;
			}
			if (system.compareVersions(plistKeyValue, '12C60') &lt; 0) {
				return false;
			}
			return true;
		}
		
		function oc(a)
		{
			// http://snook.ca/archives/javascript/testing_for_a_v
			var o = {};
			for(var i=0;i &lt; a.length;i++)
			{
				o[a[i]]='';
			}
			return o;
		}
		
		function doesAnyoneMatch(callerID,EntityToFind,vendorID,productIDArray,versionArray)
		{
			var devicesToTestArray = system.ioregistry.matchingClass(EntityToFind);
			for (var index=0; index &lt; 5; index++) 
			{
				if (devicesToTestArray.length != 0) break;
		
				// didnt find any, try again
				devicesToTestArray = system.ioregistry.matchingClass(EntityToFind);
			}
			if (index==0)
				debuglog(callerID + ": Found " + devicesToTestArray.length + " " + EntityToFind + " entities.");
			else
				debuglog(callerID + ": Had to retry " + index + " times to find " + devicesToTestArray.length + " " + EntityToFind + " entities.");
		
			for( var index=0; index &lt; devicesToTestArray.length; index++ )
			{
					// Is this device from Apple?
					var myVendor = devicesToTestArray[index].idVendor;
						debuglog(callerID + ": device #" + index + " has vendorID " + myVendor);
					if (myVendor != vendorID) continue;
					
					// Is this device the one for which we have the software?
					var myProductID = devicesToTestArray[index].idProduct;
						debuglog(callerID + ": device #" + index + " has productID " + myProductID);
					if (myProductID in oc(productIDArray))
					{
						debuglog(callerID + ": device matches productID");
						var deviceVersion = devicesToTestArray[index].bcdDevice;
						debuglog(callerID + ": device has version " + deviceVersion);
						if( deviceVersion in oc(versionArray) )
						{
							debuglog(callerID + "version matches!");
							return true; 
						}
					}
			}
				
			debuglog(callerID + ": Didn't find any matching devices, so returning false.");
			return false;	
		}
		
		function doesAnyoneMatch2(callerID,EntityToFind,vendorID,productIDArray,versionArray)
		{
			var devicesToTestArray = system.ioregistry.matchingClass(EntityToFind);
			for (var index=0; index &lt; 5; index++) 
			{
				if (devicesToTestArray.length != 0) break;
		
				// didnt find any, try again
				devicesToTestArray = system.ioregistry.matchingClass(EntityToFind);
			}
			if (index==0)
				debuglog(callerID + ": Found " + devicesToTestArray.length + " " + EntityToFind + " entities.");
			else
				debuglog(callerID + ": Had to retry " + index + " times to find " + devicesToTestArray.length + " " + EntityToFind + " entities.");
		
			for( var index=0; index &lt; devicesToTestArray.length; index++ )
			{
					// Is this device from Apple?
					var myVendor = devicesToTestArray[index].idVendor;
						debuglog(callerID + ": device #" + index + " has vendorID " + myVendor);
					if (myVendor != vendorID) continue;
					
					// Is this device the one for which we have the software?
					var myProductID = devicesToTestArray[index].ProductID;
						debuglog(callerID + ": device #" + index + " has productID " + myProductID);
					if (myProductID in oc(productIDArray))
					{
						debuglog(callerID + ": device matches productID");
						var deviceVersion = devicesToTestArray[index].VersionNumber;
						debuglog(callerID + ": device has version " + deviceVersion);
						if( deviceVersion in oc(versionArray) )
						{
							debuglog(callerID + "version matches!");
							return true; 
						}
					}
			}
				
			debuglog(callerID + ": Didn't find any matching devices, so returning false.");
			return false;	
		}

		function doesAnyoneMatchBelow(callerID,EntityToFind,vendorID,productIDArray,updatingVersion)
		{
			var devicesToTestArray = system.ioregistry.matchingClass(EntityToFind);
			for (var index=0; index &lt; 5; index++) 
			{
				if (devicesToTestArray.length != 0) break;
		
				// didnt find any, try again
				devicesToTestArray = system.ioregistry.matchingClass(EntityToFind);
			}
			if (index==0)
				debuglog(callerID + ": Found " + devicesToTestArray.length + " " + EntityToFind + " entities.");
			else
				debuglog(callerID + ": Had to retry " + index + " times to find " + devicesToTestArray.length + " " + EntityToFind + " entities.");
		
			for( var index=0; index &lt; devicesToTestArray.length; index++ )
			{
					// Is this device from Apple?
					var myVendor = devicesToTestArray[index].idVendor;
						debuglog(callerID + ": device #" + index + " has vendorID " + myVendor);
					if (myVendor != vendorID) continue;
					
					// Is this device the one for which we have the software?
					var myProductID = devicesToTestArray[index].idProduct;
						debuglog(callerID + ": device #" + index + " has productID " + myProductID);
					if (myProductID in oc(productIDArray))
					{
						debuglog(callerID + ": device matches productID");
						var deviceVersion = devicesToTestArray[index].bcdDevice;
						debuglog(callerID + ": device has version " + deviceVersion);
						if( deviceVersion &lt;= updatingVersion )
						{
							debuglog(callerID + "version matches!");
							return true; 
						}

					}
			}
				
			debuglog(callerID + ": Didn't find any matching devices, so returning false.");
			return false;	
		}

		function debuglog(message){
			// yes, this is secure
			if (system.files.fileExistsAtPath("/tmp/com.apple.pkg.testing")) system.log("********** " + message);
		}
		
    </script>
    <script>
</script>
    <platforms>
        <client arch="i386"/>
        <server arch="i386"/>
    </platforms>
    <choices-outline ui="SoftwareUpdate">
        <line choice="su"/>
    </choices-outline>
    <choices-outline>
        <line choice="su"/>
    </choices-outline>
    <choice id="su" title="SU_TITLE" versStr="SU_VERS" description="SU_DESCRIPTION" description-mime-type="text/html" secondaryDescription="SU_SERVERCOMMENT" suDisabledGroupID="LEDCinemaDisplayFirmwareUpdate1.1" start_selected="true">
        <pkg-ref id="LEDCinemaDisplayUpdate" auth="Root" packageIdentifier="com.apple.pkg.LEDCinemaDisplayUpdate">LEDCinemaDisplayUpdate.pkg</pkg-ref>
    </choice>
    <localization>
        <strings language="pl"><![CDATA["SU_TITLE" = "Uaktualnienie monitora LED Cinema Display";
"SU_VERS" = "1.1";
"SU_SERVERCOMMENT" = "Dla komputerów klienckich i serwerów";
"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>
  <style type="text/css">
	body {font: 11.0px Lucida Grande;}
    p {margin: 0.0px 0.0px 0.0px 0.0px;}
  </style>
</head>
<body>
<p>To uaktualnienie rozwiązuje problem z 27-calowym monitorem LED Cinema Display, który mógł uniemożliwiać odtwarzanie dźwięku przez głośniki monitora.</p>	
<br>
<p>W czasie uaktualniania monitor musi być podłączony do Maca, a jego ekran monitora może na chwilę zgasnąć. 
</p>
</body>
</html>
';
]]></strings>
    </localization>

	<pkg-ref id='LEDCinemaDisplayUpdate' installKBytes='726' version='1.1.0.0.1.1357255561'/>
</installer-gui-script>