/// <summary>
    /// Enumerate the schemas for an xcode project
    /// </summary>
    /// <param name="projectPath">
    /// A <see cref="System.String"/> that contains the path to folder containing the xcode project (not the project itself)
    /// </param>
    /// <returns>
    /// A <see cref="TestFlightXCodeSchemas"/> containing the targets, configs and schemes belonging to that project. Or null on any error
    /// </returns>
    public static TestFlightXCodeSchemas Enumerate(string projectPath)
    {
        TestFlightXCodeSchemas output = new TestFlightXCodeSchemas();

        try
        {
            System.Diagnostics.ProcessStartInfo pi = new System.Diagnostics.ProcessStartInfo("xcodebuild", "-list");
            pi.WorkingDirectory = projectPath;
            pi.RedirectStandardOutput = true;
            pi.RedirectStandardError = true;
            pi.UseShellExecute = false;
            System.Diagnostics.Process p = System.Diagnostics.Process.Start(pi);
            if(p == null)
                return null;

            p.WaitForExit();
            if(p.ExitCode != 0)
                return null;

            string strOutput = p.StandardOutput.ReadToEnd() + "\n";

            // build configs
            output.targets = ExtractList("Targets", strOutput);
            output.configs = ExtractList("Build Configurations", strOutput);
            output.schemes = ExtractList("Schemes", strOutput);

            output.defaultConfig = output.configs.IndexOf(FindDefaultConfig(strOutput));
        }
        catch(System.Exception e)
        {
            Debug.LogError(e);
        }

        return output;
    }
    public void OnEnable()
    {
        logoTex = TestFlightResources.GetTextureResource("logo_small.png");
        title = "Autopilot Build Options";
        preferences = TestFlightPreferences.Load();

        messageOptions = new List<string>();
        messageOptions.Add("New message...");
        messageOptions.AddRange(preferences.userPrefs.messageHistory);
        messageOptions.RemoveAll(m => m.Length == 0);
        messageOptions.Insert(1, "");
        newBundleVersion = PlayerSettings.bundleVersion;

        allProvisions = TestFlightMobileProvision.EnumerateProvisions();
        allSchemas = TestFlightXCodeSchemas.Enumerate(preferences.teamPrefs.buildPath);
        allIdentities = TestFlightDeveloperIdentities.Enumerate();
    }
    public static void DrawSubUserSettingsForIPA(TestFlightPreferences preferences, bool narrow, TestFlightMobileProvision[] availableProvisions, TestFlightXCodeSchemas availableSchemas, string[] availableIdentities)
    {
        DrawSubUserSettings_TestFlightSDK(preferences, narrow);
        DrawSubUserSettings_dSYM(preferences, narrow);
        DrawSubUserSettings_BundleId(availableProvisions, availableIdentities);
        DrawSubUserSettings_Provisions(preferences, narrow, availableProvisions, availableIdentities);

        if(preferences.userPrefs.customProvisionProfile != null && preferences.userPrefs.customProvisionProfile.Certificates == null)
            DrawSubUserSettings_Identity(preferences, narrow, availableIdentities, availableProvisions);

        DrawSubUserSettings_XCodeSchema(preferences, narrow, availableSchemas);

        if(!narrow)
        {
            GUILayout.Space(20);
            GUILayout.BeginHorizontal();
            GUILayout.Space(FieldWidth+4);
            GUILayout.Box("* Denotes settings that apply to both Autopilot and regular Unity builds");
            GUILayout.EndHorizontal();
        }
    }
 public static void DrawSubUserSettings(TestFlightPreferences preferences, ref bool showUserLists, bool narrow, TestFlightMobileProvision[] availableProvisions, TestFlightXCodeSchemas availableSchemas, string[] availableIdentities)
 {
     DrawSubUserSettings_TestFlightUpload(preferences, ref showUserLists);
     DrawSubUserSettingsForIPA(preferences, narrow, availableProvisions, availableSchemas,availableIdentities);
 }
    private static void DrawSubUserSettings_XCodeSchema(TestFlightPreferences preferences, bool narrow, TestFlightXCodeSchemas availableSchemas)
    {
        //		string[] configs = new string[] {"Release", "Debug"};
        string[] schemes = new string[] {"N/A"};
        //		string defaultConfig = preferences.userPrefs.xCodeSchema;
        if(availableSchemas != null)
        {
        //			configs = availableSchemas.Configs;
        //			defaultConfig = availableSchemas.DefaultConfig;

            if(availableSchemas.Schemes.Length > 0)
                schemes = availableSchemas.Schemes;
        }

        /*
        int currentConfig = System.Array.IndexOf(configs, preferences.userPrefs.xCodeConfig);
        if(currentConfig == -1)  currentConfig = Mathf.Max(0, System.Array.IndexOf(configs, defaultConfig));
        int newConfig = Mathf.Max(0, Popup(new GUIContent(narrow ? "Config":"XCode Configuration"), currentConfig, configs, narrow ? 5:0, narrow));
        preferences.userPrefs.xCodeConfig = newConfig < configs.Length ? configs[newConfig]:"";
        */

        int currentScheme = Mathf.Max(0, System.Array.IndexOf(schemes, preferences.userPrefs.xCodeSchema));
        int newScheme = Mathf.Max(0, Popup(new GUIContent(narrow ? "Scheme":"XCode Build Sheme", "The Xcode scheme to build with for users with customized Xcode projects.\n\nThis can be left as N/A or Unity-iPhone if you haven't haven't added extra schemas to your Xcode project"),
                                           					currentScheme, schemes, narrow ? 5:0));
        preferences.userPrefs.xCodeSchema = newScheme < schemes.Length ? schemes[newScheme]:"";
    }
    public void OnEnable()
    {
        preferences = TestFlightPreferences.Load();
        logoTex = TestFlightResources.GetTextureResource("logo_small.png");
        title = "AutoPilot Preferences";

        allProvisions = TestFlightMobileProvision.EnumerateProvisions();
        allSchemas = TestFlightXCodeSchemas.Enumerate(preferences.teamPrefs.buildPath);
        allIdentities = TestFlightDeveloperIdentities.Enumerate();
    }