<?xml version="1.0" encoding="UTF-8"?>
<installer-gui-script minSpecVersion='1'>
    <script>
var EntityToFind = "AppleGraphicsControl";
var propertyToTest = "gMux-version";
var requiredVersion = "1.7.3";
</script>
    <title>SU_TITLE</title>
    <welcome file='SUDescription.html'/>
    <license file="License.rtf" sla="EA0325" auto='false'/>
    <options customize='never' hostArchitectures='i386' rootVolumeOnly='true'/>
    <platforms>
        <client arch="i386"/>
        <server arch="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='MBPGraphicsFWUpdate10' visible='anyoneNeedsUpdate()'>
        <pkg-ref id='auto' auth='Root'>MBPGraphicsFWUpdate1.0.pkg</pkg-ref>
    </choice>
    <choices-outline>
        <line choice='manual'/>
    </choices-outline>
    <choice id='manual' title='SU_TITLE'>
        <pkg-ref id='manual' auth='Root'>#MBPGraphicsFWUpdate1.0.pkg</pkg-ref>
    </choice>
    <installation-check script='InstallationCheck()'/>
    <script>
function InstallationCheck()
{
		debuglog("Debug Logging for MacBook Pro Graphics Firmware Update 1.0 enabled.");
	return (
				isProperHW() &amp;&amp;
				rootVolumeOSGood() &amp;&amp;
				// anyoneCanHasUpdate()
				anyoneNeedsUpdateWithError()
			);
}

function isProperHW()
{
	var property = system.sysctl("hw.model");
	if( property &amp;&amp; (property == "MacBookPro5,2") ) 
	{
			debuglog("Hardware model is correct.");
		return true;
	}
	
		debuglog("Hardware model is not correct, got: " + property);
	my.result.message = system.localizedString('ERROR_HW');
	my.result.type = 'Fatal';
	return false;
}

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

		debuglog("System software version is OK.");
	return true;
}

function doesAnyoneMatch(callerID,EntityToFind,propertyToTest,requiredVersion,testFunction)
{
	var devicesToTestArray = system.ioregistry.matchingClass(EntityToFind);
	for (var index=0; index &lt; 5; index++) 
	{
		if (devicesToTestArray.length != 0) break;

		// didn't 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++) 
	{
		// Does this entity need the update?
			debuglog("Entity #" + index + " being tested.");
		var devicePropertyValue = devicesToTestArray[index][propertyToTest];
			debuglog("* The property value is " + devicePropertyValue);
		var result = testFunction(devicePropertyValue,requiredVersion);
			debuglog("* Result of the test is: " + result);
		if (result) return true;
	}
	
	return false;	
}

function anyoneNeedsUpdateWithError()
{
	if (doesAnyoneMatch("anyoneNeedsUpdateWithError",EntityToFind,propertyToTest,requiredVersion,needsUpdate))
		return true;
	
	my.result.message = system.localizedString('ERROR_HW');
	my.result.type = 'Fatal';
	return false;
}

function anyoneNeedsUpdate()
{
	return doesAnyoneMatch("anyoneNeedsUpdate",EntityToFind,propertyToTest,requiredVersion,needsUpdate);
}
	
function debuglog(message)
{
	// securely test for file existence
	if (system.files.fileExistsAtPath("/tmp/com.apple.pkg.testing")) system.log("********** " + message);
}

function needsUpdate(valueString, requiredVersion)
{
		debuglog("* * needsUpdate is checking " + valueString + " against " + requiredVersion);
	return (system.compareVersions(valueString,requiredVersion) == 0);
}
</script>
    <localization>
        <strings language="pl"><![CDATA["SU_TITLE" = "Uaktualnienie oprogramowania sprzętowego grafiki MacBooka Pro";
"SU_VERS" = "1.0";
"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>
<meta name="Generator" content="Cocoa HTML Writer">
<meta name="CocoaVersion" content="949.43">
<style type="text/css">
p.p1 {margin: 0.0px 0.0px 12.0px 0.0px; font: 12.0px Lucida Grande}
</style>
</head>
<body>
<p class="p1">To uaktualnienie jest zalecane dla wszystkich użytkowników 17-calowych MacBooków Pro (z początku 2009 roku) i rozwiązuje problem pionowych linii pojawiających się na ekranie oraz zniekształconego obrazu.</p>
</body>
</html>
';
]]></strings>
    </localization>

	<pkg-ref id='auto' installKBytes='2173' version='1.0.1.1237513593'/>
</installer-gui-script>