<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" />
using HandBrake.Interop.Interop.HbLib;
using HandBrake.Interop.Interop.Helpers;
using HandBrake.Interop.Interop.Json.Presets;
+ using HandBrake.Interop.Interop.Model;
using Newtonsoft.Json;
/// <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);
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);
+ }
}
}
// 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);
}
}
/// <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;
/// <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; }
}
}
--- /dev/null
+// --------------------------------------------------------------------------------------------------------------------
+// <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; }
+ }
+}
public const string SourcePath = "{source_path}";\r
public const string SourceFolderName = "{source_folder_name}";\r
\r
- /* Preset Versions */\r
- public const string PresetVersionMajor = "35";\r
- public const string PresetVersionMinor = "0";\r
- public const string PresetVersionMicro = "0";\r
-\r
public const string FileScanMru = "FileScanMru";\r
public const string FileSaveMru = "FileSaveMru";\r
}\r
}
}
- /// <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>
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
: 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>
<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>
<data name="CollisionBehaviour_AppendNumber" xml:space="preserve">
<value>Zahl anhängen</value>
</data>
-</root>
+</root>
\ No newline at end of file
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
: 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>
<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>
<data name="CollisionBehaviour_AppendNumber" xml:space="preserve">
<value>Append Number</value>
</data>
-</root>
+</root>
\ No newline at end of file
<data name="PresetService_ArchiveFile" xml:space="preserve">\r
<value>Archived File:</value>\r
</data>\r
- <data name="PresetService_PresetsOutOfDate" xml:space="preserve">\r
- <value>HandBrake has detected your presets file is from an older version.\r
-It will try and load the file anyway.\r
-If it fails, it will archive off the old file and create a new one.</value>\r
- </data>\r
<data name="PresetService_UnableToLoad" xml:space="preserve">\r
<value>Unable to load presets.</value>\r
</data>\r
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
: 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>
<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>
<data name="CollisionBehaviour_AppendNumber" xml:space="preserve">
<value>Append Number</value>
</data>
-</root>
+</root>
\ No newline at end of file
/// </returns>\r
public static PresetTransportContainer ExportPreset(Preset export, HBConfiguration config)\r
{\r
- PresetTransportContainer container = new PresetTransportContainer();\r
- container.VersionMajor = Constants.PresetVersionMajor;\r
- container.VersionMinor = Constants.PresetVersionMinor;\r
- container.VersionMicro = Constants.PresetVersionMicro;\r
+ PresetVersion presetVersion = HandBrakePresetService.GetCurrentPresetVersion();\r
+ PresetTransportContainer container = new PresetTransportContainer(presetVersion.Major, presetVersion.Minor, presetVersion.Micro);\r
\r
container.PresetList = new List<object> { CreateHbPreset(export, config) };\r
\r
/// <returns>A list of JSON object presets.</returns>\r
public static PresetTransportContainer ExportPresets(IEnumerable<Preset> exportList, HBConfiguration config)\r
{\r
- PresetTransportContainer container = new PresetTransportContainer();\r
- container.VersionMajor = Constants.PresetVersionMajor;\r
- container.VersionMinor = Constants.PresetVersionMinor;\r
- container.VersionMicro = Constants.PresetVersionMicro;\r
+ PresetVersion presetVersion = HandBrakePresetService.GetCurrentPresetVersion();\r
+ PresetTransportContainer container = new PresetTransportContainer(presetVersion.Major, presetVersion.Minor, presetVersion.Micro);\r
\r
List<HBPreset> presets = exportList.Select(item => CreateHbPreset(item, config)).ToList();\r
\r
\r
using HandBrake.Interop.Interop;\r
using HandBrake.Interop.Interop.Json.Presets;\r
+ using HandBrake.Interop.Interop.Model;\r
using HandBrake.Interop.Model;\r
using HandBrake.Interop.Utilities;\r
\r
PresetTransportContainer container = null;\r
try\r
{\r
- container = HandBrakePresetService.GetPresetFromFile(filename);\r
+ container = HandBrakePresetService.GetPresetsFromFile(filename);\r
}\r
catch (Exception exc)\r
{\r
\r
// Otherwise, we already have a file, so lets try load it.\r
PresetTransportContainer container = null;\r
- using (StreamReader reader = new StreamReader(this.presetFile))\r
+ try\r
{\r
- try\r
- {\r
- container = JsonConvert.DeserializeObject<PresetTransportContainer>(reader.ReadToEnd());\r
- }\r
- catch (Exception exc)\r
- {\r
- this.ServiceLogMessage("Corrupted Presets File Detected: " + Environment.NewLine + exc);\r
- }\r
+ container = HandBrakePresetService.GetPresetsFromFile(this.presetFile);\r
+ }\r
+ catch (Exception exc)\r
+ {\r
+ this.ServiceLogMessage("Corrupted Presets File Detected: " + Environment.NewLine + exc);\r
}\r
\r
// Sanity Check. Did the container deserialise.\r
return; // Update built-in presets stores the presets locally, so just return.\r
}\r
\r
- // Version Check\r
- // If we have old presets, or the container wasn't parseable, or we have a version mismatch, backup the user preset file \r
- // incase something goes wrong and reset built-in presets, then re-save.\r
- bool ignoreBuildIn = false;\r
- if (container.VersionMajor != Constants.PresetVersionMajor || container.VersionMinor != Constants.PresetVersionMinor || container.VersionMicro != Constants.PresetVersionMicro)\r
- {\r
- string fileName = this.ArchivePresetFile(this.presetFile);\r
- this.errorService.ShowMessageBox(\r
- Resources.PresetService_PresetsOutOfDate\r
- + Environment.NewLine + Environment.NewLine + Resources.PresetService_ArchiveFile + fileName,\r
- Resources.PresetService_UnableToLoad,\r
- MessageBoxButton.OK,\r
- MessageBoxImage.Information);\r
- this.UpdateBuiltInPresets(); // Update built-in presets stores the presets locally, so just return.\r
- ignoreBuildIn = true;\r
- }\r
-\r
// Force Upgrade of presets\r
if (this.userSettingService.GetUserSetting<int>(UserSettingConstants.ForcePresetReset, typeof(int)) < ForcePresetReset)\r
{\r
return;\r
}\r
\r
- this.ProcessPresetList(container, ignoreBuildIn);\r
+ this.ProcessPresetList(container);\r
}\r
catch (Exception ex)\r
{\r
}\r
}\r
\r
- private void ProcessPresetList(PresetTransportContainer container, bool ignoreOldBuiltIn)\r
+ private void ProcessPresetList(PresetTransportContainer container)\r
{\r
// The presets file loaded was OK, so process it.\r
foreach (var item in container.PresetList)\r
{\r
Preset preset = JsonPresetFactory.ImportPreset(hbpreset);\r
\r
- if (preset.IsBuildIn && ignoreOldBuiltIn)\r
- {\r
- continue;\r
- }\r
-\r
// Migration\r
preset.Category = category.PresetName == "User Presets" ? UserPresetCatgoryName : category.PresetName;\r
preset.IsBuildIn = hbpreset.Type == 0;\r
\r
// Wrap the categories in a container. \r
JsonSerializerSettings settings = new JsonSerializerSettings { MissingMemberHandling = MissingMemberHandling.Ignore };\r
- PresetTransportContainer container = new PresetTransportContainer(\r
- Constants.PresetVersionMajor,\r
- Constants.PresetVersionMinor,\r
- Constants.PresetVersionMicro)\r
- { PresetList = new List<object>() };\r
+\r
+ PresetVersion presetVersion = HandBrakePresetService.GetCurrentPresetVersion();\r
+ PresetTransportContainer container = new PresetTransportContainer(presetVersion.Major, presetVersion.Minor, presetVersion.Micro) { PresetList = new List<object>() };\r
container.PresetList.AddRange(presetCategories.Values);\r
container.PresetList.AddRange(uncategorisedPresets);\r
\r