// --------------------------------------------------------------------------------------------------------------------
//
// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
//
//
// The hand brake preset service.
//
// --------------------------------------------------------------------------------------------------------------------
namespace HandBrake.ApplicationServices.Interop
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using HandBrake.ApplicationServices.Interop.HbLib;
using HandBrake.ApplicationServices.Interop.Helpers;
using HandBrake.ApplicationServices.Interop.Json.Presets;
using HandBrake.ApplicationServices.Services.Logging;
using HandBrake.ApplicationServices.Services.Logging.Interfaces;
using HandBrake.ApplicationServices.Services.Logging.Model;
using Newtonsoft.Json;
///
/// The hand brake preset service.
///
public class HandBrakePresetService
{
private static readonly ILog log = LogService.GetLogger();
///
/// The get built in presets.
/// Requires an hb_init to have been invoked.
///
///
/// The .
///
public static IList GetBuiltInPresets()
{
IntPtr presets = HBFunctions.hb_presets_builtin_get_json();
string presetJson = Marshal.PtrToStringAnsi(presets);
log.LogMessage(presetJson, LogMessageType.API, LogLevel.Debug);
IList presetList = JsonConvert.DeserializeObject>(presetJson);
return presetList;
}
///
/// The get preset from file.
///
///
/// The filename.
///
///
/// The .
///
public static PresetTransportContainer GetPresetFromFile(string filename)
{
IntPtr presetStringPointer = HBFunctions.hb_presets_read_file_json(InteropUtilities.ToUtf8PtrFromString(filename));
string presetJson = Marshal.PtrToStringAnsi(presetStringPointer);
log.LogMessage(presetJson, LogMessageType.API, LogLevel.Debug);
PresetTransportContainer preset = JsonConvert.DeserializeObject(presetJson);
return preset;
}
///
/// The export preset.
///
///
/// The filename.
///
///
/// The container.
///
public static void ExportPreset(string filename, PresetTransportContainer container)
{
string preset = JsonConvert.SerializeObject(container, Formatting.Indented);
using (StreamWriter writer = new StreamWriter(filename))
{
writer.Write(preset);
}
}
}
}