diff options
author | sr55 <[email protected]> | 2019-05-11 20:39:00 +0100 |
---|---|---|
committer | sr55 <[email protected]> | 2019-05-11 20:39:00 +0100 |
commit | 50f8adb4efdf43eba77d92d8ef86eacee21fe201 (patch) | |
tree | 32ca18fc8ee6383fd02741f79d219b2b55bdbe37 /win | |
parent | 4b8c299e283bcce467eebf59248524ed94befa5d (diff) |
WinGui: Use hb_presets_read_file_json to read the UI presets file. This allows us to better handle version upgrades without resetting everything back to 0.
Diffstat (limited to 'win')
13 files changed, 125 insertions, 142 deletions
diff --git a/win/CS/HandBrake.Interop/HandBrake.Interop.csproj b/win/CS/HandBrake.Interop/HandBrake.Interop.csproj index a4aff67fe..733c81248 100644 --- a/win/CS/HandBrake.Interop/HandBrake.Interop.csproj +++ b/win/CS/HandBrake.Interop/HandBrake.Interop.csproj @@ -121,6 +121,7 @@ <Compile Include="Interop\Model\Encoding\Detelecine.cs" /> <Compile Include="Interop\Model\Encoding\HBPresetTune.cs" /> <Compile Include="Interop\Model\Encoding\Sharpen.cs" /> + <Compile Include="Interop\Model\PresetVersion.cs" /> <Compile Include="Interop\Model\Preview\RawPreviewData.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Interop\Json\Scan\SourceAudioTrack.cs" /> diff --git a/win/CS/HandBrake.Interop/Interop/HandBrakePresetService.cs b/win/CS/HandBrake.Interop/Interop/HandBrakePresetService.cs index a51a44fd1..98eb6071b 100644 --- a/win/CS/HandBrake.Interop/Interop/HandBrakePresetService.cs +++ b/win/CS/HandBrake.Interop/Interop/HandBrakePresetService.cs @@ -17,6 +17,7 @@ namespace HandBrake.Interop.Interop using HandBrake.Interop.Interop.HbLib; using HandBrake.Interop.Interop.Helpers; using HandBrake.Interop.Interop.Json.Presets; + using HandBrake.Interop.Interop.Model; using Newtonsoft.Json; @@ -50,7 +51,7 @@ namespace HandBrake.Interop.Interop /// <returns> /// The <see cref="PresetCategory"/>. /// </returns> - public static PresetTransportContainer GetPresetFromFile(string filename) + public static PresetTransportContainer GetPresetsFromFile(string filename) { IntPtr presetStringPointer = HBFunctions.hb_presets_read_file_json(InteropUtilities.ToUtf8PtrFromString(filename)); string presetJson = Marshal.PtrToStringAnsi(presetStringPointer); @@ -88,5 +89,24 @@ namespace HandBrake.Interop.Interop writer.Write(preset); } } + + public static PresetVersion GetCurrentPresetVersion() + { + IntPtr major = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(int))); + IntPtr minor = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(int))); + IntPtr micro = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(int))); + + HBFunctions.hb_presets_current_version(major, minor, micro); + + int majorVersion = Marshal.ReadInt32(major); + int minorVersion = Marshal.ReadInt32(minor); + int microVersion = Marshal.ReadInt32(micro); + + Marshal.FreeHGlobal(major); + Marshal.FreeHGlobal(minor); + Marshal.FreeHGlobal(micro); + + return new PresetVersion(majorVersion, minorVersion, microVersion); + } } } diff --git a/win/CS/HandBrake.Interop/Interop/HbLib/HbFunctions.cs b/win/CS/HandBrake.Interop/Interop/HbLib/HbFunctions.cs index 689ceb937..7fc1ed500 100644 --- a/win/CS/HandBrake.Interop/Interop/HbLib/HbFunctions.cs +++ b/win/CS/HandBrake.Interop/Interop/HbLib/HbFunctions.cs @@ -469,5 +469,8 @@ namespace HandBrake.Interop.Interop.HbLib // char * hb_presets_read_file_json(const char *filename); [DllImport("hb", EntryPoint = "hb_presets_read_file_json", CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr hb_presets_read_file_json(IntPtr filename); + + [DllImport("hb", EntryPoint = "hb_presets_current_version", CallingConvention = CallingConvention.Cdecl)] + public static extern IntPtr hb_presets_current_version(IntPtr major, IntPtr minor, IntPtr micro); } } diff --git a/win/CS/HandBrake.Interop/Interop/Json/Presets/PresetTransportContainer.cs b/win/CS/HandBrake.Interop/Interop/Json/Presets/PresetTransportContainer.cs index 91ce48de5..4d72e70ff 100644 --- a/win/CS/HandBrake.Interop/Interop/Json/Presets/PresetTransportContainer.cs +++ b/win/CS/HandBrake.Interop/Interop/Json/Presets/PresetTransportContainer.cs @@ -37,7 +37,7 @@ namespace HandBrake.Interop.Interop.Json.Presets /// <param name="versionMicro"> /// The version micro. /// </param> - public PresetTransportContainer(string versionMajor, string versionMinor, string versionMicro) + public PresetTransportContainer(int versionMajor, int versionMinor, int versionMicro) { this.VersionMajor = versionMajor; this.VersionMicro = versionMicro; @@ -52,16 +52,16 @@ namespace HandBrake.Interop.Interop.Json.Presets /// <summary> /// Gets or sets the version major. /// </summary> - public string VersionMajor { get; set; } + public int VersionMajor { get; set; } /// <summary> /// Gets or sets the version micro. /// </summary> - public string VersionMicro { get; set; } + public int VersionMicro { get; set; } /// <summary> /// Gets or sets the version minor. /// </summary> - public string VersionMinor { get; set; } + public int VersionMinor { get; set; } } } diff --git a/win/CS/HandBrake.Interop/Interop/Model/PresetVersion.cs b/win/CS/HandBrake.Interop/Interop/Model/PresetVersion.cs new file mode 100644 index 000000000..dbe5578f8 --- /dev/null +++ b/win/CS/HandBrake.Interop/Interop/Model/PresetVersion.cs @@ -0,0 +1,25 @@ +// -------------------------------------------------------------------------------------------------------------------- +// <copyright file="PresetVersion.cs" company="HandBrake Project (http://handbrake.fr)"> +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// </copyright> +// <summary> +// Defines the PresetVersion type. +// </summary> +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrake.Interop.Interop.Model +{ + public class PresetVersion + { + public PresetVersion(int major, int minor, int micro) + { + this.Major = major; + this.Minor = minor; + this.Micro = micro; + } + + public int Major { get; } + public int Minor { get; } + public int Micro { get; } + } +} diff --git a/win/CS/HandBrakeWPF/Constants.cs b/win/CS/HandBrakeWPF/Constants.cs index f4a65d7d2..5ee22d03d 100644 --- a/win/CS/HandBrakeWPF/Constants.cs +++ b/win/CS/HandBrakeWPF/Constants.cs @@ -37,11 +37,6 @@ namespace HandBrakeWPF public const string SourcePath = "{source_path}";
public const string SourceFolderName = "{source_folder_name}";
- /* Preset Versions */
- public const string PresetVersionMajor = "35";
- public const string PresetVersionMinor = "0";
- public const string PresetVersionMicro = "0";
-
public const string FileScanMru = "FileScanMru";
public const string FileSaveMru = "FileSaveMru";
}
diff --git a/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs b/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs index a3583ef4a..8c460eca0 100644 --- a/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs +++ b/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs @@ -3738,17 +3738,6 @@ namespace HandBrakeWPF.Properties { } /// <summary> - /// Looks up a localized string similar to HandBrake has detected your presets file is from an older version. - ///It will try and load the file anyway. - ///If it fails, it will archive off the old file and create a new one.. - /// </summary> - public static string PresetService_PresetsOutOfDate { - get { - return ResourceManager.GetString("PresetService_PresetsOutOfDate", resourceCulture); - } - } - - /// <summary> /// Looks up a localized string similar to Unable to load presets.. /// </summary> public static string PresetService_UnableToLoad { diff --git a/win/CS/HandBrakeWPF/Properties/Resources.de.resx b/win/CS/HandBrakeWPF/Properties/Resources.de.resx index 5c330036f..e0d6029c8 100644 --- a/win/CS/HandBrakeWPF/Properties/Resources.de.resx +++ b/win/CS/HandBrakeWPF/Properties/Resources.de.resx @@ -1,4 +1,4 @@ -<?xml version="1.0" encoding="utf-8"?> +<?xml version="1.0" encoding="utf-8"?> <root> <!-- Microsoft ResX Schema @@ -60,45 +60,45 @@ : and then encoded with base64 encoding. --> <xsd:schema xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="root"> - <xsd:import namespace="http://www.w3.org/XML/1998/namespace"/> + <xsd:import namespace="http://www.w3.org/XML/1998/namespace" /> <xsd:element name="root" msdata:IsDataSet="true"> <xsd:complexType> <xsd:choice maxOccurs="unbounded"> <xsd:element name="metadata"> <xsd:complexType> <xsd:sequence> - <xsd:element name="value" type="xsd:string" minOccurs="0"/> + <xsd:element name="value" type="xsd:string" minOccurs="0" /> </xsd:sequence> - <xsd:attribute name="name" use="required" type="xsd:string"/> - <xsd:attribute name="type" type="xsd:string"/> - <xsd:attribute name="mimetype" type="xsd:string"/> - <xsd:attribute ref="xml:space"/> + <xsd:attribute name="name" use="required" type="xsd:string" /> + <xsd:attribute name="type" type="xsd:string" /> + <xsd:attribute name="mimetype" type="xsd:string" /> + <xsd:attribute ref="xml:space" /> </xsd:complexType> </xsd:element> <xsd:element name="assembly"> <xsd:complexType> - <xsd:attribute name="alias" type="xsd:string"/> - <xsd:attribute name="name" type="xsd:string"/> + <xsd:attribute name="alias" type="xsd:string" /> + <xsd:attribute name="name" type="xsd:string" /> </xsd:complexType> </xsd:element> <xsd:element name="data"> <xsd:complexType> <xsd:sequence> - <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1"/> - <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2"/> + <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> + <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" /> </xsd:sequence> - <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1"/> - <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3"/> - <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4"/> - <xsd:attribute ref="xml:space"/> + <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" /> + <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" /> + <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" /> + <xsd:attribute ref="xml:space" /> </xsd:complexType> </xsd:element> <xsd:element name="resheader"> <xsd:complexType> <xsd:sequence> - <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1"/> + <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> </xsd:sequence> - <xsd:attribute name="name" type="xsd:string" use="required"/> + <xsd:attribute name="name" type="xsd:string" use="required" /> </xsd:complexType> </xsd:element> </xsd:choice> @@ -559,11 +559,6 @@ Bitte stellen Sie sicher, dass VLC installiert und der Pfad in den HandBrake-Ein <data name="PresetService_ArchiveFile" xml:space="preserve"> <value>Archivierte Datei:</value> </data> - <data name="PresetService_PresetsOutOfDate" xml:space="preserve"> - <value>HandBrake hat festgestellt, dass die Voreinstellungsdatei von einer älteren Version stammt. -Es wird versucht die Datei trotzdem zu laden. -Schlägt dies fehl, wird die Datei archiviert und eine neue erstellt.</value> - </data> <data name="PresetService_UnableToLoad" xml:space="preserve"> <value>Laden der Voreinstellung fehlgeschlagen.</value> </data> @@ -1964,4 +1959,4 @@ Nicht-Echtzeit Optionen: {date} {time} {creation-date} {creation-time} {quality} <data name="CollisionBehaviour_AppendNumber" xml:space="preserve"> <value>Zahl anhängen</value> </data> -</root> +</root>
\ No newline at end of file diff --git a/win/CS/HandBrakeWPF/Properties/Resources.fr.resx b/win/CS/HandBrakeWPF/Properties/Resources.fr.resx index ab85f8933..d8aa30d8f 100644 --- a/win/CS/HandBrakeWPF/Properties/Resources.fr.resx +++ b/win/CS/HandBrakeWPF/Properties/Resources.fr.resx @@ -1,4 +1,4 @@ -<?xml version="1.0" encoding="utf-8"?> +<?xml version="1.0" encoding="utf-8"?> <root> <!-- Microsoft ResX Schema @@ -60,45 +60,45 @@ : and then encoded with base64 encoding. --> <xsd:schema xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="root"> - <xsd:import namespace="http://www.w3.org/XML/1998/namespace"/> + <xsd:import namespace="http://www.w3.org/XML/1998/namespace" /> <xsd:element name="root" msdata:IsDataSet="true"> <xsd:complexType> <xsd:choice maxOccurs="unbounded"> <xsd:element name="metadata"> <xsd:complexType> <xsd:sequence> - <xsd:element name="value" type="xsd:string" minOccurs="0"/> + <xsd:element name="value" type="xsd:string" minOccurs="0" /> </xsd:sequence> - <xsd:attribute name="name" use="required" type="xsd:string"/> - <xsd:attribute name="type" type="xsd:string"/> - <xsd:attribute name="mimetype" type="xsd:string"/> - <xsd:attribute ref="xml:space"/> + <xsd:attribute name="name" use="required" type="xsd:string" /> + <xsd:attribute name="type" type="xsd:string" /> + <xsd:attribute name="mimetype" type="xsd:string" /> + <xsd:attribute ref="xml:space" /> </xsd:complexType> </xsd:element> <xsd:element name="assembly"> <xsd:complexType> - <xsd:attribute name="alias" type="xsd:string"/> - <xsd:attribute name="name" type="xsd:string"/> + <xsd:attribute name="alias" type="xsd:string" /> + <xsd:attribute name="name" type="xsd:string" /> </xsd:complexType> </xsd:element> <xsd:element name="data"> <xsd:complexType> <xsd:sequence> - <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1"/> - <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2"/> + <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> + <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" /> </xsd:sequence> - <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1"/> - <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3"/> - <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4"/> - <xsd:attribute ref="xml:space"/> + <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" /> + <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" /> + <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" /> + <xsd:attribute ref="xml:space" /> </xsd:complexType> </xsd:element> <xsd:element name="resheader"> <xsd:complexType> <xsd:sequence> - <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1"/> + <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> </xsd:sequence> - <xsd:attribute name="name" type="xsd:string" use="required"/> + <xsd:attribute name="name" type="xsd:string" use="required" /> </xsd:complexType> </xsd:element> </xsd:choice> @@ -573,11 +573,6 @@ Assurez-vous que VLC est installé et que le répertoire spécifié dans les opt <data name="PresetService_ArchiveFile" xml:space="preserve"> <value>Fichier archivé:</value> </data> - <data name="PresetService_PresetsOutOfDate" xml:space="preserve"> - <value>HandBrake a détecté que votre fichier de préréglages provient d'une version antérieure. -Il va quand même essayer de charger le fichier. -Si cela échoue, il archivera l'ancien fichier et en créera un nouveau.</value> - </data> <data name="PresetService_UnableToLoad" xml:space="preserve"> <value>Impossible de charger les préréglages.</value> </data> @@ -1978,4 +1973,4 @@ Non-Live Options: {date} {time} {creation-date} {creation-time} {quality} {bitra <data name="CollisionBehaviour_AppendNumber" xml:space="preserve"> <value>Append Number</value> </data> -</root> +</root>
\ No newline at end of file diff --git a/win/CS/HandBrakeWPF/Properties/Resources.resx b/win/CS/HandBrakeWPF/Properties/Resources.resx index 66a4cf97f..d7d5dedcb 100644 --- a/win/CS/HandBrakeWPF/Properties/Resources.resx +++ b/win/CS/HandBrakeWPF/Properties/Resources.resx @@ -573,11 +573,6 @@ Please make sure VLC is installed and the directory specified in HandBrake's opt <data name="PresetService_ArchiveFile" xml:space="preserve">
<value>Archived File:</value>
</data>
- <data name="PresetService_PresetsOutOfDate" xml:space="preserve">
- <value>HandBrake has detected your presets file is from an older version.
-It will try and load the file anyway.
-If it fails, it will archive off the old file and create a new one.</value>
- </data>
<data name="PresetService_UnableToLoad" xml:space="preserve">
<value>Unable to load presets.</value>
</data>
diff --git a/win/CS/HandBrakeWPF/Properties/Resources.zh.resx b/win/CS/HandBrakeWPF/Properties/Resources.zh.resx index dda1f9d5b..a9fbe4434 100644 --- a/win/CS/HandBrakeWPF/Properties/Resources.zh.resx +++ b/win/CS/HandBrakeWPF/Properties/Resources.zh.resx @@ -1,4 +1,4 @@ -<?xml version="1.0" encoding="utf-8"?> +<?xml version="1.0" encoding="utf-8"?> <root> <!-- Microsoft ResX Schema @@ -60,45 +60,45 @@ : and then encoded with base64 encoding. --> <xsd:schema xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="root"> - <xsd:import namespace="http://www.w3.org/XML/1998/namespace"/> + <xsd:import namespace="http://www.w3.org/XML/1998/namespace" /> <xsd:element name="root" msdata:IsDataSet="true"> <xsd:complexType> <xsd:choice maxOccurs="unbounded"> <xsd:element name="metadata"> <xsd:complexType> <xsd:sequence> - <xsd:element name="value" type="xsd:string" minOccurs="0"/> + <xsd:element name="value" type="xsd:string" minOccurs="0" /> </xsd:sequence> - <xsd:attribute name="name" use="required" type="xsd:string"/> - <xsd:attribute name="type" type="xsd:string"/> - <xsd:attribute name="mimetype" type="xsd:string"/> - <xsd:attribute ref="xml:space"/> + <xsd:attribute name="name" use="required" type="xsd:string" /> + <xsd:attribute name="type" type="xsd:string" /> + <xsd:attribute name="mimetype" type="xsd:string" /> + <xsd:attribute ref="xml:space" /> </xsd:complexType> </xsd:element> <xsd:element name="assembly"> <xsd:complexType> - <xsd:attribute name="alias" type="xsd:string"/> - <xsd:attribute name="name" type="xsd:string"/> + <xsd:attribute name="alias" type="xsd:string" /> + <xsd:attribute name="name" type="xsd:string" /> </xsd:complexType> </xsd:element> <xsd:element name="data"> <xsd:complexType> <xsd:sequence> - <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1"/> - <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2"/> + <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> + <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" /> </xsd:sequence> - <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1"/> - <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3"/> - <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4"/> - <xsd:attribute ref="xml:space"/> + <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" /> + <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" /> + <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" /> + <xsd:attribute ref="xml:space" /> </xsd:complexType> </xsd:element> <xsd:element name="resheader"> <xsd:complexType> <xsd:sequence> - <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1"/> + <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> </xsd:sequence> - <xsd:attribute name="name" type="xsd:string" use="required"/> + <xsd:attribute name="name" type="xsd:string" use="required" /> </xsd:complexType> </xsd:element> </xsd:choice> @@ -566,11 +566,6 @@ Foreign Audio Preferred, else First - 如果存在外语轨道,则会将其烧 <data name="PresetService_ArchiveFile" xml:space="preserve"> <value>存档的文件:</value> </data> - <data name="PresetService_PresetsOutOfDate" xml:space="preserve"> - <value>HandBrake 检测到预设文件来自旧版本。 -它将尝试加载文件。 -如果失败,它将存档旧文件并创建新文件。</value> - </data> <data name="PresetService_UnableToLoad" xml:space="preserve"> <value>无法加载预设。</value> </data> @@ -1966,4 +1961,4 @@ Non-Live Options: {date} {time} {creation-date} {creation-time} {quality} {bitra <data name="CollisionBehaviour_AppendNumber" xml:space="preserve"> <value>Append Number</value> </data> -</root> +</root>
\ No newline at end of file diff --git a/win/CS/HandBrakeWPF/Services/Presets/Factories/JsonPresetFactory.cs b/win/CS/HandBrakeWPF/Services/Presets/Factories/JsonPresetFactory.cs index c6dd9595e..91efcc7f9 100644 --- a/win/CS/HandBrakeWPF/Services/Presets/Factories/JsonPresetFactory.cs +++ b/win/CS/HandBrakeWPF/Services/Presets/Factories/JsonPresetFactory.cs @@ -483,10 +483,8 @@ namespace HandBrakeWPF.Services.Presets.Factories /// </returns>
public static PresetTransportContainer ExportPreset(Preset export, HBConfiguration config)
{
- PresetTransportContainer container = new PresetTransportContainer();
- container.VersionMajor = Constants.PresetVersionMajor;
- container.VersionMinor = Constants.PresetVersionMinor;
- container.VersionMicro = Constants.PresetVersionMicro;
+ PresetVersion presetVersion = HandBrakePresetService.GetCurrentPresetVersion();
+ PresetTransportContainer container = new PresetTransportContainer(presetVersion.Major, presetVersion.Minor, presetVersion.Micro);
container.PresetList = new List<object> { CreateHbPreset(export, config) };
@@ -501,10 +499,8 @@ namespace HandBrakeWPF.Services.Presets.Factories /// <returns>A list of JSON object presets.</returns>
public static PresetTransportContainer ExportPresets(IEnumerable<Preset> exportList, HBConfiguration config)
{
- PresetTransportContainer container = new PresetTransportContainer();
- container.VersionMajor = Constants.PresetVersionMajor;
- container.VersionMinor = Constants.PresetVersionMinor;
- container.VersionMicro = Constants.PresetVersionMicro;
+ PresetVersion presetVersion = HandBrakePresetService.GetCurrentPresetVersion();
+ PresetTransportContainer container = new PresetTransportContainer(presetVersion.Major, presetVersion.Minor, presetVersion.Micro);
List<HBPreset> presets = exportList.Select(item => CreateHbPreset(item, config)).ToList();
diff --git a/win/CS/HandBrakeWPF/Services/Presets/PresetService.cs b/win/CS/HandBrakeWPF/Services/Presets/PresetService.cs index 52f1d5d7f..56bbbf8d0 100644 --- a/win/CS/HandBrakeWPF/Services/Presets/PresetService.cs +++ b/win/CS/HandBrakeWPF/Services/Presets/PresetService.cs @@ -21,6 +21,7 @@ namespace HandBrakeWPF.Services.Presets using HandBrake.Interop.Interop;
using HandBrake.Interop.Interop.Json.Presets;
+ using HandBrake.Interop.Interop.Model;
using HandBrake.Interop.Model;
using HandBrake.Interop.Utilities;
@@ -174,7 +175,7 @@ namespace HandBrakeWPF.Services.Presets PresetTransportContainer container = null;
try
{
- container = HandBrakePresetService.GetPresetFromFile(filename);
+ container = HandBrakePresetService.GetPresetsFromFile(filename);
}
catch (Exception exc)
{
@@ -681,16 +682,13 @@ namespace HandBrakeWPF.Services.Presets // Otherwise, we already have a file, so lets try load it.
PresetTransportContainer container = null;
- using (StreamReader reader = new StreamReader(this.presetFile))
+ try
{
- try
- {
- container = JsonConvert.DeserializeObject<PresetTransportContainer>(reader.ReadToEnd());
- }
- catch (Exception exc)
- {
- this.ServiceLogMessage("Corrupted Presets File Detected: " + Environment.NewLine + exc);
- }
+ container = HandBrakePresetService.GetPresetsFromFile(this.presetFile);
+ }
+ catch (Exception exc)
+ {
+ this.ServiceLogMessage("Corrupted Presets File Detected: " + Environment.NewLine + exc);
}
// Sanity Check. Did the container deserialise.
@@ -709,23 +707,6 @@ namespace HandBrakeWPF.Services.Presets return; // Update built-in presets stores the presets locally, so just return.
}
- // 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.
- bool ignoreBuildIn = false;
- 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.Information);
- this.UpdateBuiltInPresets(); // Update built-in presets stores the presets locally, so just return.
- ignoreBuildIn = true;
- }
-
// Force Upgrade of presets
if (this.userSettingService.GetUserSetting<int>(UserSettingConstants.ForcePresetReset, typeof(int)) < ForcePresetReset)
{
@@ -742,7 +723,7 @@ namespace HandBrakeWPF.Services.Presets return;
}
- this.ProcessPresetList(container, ignoreBuildIn);
+ this.ProcessPresetList(container);
}
catch (Exception ex)
{
@@ -752,7 +733,7 @@ namespace HandBrakeWPF.Services.Presets }
}
- private void ProcessPresetList(PresetTransportContainer container, bool ignoreOldBuiltIn)
+ private void ProcessPresetList(PresetTransportContainer container)
{
// The presets file loaded was OK, so process it.
foreach (var item in container.PresetList)
@@ -767,11 +748,6 @@ namespace HandBrakeWPF.Services.Presets {
Preset preset = JsonPresetFactory.ImportPreset(hbpreset);
- if (preset.IsBuildIn && ignoreOldBuiltIn)
- {
- continue;
- }
-
// Migration
preset.Category = category.PresetName == "User Presets" ? UserPresetCatgoryName : category.PresetName;
preset.IsBuildIn = hbpreset.Type == 0;
@@ -834,11 +810,9 @@ namespace HandBrakeWPF.Services.Presets // Wrap the categories in a container.
JsonSerializerSettings settings = new JsonSerializerSettings { MissingMemberHandling = MissingMemberHandling.Ignore };
- PresetTransportContainer container = new PresetTransportContainer(
- Constants.PresetVersionMajor,
- Constants.PresetVersionMinor,
- Constants.PresetVersionMicro)
- { PresetList = new List<object>() };
+
+ PresetVersion presetVersion = HandBrakePresetService.GetCurrentPresetVersion();
+ PresetTransportContainer container = new PresetTransportContainer(presetVersion.Major, presetVersion.Minor, presetVersion.Micro) { PresetList = new List<object>() };
container.PresetList.AddRange(presetCategories.Values);
container.PresetList.AddRange(uncategorisedPresets);
|