using System;\r
using System.Collections.Generic;\r
using System.Diagnostics;\r
+ using System.Globalization;\r
using System.IO;\r
using System.Text;\r
using System.Windows.Forms;\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) +\r
+ "\\HandBrake\\logs";\r
+\r
/// <summary>\r
/// The User Setting Service\r
/// </summary>\r
private static readonly IUserSettingService UserSettingService = IoC.Get<IUserSettingService>();\r
\r
/// <summary>\r
- /// The Default Log Directory\r
+ /// The Instance ID\r
+ /// </summary>\r
+ private static int instanceId = 0;\r
+\r
+ #endregion\r
+\r
+ #region Properties\r
+\r
+ /// <summary>\r
+ /// Gets the number of HandBrake instances running.\r
/// </summary>\r
- private static readonly string LogDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";\r
+ public static string GetInstanceCount\r
+ {\r
+ get\r
+ {\r
+ return instanceId == 0 ? string.Empty : instanceId.ToString(CultureInfo.InvariantCulture);\r
+ }\r
+ }\r
+\r
+ /// <summary>\r
+ /// Gets a value indicating whether HandBrake is running in multi instance mode\r
+ /// </summary>\r
+ /// <returns>True if the UI has another instance running</returns>\r
+ public static bool IsMultiInstance\r
+ {\r
+ get\r
+ {\r
+ return Process.GetProcessesByName("HandBrake").Length > 1 ? true : false;\r
+ }\r
+ }\r
+\r
+ #endregion\r
+\r
+ #region Public Methods\r
\r
/// <summary>\r
/// Clear all the log files older than 30 Days\r
if (Directory.Exists(LogDir))\r
{\r
// Get all the log files\r
- DirectoryInfo info = new DirectoryInfo(LogDir);\r
+ var info = new DirectoryInfo(LogDir);\r
FileInfo[] logFiles = info.GetFiles("*.txt");\r
\r
// Delete Them\r
}\r
}\r
\r
+ /// <summary>\r
+ /// Add the CLI Query to the Log File.\r
+ /// </summary>\r
+ /// <returns>\r
+ /// The create cli log header.\r
+ /// </returns>\r
+ public static StringBuilder CreateCliLogHeader()\r
+ {\r
+ var logHeader = new StringBuilder();\r
+\r
+ logHeader.AppendLine(\r
+ String.Format(\r
+ "HandBrake {0} {1}", \r
+ UserSettingService.GetUserSetting<string>(ASUserSettingConstants.HandBrakeVersion), \r
+ UserSettingService.GetUserSetting<int>(ASUserSettingConstants.HandBrakeBuild)));\r
+ logHeader.AppendLine(String.Format("OS: {0}", Environment.OSVersion));\r
+ logHeader.AppendLine(String.Format("CPU: {0}", SystemInfo.GetCpuCount));\r
+ logHeader.Append(String.Format("Ram: {0} MB, ", SystemInfo.TotalPhysicalMemory));\r
+ logHeader.AppendLine(\r
+ String.Format(\r
+ "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
+ /// Get the Process ID of HandBrakeCLI for the current instance.\r
+ /// </summary>\r
+ /// <returns>A list of processes</returns>\r
+ public static Process[] GetCliProcess()\r
+ {\r
+ return Process.GetProcessesByName("HandBrakeCLI");\r
+ }\r
+\r
/// <summary>\r
/// Get a list of available DVD drives which are ready and contain DVD content.\r
/// </summary>\r
/// <returns>A List of Drives with their details</returns>\r
public static List<DriveInformation> GetDrives()\r
{\r
- List<DriveInformation> drives = new List<DriveInformation>();\r
+ var drives = new List<DriveInformation>();\r
DriveInfo[] theCollectionOfDrives = DriveInfo.GetDrives();\r
int id = 0;\r
foreach (DriveInfo curDrive in theCollectionOfDrives)\r
{\r
if (curDrive.DriveType == DriveType.CDRom && curDrive.IsReady)\r
{\r
- if (Directory.Exists(curDrive.RootDirectory + "VIDEO_TS") || Directory.Exists(curDrive.RootDirectory + "BDMV"))\r
+ if (Directory.Exists(curDrive.RootDirectory + "VIDEO_TS") ||\r
+ Directory.Exists(curDrive.RootDirectory + "BDMV"))\r
{\r
drives.Add(\r
new DriveInformation\r
{\r
- Id = id,\r
- VolumeLabel = curDrive.VolumeLabel,\r
+ Id = id, \r
+ VolumeLabel = curDrive.VolumeLabel, \r
RootDirectory = curDrive.RootDirectory.ToString()\r
});\r
id++;\r
return drives;\r
}\r
\r
- /// <summary>\r
- /// Get the Process ID of HandBrakeCLI for the current instance.\r
- /// </summary>\r
- /// <returns>A list of processes</returns>\r
- public static Process[] GetCliProcess()\r
- {\r
- return Process.GetProcessesByName("HandBrakeCLI");\r
- }\r
-\r
- /// <summary>\r
- /// Add the CLI Query to the Log File.\r
- /// </summary>\r
- /// <returns>\r
- /// The create cli log header.\r
- /// </returns>\r
- public static StringBuilder CreateCliLogHeader()\r
- {\r
- StringBuilder logHeader = new StringBuilder();\r
-\r
- logHeader.AppendLine(String.Format("HandBrake {0} {1}", UserSettingService.GetUserSetting<string>(ASUserSettingConstants.HandBrakeVersion), UserSettingService.GetUserSetting<int>(ASUserSettingConstants.HandBrakeBuild)));\r
- logHeader.AppendLine(String.Format("OS: {0}", Environment.OSVersion));\r
- logHeader.AppendLine(String.Format("CPU: {0}", SystemInfo.GetCpuCount));\r
- logHeader.Append(String.Format("Ram: {0} MB, ", SystemInfo.TotalPhysicalMemory));\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">The Log Message</param>\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
}\r
\r
/// <summary>\r
- /// Gets a value indicating whether HandBrake is running in multi instance mode\r
+ /// Set the Instance ID\r
/// </summary>\r
- /// <returns>True if the UI has another instance running</returns>\r
- public static bool IsMultiInstance\r
+ public static void SetInstanceId()\r
{\r
- get\r
- {\r
- return Process.GetProcessesByName("HandBrake").Length > 1 ? true : false;\r
- }\r
- }\r
-\r
- /// <summary>\r
- /// Gets the number of HandBrake instances running.\r
- /// </summary>\r
- public static string GetInstanceCount\r
- {\r
- get\r
- {\r
- return Process.GetProcessesByName("HandBrake").Length == 0 ? string.Empty : Process.GetProcessesByName("HandBrake").Length.ToString();\r
- }\r
+ instanceId = Process.GetProcessesByName("HandBrake").Length;\r
}\r
+ #endregion\r
}\r
-}\r
+}
\ No newline at end of file