Пример #1
0
        private static void UpgradeEncodingProfiles(int databaseVersion)
        {
            // Upgrade encoding profiles on presets (encoder/mixdown changes)
            var presets = PresetStorage.GetJsonPresetListFromDb();

            foreach (Preset preset in presets)
            {
                PresetStorage.UpgradeEncodingProfile(preset.EncodingProfile, databaseVersion);
            }

            var presetJsonList = presets.Select(PresetStorage.SerializePreset).ToList();

            PresetStorage.SavePresets(presetJsonList, Connection);

            // Upgrade encoding profiles on old queue items.
            Config.EnsureInitialized(Connection);
            string jobsJson = Config.EncodeJobs2;

            if (!string.IsNullOrEmpty(jobsJson))
            {
                IList <EncodeJobWithMetadata> jobs = EncodeJobStorage.ParseJobsJson(jobsJson);
                foreach (EncodeJobWithMetadata job in jobs)
                {
                    PresetStorage.UpgradeEncodingProfile(job.Job.EncodingProfile, databaseVersion);
                }

                Config.EncodeJobs2 = EncodeJobStorage.SerializeJobs(jobs);
            }
        }
Пример #2
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);
        }