Пример #1
0
        private void sendState(IList <InstallStep> lstSteps, string strPrefixPath, int stepIdx)
        {
            Func <IEnumerable <InstallStep>, IEnumerable <InstallerStep> > convertSteps = steps =>
            {
                int idx = 0;
                return(steps.Select(step => new InstallerStep(idx++, step.Name,
                                                              step.VisibilityCondition == null || step.VisibilityCondition.GetIsFulfilled(m_csmState, m_Delegates))));
            };

            Func <IEnumerable <Option>, IEnumerable <Interface.ui.Option> > convertOptions = options =>
            {
                int idx = 0;
                return(options.Select(option => new Interface.ui.Option(idx++, option.Name, option.Description,
                                                                        string.IsNullOrEmpty(option.ImagePath) ? null : Path.Combine(strPrefixPath, option.ImagePath),
                                                                        m_SelectedOptions.Contains(option), resolveOptionType(option).ToString())));
            };

            Func <IEnumerable <OptionGroup>, IEnumerable <Group> > convertGroups = groups =>
            {
                int idx = 0;
                return(groups.Select(group => new Group(idx++, group.Name, group.Type.ToString(), convertOptions(group.Options).ToArray())));
            };

            Action <InstallerStep[], int> insertGroups = (InstallerStep[] steps, int idx) =>
            {
                InstallStep inStep = lstSteps[idx];
                steps[idx].optionalFileGroups.order = inStep.GroupSortOrder.ToString();
                steps[idx].optionalFileGroups.group = convertGroups(inStep.OptionGroups).ToArray();
            };

            InstallerStep[] uiSteps = convertSteps(lstSteps).ToArray();
            insertGroups(uiSteps, stepIdx);
            m_Delegates.ui.UpdateState(uiSteps, stepIdx);
        }
Пример #2
0
 private void fixSelected(InstallStep step)
 {
     foreach (OptionGroup group in step.OptionGroups)
     {
         foreach (Option option in group.Options)
         {
             OptionType type = resolveOptionType(option);
             if (type == OptionType.Required)
             {
                 enableOption(option);
             }
             else if (type == OptionType.NotUsable)
             {
                 disableOption(option);
             }
         }
     }
 }
