public static HBPresetCategory CreatePresetCategory(PresetDisplayCategory category, HBConfiguration config) { HBPresetCategory preset = new HBPresetCategory(); preset.Folder = true; preset.PresetName = category.Category; preset.PresetDescription = string.Empty; preset.ChildrenArray = new List <HBPreset>(); foreach (Preset singlePreset in category.Presets) { preset.ChildrenArray.Add(CreateHbPreset(singlePreset, config)); } return(preset); }
private void ProcessPresetList(PresetTransportContainer container) { // The presets file loaded was OK, so process it. foreach (var item in container.PresetList) { object deserializedItem = JsonSerializer.Deserialize <HBPresetCategory>(item.ToString(), JsonSettings.Options); // Handle Categorised Presets. HBPresetCategory category = deserializedItem as HBPresetCategory; if (category != null && category.Folder) { foreach (HBPreset hbpreset in category.ChildrenArray) { Preset preset = JsonPresetFactory.ImportPreset(hbpreset); // Migration preset.Category = category.PresetName == "User Presets" ? UserPresetCategoryName : category.PresetName; preset.IsBuildIn = hbpreset.Type == 0; preset.IsPresetDisabled = this.IsPresetDisabled(preset); this.Add(preset, true); } } // Uncategorised Presets deserializedItem = JsonSerializer.Deserialize <HBPreset>(item.ToString(), JsonSettings.Options); HBPreset hbPreset = deserializedItem as HBPreset; if (hbPreset != null && !hbPreset.Folder) { Preset preset = JsonPresetFactory.ImportPreset(hbPreset); preset.Category = UserPresetCategoryName; preset.IsBuildIn = hbPreset.Type == 0; preset.IsPresetDisabled = this.IsPresetDisabled(preset); this.Add(preset, true); } } }
public void Import(string filename) { if (!string.IsNullOrEmpty(filename)) { PresetTransportContainer container; try { container = HandBrakePresetService.GetPresetsFromFile(filename); } catch (Exception exc) { this.errorService.ShowError(Resources.Main_PresetImportFailed, Resources.Main_PresetImportFailedSolution, exc); return; } if (container?.PresetList == null || container.PresetList.Count == 0) { this.errorService.ShowError(Resources.Main_PresetImportFailed, Resources.Main_PresetImportFailedSolution, Resources.NoAdditionalInformation); return; } // HBPreset Handling if (container.PresetList != null) { bool containsBuildInPreset = false; foreach (var objectPreset in container.PresetList) { HBPresetCategory category = JsonSerializer.Deserialize <HBPresetCategory>(objectPreset.ToString(), JsonSettings.Options); if (category != null && category.ChildrenArray != null && category.ChildrenArray.Count > 0) { foreach (HBPreset hbPreset in category.ChildrenArray) { Preset preset = this.ConvertHbPreset(hbPreset, category.PresetName); preset.IsPresetDisabled = this.IsPresetDisabled(preset); preset.IsDefault = false; // When importing, force the user to reset default manually. This prevents conflicts. if (!preset.IsBuildIn) { this.AddOrUpdateImportedPreset(preset); } else { containsBuildInPreset = true; } } } else { HBPreset hbPreset = JsonSerializer.Deserialize <HBPreset>(objectPreset.ToString(), JsonSettings.Options); if (hbPreset != null) { Preset preset = this.ConvertHbPreset(hbPreset, null); preset.IsDefault = false; // When importing, force the user to reset default manually. This prevents conflicts. preset.IsPresetDisabled = this.IsPresetDisabled(preset); if (!preset.IsBuildIn) { this.AddOrUpdateImportedPreset(preset); } else { containsBuildInPreset = true; } } } } if (containsBuildInPreset) { this.errorService.ShowMessageBox( Properties.Resources.PresetService_ImportingBuiltInWarning, Properties.Resources.Warning, MessageBoxButton.OK, MessageBoxImage.Warning); } } } }