mirror of
https://github.com/Tichau/FileConverter.git
synced 2026-11-19 09:01:32 +01:00
Add settings migration system to upgrade user settings.
This commit is contained in:
1 parent
8d8666e1e1
commit
dfb05980e6
3 files changed
+64
-1
No files matched your search
@@ -0,0 +1,59 @@
|
||||
// // <copyright file="Settings.Migration.cs" company="AAllard">License: http://www.gnu.org/licenses/gpl.html GPL version 3.</copyright>
|
||||
|
||||
namespace FileConverter
|
||||
{
|
||||
using System;
|
||||
|
||||
using FileConverter.ConversionJobs;
|
||||
|
||||
public partial class Settings
|
||||
{
|
||||
private static void MigrateSettingsToCurrentVersion(Settings settings)
|
||||
{
|
||||
int settingsVersion = settings.SerializationVersion;
|
||||
|
||||
// Migrate conversion settings.
|
||||
if (settings.ConversionPresets != null)
|
||||
{
|
||||
foreach (ConversionPreset conversionPreset in settings.ConversionPresets)
|
||||
{
|
||||
Settings.MigrateConversionPresetToCurrentVersion(conversionPreset, settingsVersion);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void MigrateConversionPresetToCurrentVersion(ConversionPreset preset, int settingsVersion)
|
||||
{
|
||||
if (settingsVersion <= 2)
|
||||
{
|
||||
// Migrate video encoding speed.
|
||||
string videoEncodingSpeed = preset.GetSettingsValue(ConversionPreset.ConversionSettingKeys.VideoEncodingSpeed);
|
||||
if (videoEncodingSpeed != null)
|
||||
{
|
||||
VideoEncodingSpeed encodingSpeed;
|
||||
if (!Enum.TryParse(videoEncodingSpeed, out encodingSpeed))
|
||||
{
|
||||
switch (videoEncodingSpeed)
|
||||
{
|
||||
case "Ultra Fast":
|
||||
preset.SetSettingsValue(ConversionPreset.ConversionSettingKeys.VideoEncodingSpeed, VideoEncodingSpeed.UltraFast.ToString());
|
||||
break;
|
||||
|
||||
case "Super Fast":
|
||||
preset.SetSettingsValue(ConversionPreset.ConversionSettingKeys.VideoEncodingSpeed, VideoEncodingSpeed.SuperFast.ToString());
|
||||
break;
|
||||
|
||||
case "Very Fast":
|
||||
preset.SetSettingsValue(ConversionPreset.ConversionSettingKeys.VideoEncodingSpeed, VideoEncodingSpeed.VeryFast.ToString());
|
||||
break;
|
||||
|
||||
case "Very Slow":
|
||||
preset.SetSettingsValue(ConversionPreset.ConversionSettingKeys.VideoEncodingSpeed, VideoEncodingSpeed.VerySlow.ToString());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@ namespace FileConverter
|
||||
|
||||
public partial class Settings : IXmlSerializable
|
||||
{
|
||||
public const int Version = 1;
|
||||
public const int Version = 3;
|
||||
|
||||
private bool exitApplicationWhenConversionsFinished = true;
|
||||
private float durationBetweenEndOfConversionsAndApplicationExit = 3f;
|
||||
|
||||
@@ -133,6 +133,8 @@ namespace FileConverter
|
||||
{
|
||||
if (userSettings.SerializationVersion != Version)
|
||||
{
|
||||
Settings.MigrateSettingsToCurrentVersion(userSettings);
|
||||
|
||||
Diagnostics.Debug.Log("File converter settings has been imported from version {0} to version {1}.", userSettings.SerializationVersion, Version);
|
||||
userSettings.SerializationVersion = Version;
|
||||
}
|
||||
@@ -189,6 +191,8 @@ namespace FileConverter
|
||||
|
||||
if (userSettings != null && userSettings.SerializationVersion != Version)
|
||||
{
|
||||
Settings.MigrateSettingsToCurrentVersion(userSettings);
|
||||
|
||||
Diagnostics.Debug.Log("File converter settings has been imported from version {0} to version {1}.", userSettings.SerializationVersion, Version);
|
||||
userSettings.SerializationVersion = Version;
|
||||
userSettings.Save();
|
||||
|
||||
Reference in new issue
Block a user