using HandBrakeWPF.Properties;\r
using HandBrakeWPF.Services.Encode.Model.Models;\r
using HandBrakeWPF.Services.Interfaces;\r
+ using HandBrakeWPF.Services.Logging;\r
+ using HandBrakeWPF.Services.Logging.Interfaces;\r
+ using HandBrakeWPF.Services.Logging.Model;\r
using HandBrakeWPF.Services.Presets.Factories;\r
using HandBrakeWPF.Services.Presets.Interfaces;\r
using HandBrakeWPF.Services.Presets.Model;\r
/// </summary>\r
public class PresetService : IPresetService\r
{\r
- // TODO Strip out the error handling from this service and let upstream UI layer handle it.\r
-\r
- #region Private Variables\r
-\r
public const int ForcePresetReset = 3;\r
public static string UserPresetCatgoryName = "Custom Presets";\r
private readonly string presetFile = Path.Combine(DirectoryUtilities.GetUserStoragePath(VersionHelper.IsNightly()), "presets.json");\r
private readonly List<Preset> flatPresetList = new List<Preset>();\r
private readonly IErrorService errorService;\r
private readonly IUserSettingService userSettingService;\r
+ private ILog log = LogService.GetLogger();\r
\r
- #endregion\r
\r
/// <summary>\r
/// Initializes a new instance of the <see cref="PresetService"/> class.\r
}\r
}\r
\r
- #region Public Methods\r
-\r
/// <summary>\r
/// The load.\r
/// </summary>\r
// Verify we have presets.\r
if (this.presets.Count == 0)\r
{\r
+ this.ServiceLogMessage("Failed to load built-in presets.");\r
throw new GeneralApplicationException("Failed to load built-in presets.", "Restarting HandBrake may resolve this issue", null);\r
}\r
\r
return categoriesList;\r
}\r
\r
- #endregion\r
-\r
- #region Private Helpers\r
-\r
/// <summary>\r
/// Recover from a corrupted preset file\r
/// Add .old to the current filename, and delete the current file.\r
\r
return disabledFile;\r
}\r
- catch (IOException)\r
+ catch (IOException e)\r
{\r
+ this.ServiceLogMessage(e.ToString());\r
// Give up\r
}\r
\r
}\r
catch (Exception exc)\r
{\r
- Debug.WriteLine("Failed to parse presets file: " + exc);\r
+ this.ServiceLogMessage("Corrupted Presets File Detected: " + Environment.NewLine + exc);\r
}\r
}\r
\r
// Sanity Check. Did the container deserialise.\r
- if (container == null || container.PresetList == null)\r
+ if (container?.PresetList == null)\r
{\r
+ this.ServiceLogMessage("Attempting Preset Recovery ...");\r
string filename = this.RecoverFromCorruptedPresetFile(this.presetFile);\r
this.errorService.ShowMessageBox(\r
Resources.PresetService_UnableToLoadPresets + filename,\r
MessageBoxImage.Exclamation);\r
\r
this.UpdateBuiltInPresets();\r
+ this.ServiceLogMessage("Recovery Completed!");\r
return; // Update built-in presets stores the presets locally, so just return.\r
}\r
\r
}\r
catch (Exception ex)\r
{\r
- Debug.WriteLine(ex);\r
+ this.ServiceLogMessage(ex.ToString());\r
this.RecoverFromCorruptedPresetFile(this.presetFile);\r
this.UpdateBuiltInPresets();\r
}\r
}\r
catch (Exception exc)\r
{\r
- Debug.WriteLine(exc);\r
throw new GeneralApplicationException("Unable to write to the presets file.", "The details section below may indicate why this error has occurred.", exc);\r
}\r
}\r
}\r
}\r
\r
- #endregion\r
+ protected void ServiceLogMessage(string message)\r
+ {\r
+ this.log.LogMessage(string.Format("Preset Service: {0}{1}{0}", Environment.NewLine, message), LogMessageType.Application, LogLevel.Info);\r
+ }\r
}\r
}
\ No newline at end of file