Example #1
0
        /// <summary>
        /// The import.
        /// </summary>
        /// <param name="filename">
        /// The filename.
        /// </param>
        public void Import(string filename)
        {
            if (!string.IsNullOrEmpty(filename))
            {
                PresetTransportContainer container = null;
                try
                {
                    container = HandBrakePresetService.GetPresetFromFile(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)
                {
                    foreach (var objectPreset in container.PresetList)
                    {
                        PresetCategory category = JsonConvert.DeserializeObject <PresetCategory>(objectPreset.ToString());
                        if (category != null && category.ChildrenArray != null && category.ChildrenArray.Count > 0)
                        {
                            foreach (HBPreset hbPreset in category.ChildrenArray)
                            {
                                Preset preset = this.ConvertHbPreset(hbPreset);
                                if (preset != null)
                                {
                                    this.AddOrUpdateImportedPreset(preset);
                                }
                            }
                        }
                        else
                        {
                            HBPreset hbPreset = JsonConvert.DeserializeObject <HBPreset>(objectPreset.ToString());
                            if (hbPreset != null)
                            {
                                Preset preset = this.ConvertHbPreset(hbPreset);
                                if (preset != null)
                                {
                                    this.AddOrUpdateImportedPreset(preset);
                                }
                            }
                        }
                    }
                }
            }
        }
Example #2
0
        /// <summary>
        /// The import.
        /// </summary>
        /// <param name="filename">
        /// The filename.
        /// </param>
        public void Import(string filename)
        {
            if (!string.IsNullOrEmpty(filename))
            {
                PresetTransportContainer container = HandBrakePresetService.GetPresetFromFile(filename);

                if (container?.PresetList == null || container.PresetList.Count == 0)
                {
                    this.errorService.ShowError(Resources.Main_PresetImportFailed, Resources.Main_PresetImportFailedSolution, string.Empty);
                    return;
                }

                // HBPreset Handling
                if (container.PresetList != null)
                {
                    foreach (var objectPreset in container.PresetList)
                    {
                        HBPreset hbPreset = JsonConvert.DeserializeObject <HBPreset>(objectPreset.ToString());

                        Preset preset = null;
                        try
                        {
                            preset          = JsonPresetFactory.ImportPreset(hbPreset);
                            preset.Category = UserPresetCatgoryName;

                            // IF we are using Source Max, Set the Max Width / Height values.
                            if (preset.PictureSettingsMode == PresetPictureSettingsMode.SourceMaximum)
                            {
                                preset.Task.MaxWidth  = preset.Task.Height;
                                preset.Task.MaxHeight = preset.Task.Width;
                            }
                        }
                        catch (Exception exc)
                        {
                            this.errorService.ShowError(Resources.Main_PresetImportFailed, Resources.Main_PresetImportFailedSolution, exc);
                        }

                        if (preset == null)
                        {
                            this.errorService.ShowError(Resources.Main_PresetImportFailed, Resources.Main_PresetImportFailedSolution, string.Empty);
                            return;
                        }

                        if (this.CheckIfPresetExists(preset.Name))
                        {
                            if (!this.CanUpdatePreset(preset.Name))
                            {
                                MessageBox.Show(Resources.Main_PresetErrorBuiltInName, Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
                                return;
                            }

                            MessageBoxResult result = MessageBox.Show(Resources.Main_PresetOverwriteWarning, Resources.Overwrite, MessageBoxButton.YesNo, MessageBoxImage.Warning);
                            if (result == MessageBoxResult.Yes)
                            {
                                this.Update(preset);
                            }
                        }
                        else
                        {
                            this.Add(preset);
                        }
                    }
                }

                // Category Handling.
                // TODO maybe for a future release.
            }
        }
Example #3
0
        /// <summary>
        /// The import.
        /// </summary>
        /// <param name="filename">
        /// The filename.
        /// </param>
        public void Import(string filename)
        {
            // TODO needs a tidy up but will do for now.
            if (!string.IsNullOrEmpty(filename))
            {
                PresetTransportContainer container = HandBrakePresetService.GetPresetFromFile(filename);

                if (container == null || container.PresetList == null || container.PresetList.Count == 0)
                {
                    this.errorService.ShowError(Resources.Main_PresetImportFailed, Resources.Main_PresetImportFailedSolution, string.Empty);
                    return;
                }

                // HBPreset Handling
                IList <HBPreset> hbPresets = container.PresetList as IList <HBPreset>;
                if (hbPresets != null)
                {
                    foreach (var hbPreset in hbPresets)
                    {
                        Preset preset = null;
                        try
                        {
                            preset          = JsonPresetFactory.ImportPreset(hbPreset);
                            preset.Category = UserPresetCatgoryName;

                            // IF we are using Source Max, Set the Max Width / Height values.
                            if (preset.PictureSettingsMode == PresetPictureSettingsMode.SourceMaximum)
                            {
                                preset.Task.MaxWidth  = preset.Task.Height;
                                preset.Task.MaxHeight = preset.Task.Width;
                            }
                        }
                        catch (Exception exc)
                        {
                            this.errorService.ShowError(Resources.Main_PresetImportFailed, Resources.Main_PresetImportFailedSolution, exc);
                        }

                        if (preset == null)
                        {
                            this.errorService.ShowError(Resources.Main_PresetImportFailed, Resources.Main_PresetImportFailedSolution, string.Empty);
                            return;
                        }

                        // TODO Better version checking.

                        if (this.CheckIfPresetExists(preset.Name))
                        {
                            if (!CanUpdatePreset(preset.Name))
                            {
                                MessageBox.Show(Resources.Main_PresetErrorBuiltInName, Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
                                return;
                            }

                            MessageBoxResult result = MessageBox.Show(Resources.Main_PresetOverwriteWarning, Resources.Overwrite, MessageBoxButton.YesNo, MessageBoxImage.Warning);
                            if (result == MessageBoxResult.Yes)
                            {
                                Update(preset);
                            }
                        }
                        else
                        {
                            Add(preset);
                        }
                    }
                }

                // Category Handling.
            }
        }