summaryrefslogtreecommitdiffstats
path: root/win/CS
diff options
context:
space:
mode:
authorScott <[email protected]>2015-12-13 21:10:09 +0000
committerScott <[email protected]>2015-12-14 20:12:28 +0000
commit808c4c5e353e08e32d54c48dce96598996b1c91c (patch)
tree088e01178c58410c3d44f1df64315a96d3185b5e /win/CS
parent49c9165debefbae9a5b944033c51af5c565db857 (diff)
WinGui: Re-implement the ability to force a preset upgrade on nightly build users.
Diffstat (limited to 'win/CS')
-rw-r--r--win/CS/HandBrakeWPF/Services/Presets/PresetService.cs160
-rw-r--r--win/CS/HandBrakeWPF/UserSettingConstants.cs7
-rw-r--r--win/CS/HandBrakeWPF/defaultsettings.xml8
3 files changed, 99 insertions, 76 deletions
diff --git a/win/CS/HandBrakeWPF/Services/Presets/PresetService.cs b/win/CS/HandBrakeWPF/Services/Presets/PresetService.cs
index ba2c61e63..de1aefbf8 100644
--- a/win/CS/HandBrakeWPF/Services/Presets/PresetService.cs
+++ b/win/CS/HandBrakeWPF/Services/Presets/PresetService.cs
@@ -43,10 +43,12 @@ namespace HandBrakeWPF.Services.Presets
{
#region Private Variables
+ public const int ForcePresetReset = 0;
public static string UserPresetCatgoryName = "User Presets";
private readonly string presetFile = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\presets.json";
private readonly ObservableCollection<Preset> presets = new ObservableCollection<Preset>();
private readonly IErrorService errorService;
+ private readonly IUserSettingService userSettingService;
#endregion
@@ -56,9 +58,13 @@ namespace HandBrakeWPF.Services.Presets
/// <param name="errorService">
/// The error service.
/// </param>
- public PresetService(IErrorService errorService)
+ /// <param name="userSettingService">
+ /// The User setting service.
+ /// </param>
+ public PresetService(IErrorService errorService, IUserSettingService userSettingService)
{
this.errorService = errorService;
+ this.userSettingService = userSettingService;
}
/// <summary>
@@ -489,91 +495,82 @@ namespace HandBrakeWPF.Services.Presets
if (!File.Exists(this.presetFile))
{
this.UpdateBuiltInPresets();
- return;
+ return; // Update built-in presets stores the presets locally, so just return.
}
// Otherwise, we already have a file, so lets try load it.
- bool versionCheckChange = false;
+ PresetTransportContainer container = null;
using (StreamReader reader = new StreamReader(this.presetFile))
{
- // New Preset Format.
- PresetTransportContainer container = null;
+
try
{
container = JsonConvert.DeserializeObject<PresetTransportContainer>(reader.ReadToEnd());
}
- catch (Exception)
+ catch (Exception exc)
{
- // ignored
+ Debug.WriteLine("Failed to parse presets file: " + exc);
}
+ }
- // Sanity Check. Did the container deserialise.
- if (container?.PresetList == null)
- {
- // Close and Dispose of early.
- reader.Close();
- reader.Dispose();
-
- string filename = this.RecoverFromCorruptedPresetFile(this.presetFile);
- this.errorService.ShowMessageBox(
- Resources.PresetService_UnableToLoadPresets + filename,
- Resources.PresetService_UnableToLoad,
- MessageBoxButton.OK,
- MessageBoxImage.Exclamation);
-
- this.UpdateBuiltInPresets();
- return;
- }
+ // Sanity Check. Did the container deserialise.
+ if (container == null || container.PresetList == null)
+ {
+ string filename = this.RecoverFromCorruptedPresetFile(this.presetFile);
+ this.errorService.ShowMessageBox(
+ Resources.PresetService_UnableToLoadPresets + filename,
+ Resources.PresetService_UnableToLoad,
+ MessageBoxButton.OK,
+ MessageBoxImage.Exclamation);
- // Version Check
- // If we have old presets, or the container wasn't parseable, or we have a version mismatch, backup the user preset file
- // incase something goes wrong.
- if (container.VersionMajor != Constants.PresetVersionMajor || container.VersionMinor != Constants.PresetVersionMinor || container.VersionMicro != Constants.PresetVersionMicro)
- {
- string fileName = this.ArchivePresetFile(this.presetFile);
- this.errorService.ShowMessageBox(
- Resources.PresetService_PresetsOutOfDate
- + Environment.NewLine + Environment.NewLine + Resources.PresetService_ArchiveFile + fileName,
- Resources.PresetService_UnableToLoad,
- MessageBoxButton.OK,
- MessageBoxImage.Exclamation);
- versionCheckChange = true;
- }
+ this.UpdateBuiltInPresets();
+ return; // Update built-in presets stores the presets locally, so just return.
+ }
- // Process the presets.
- foreach (var item in container.PresetList)
- {
- object deserialisedItem = JsonConvert.DeserializeObject<PresetCategory>(item.ToString()); ;
-
- // Handle Categorised Presets.
- PresetCategory category = deserialisedItem as PresetCategory;
- if (category != null && category.Folder)
- {
- foreach (HBPreset hbpreset in category.ChildrenArray)
- {
- Preset preset = JsonPresetFactory.ImportPreset(hbpreset);
- preset.Category = category.PresetName;
- preset.IsBuildIn = hbpreset.Type == 0;
-
- // 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;
- }
-
- this.presets.Add(preset);
- }
- }
+ // Version Check
+ // If we have old presets, or the container wasn't parseable, or we have a version mismatch, backup the user preset file
+ // incase something goes wrong and reset built-in presets, then re-save.
+ if (container.VersionMajor != Constants.PresetVersionMajor || container.VersionMinor != Constants.PresetVersionMinor || container.VersionMicro != Constants.PresetVersionMicro)
+ {
+ string fileName = this.ArchivePresetFile(this.presetFile);
+ this.errorService.ShowMessageBox(
+ Resources.PresetService_PresetsOutOfDate
+ + Environment.NewLine + Environment.NewLine + Resources.PresetService_ArchiveFile + fileName,
+ Resources.PresetService_UnableToLoad,
+ MessageBoxButton.OK,
+ MessageBoxImage.Exclamation);
+ this.UpdateBuiltInPresets(); // Update built-in presets stores the presets locally, so just return.
+ return;
+ }
+
+ // Force Upgrade of presets
+ if (this.userSettingService.GetUserSetting<int>(UserSettingConstants.ForcePresetReset) > ForcePresetReset)
+ {
+ string fileName = this.ArchivePresetFile(this.presetFile);
+ this.errorService.ShowMessageBox(
+ Resources.PresetService_PresetsOutOfDate
+ + Environment.NewLine + Environment.NewLine + Resources.PresetService_ArchiveFile + fileName,
+ Resources.PresetService_UnableToLoad,
+ MessageBoxButton.OK,
+ MessageBoxImage.Exclamation);
+ this.UpdateBuiltInPresets(); // Update built-in presets stores the presets locally, so just return.
+ return;
+ }
- // Uncategorised Presets
- deserialisedItem = JsonConvert.DeserializeObject<HBPreset>(item.ToString());
- HBPreset hbPreset = deserialisedItem as HBPreset;
- if (hbPreset != null && !hbPreset.Folder)
+ // The presets file loaded was OK, so process it.
+ foreach (var item in container.PresetList)
+ {
+ object deserialisedItem = JsonConvert.DeserializeObject<PresetCategory>(item.ToString());
+
+ // Handle Categorised Presets.
+ PresetCategory category = deserialisedItem as PresetCategory;
+ if (category != null && category.Folder)
+ {
+ foreach (HBPreset hbpreset in category.ChildrenArray)
{
- Preset preset = JsonPresetFactory.ImportPreset(hbPreset);
- preset.Category = UserPresetCatgoryName;
- preset.IsBuildIn = hbPreset.Type == 1;
+ Preset preset = JsonPresetFactory.ImportPreset(hbpreset);
+ preset.Category = category.PresetName;
+ preset.IsBuildIn = hbpreset.Type == 0;
// IF we are using Source Max, Set the Max Width / Height values.
if (preset.PictureSettingsMode == PresetPictureSettingsMode.SourceMaximum)
@@ -585,12 +582,25 @@ namespace HandBrakeWPF.Services.Presets
this.presets.Add(preset);
}
}
- }
- // Resave the presets if we failed the version check to update the container
- if (versionCheckChange)
- {
- this.SavePresetFiles();
+ // Uncategorised Presets
+ deserialisedItem = JsonConvert.DeserializeObject<HBPreset>(item.ToString());
+ HBPreset hbPreset = deserialisedItem as HBPreset;
+ if (hbPreset != null && !hbPreset.Folder)
+ {
+ Preset preset = JsonPresetFactory.ImportPreset(hbPreset);
+ preset.Category = UserPresetCatgoryName;
+ preset.IsBuildIn = hbPreset.Type == 1;
+
+ // 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;
+ }
+
+ this.presets.Add(preset);
+ }
}
}
catch (Exception ex)
diff --git a/win/CS/HandBrakeWPF/UserSettingConstants.cs b/win/CS/HandBrakeWPF/UserSettingConstants.cs
index 3956827bd..f623c15d4 100644
--- a/win/CS/HandBrakeWPF/UserSettingConstants.cs
+++ b/win/CS/HandBrakeWPF/UserSettingConstants.cs
@@ -220,7 +220,12 @@ namespace HandBrakeWPF
/// The Show Queue in-line option.
/// </summary>
public const string ShowQueueInline = "ShowQueueInline";
-
+
+ /// <summary>
+ /// Setting to allow mid-version upgrades of presets.
+ /// </summary>
+ public const string ForcePresetReset = "ForcePresetReset";
+
#endregion
}
} \ No newline at end of file
diff --git a/win/CS/HandBrakeWPF/defaultsettings.xml b/win/CS/HandBrakeWPF/defaultsettings.xml
index cd7284a2b..762734009 100644
--- a/win/CS/HandBrakeWPF/defaultsettings.xml
+++ b/win/CS/HandBrakeWPF/defaultsettings.xml
@@ -472,4 +472,12 @@
<anyType xmlns:q1="http://www.w3.org/2001/XMLSchema" d4p1:type="q1:long" xmlns:d4p1="http://www.w3.org/2001/XMLSchema-instance">10000000000</anyType>
</value>
</item>
+ <item>
+ <key>
+ <string>ForcePresetReset</string>
+ </key>
+ <value>
+ <anyType xmlns:q1="http://www.w3.org/2001/XMLSchema" d4p1:type="q1:int" xmlns:d4p1="http://www.w3.org/2001/XMLSchema-instance">0</anyType>
+ </value>
+ </item>
</dictionary> \ No newline at end of file