<?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='FrontRowUpdate2.1.7' 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'>FrontRowUpdate2.1.7.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>
    <volume-check script="volumeCheck()"/>
    <script>
    
    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.5 or higher
        if(-1 == system.compareVersions(my.target.systemVersion.ProductVersion, '10.5.0')) {
            my.result.message = system.localizedStringWithFormat('ERROR_OS');
            my.result.type = 'Fatal';
            return(false);
        }

		var plist = system.files.plistAtPath(my.target.mountpoint + "/System/Library/Frameworks/QuickTime.framework/Versions/A/Resources/Info.plist");
		var version; if( plist ){ version = plist.CFBundleShortVersionString; }

		var plist2 = system.files.plistAtPath(my.target.mountpoint + "/Applications/iTunes.app/Contents/Info.plist");
		var version2; if( plist2 ){ var version2 = plist2.CFBundleShortVersionString; }

		if( !( (version  &amp;&amp; (system.compareVersions(version,  "7.5.5") >= 0)) ||
			   (version2 &amp;&amp; (system.compareVersions(version2, "8.0.0") >= 0)) ) )
		{
			my.result.type = 'Fatal';
			my.result.message = system.localizedString('ERROR_QTITUNES');
			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 2.1.7 (hasBundle function uses non-inclusive max-value)
        if(!hasBundle(my.target.mountpoint + "/System/Library/CoreServices/Front Row.app","0","2.1.8")) {
            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","2.1.7","9.9.9") )
    }
    
    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" = "Uaktualnienie Front Row";
"SU_VERS" = "2.1.7";
"SU_SERVERCOMMENT" = "Dla komputerów klienckich.";

"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 Front Row poprawia zgodność z programem iTunes 8.1.</p>
</body>
</html>
';
]]></strings>
    </localization>
</installer-gui-script>