<?xml version="1.0" encoding="UTF-8"?>
<installer-gui-script minSpecVersion='1'>
    <title>SU_TITLE</title>
    <options hostArchitectures='i386' customize='never' rootVolumeOnly='true'/>
    <choices-outline>
        <line choice='manual'/>
    </choices-outline>
    <choices-outline ui='SoftwareUpdate'>
        <line choice='su'/>
    </choices-outline>
    <choice id='manual' title='SU_TITLE' versStr='SU_VERSION'>
        <pkg-ref auth='Root' id='manual'>.</pkg-ref>
    </choice>
    <choice id='su' suDisabledGroupID='HardDriveUpdate'>
        <pkg-ref auth='Root' id='su'>HardDriveUpdate1.0.pkg</pkg-ref>
    </choice>
    <choice id='su' visible='VisibleCheck()'/>
    <choice id='su' title='SU_TITLE' versStr='SU_VERSION'/>
    <choice id='su' description='SU_DESCRIPTION' description-mime-type='text/html'/>
    <installation-check script='InstallationCheck()'/>
    <volume-check script='VolumeCheck()'/>
    <script>
	
	function InstallationCheck()
	{
		if ( !validHW() ) {
            my.result.message = system.localizedStringWithFormat('ERR_HW');
            my.result.type = 'Fatal';
            return false;	       
        }
        
        return true;	   
	}
	
	function VolumeCheck()
	{
        if (system.env.OS_INSTALL == 1) {
            return true;
        }

        if ( !hasOS() || !hasOSVer() ) {
            my.result.message = system.localizedStringWithFormat('ERR_OS');
            my.result.type = 'Fatal';
            return false;	       
        }
        
        if ( hasTier3() ) {
            my.result.message = system.localizedStringWithFormat('ERR_T3');
            my.result.type = 'Fatal';
            return false;	       
        }
        
        return true;
	}

    function VisibleCheck()
	{
        return ( validHW() &amp;&amp; hasOSVer() );
    }

    function hasOS()
    {
        return (system.files.fileExistsAtPath(my.target.mountpoint + "/System/Library/CoreServices/SystemVersion.plist"));
    }

	function hasOSVer()
    {
        if (-1 == system.compareVersions(my.target.systemVersion.ProductVersion, '10.4.7')) {
            return false;
        }
        return true;
    }
    
    function hasTier3()
    {
        return (system.files.fileExistsAtPath(my.target.mountpoint + "/var/db/.AppleTier3Language"));
    }
    
    function validHW()
    {
		var retVal = false;
		
		var reg;
		try {
			reg = system.ioregistry.matchingName('IOAHCIDevice');
			for( var i = 0 ; i &lt; reg.length ; i++ )
			{
				var childrenArray = system.ioregistry.childrenOf(reg[i]);
				for( var j = 0 ; j &lt; childrenArray.length ; j++ )
				{
					var model = childrenArray[j]['Model'];
					var revision = childrenArray[j]['Revision'];
					
					if( null != model &amp;&amp; null != revision )
					{
						if( model.match(/ST3500641AS/) )
						{
							if( revision.match(/3.BTD/) )
							{
								system.log("Firmware requires updating");
								retVal = true;
								break;
							}
						}
						
						if( model.match(/ST3750640AS/) )
						{
							if( revision.match(/3.BTF/) )
							{
								system.log("Firmware requires updating");
								retVal = true;
								break;
							}
						}
						else
						{
							system.log("Firmware is up to date.");
						}
					}
				}
				
				if( retVal == true ){ break; }
			}
			
		} catch(err) {return false;}
             
        return(retVal);
    }
    
	</script>
    <readme file="ReadMe.rtf"/>
    <license file="License.rtf"/>
    <localization>
        <strings language="pl"><![CDATA["SU_TITLE" = "Hard Drive Update";
"SU_VERSION" = "1.0";

"SU_DESCRIPTION"='<HTML>
<FONT FACE="Lucida Grande">
<P>
The Hard Drive Update 1.0 includes bug fixes and important updates.
</P>
<P>
To complete the firmware update process, please follow the instructions in the updater application (/Applications/Utilities/Hard Drive Update 1.0.app). The updater will launch automatically when the Installer closes. 
</P>
</FONT> 
</HTML>
';
]]></strings>
    </localization>
</installer-gui-script>