Exemplo n.º 1
0
        /// <summary>
        /// Reads the CLI's CLI output format and load's them into the preset List Preset
        /// </summary>
        public void UpdateBuiltInPresets()
        {
            // Clear the current built in Presets and now parse the temporary Presets file.
            this.ClearBuiltIn();

            IList <PresetCategory> presetCategories = HandBrakePresetService.GetBuiltInPresets();

            foreach (var category in presetCategories)
            {
                foreach (var hbpreset in category.ChildrenArray)
                {
                    Preset preset = JsonPresetFactory.ImportPreset(hbpreset);
                    preset.IsBuildIn = true;
                    preset.Category  = category.PresetName;
                    preset.Task.AllowedPassthruOptions = new AllowedPassthru(true); // We don't want to override the built-in preset

                    this.Add(preset, true);
                }
            }

            // Verify we have presets.
            if (this.presets.Count == 0)
            {
                this.ServiceLogMessage("Failed to load built-in presets.");
                throw new GeneralApplicationException("Failed to load built-in presets.", "Restarting HandBrake may resolve this issue", null);
            }

            // Store the changes to disk
            this.SavePresetFiles();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Reads the CLI's CLI output format and load's them into the preset List Preset
        /// </summary>
        public void UpdateBuiltInPresets()
        {
            // Clear the current built in Presets and now parse the tempory Presets file.
            this.ClearBuiltIn();

            IList <PresetCategory> presetCategories = HandBrakePresetService.GetBuiltInPresets();

            foreach (var item in presetCategories)
            {
                foreach (var hbpreset in item.ChildrenArray)
                {
                    Preset preset = JsonPresetFactory.ImportPreset(hbpreset);
                    preset.Version           = VersionHelper.GetVersion();
                    preset.UsePictureFilters = true;
                    preset.IsBuildIn         = true; // Older versions did not have this flag so explicitly make sure it is set.
                    preset.Category          = item.PresetName;

                    if (preset.Name == "iPod")
                    {
                        preset.Task.KeepDisplayAspect = true;
                    }

                    preset.Task.AllowedPassthruOptions = new AllowedPassthru(true); // We don't want to override the built-in preset

                    if (preset.Name == "Normal")
                    {
                        preset.IsDefault = true;
                    }

                    this.presets.Add(preset);
                }
            }

            // Verify we have presets.
            if (this.presets.Count == 0)
            {
                throw new GeneralApplicationException("Failed to load built-in presets.", "Restarting HandBrake may resolve this issue", null);
            }

            // Store the changes to disk
            this.UpdatePresetFiles();
        }
Exemplo n.º 3
0
        public void UpdateBuiltInPresets()
        {
            // Clear the current built in Presets and now parse the temporary Presets file.
            this.ClearBuiltIn();

            bool hasUserDefault = this.flatPresetDict.Values.FirstOrDefault(f => f.IsDefault) != null;

            IList <HBPresetCategory> presetCategories = HandBrakePresetService.GetBuiltInPresets();

            foreach (var category in presetCategories)
            {
                foreach (var hbpreset in category.ChildrenArray)
                {
                    Preset preset = JsonPresetFactory.ImportPreset(hbpreset);
                    preset.IsBuildIn        = true;
                    preset.Category         = category.PresetName;
                    preset.IsPresetDisabled = this.IsPresetDisabled(preset) || hbpreset.PresetDisabled;

                    if (hbpreset.Default && hasUserDefault)
                    {
                        preset.IsDefault = false;
                    }

                    this.Add(preset, true);
                }
            }

            // Verify we have presets.
            if (this.presets.Count == 0)
            {
                this.ServiceLogMessage("Failed to load built-in presets.");
                throw new GeneralApplicationException("Failed to load built-in presets.", "Restarting HandBrake may resolve this issue", null);
            }

            // Store the changes to disk
            this.SavePresetFiles();
        }
Exemplo n.º 4
0
        public PresetsService()
        {
            List <Preset> userPresets = PresetStorage.UserPresets;

            this.presetFolders           = PresetFolderStorage.PresetFolders;
            this.collapsedBuiltInFolders = CustomConfig.CollapsedBuiltInFolders;

            var    unmodifiedPresets = userPresets.Where(preset => !preset.IsModified);
            Preset modifiedPreset    = userPresets.FirstOrDefault(preset => preset.IsModified);

            this.allPresets = new ObservableCollection <PresetViewModel>();
            int modifiedPresetIndex = -1;
            int defaultPresetIndex  = 0;

            foreach (Preset userPreset in unmodifiedPresets)
            {
                PresetViewModel presetVM;
                if (modifiedPreset != null && modifiedPreset.Name == userPreset.Name)
                {
                    modifiedPresetIndex      = this.allPresets.Count;
                    presetVM                 = new PresetViewModel(modifiedPreset);
                    presetVM.OriginalProfile = userPreset.EncodingProfile;
                }
                else
                {
                    presetVM = new PresetViewModel(userPreset);
                }

                this.allPresets.Add(presetVM);
            }

            // Populate the custom preset folder before built-in presets are added to AllPresets collection.
            this.customPresetFolder = new PresetFolderViewModel(this, !this.collapsedBuiltInFolders.Contains(CustomFolderKey))
            {
                Name = EncodingRes.PresetFolder_Custom, Id = 0, IsBuiltIn = false
            };
            this.PopulateCustomFolder(this.customPresetFolder);

            // Populate built-in folder from HandBrake presets
            IList <PresetCategory> handBrakePresets = HandBrakePresetService.GetBuiltInPresets();

            this.builtInFolder = new PresetFolderViewModel(this, !this.collapsedBuiltInFolders.Contains(BuiltInFolderKey))
            {
                Name = EncodingRes.PresetFolder_BuiltIn, IsBuiltIn = true
            };
            foreach (PresetCategory handbrakePresetCategory in handBrakePresets)
            {
                var builtInSubfolder = new PresetFolderViewModel(this, !this.collapsedBuiltInFolders.Contains(handbrakePresetCategory.PresetName))
                {
                    Name      = handbrakePresetCategory.PresetName,
                    IsBuiltIn = true,
                };

                this.builtInFolder.AddSubfolder(builtInSubfolder);

                foreach (HBPreset handbrakePreset in handbrakePresetCategory.ChildrenArray)
                {
                    if (handbrakePreset.Default)
                    {
                        defaultPresetIndex = this.allPresets.Count;
                    }

                    Preset          builtInPreset          = PresetConverter.ConvertHandBrakePresetToVC(handbrakePreset);
                    PresetViewModel builtInPresetViewModel = new PresetViewModel(builtInPreset);

                    this.allPresets.Add(builtInPresetViewModel);
                    builtInSubfolder.AddItem(builtInPresetViewModel);
                }
            }

            this.allPresetsTree = new ObservableCollection <PresetFolderViewModel>();

            if (this.customPresetFolder.Items.Count > 0 || this.customPresetFolder.SubFolders.Count > 0)
            {
                this.AllPresetsTree.Add(this.customPresetFolder);
            }

            this.AllPresetsTree.Add(this.builtInFolder);



            // Always select the modified preset if it exists.
            // Otherwise, choose the last selected preset.
            int presetIndex;

            if (modifiedPresetIndex >= 0)
            {
                presetIndex = modifiedPresetIndex;
            }
            else
            {
                int lastPresetIndex = Config.LastPresetIndex;
                if (lastPresetIndex >= 0)
                {
                    presetIndex = lastPresetIndex;
                }
                else
                {
                    presetIndex = defaultPresetIndex;
                }
            }

            if (presetIndex >= this.allPresets.Count)
            {
                presetIndex = 0;
            }

            this.SelectedPreset = this.allPresets[presetIndex];
        }