<?xml version="1.0" encoding="UTF-8"?>
<installer-gui-script minSpecVersion='1'>
    <script>
var EntityToFind1	= "IOBluetoothHIDDriver";
var EntityToFind2	= "IOAppleBluetoothHIDDriver";
var vendorID		= 0x5AC;
var productIDArray	= [0x030D];
</script>
    <title>SU_TITLE</title>
    <welcome file='Welcome.html'/>
    <readme file='Readme.rtf'/>
    <license file="License.rtf" sla="EA0325" auto='false'/>
    <options customize='never' hostArchitectures='ppc,i386' rootVolumeOnly='true'/>
    <platforms>
        <client arch="ppc,i386"/>
        <server arch="ppc,i386"/>
    </platforms>
    <choices-outline ui='SoftwareUpdate'>
        <line choice='su'/>
    </choices-outline>
    <choice id='su' title='SU_TITLE' versStr='SU_VERS' description='SU_DESCRIPTION' description-mime-type='text/html' suDisabledGroupID='WirelessMouseSoftware' visible='canSeeUpdate()'>
        <pkg-ref id='auto' auth='Root' onConclusion='RequireRestart'>WirelessMouseSoftware.pkg</pkg-ref>
    </choice>
    <choices-outline>
        <line choice='manual'/>
    </choices-outline>
    <choice id='manual' title='SU_TITLE'>
        <pkg-ref id='manual' auth='Root' onConclusion='RequireRestart'>#WirelessMouseSoftware.pkg</pkg-ref>
    </choice>
    <installation-check script='InstallationCheck()'/>
    <volume-check script="VolumeCheck()"/>
    <script>

function InstallationCheck()
{
	debuglog("Debug Logging for Wireless Mouse Software Update 1.0 enabled.");
	return ( rootVolumeOSGood() );
}

function VolumeCheck()
{
	var plist = system.files.plistAtPath(my.target.mountpoint + "/System/Library/Extensions/AppleBluetoothMultitouch.kext/Contents/version.plist");
	if( plist )
	{
		var version = plist.CFBundleShortVersionString;
		if( version &amp;&amp; (system.compareVersions(version, "1.0") > 0))
		{
			my.result.message = system.localizedString('ERROR_VOLUME');
			my.result.type = 'Fatal';
			return false;
		}
	}
	
	return true;
}

function rootVolumeOSGood()
{
	if( -1 == system.compareVersions(system.version.ProductVersion, '10.5.8') )
	{
		debuglog("System software version is not correct, got: " + system.version.ProductVersion);
		my.result.message = system.localizedStringWithFormat('ERROR_OS', '10.5.8');
		my.result.type = 'Fatal';
		return false;
	}

	if( -1 != system.compareVersions(system.version.ProductVersion, '10.6.2') )
	{
		debuglog("System software version is not correct, got: " + system.version.ProductVersion);
		my.result.message = system.localizedStringWithFormat('ERROR_NEWER');
		my.result.type = 'Fatal';
		return false;
	}

	if( -1 != system.compareVersions(system.version.ProductVersion, '10.6') )
	{
		debuglog("System software version is not correct, got: " + system.version.ProductVersion);
		my.result.message = system.localizedStringWithFormat('ERROR_OSNEW', '10.6.2');
		my.result.type = 'Fatal';
		return false;
	}
	
	debuglog("System software version is OK.");
	return true;
}

function canSeeUpdate()
{
	return ( (doesAnyoneMatch("canSeeUpdate",EntityToFind1,vendorID,productIDArray) || doesAnyoneMatch("canSeeUpdate",EntityToFind2,vendorID,productIDArray)) );
}

function doesAnyoneMatch(callerID,EntityToFind,vendorID,productIDArray)
{
	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].VendorID;
				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)) return true;
	}
		
	debuglog(callerID + ": Didn't find any matching devices, so returning false.");
	return false;	
}

function canHasUpdateWithErrors(bundlePath, minVersionString, maxVersionString, minErrString, maxErrString)
{
	var bundleVersion = PathGetShortVersion(bundlePath);
	debuglog("canHasUpdateWithErrors checking " + bundlePath + " which has version " + bundleVersion);

	if( !bundleVersion &amp;&amp; minVersionString &amp;&amp; (minVersionString != 0) )
	{
		my.result.message = system.localizedStringWithFormat('ERROR_' + minErrString);
		my.result.type = 'Fatal';
		return false;
	}
	
	if( system.compareVersions(bundleVersion,minVersionString) == -1 )
	{
		my.result.message = system.localizedStringWithFormat('ERROR_' + minErrString);
		my.result.type = 'Fatal';
		return false;
	}
	
	if( system.compareVersions(bundleVersion,maxVersionString) == 1 )
	{
		my.result.message = system.localizedStringWithFormat('ERROR_' + maxErrString);
		my.result.type = 'Fatal';
		return false;
	}
	
	return true;
}

function needsUpdate(bundlePath, minVersionString, maxVersionString)
{
	var bundleVersion = PathGetShortVersion(bundlePath);
	debuglog("needsUpdate checking " + bundlePath + " which has version " + bundleVersion);

	if (!bundleVersion) return true;
	
	return ( (system.compareVersions(bundleVersion,minVersionString) >= 0) &amp;&amp; (system.compareVersions(bundleVersion,maxVersionString) &lt;0) );
}

function PathGetShortVersion(path)
{
	var bundle = system.files.bundleAtPath(path);
	if (bundle == null)
		return null;
	var shortVers = bundle.CFBundleShortVersionString;
	shortVers = _PadVersionString(shortVers, 3);
	return shortVers;
}

function oc(a)
{
	var o = {};
	for(var i=0;i &lt; a.length;i++)
	{
		o[a[i]]='';
	}
	return o;
}

function debuglog(message){ if (system.files.fileExistsAtPath("/tmp/com.apple.pkg.testing")) system.log("********** " + message); }

</script>
    <localization>
        <strings language="pl"><![CDATA["SU_TITLE" = "Uaktualnienie oprogramowania Wireless Mouse";
"SU_VERS" = "1.0";
"SU_SERVERCOMMENT" = "Dla komputerów klienckich i serwerów.";

"SU_DESCRIPTION"='<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8"></meta></HEAD>
<BODY><FONT FACE="Lucida Grande">
<P>
Zainstaluj to oprogramowanie, aby korzystać z funkcji specjalnych myszy Magic Mouse.
</p>
</FONT></BODY></HTML>
';
]]></strings>
    </localization>

	<pkg-ref id='auto' installKBytes='98942' version='1.0.1.1191932192'/>
</installer-gui-script>