Пример #3
0
        private void preselectOptions(InstallStep step)
        {
            foreach (OptionGroup group in step.OptionGroups)
            {
                bool setFirst = group.Type == OptionGroupType.SelectExactlyOne;
                foreach (Option option in group.Options)
                {
                    OptionType type = resolveOptionType(option);
                    if ((type == OptionType.Required) ||
                        (type == OptionType.Recommended) ||
                        (group.Type == OptionGroupType.SelectAll))
                    {
                        enableOption(option);
                        setFirst = false;
                    }
                }

                if (setFirst)
                {
                    enableOption(group.Options[0]);
                }
            }
        }
        private void sendState(IList <InstallStep> lstSteps, string strPrefixPath, int stepIdx)
        {
            Func <IEnumerable <InstallStep>, IEnumerable <InstallerStep> > convertSteps = steps =>
            {
                int idx = 0;
                return(steps.Select(step => new InstallerStep(idx++, step.Name,
                                                              step.VisibilityCondition == null || step.VisibilityCondition.GetIsFulfilled(m_csmState, m_Delegates))));
            };

            Func <IEnumerable <Option>, OptionsPresetGroup?, bool, IEnumerable <Interface.ui.Option> > convertOptions = (options, groupPreset, selectAll) =>
            {
                int idx = 0;
                return(options.Select(option =>
                {
                    OptionType type = resolveOptionType(option);

                    bool choicePreset = false;
                    if (groupPreset.HasValue &&
                        (type != OptionType.Required) &&
                        !selectAll &&
                        (groupPreset.Value.choices != null))
                    {
                        choicePreset = groupPreset.Value.choices.Any(preOption => preOption.name == option.Name);
                    }

                    string conditionMsg = type == OptionType.NotUsable
                    ? option.GetConditionMessage(m_csmState, m_Delegates)
                    : null;
                    return new Interface.ui.Option(idx++, option.Name, option.Description,
                                                   string.IsNullOrEmpty(option.ImagePath) ? null : Path.Combine(strPrefixPath, option.ImagePath),
                                                   m_SelectedOptions.Contains(option), choicePreset, type.ToString(), conditionMsg);
                }));
            };

            Func <IEnumerable <OptionGroup>, OptionsPresetStep?, IEnumerable <Group> > convertGroups = (groups, stepPreset) =>
            {
                int idx = 0;
                return(groups.Select(group =>
                {
                    OptionsPresetGroup?groupPreset = null;
                    if ((stepPreset.HasValue) && (stepPreset.Value.groups != null))
                    {
                        groupPreset = stepPreset.Value.groups.FirstOrDefault(preGroup => preGroup.name == group.Name);
                    }

                    return new Group(idx++, group.Name, group.Type.ToString(),
                                     convertOptions(group.Options, groupPreset, group.Type == OptionGroupType.SelectAll).ToArray());
                }));
            };

            Action <InstallerStep[], int> insertGroups = (InstallerStep[] steps, int idx) =>
            {
                InstallStep       inStep     = lstSteps[idx];
                OptionsPresetStep?stepPreset = null;
                if ((m_Preset.HasValue) && (m_Preset.Value.steps != null))
                {
                    stepPreset = m_Preset.Value.steps.FirstOrDefault(preStep => preStep.name == inStep.Name);
                }

                steps[idx].optionalFileGroups.order = inStep.GroupSortOrder.ToString();
                steps[idx].optionalFileGroups.group = convertGroups(inStep.OptionGroups, stepPreset).ToArray();
            };

            InstallerStep[] uiSteps = convertSteps(lstSteps).ToArray();
            // previously we only sent the groups for the current step but sending all makes it easier to track and save all
            // installer choices made
            for (int i = 0; i < lstSteps.Count; ++i)
            {
                insertGroups(uiSteps, i);
            }
            m_Delegates.ui.UpdateState(uiSteps, stepIdx);
        }
        private void preselectOptions(InstallStep step)
        {
            IList <OptionsPresetStep> stepPresets = null;

            if (m_Preset.HasValue)
            {
                // step names are not unique :(
                stepPresets = m_Preset.Value.steps.Where(preStep => preStep.name == step.Name).ToList();
            }

            foreach (OptionGroup group in step.OptionGroups)
            {
                List <OptionsPresetGroup> groupPresets = new List <OptionsPresetGroup>();
                if ((stepPresets != null) && stepPresets.Count > 0)
                {
                    foreach (OptionsPresetStep stepPreset in stepPresets)
                    {
                        // group names not unique either...
                        groupPresets.AddRange(stepPreset.groups.Where(preGroup => preGroup.name == group.Name));
                    }
                }

                if (group.Options.FirstOrDefault(opt => m_SelectedOptions.Contains(opt)) == null)
                {
                    bool setFirst = group.Type == OptionGroupType.SelectExactlyOne;
                    foreach (Option option in group.Options)
                    {
                        OptionType type     = resolveOptionType(option);
                        bool       isPreset = false;
                        foreach (OptionsPresetGroup groupPreset in groupPresets)
                        {
                            if (groupPreset.choices.Any(preChoice => preChoice.name == option.Name))
                            {
                                isPreset = true;
                            }
                        }
                        if (isPreset && type == OptionType.NotUsable)
                        {
                            // force preset options to be selectable, otherwise the user might not be able to deselect it
                            // even if it is actually invalid
                            option.OptionTypeResolver = new StaticOptionTypeResolver(OptionType.CouldBeUsable);
                            type = OptionType.CouldBeUsable;
                        }
                        if ((type == OptionType.Required) ||
                            (type == OptionType.Recommended) ||
                            (group.Type == OptionGroupType.SelectAll) ||
                            isPreset)
                        {
                            // in case there are multiple recommended options in a group that only
                            // supports one selection, disable all other options, otherwise we would
                            // create an invalid pre-selection
                            if ((type == OptionType.Recommended) &&
                                ((group.Type == OptionGroupType.SelectExactlyOne) ||
                                 (group.Type == OptionGroupType.SelectAtMostOne)))
                            {
                                foreach (Option innerOption in group.Options)
                                {
                                    disableOption(innerOption);
                                }
                            }

                            setFirst = false;

                            if ((groupPresets.Count > 0) && !isPreset)
                            {
                                // We have a groupPreset setting available and this option is _not_
                                //  part of it - disable the option.
                                disableOption(option);
                            }
                            else
                            {
                                enableOption(option);
                            }
                        }
                    }

                    if (setFirst)
                    {
                        enableOption(group.Options[0]);
                    }
                }
            }
        }