-// --------------------------------------------------------------------------------------------------------------------\r
-// <copyright file="GeneralApplicationException.cs" company="HandBrake Project (http://handbrake.fr)">\r
-// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.\r
-// </copyright>\r
-// <summary>\r
-// The Encode Failure Exception\r
-// </summary>\r
-// --------------------------------------------------------------------------------------------------------------------\r
-\r
-namespace HandBrake.ApplicationServices.Exceptions\r
-{\r
- using System;\r
-\r
- /// <summary>\r
- /// The Encode Failure Exception\r
- /// </summary>\r
- public class GeneralApplicationException : Exception\r
- {\r
- /// <summary>\r
- /// Initializes a new instance of the <see cref="GeneralApplicationException"/> class. \r
- /// </summary>\r
- /// <param name="error">\r
- /// The error.\r
- /// </param>\r
- /// <param name="solution">\r
- /// The solution.\r
- /// </param>\r
- /// <param name="innerException">\r
- /// The inner Exception.\r
- /// </param>\r
- public GeneralApplicationException(string error, string solution, Exception innerException)\r
- {\r
- this.Error = error;\r
- this.Solution = solution;\r
- this.ActualException = innerException;\r
- }\r
-\r
- /// <summary>\r
- /// Gets or sets FailureReason.\r
- /// </summary>\r
- public string Error { get; set; }\r
-\r
- /// <summary>\r
- /// Gets or sets Solution.\r
- /// </summary>\r
- public string Solution { get; set; }\r
-\r
- /// <summary>\r
- /// Gets or sets InnerException.\r
- /// </summary>\r
- public Exception ActualException { get; set; }\r
- }\r
-}\r
+// --------------------------------------------------------------------------------------------------------------------
+// <copyright file="GeneralApplicationException.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>
+// The Encode Failure Exception
+// </summary>
+// --------------------------------------------------------------------------------------------------------------------
+
+namespace HandBrakeWPF.Exceptions
+{
+ using System;
+
+ /// <summary>
+ /// The Encode Failure Exception
+ /// </summary>
+ public class GeneralApplicationException : Exception
+ {
+ /// <summary>
+ /// Initializes a new instance of the <see cref="GeneralApplicationException"/> class.
+ /// </summary>
+ /// <param name="error">
+ /// The error.
+ /// </param>
+ /// <param name="solution">
+ /// The solution.
+ /// </param>
+ /// <param name="innerException">
+ /// The inner Exception.
+ /// </param>
+ public GeneralApplicationException(string error, string solution, Exception innerException)
+ {
+ this.Error = error;
+ this.Solution = solution;
+ this.ActualException = innerException;
+ }
+
+ /// <summary>
+ /// Gets or sets FailureReason.
+ /// </summary>
+ public string Error { get; set; }
+
+ /// <summary>
+ /// Gets or sets Solution.
+ /// </summary>
+ public string Solution { get; set; }
+
+ /// <summary>
+ /// Gets or sets InnerException.
+ /// </summary>
+ public Exception ActualException { get; set; }
+ }
+}
-// --------------------------------------------------------------------------------------------------------------------\r
-// <copyright file="GeneralUtilities.cs" company="HandBrake Project (http://handbrake.fr)">\r
-// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.\r
-// </copyright>\r
-// <summary>\r
-// A Set of Static Utilites\r
-// </summary>\r
-// --------------------------------------------------------------------------------------------------------------------\r
-\r
-namespace HandBrake.ApplicationServices.Utilities\r
-{\r
- using System;\r
- using System.Collections.Generic;\r
- using System.Diagnostics;\r
- using System.IO;\r
- using System.Linq;\r
- using System.Text;\r
- using System.Windows.Forms;\r
-\r
- /// <summary>\r
- /// A Set of Static Utilites\r
- /// </summary>\r
- public class GeneralUtilities\r
- {\r
- #region Constants and Fields\r
-\r
- /// <summary>\r
- /// The Default Log Directory\r
- /// </summary>\r
- private static readonly string LogDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";\r
-\r
- #endregion\r
-\r
- #region Properties\r
-\r
- /// <summary>\r
- /// Gets the number of HandBrake instances running.\r
- /// </summary>\r
- public static int ProcessId\r
- {\r
- get\r
- {\r
- return Process.GetCurrentProcess().Id;\r
- }\r
- }\r
-\r
- #endregion\r
-\r
- #region Public Methods\r
-\r
- /// <summary>\r
- /// Clear all the log files older than 30 Days\r
- /// </summary>\r
- /// <param name="daysToKeep">\r
- /// The Number of Days to Keep\r
- /// </param>\r
- public static void ClearLogFiles(int daysToKeep)\r
- {\r
- if (Directory.Exists(LogDir))\r
- {\r
- // Get all the log files\r
- var info = new DirectoryInfo(LogDir);\r
- FileInfo[] logFiles = info.GetFiles("*.txt");\r
-\r
- // Delete old and excessivly large files (> ~50MB).\r
- foreach (FileInfo file in logFiles)\r
- {\r
- try\r
- {\r
- if (file.LastWriteTime < DateTime.Now.AddDays(-daysToKeep))\r
- {\r
- File.Delete(file.FullName);\r
- }\r
- else if (file.Length > 50000000)\r
- {\r
- File.Delete(file.FullName);\r
- }\r
- }\r
- catch (Exception)\r
- {\r
- // Silently ignore files we can't delete. They are probably being used by the app right now.\r
- }\r
- }\r
- }\r
- }\r
-\r
- /// <summary>\r
- /// Generate the header for the log file.\r
- /// </summary>\r
- /// <returns>\r
- /// The generatedlog header.\r
- /// </returns>\r
- public static StringBuilder CreateLogHeader()\r
- {\r
- var logHeader = new StringBuilder();\r
-\r
- StringBuilder gpuBuilder = new StringBuilder();\r
- foreach (var item in SystemInfo.GetGPUInfo)\r
- {\r
- gpuBuilder.AppendLine(string.Format(" {0}", item));\r
- }\r
-\r
- if (string.IsNullOrEmpty(gpuBuilder.ToString().Trim()))\r
- {\r
- gpuBuilder.Append("GPU Information is unavailable");\r
- }\r
-\r
- logHeader.AppendLine(String.Format("HandBrake {0} - {1}", VersionHelper.GetVersion(), VersionHelper.GetPlatformBitnessVersion()));\r
- logHeader.AppendLine(String.Format("OS: {0} - {1}", Environment.OSVersion, Environment.Is64BitOperatingSystem ? "64bit" : "32bit"));\r
- logHeader.AppendLine(String.Format("CPU: {0}", SystemInfo.GetCpuCount));\r
- logHeader.AppendLine(String.Format("Ram: {0} MB, ", SystemInfo.TotalPhysicalMemory));\r
- logHeader.AppendLine(String.Format("GPU Information:{0}{1}", Environment.NewLine, gpuBuilder.ToString().TrimEnd()));\r
- logHeader.AppendLine(String.Format("Screen: {0}x{1}", SystemInfo.ScreenBounds.Bounds.Width, SystemInfo.ScreenBounds.Bounds.Height));\r
- logHeader.AppendLine(String.Format("Temp Dir: {0}", Path.GetTempPath()));\r
- logHeader.AppendLine(String.Format("Install Dir: {0}", Application.StartupPath));\r
- logHeader.AppendLine(String.Format("Data Dir: {0}\n", Application.UserAppDataPath));\r
-\r
- logHeader.AppendLine("-------------------------------------------");\r
-\r
- return logHeader;\r
- }\r
-\r
- /// <summary>\r
- /// Return the standard log format line of text for a given log message\r
- /// </summary>\r
- /// <param name="message">\r
- /// The Log Message\r
- /// </param>\r
- /// <returns>\r
- /// A Log Message in the format: "[hh:mm:ss] message"\r
- /// </returns>\r
- public static string LogLine(string message)\r
- {\r
- return string.Format("[{0}] {1}", DateTime.Now.TimeOfDay, message);\r
- }\r
-\r
- /// <summary>\r
- /// The find hand brake instance ids.\r
- /// </summary>\r
- /// <param name="id">\r
- /// The id.\r
- /// </param>\r
- /// <returns>\r
- /// The <see cref="bool"/>. True if it's a running HandBrake instance.\r
- /// </returns>\r
- public static bool IsPidACurrentHandBrakeInstance(int id)\r
- {\r
- List<int> ids = Process.GetProcessesByName("HandBrake").Select(process => process.Id).ToList();\r
- return ids.Contains(id);\r
- }\r
-\r
- #endregion\r
- }\r
+// --------------------------------------------------------------------------------------------------------------------
+// <copyright file="GeneralUtilities.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>
+// A Set of Static Utilites
+// </summary>
+// --------------------------------------------------------------------------------------------------------------------
+
+namespace HandBrakeWPF.Utilities
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Diagnostics;
+ using System.IO;
+ using System.Linq;
+ using System.Text;
+ using System.Windows.Forms;
+
+ using HandBrake.ApplicationServices.Utilities;
+
+ /// <summary>
+ /// A Set of Static Utilites
+ /// </summary>
+ public class GeneralUtilities
+ {
+ #region Constants and Fields
+
+ /// <summary>
+ /// The Default Log Directory
+ /// </summary>
+ private static readonly string LogDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";
+
+ #endregion
+
+ #region Properties
+
+ /// <summary>
+ /// Gets the number of HandBrake instances running.
+ /// </summary>
+ public static int ProcessId
+ {
+ get
+ {
+ return Process.GetCurrentProcess().Id;
+ }
+ }
+
+ #endregion
+
+ #region Public Methods
+
+ /// <summary>
+ /// Clear all the log files older than 30 Days
+ /// </summary>
+ /// <param name="daysToKeep">
+ /// The Number of Days to Keep
+ /// </param>
+ public static void ClearLogFiles(int daysToKeep)
+ {
+ if (Directory.Exists(LogDir))
+ {
+ // Get all the log files
+ var info = new DirectoryInfo(LogDir);
+ FileInfo[] logFiles = info.GetFiles("*.txt");
+
+ // Delete old and excessivly large files (> ~50MB).
+ foreach (FileInfo file in logFiles)
+ {
+ try
+ {
+ if (file.LastWriteTime < DateTime.Now.AddDays(-daysToKeep))
+ {
+ File.Delete(file.FullName);
+ }
+ else if (file.Length > 50000000)
+ {
+ File.Delete(file.FullName);
+ }
+ }
+ catch (Exception)
+ {
+ // Silently ignore files we can't delete. They are probably being used by the app right now.
+ }
+ }
+ }
+ }
+
+ /// <summary>
+ /// Generate the header for the log file.
+ /// </summary>
+ /// <returns>
+ /// The generatedlog header.
+ /// </returns>
+ public static StringBuilder CreateLogHeader()
+ {
+ var logHeader = new StringBuilder();
+
+ StringBuilder gpuBuilder = new StringBuilder();
+ foreach (var item in SystemInfo.GetGPUInfo)
+ {
+ gpuBuilder.AppendLine(string.Format(" {0}", item));
+ }
+
+ if (string.IsNullOrEmpty(gpuBuilder.ToString().Trim()))
+ {
+ gpuBuilder.Append("GPU Information is unavailable");
+ }
+
+ logHeader.AppendLine(String.Format("HandBrake {0} - {1}", VersionHelper.GetVersion(), VersionHelper.GetPlatformBitnessVersion()));
+ logHeader.AppendLine(String.Format("OS: {0} - {1}", Environment.OSVersion, Environment.Is64BitOperatingSystem ? "64bit" : "32bit"));
+ logHeader.AppendLine(String.Format("CPU: {0}", SystemInfo.GetCpuCount));
+ logHeader.AppendLine(String.Format("Ram: {0} MB, ", SystemInfo.TotalPhysicalMemory));
+ logHeader.AppendLine(String.Format("GPU Information:{0}{1}", Environment.NewLine, gpuBuilder.ToString().TrimEnd()));
+ logHeader.AppendLine(String.Format("Screen: {0}x{1}", SystemInfo.ScreenBounds.Bounds.Width, SystemInfo.ScreenBounds.Bounds.Height));
+ logHeader.AppendLine(String.Format("Temp Dir: {0}", Path.GetTempPath()));
+ logHeader.AppendLine(String.Format("Install Dir: {0}", Application.StartupPath));
+ logHeader.AppendLine(String.Format("Data Dir: {0}\n", Application.UserAppDataPath));
+
+ logHeader.AppendLine("-------------------------------------------");
+
+ return logHeader;
+ }
+
+ /// <summary>
+ /// Return the standard log format line of text for a given log message
+ /// </summary>
+ /// <param name="message">
+ /// The Log Message
+ /// </param>
+ /// <returns>
+ /// A Log Message in the format: "[hh:mm:ss] message"
+ /// </returns>
+ public static string LogLine(string message)
+ {
+ return string.Format("[{0}] {1}", DateTime.Now.TimeOfDay, message);
+ }
+
+ /// <summary>
+ /// The find hand brake instance ids.
+ /// </summary>
+ /// <param name="id">
+ /// The id.
+ /// </param>
+ /// <returns>
+ /// The <see cref="bool"/>. True if it's a running HandBrake instance.
+ /// </returns>
+ public static bool IsPidACurrentHandBrakeInstance(int id)
+ {
+ List<int> ids = Process.GetProcessesByName("HandBrake").Select(process => process.Id).ToList();
+ return ids.Contains(id);
+ }
+
+ #endregion
+ }
}
\ No newline at end of file