Beispiel #1
0
        private static void UpgradePickers(int databaseVersion)
        {
            var pickers = PickerStorage.GetPickerListFromDb();

            foreach (Picker picker in pickers)
            {
                PickerStorage.UpgradePicker(picker, databaseVersion);
            }

            var pickerJsonList = pickers.Select(PickerStorage.SerializePicker).ToList();

            PickerStorage.SavePickers(pickerJsonList, Connection);
        }
Beispiel #2
0
        private static void UpgradeDatabaseTo27()
        {
            ExecuteNonQuery("CREATE TABLE pickersJson (json TEXT)", connection);

            Config.EnsureInitialized(connection);

            // If the user has chosen some auto audio or subtitle picker options, migrate them to a new picker
            if (CustomConfig.AutoAudio != AudioSelectionMode.Disabled || CustomConfig.AutoSubtitle != SubtitleSelectionMode.Disabled)
            {
                using (var pickerInsertCommand = new SQLiteCommand("INSERT INTO pickersJson(json) VALUES (?)", connection))
                {
                    var pickerParameter = new SQLiteParameter();
                    pickerInsertCommand.Parameters.Add(pickerParameter);

                    var convertedPicker = new Picker
                    {
                        Name = string.Format(MainRes.PickerNameTemplate, 1),
                        AudioSelectionMode              = CustomConfig.AutoAudio,
                        AudioLanguageCode               = Config.AudioLanguageCode,
                        AudioLanguageAll                = Config.AutoAudioAll,
                        SubtitleSelectionMode           = CustomConfig.AutoSubtitle,
                        SubtitleForeignBurnIn           = Config.AutoSubtitleBurnIn,
                        SubtitleLanguageCode            = Config.SubtitleLanguageCode,
                        SubtitleLanguageAll             = Config.AutoSubtitleAll,
                        SubtitleLanguageBurnIn          = Config.AutoSubtitleLanguageBurnIn,
                        SubtitleLanguageDefault         = Config.AutoSubtitleLanguageDefault,
                        SubtitleLanguageOnlyIfDifferent = Config.AutoSubtitleOnlyIfDifferent
                    };

                    pickerParameter.Value = PickerStorage.SerializePicker(convertedPicker);
                    pickerInsertCommand.ExecuteNonQuery();
                }

                Config.LastPickerIndex = 1;
            }
        }
Beispiel #3
0
        private static void UpgradeDatabaseTo28(int oldDatabaseVersion)
        {
            // Upgrade from XML to JSON
            Config.EnsureInitialized(connection);

            // Presets
            ExecuteNonQuery("CREATE TABLE presetsJson (json TEXT)", connection);

            var selectPresetsCommand = new SQLiteCommand("SELECT * FROM presetsXml", connection);

            using (SQLiteDataReader reader = selectPresetsCommand.ExecuteReader())
                using (var presetInsertCommand = new SQLiteCommand("INSERT INTO presetsJson(json) VALUES (?)", connection))
                {
                    var presetParameter = new SQLiteParameter();
                    presetInsertCommand.Parameters.Add(presetParameter);

                    XmlSerializer presetSerializer = new XmlSerializer(typeof(Preset));
                    while (reader.Read())
                    {
                        string presetXml = reader.GetString("xml");
                        var    preset    = PresetStorage.ParsePresetXml(presetXml, presetSerializer);

                        // Bring them all up to 28. The preset upgrade will cover them after that.
                        PresetStorage.UpgradeEncodingProfile(preset.EncodingProfile, oldDatabaseVersion, 28);

                        presetParameter.Value = PresetStorage.SerializePreset(preset);
                        presetInsertCommand.ExecuteNonQuery();
                    }
                }

            ExecuteNonQuery("DROP TABLE presetsXml", connection);

            // Pickers
            if (oldDatabaseVersion >= 27)
            {
                ExecuteNonQuery("CREATE TABLE pickersJson (json TEXT)", connection);

                var selectPickersCommand = new SQLiteCommand("SELECT * FROM pickersXml", connection);

                using (SQLiteDataReader reader = selectPickersCommand.ExecuteReader())
                    using (var pickerInsertCommand = new SQLiteCommand("INSERT INTO pickersJson(json) VALUES (?)", connection))
                    {
                        var pickerParameter = new SQLiteParameter();
                        pickerInsertCommand.Parameters.Add(pickerParameter);

                        XmlSerializer pickerSerializer = new XmlSerializer(typeof(Picker));
                        while (reader.Read())
                        {
                            string pickerXml = reader.GetString("xml");
                            var    picker    = PickerStorage.ParsePickerXml(pickerXml, pickerSerializer);

                            pickerParameter.Value = PickerStorage.SerializePicker(picker);
                            pickerInsertCommand.ExecuteNonQuery();
                        }
                    }

                ExecuteNonQuery("DROP TABLE pickersXml", connection);
            }

            // Saved jobs on queue
            string xmlEncodeJobs = Config.EncodeJobs2;

            if (!string.IsNullOrEmpty(xmlEncodeJobs))
            {
                XmlSerializer encodeJobSerializer = new XmlSerializer(typeof(EncodeJobPersistGroup));

                using (var stringReader = new StringReader(xmlEncodeJobs))
                    using (var xmlReader = new XmlTextReader(stringReader))
                    {
                        IList <EncodeJobWithMetadata> convertedJobs = new List <EncodeJobWithMetadata>();

                        var jobPersistGroup = encodeJobSerializer.Deserialize(xmlReader) as EncodeJobPersistGroup;
                        if (jobPersistGroup != null)
                        {
                            foreach (var job in jobPersistGroup.EncodeJobs)
                            {
                                convertedJobs.Add(job);
                            }
                        }

                        Config.SetLegacy("EncodeJobs2", EncodeJobStorage.SerializeJobs(convertedJobs));
                    }
            }

            // Window placement
            var windowPlacementKeys = new []
            {
                "MainWindowPlacement",
                "SubtitlesDialogPlacement",
                "EncodingDialogPlacement",
                "ChapterMarkersDialogPlacement",
                "PreviewWindowPlacement",
                "QueueTitlesDialogPlacement2",
                "AddAutoPauseProcessDialogPlacement",
                "OptionsDialogPlacement",
                "EncodeDetailsWindowPlacement",
                "PickerWindowPlacement",
                "LogWindowPlacement"
            };

            Encoding      encoding   = new UTF8Encoding();
            XmlSerializer serializer = new XmlSerializer(typeof(WINDOWPLACEMENT));

            foreach (string key in windowPlacementKeys)
            {
                UpgradeWindowPlacementConfig(key, encoding, serializer);
            }

            Config.EnsureInitialized(connection);
        }