]> granicus.if.org Git - handbrake/commitdiff
WinGui: Additional fixes for multi-instance.
authorsr55 <sr55.hb@outlook.com>
Sat, 7 Jul 2012 15:49:55 +0000 (15:49 +0000)
committersr55 <sr55.hb@outlook.com>
Sat, 7 Jul 2012 15:49:55 +0000 (15:49 +0000)
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4819 b64f7644-9d1e-0410-96f1-a4d463321fa5

win/CS/HandBrake.ApplicationServices/Services/Interfaces/IQueueManager.cs
win/CS/HandBrake.ApplicationServices/Services/QueueManager.cs
win/CS/HandBrake.ApplicationServices/Services/ScanService.cs
win/CS/HandBrake.ApplicationServices/Utilities/GeneralUtilities.cs
win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs

index e86b5fe7c1661bf1d27105b2af11f78c0e71722b..0ae6bf518bb53794413bcf163c546af248fa6bc6 100644 (file)
@@ -131,5 +131,10 @@ namespace HandBrake.ApplicationServices.Services.Interfaces
         /// True if sucessful\r
         /// </returns>\r
         bool WriteBatchScriptToFile(string path);\r
+\r
+        /// <summary>\r
+        /// Temp workaround until this can be fixed properly.\r
+        /// </summary>\r
+        void ResetInstanceId();\r
     }\r
 }
\ No newline at end of file
index 452f47365142c846bca5aaff1637d2ec017db271..abe684a171d242cb3ea9e2fb76421778f406faa0 100644 (file)
@@ -54,7 +54,7 @@ namespace HandBrake.ApplicationServices.Services
         /// <summary>\r
         /// HandBrakes Queue file with a place holder for an extra string.\r
         /// </summary>\r
-        private readonly string queueFile;\r
+        private string queueFile;\r
 \r
         #endregion\r
 \r
@@ -408,6 +408,14 @@ namespace HandBrake.ApplicationServices.Services
             return false;\r
         }\r
 \r
+        /// <summary>\r
+        /// Temp workaround until this can be fixed properly.\r
+        /// </summary>\r
+        public void ResetInstanceId()\r
+        {\r
+            this.queueFile = string.Format("hb_queue_recovery{0}.xml", GeneralUtilities.GetInstanceCount);\r
+        }\r
+\r
         #endregion\r
     }\r
 }\r
index fc8bb3f632cdb85d0cafe5cecb80ae4b3279f3bd..742a46b088dc805a4ae1e7a0444801d87882062a 100644 (file)
@@ -25,7 +25,7 @@ namespace HandBrake.ApplicationServices.Services
     /// <summary>\r
     /// Scan a Source\r
     /// </summary>\r
-    public class  ScanService : IScan\r
+    public class ScanService : IScan\r
     {\r
         #region Private Variables\r
 \r
index 34a078a7c357a50812f7cece1456c95652e25c53..773de5bfcacb4f0f6a981bdc09de6aad1f1084ab 100644 (file)
@@ -12,6 +12,7 @@ namespace HandBrake.ApplicationServices.Utilities
     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
@@ -27,15 +28,54 @@ namespace HandBrake.ApplicationServices.Utilities
     /// </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
@@ -48,7 +88,7 @@ namespace HandBrake.ApplicationServices.Utilities
             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
@@ -69,26 +109,66 @@ namespace HandBrake.ApplicationServices.Utilities
             }\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
@@ -99,43 +179,12 @@ namespace HandBrake.ApplicationServices.Utilities
             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
@@ -145,26 +194,12 @@ namespace HandBrake.ApplicationServices.Utilities
         }\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
index 44dc15effa71d98973390df5171b6fd41f6a92b1..d63915624838a6c64c956b892c96445b01a70130 100644 (file)
@@ -181,6 +181,9 @@ namespace HandBrakeWPF.ViewModels
         public MainViewModel(IWindowManager windowManager, IUserSettingService userSettingService, IScan scanService, IEncode encodeService, IPresetService presetService,\r
             IErrorService errorService, IShellViewModel shellViewModel, IUpdateService updateService)\r
         {\r
+            GeneralUtilities.SetInstanceId();\r
+            \r
+\r
             this.scanService = scanService;\r
             this.encodeService = encodeService;\r
             this.presetService = presetService;\r
@@ -189,6 +192,7 @@ namespace HandBrakeWPF.ViewModels
             this.updateService = updateService;\r
             this.userSettingService = userSettingService;\r
             this.queueProcessor = IoC.Get<IQueueProcessor>();\r
+            queueProcessor.QueueManager.ResetInstanceId();\r
 \r
             // Setup Properties\r
             this.WindowTitle = "HandBrake";\r