<?xml version="1.0" encoding="utf-8"?>
<installer-gui-script minSpecVersion="2">
    <title>Codex Platform with Device Manager</title>
    <organization>com.codexdigital</organization>
    <domains enable_localSystem="true" enable_currentUserHome="false" enable_anywhere="false"/>
    <allowed-os-versions>
        <os-version min="13.0.0"/>
    </allowed-os-versions>
    <!-- Define documents displayed at various steps -->
    <!--welcome    file="welcome.html"    mime-type="text/html" /-->
    <license file="Licence.rtf" mime-type="text/rtf"/>
    <!--conclusion file="conclusion.html" mime-type="text/html" /-->
    <background file="background.png" mime-type="image/png"/>
    <pkg-ref id="com.codexdigital.codexserver"/>
    <pkg-ref id="com.codexdigital.codexserver">
        <must-close>
            <app id="com.apple.systempreferences"/>
            <app id="com.codexdigital.codexdevman"/>
        </must-close>
        <bundle-version>
            <bundle CFBundleVersion="1.0" id="com.codexdigital.prefpane" path="Library/PreferencePanes/Codex.prefPane"/>
            <bundle CFBundleShortVersionString="7.5.6" CFBundleVersion="7.5.6" id="com.codexdigital.codexdevman" path="Applications/Codex/Codex Device Manager.app"/>
            <bundle CFBundleShortVersionString="4.14" CFBundleVersion="4.14" id="online.codex.x2xfuse.Mounter" path="Library/Filesystems/x2xfuse.fs/Contents/Resources/mount_x2xfuse.app"/>
            <bundle CFBundleVersion="4.8.3" id="online.codex.x2xfuse.filesystems.x2xfuse.13" path="Library/Filesystems/x2xfuse.fs/Contents/Resources/mount_x2xfuse.app/Contents/Extensions/10.9/x2xfuse.kext"/>
            <bundle CFBundleVersion="4.8.3" id="online.codex.x2xfuse.filesystems.x2xfuse.20" path="Library/Filesystems/x2xfuse.fs/Contents/Resources/mount_x2xfuse.app/Contents/Extensions/11/x2xfuse.kext"/>
            <bundle CFBundleShortVersionString="4.8.3" CFBundleVersion="4.8.3" id="online.codex.x2xfuse.frameworks.x2xfuse" path="Library/Filesystems/x2xfuse.fs/Contents/Frameworks/X2XFUSE.framework"/>
            <bundle CFBundleVersion="4.8.3" id="online.codex.x2xfuse.filesystems.x2xfuse.15" path="Library/Filesystems/x2xfuse.fs/Contents/Resources/mount_x2xfuse.app/Contents/Extensions/10.11/x2xfuse.kext"/>
            <bundle CFBundleShortVersionString="1.0" CFBundleVersion="1.0" id="com.codexdigital.filesystems.codexfs.fs" path="Library/Filesystems/codexfs.fs"/>
            <bundle SourceVersion="10000" CFBundleShortVersionString="4.8.3" CFBundleVersion="4.8.3" id="online.codex.x2xfuse" path="Library/Filesystems/x2xfuse.fs"/>
            <bundle CFBundleShortVersionString="1.0" CFBundleVersion="1.0" id="com.codexdigital.filesystems.cdx_encrypted.fs" path="Library/Filesystems/cdx_encrypted.fs"/>
            <bundle CFBundleVersion="4.8.3" id="online.codex.x2xfuse.filesystems.x2xfuse.16" path="Library/Filesystems/x2xfuse.fs/Contents/Resources/mount_x2xfuse.app/Contents/Extensions/10.12/x2xfuse.kext"/>
        </bundle-version>
    </pkg-ref>
    <options customize="always" require-scripts="true" rootVolumeOnly="true" hostArchitectures="arm64,x86_64" allow-external-scripts="false"/>
    <choices-outline>
        <line choice="com.codexdigital.codexserver"/>
        <line choice="com.codexdigital.driver.SRAID"/>
        <line choice="com.codexdigital.driver.CodexDiskDriver"/>
        <line choice="com.codexdigital.driver.usbDockDriver"/>
        <line choice="com.codexdigital.driver.TbtDockDriver"/>
        <line choice="com.jmicron.pkg.JMicronFWUpdateUtilityCodex"/>
        <line choice="com.ATTO.pkg.ATTOExpressSASHBA2"/>
        <line choice="com.ATTO.pkg.ATTOExpressSASHBA5"/>
    </choices-outline>
    <choice id="com.codexdigital.codexserver" title="Codex Platform with Device Manager" description="This package contains Device Manager and all Codex Platform software, hardware support and libraries." description-mime-type="text/plain" enabled="false" selected="true">
        <pkg-ref id="com.codexdigital.codexserver"/>
    </choice>
    <pkg-ref id="com.codexdigital.codexserver" onConclusion="None" packageIdentifier="com.codexdigital.vaultplatform" version="7.5.6" installKBytes="99830">#vault-7.5.6-06652-codexplatform.pkg</pkg-ref>
    <choice id="com.codexdigital.driver.SRAID" title="Codex SRAID Driver" description="Codex SRAID is required for ProRes Capture Drives from ALEXA cameras, as well as for HFS+ and ExFAT formatted Transfer Drives." description-mime-type="text/plain" start_selected="installPackage('com.codexdigital.driver.SRAID', '7.5.6', true)" enabled="!installPackage('com.codexdigital.driver.SRAID', '7.5.6', true)">
        <pkg-ref id="com.codexdigital.driver.SRAID"/>
    </choice>
    <pkg-ref id="com.codexdigital.driver.SRAID" auth="root" onConclusionScript="require_restart_for_kext()" version="2.0.6" installKBytes="3557">#SRAID-2.0.6-SRAID.pkg</pkg-ref>
    <choice id="com.codexdigital.driver.CodexDiskDriver" title="Codex Disk Driver" description="" description-mime-type="text/plain" start_selected="installPackage('com.codexdigital.driver.CodexDiskDriver', '7.5.6', true)" enabled="!installPackage('com.codexdigital.driver.CodexDiskDriver', '7.5.6', true)">
        <pkg-ref id="com.codexdigital.driver.CodexDiskDriver"/>
    </choice>
    <pkg-ref id="com.codexdigital.driver.CodexDiskDriver" auth="root" onConclusionScript="require_restart_for_kext()" version="1.3.0" installKBytes="233">#CodexDiskDriver-1.3.0-CodexDiskDriver.pkg</pkg-ref>
    <choice id="com.codexdigital.driver.usbDockDriver" title="Codex USB Dock Driver" description="Enables use of Codex USB Capture Drive Docks" description-mime-type="text/plain" start_selected="installPackage('com.codexdigital.driver.usbDockDriver', '7.5.6', true)" enabled="!installPackage('com.codexdigital.driver.usbDockDriver', '7.5.6', true)">
        <pkg-ref id="com.codexdigital.driver.usbDockDriver"/>
    </choice>
    <pkg-ref id="com.codexdigital.driver.usbDockDriver" auth="root" onConclusionScript="require_restart_for_kext()" packageIdentifier="com.codexdigital.driver.CodexDigitalUSB3DockDriver" version="1.3.10" installKBytes="276">#CodexUSBDockDriver-1.3.10-CodexDigitalUSB3DockDriver.pkg</pkg-ref>
    <choice id="com.codexdigital.driver.TbtDockDriver" title="Codex Thunderbolt Dock Driver" description="Enables use of Codex Thunderbolt Capture Drive Docks" description-mime-type="text/plain" start_selected="installPackage('com.codexdigital.driver.TbtDockDriver', '7.5.6', true)" enabled="!installPackage('com.codexdigital.driver.TbtDockDriver', '7.5.6', true)">
        <pkg-ref id="com.codexdigital.driver.TbtDockDriver"/>
    </choice>
    <pkg-ref id="com.codexdigital.driver.TbtDockDriver" auth="root" onConclusionScript="require_restart_for_kext()" packageIdentifier="com.codexdigital.driver.CodexDigitalTbtDockDriver" version="1.2.8" installKBytes="209">#CodexThunderboltDockDriver-1.2.8-CodexDigitalTbtDockDriver.pkg</pkg-ref>
    <choice id="com.jmicron.pkg.JMicronFWUpdateUtilityCodex" title="Codex Compact Drive Reader FW Update Utility" description="Enables firmware to be updated on Codex Compact Drive Reader (USB-C)." description-mime-type="text/plain" start_selected="installPackage('com.jmicron.pkg.JMicronFWUpdateUtilityCodex', '7.5.6', true)" enabled="!installPackage('com.jmicron.pkg.JMicronFWUpdateUtilityCodex', '7.5.6', true)">
        <pkg-ref id="com.jmicron.pkg.JMicronFWUpdateUtilityCodex"/>
    </choice>
    <pkg-ref id="com.jmicron.pkg.JMicronFWUpdateUtilityCodex" auth="root" onConclusionScript="require_restart_for_kext()" version="1.0" installKBytes="2279">#JMicron_FWUpdate_Utility_Codex.pkg</pkg-ref>
    <choice id="com.ATTO.pkg.ATTOExpressSASHBA2" title="ATTO SAS driver H608" description="Enables use of Codex Thunderbolt Transfer Drive Docks fitted with the ATTO H608 card." description-mime-type="text/plain" start_selected="installPackage('com.ATTO.pkg.ATTOExpressSASHBA2', '7.5.6', false)" enabled="!installPackage('com.ATTO.pkg.ATTOExpressSASHBA2', '7.5.6', false)">
        <pkg-ref id="com.ATTO.pkg.ATTOExpressSASHBA2"/>
    </choice>
    <pkg-ref id="com.ATTO.pkg.ATTOExpressSASHBA2" onConclusion="None" version="2.68.0" installKBytes="4546">#ATTOExpressSASHBA2.pkg</pkg-ref>
    <choice id="com.ATTO.pkg.ATTOExpressSASHBA5" title="ATTO SAS driver H1208GT" description="Enables use of Codex Thunderbolt Transfer Drive Docks fitted with the ATTO H1208 GT card." description-mime-type="text/plain" start_selected="installPackage('com.ATTO.pkg.ATTOExpressSASHBA5', '7.5.6', false)" enabled="!installPackage('com.ATTO.pkg.ATTOExpressSASHBA5', '7.5.6', false)">
        <pkg-ref id="com.ATTO.pkg.ATTOExpressSASHBA5"/>
    </choice>
    <pkg-ref id="com.ATTO.pkg.ATTOExpressSASHBA5" onConclusion="None" version="1.04.0" installKBytes="4667">#ATTOExpressSASHBA5.pkg</pkg-ref>
    <installation-check script="installation_check(&quot;7.5.6&quot;)"/>
    <script><![CDATA[

function get_installed_version()
{
    try {

        // get installed short version from plist - due to bug some don't have this so
        // parse long version to get short if not found
        var installedInfo = system.files.bundleAtPath("/Applications/Codex/Codex Device Manager.app");
        var installedShortVersion = installedInfo.CFBundleShortVersionString;
        if (!installedShortVersion)
        {
            // no short version - get long version and strip out major.minor.patch short version
            installedLongVersion = installedInfo.CFBundleLongVersionString;
            installedShortVersion = installedLongVersion.replace(/.*vlt-([0-9\.]*).*/, "$1");
        }

        return installedShortVersion;

    } catch (e) {
    }

    return "";
}

function downgrade(thisVersion)
{
    try {

        var installedShortVersion = get_installed_version();

        system.log('Downgrade check - installed: ' + installedShortVersion + " installing: " + thisVersion);
        if (installedShortVersion && system.compareVersions(thisVersion,  installedShortVersion) < 0)
            return true;

    } catch (e) {
    }

    system.log('Downgrade check - downgrade not detected');
    return false;
}

function upgrade_from_unsupported_version(thisVersion)
{
    try {

        var installedShortVersion = get_installed_version();

        if (installedShortVersion)
        {
            if (system.compareVersions(installedShortVersion, "5.1.2") < 0)
                return true;
        }

    } catch (e) {
    }

    return false;
}

function installation_check(thisVersion)
{
    if(system.compareVersions(system.version.ProductVersion, "13.0.0") < 0)
    {
        // need to set error type
        my.result.type = "Fatal";
        my.result.title = "Incompatible OS version";
        my.result.message = "This software requires macOS version 13.0.0 or later.";
        return false;
    }

    if(system.compareVersions(system.version.ProductVersion, "16.0.0") >= 0)
    {
        // need to set error type
        my.result.type = "Fatal";
        my.result.title = "Incompatible OS version";
        my.result.message = "This software is not compatible with macOS version 16.0.0 or above.";
        return false;
    }

    if (downgrade(thisVersion))
    {
        var systemPreferencesName = (system.compareVersions(system.version.ProductVersion, "13.0") < 0) ? "System Preferences" : "System Settings";

        // need to set error type
        my.result.type = "Fatal";
        my.result.title = "Downgrade detected";
        my.result.message = "The installed version of this software is newer than the version you are installing.\n\n" +
                            "Please go to " + systemPreferencesName + " > Codex > General and use the Remove Software option, " +
                            "then re-attempt this installation.";
        return false;
    }

    return true;
}

function installPackage(id, thisVersion, allowDowngrade)
{
    var action = choices[id].packageUpgradeAction;

    // if clean, upgrade, downgrade and allowed, or installed by from an unsupported version then install package
    var result = false;
    if ((action == 'clean') || (action == 'upgrade') || ((action == 'downgrade') && allowDowngrade) || upgrade_from_unsupported_version(thisVersion))
    {
        result = true;
    }
    system.log('installPackage: ' + id + ", action: " + action + ", result: " + result);
    return result;
}

function require_restart_for_kext()
{
    // Will be running on a product version >= 12.5
    // let the OS deal with restarting the machine
    return "None";
}

    ]]></script>
    <pkg-ref id="com.codexdigital.driver.SRAID">
        <bundle-version>
            <bundle CFBundleShortVersionString="2.0.6" CFBundleVersion="2.0.6" id="com.codexdigital.driver.SRAIDMD" path="Library/Extensions/SRAIDMD.kext"/>
            <bundle CFBundleShortVersionString="2.0.6" CFBundleVersion="2.0.6" id="com.codexdigital.driver.SRAID" path="Library/Extensions/SRAID.kext"/>
        </bundle-version>
    </pkg-ref>
    <pkg-ref id="com.codexdigital.driver.CodexDiskDriver">
        <bundle-version>
            <bundle CFBundleVersion="1.3.0" id="com.codexdigital.driver.CodexDiskDriver" path="Library/Extensions/CodexDiskDriver.kext"/>
        </bundle-version>
    </pkg-ref>
    <pkg-ref id="com.codexdigital.driver.usbDockDriver">
        <bundle-version>
            <bundle CFBundleVersion="1.3.10" id="com.codexdigital.driver.usbDockDriver" path="Library/Extensions/CodexDigitalUSB3DockDriver.kext"/>
        </bundle-version>
    </pkg-ref>
    <pkg-ref id="com.codexdigital.driver.TbtDockDriver">
        <bundle-version>
            <bundle CFBundleVersion="1.2.8" id="com.codexdigital.driver.TbtDockDriver" path="Library/Extensions/CodexDigitalTbtDockDriver.kext"/>
        </bundle-version>
    </pkg-ref>
    <pkg-ref id="com.jmicron.pkg.JMicronFWUpdateUtilityCodex">
        <bundle-version>
            <bundle CFBundleVersion="2.0.12" id="com.jmicron.driver.jmPeripheralDevice" path="Library/Extensions/jmPeripheralDevice.kext"/>
            <bundle CFBundleShortVersionString="1.0.0.2" id="JMicron.JMS583Updater" path="Applications/Codex/Codex Compact Drive Reader FW Update Utility.app"/>
        </bundle-version>
    </pkg-ref>
    <pkg-ref id="com.ATTO.pkg.ATTOExpressSASHBA2">
        <bundle-version>
            <bundle CFBundleShortVersionString="2.68.0" CFBundleVersion="2.68.0" id="com.ATTO.driver.ATTOExpressSASHBA2" path="usr/local/libexec/ATTOExpressSASHBA2_tmp/ATTOExpressSASHBA2.kext"/>
        </bundle-version>
    </pkg-ref>
    <pkg-ref id="com.ATTO.pkg.ATTOExpressSASHBA5">
        <bundle-version>
            <bundle CFBundleShortVersionString="1.04.0" CFBundleVersion="1.04.0" id="com.ATTO.driver.ATTOExpressSASHBA5" path="usr/local/libexec/ATTOExpressSASHBA5_tmp/ATTOExpressSASHBA5.kext"/>
        </bundle-version>
    </pkg-ref>
    <product version="7.5.6"/>
</installer-gui-script>