From 7746907bf0ae4ef3f02aaa28a34a493dade912a2 Mon Sep 17 00:00:00 2001 From: sr55 Date: Sat, 7 Jul 2012 15:49:55 +0000 Subject: WinGui: Additional fixes for multi-instance. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4819 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- .../Services/Interfaces/IQueueManager.cs | 5 + .../Services/QueueManager.cs | 10 +- .../Services/ScanService.cs | 2 +- .../Utilities/GeneralUtilities.cs | 155 +++++++++++++-------- win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs | 4 + 5 files changed, 114 insertions(+), 62 deletions(-) (limited to 'win/CS') diff --git a/win/CS/HandBrake.ApplicationServices/Services/Interfaces/IQueueManager.cs b/win/CS/HandBrake.ApplicationServices/Services/Interfaces/IQueueManager.cs index e86b5fe7c..0ae6bf518 100644 --- a/win/CS/HandBrake.ApplicationServices/Services/Interfaces/IQueueManager.cs +++ b/win/CS/HandBrake.ApplicationServices/Services/Interfaces/IQueueManager.cs @@ -131,5 +131,10 @@ namespace HandBrake.ApplicationServices.Services.Interfaces /// True if sucessful /// bool WriteBatchScriptToFile(string path); + + /// + /// Temp workaround until this can be fixed properly. + /// + void ResetInstanceId(); } } \ No newline at end of file diff --git a/win/CS/HandBrake.ApplicationServices/Services/QueueManager.cs b/win/CS/HandBrake.ApplicationServices/Services/QueueManager.cs index 452f47365..abe684a17 100644 --- a/win/CS/HandBrake.ApplicationServices/Services/QueueManager.cs +++ b/win/CS/HandBrake.ApplicationServices/Services/QueueManager.cs @@ -54,7 +54,7 @@ namespace HandBrake.ApplicationServices.Services /// /// HandBrakes Queue file with a place holder for an extra string. /// - private readonly string queueFile; + private string queueFile; #endregion @@ -408,6 +408,14 @@ namespace HandBrake.ApplicationServices.Services return false; } + /// + /// Temp workaround until this can be fixed properly. + /// + public void ResetInstanceId() + { + this.queueFile = string.Format("hb_queue_recovery{0}.xml", GeneralUtilities.GetInstanceCount); + } + #endregion } } diff --git a/win/CS/HandBrake.ApplicationServices/Services/ScanService.cs b/win/CS/HandBrake.ApplicationServices/Services/ScanService.cs index fc8bb3f63..742a46b08 100644 --- a/win/CS/HandBrake.ApplicationServices/Services/ScanService.cs +++ b/win/CS/HandBrake.ApplicationServices/Services/ScanService.cs @@ -25,7 +25,7 @@ namespace HandBrake.ApplicationServices.Services /// /// Scan a Source /// - public class ScanService : IScan + public class ScanService : IScan { #region Private Variables diff --git a/win/CS/HandBrake.ApplicationServices/Utilities/GeneralUtilities.cs b/win/CS/HandBrake.ApplicationServices/Utilities/GeneralUtilities.cs index 34a078a7c..773de5bfc 100644 --- a/win/CS/HandBrake.ApplicationServices/Utilities/GeneralUtilities.cs +++ b/win/CS/HandBrake.ApplicationServices/Utilities/GeneralUtilities.cs @@ -12,6 +12,7 @@ namespace HandBrake.ApplicationServices.Utilities using System; using System.Collections.Generic; using System.Diagnostics; + using System.Globalization; using System.IO; using System.Text; using System.Windows.Forms; @@ -27,15 +28,54 @@ namespace HandBrake.ApplicationServices.Utilities /// public class GeneralUtilities { + #region Constants and Fields + + /// + /// The Default Log Directory + /// + private static readonly string LogDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + + "\\HandBrake\\logs"; + /// /// The User Setting Service /// private static readonly IUserSettingService UserSettingService = IoC.Get(); /// - /// The Default Log Directory + /// The Instance ID + /// + private static int instanceId = 0; + + #endregion + + #region Properties + + /// + /// Gets the number of HandBrake instances running. /// - private static readonly string LogDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs"; + public static string GetInstanceCount + { + get + { + return instanceId == 0 ? string.Empty : instanceId.ToString(CultureInfo.InvariantCulture); + } + } + + /// + /// Gets a value indicating whether HandBrake is running in multi instance mode + /// + /// True if the UI has another instance running + public static bool IsMultiInstance + { + get + { + return Process.GetProcessesByName("HandBrake").Length > 1 ? true : false; + } + } + + #endregion + + #region Public Methods /// /// Clear all the log files older than 30 Days @@ -48,7 +88,7 @@ namespace HandBrake.ApplicationServices.Utilities if (Directory.Exists(LogDir)) { // Get all the log files - DirectoryInfo info = new DirectoryInfo(LogDir); + var info = new DirectoryInfo(LogDir); FileInfo[] logFiles = info.GetFiles("*.txt"); // Delete Them @@ -69,26 +109,66 @@ namespace HandBrake.ApplicationServices.Utilities } } + /// + /// Add the CLI Query to the Log File. + /// + /// + /// The create cli log header. + /// + public static StringBuilder CreateCliLogHeader() + { + var logHeader = new StringBuilder(); + + logHeader.AppendLine( + String.Format( + "HandBrake {0} {1}", + UserSettingService.GetUserSetting(ASUserSettingConstants.HandBrakeVersion), + UserSettingService.GetUserSetting(ASUserSettingConstants.HandBrakeBuild))); + logHeader.AppendLine(String.Format("OS: {0}", Environment.OSVersion)); + logHeader.AppendLine(String.Format("CPU: {0}", SystemInfo.GetCpuCount)); + logHeader.Append(String.Format("Ram: {0} MB, ", SystemInfo.TotalPhysicalMemory)); + 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; + } + + /// + /// Get the Process ID of HandBrakeCLI for the current instance. + /// + /// A list of processes + public static Process[] GetCliProcess() + { + return Process.GetProcessesByName("HandBrakeCLI"); + } + /// /// Get a list of available DVD drives which are ready and contain DVD content. /// /// A List of Drives with their details public static List GetDrives() { - List drives = new List(); + var drives = new List(); DriveInfo[] theCollectionOfDrives = DriveInfo.GetDrives(); int id = 0; foreach (DriveInfo curDrive in theCollectionOfDrives) { if (curDrive.DriveType == DriveType.CDRom && curDrive.IsReady) { - if (Directory.Exists(curDrive.RootDirectory + "VIDEO_TS") || Directory.Exists(curDrive.RootDirectory + "BDMV")) + if (Directory.Exists(curDrive.RootDirectory + "VIDEO_TS") || + Directory.Exists(curDrive.RootDirectory + "BDMV")) { drives.Add( new DriveInformation { - Id = id, - VolumeLabel = curDrive.VolumeLabel, + Id = id, + VolumeLabel = curDrive.VolumeLabel, RootDirectory = curDrive.RootDirectory.ToString() }); id++; @@ -99,43 +179,12 @@ namespace HandBrake.ApplicationServices.Utilities return drives; } - /// - /// Get the Process ID of HandBrakeCLI for the current instance. - /// - /// A list of processes - public static Process[] GetCliProcess() - { - return Process.GetProcessesByName("HandBrakeCLI"); - } - - /// - /// Add the CLI Query to the Log File. - /// - /// - /// The create cli log header. - /// - public static StringBuilder CreateCliLogHeader() - { - StringBuilder logHeader = new StringBuilder(); - - logHeader.AppendLine(String.Format("HandBrake {0} {1}", UserSettingService.GetUserSetting(ASUserSettingConstants.HandBrakeVersion), UserSettingService.GetUserSetting(ASUserSettingConstants.HandBrakeBuild))); - logHeader.AppendLine(String.Format("OS: {0}", Environment.OSVersion)); - logHeader.AppendLine(String.Format("CPU: {0}", SystemInfo.GetCpuCount)); - logHeader.Append(String.Format("Ram: {0} MB, ", SystemInfo.TotalPhysicalMemory)); - 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; - } - /// /// Return the standard log format line of text for a given log message /// - /// The Log Message + /// + /// The Log Message + /// /// /// A Log Message in the format: "[hh:mm:ss] message" /// @@ -145,26 +194,12 @@ namespace HandBrake.ApplicationServices.Utilities } /// - /// Gets a value indicating whether HandBrake is running in multi instance mode + /// Set the Instance ID /// - /// True if the UI has another instance running - public static bool IsMultiInstance + public static void SetInstanceId() { - get - { - return Process.GetProcessesByName("HandBrake").Length > 1 ? true : false; - } - } - - /// - /// Gets the number of HandBrake instances running. - /// - public static string GetInstanceCount - { - get - { - return Process.GetProcessesByName("HandBrake").Length == 0 ? string.Empty : Process.GetProcessesByName("HandBrake").Length.ToString(); - } + instanceId = Process.GetProcessesByName("HandBrake").Length; } + #endregion } -} +} \ No newline at end of file diff --git a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs index 44dc15eff..d63915624 100644 --- a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs @@ -181,6 +181,9 @@ namespace HandBrakeWPF.ViewModels public MainViewModel(IWindowManager windowManager, IUserSettingService userSettingService, IScan scanService, IEncode encodeService, IPresetService presetService, IErrorService errorService, IShellViewModel shellViewModel, IUpdateService updateService) { + GeneralUtilities.SetInstanceId(); + + this.scanService = scanService; this.encodeService = encodeService; this.presetService = presetService; @@ -189,6 +192,7 @@ namespace HandBrakeWPF.ViewModels this.updateService = updateService; this.userSettingService = userSettingService; this.queueProcessor = IoC.Get(); + queueProcessor.QueueManager.ResetInstanceId(); // Setup Properties this.WindowTitle = "HandBrake"; -- cgit v1.2.3