<?xml version="1.0" encoding="UTF-8"?>
<installer-gui-script minSpecVersion='1'>
    <title>SU_TITLE</title>
    <options customize='never' hostArchitectures='i386,ppc'/>
    <platforms>
        <client arch="ppc,i386"/>
    </platforms>
    <!-- SU package -->
    <choices-outline ui='SoftwareUpdate'>
        <line choice='su'/>
    </choices-outline>
    <choice id='su' suDisabledGroupID='FrontRowUpdate1.3.1' visible='!alreadyInstalled()' title='SU_TITLE' versStr='SU_VERS' description='SU_DESCRIPTION' description-mime-type='text/html' secondaryDescription='SU_SERVERCOMMENT'>
        <pkg-ref auth='Root' id='auto'>FrontRowUpdate1.3.1.pkg</pkg-ref>
    </choice>
    <!-- manual package -->
    <choices-outline>
        <line choice='manual'/>
    </choices-outline>
    <choice id='manual' title='SU_TITLE' versStr='SU_VERS'>
        <pkg-ref id='manual' auth='Root'>.</pkg-ref>
    </choice>
    <installation-check script='installationCheck()'/>
    <volume-check script="volumeCheck()"/>
    <script>
    
    function installationCheck()
    {
        if (!hasIR()) {
            my.result.message = system.localizedStringWithFormat('ERROR_MODEL');
            my.result.type = 'Fatal';
            return false;
        }
    
        return true;
    }
    
    function volumeCheck()
    {
        // must have an OS
        if(!system.files.fileExistsAtPath(my.target.mountpoint + "/System/Library/CoreServices/SystemVersion.plist")) {
            my.result.message = system.localizedStringWithFormat('ERROR_OS');
            my.result.type = 'Fatal';
            return(false);
        }

        // must have 10.4.5 or higher
        if(-1 == system.compareVersions(my.target.systemVersion.ProductVersion, '10.4.5')) {
            my.result.message = system.localizedStringWithFormat('ERROR_OS');
            my.result.type = 'Fatal';
            return(false);
        }

        // must not be server
        if(system.files.fileExistsAtPath(my.target.mountpoint + "/System/Library/CoreServices/ServerVersion.plist")) {
            my.result.message = system.localizedStringWithFormat('ERROR_SERVER');
            my.result.type = 'Fatal';
            return(false);
        }
    
        // must not have Tier3
        if(system.files.fileExistsAtPath(my.target.mountpoint + "/var/db/.AppleTier3Language")) {
            my.result.message = system.localizedStringWithFormat('ERROR_LANG');
            my.result.type = 'Fatal';
            return(false);
        }    

        // must have Front Row
        if(!system.files.bundleAtPath(my.target.mountpoint + "/System/Library/CoreServices/Front Row.app")) {
            my.result.message = system.localizedStringWithFormat('ERROR_FR');
            my.result.type = 'Fatal';
            return false;
        }
        
        // must have Front Row prior to or equal to 1.3.1 (hasBundle function uses non-inclusive max-value)
        if(!hasBundle(my.target.mountpoint + "/System/Library/CoreServices/Front Row.app","0","1.3.2")) {
            my.result.message = system.localizedStringWithFormat('ERROR_VERSION');
            my.result.type = 'Fatal';
            return false;
        }

        return true;
    }
    
    // for SU
    function alreadyInstalled()
    {
        return (hasBundle(my.target.mountpoint + "/System/Library/CoreServices/Front Row.app","1.3.1","9.9.9") )
    }


    function hasIR()
    {
        return (system.ioregistry.matchingClass('AppleIRController'));
    }
    
    function hasBundle(path,startVer,endVer)
    {
        var appBundle = system.files.bundleAtPath(path);
        var appVersion = GetBundleFiveTupleVersion(appBundle);
        if (appBundle &amp;&amp; (system.compareVersions(appVersion, PadVersion(startVer,5)) >= 0) &amp;&amp; (system.compareVersions(appVersion, PadVersion(endVer,5)) &lt; 0)){
            return true;
        }       
        return false;
    }

    function GetBundleFiveTupleVersion(bundle)
    {
        if (bundle == null)
            return null;
        var shortVers = bundle.CFBundleShortVersionString;
        shortVers = PadVersion(shortVers, 3);
        var sourceVers = bundle.SourceVersion;
        sourceVers = PadVersion(sourceVers, 1);
        var buildVers = bundle.BuildVersion;
        buildVers = PadVersion(buildVers, 1);
        var fiveTupleVers = shortVers + "." + sourceVers + "." + buildVers;
        return fiveTupleVers;
    }

    function PadVersion(version, tupleCount)
    {
        if (version == null)
            version = "0";
        var components = version.split(".");
        if (components.length > tupleCount)
            components = components.slice(0, tupleCount);
        else
            for (; components.length&lt;tupleCount; )
                components.push("0");
        return components.join(".");
    }
    
    </script>
    <license file='License.rtf'/>
    <welcome file="Welcome.rtf"/>
    <readme file="ReadMe.rtf"/>
    <localization>
        <strings language="pl"><![CDATA["SU_TITLE" = "Front Row Update";
"SU_VERS" = "1.3.1";
"SU_SERVERCOMMENT" = "For Desktop systems.";

"SU_DESCRIPTION"='<HTML>
<HEAD> <meta http-equiv="content-type" content="text/html;charset=utf-8"> </meta> </HEAD>
<BODY>
<FONT FACE="Lucida Grande">
<P>
This Front Row update provides for improved iPhoto compatibility.
</P>
</FONT> 
</BODY>
</HTML>
';
]]></strings>
    </localization>
</installer-gui-script>