]> granicus.if.org Git - handbrake/commitdiff
WinGui: Add a log message whent he queue is paused due to low disk space. Improve...
authorsr55 <sr55.hb@outlook.com>
Sat, 27 May 2017 18:46:55 +0000 (19:46 +0100)
committersr55 <sr55.hb@outlook.com>
Sat, 27 May 2017 18:47:08 +0000 (19:47 +0100)
win/CS/HandBrakeWPF/Properties/Resources.Designer.cs
win/CS/HandBrakeWPF/Properties/Resources.resx
win/CS/HandBrakeWPF/Services/Queue/Interfaces/IQueueProcessor.cs
win/CS/HandBrakeWPF/Services/Queue/QueueProcessor.cs
win/CS/HandBrakeWPF/Utilities/DriveUtilities.cs
win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs
win/CS/HandBrakeWPF/ViewModels/QueueViewModel.cs

index d0b3c079bce1ef0d1669056ba2f77f6ef5ab4a92..92d55b507ab329cdf8413c616373dd57bfa9b9ee 100644 (file)
@@ -896,6 +896,15 @@ namespace HandBrakeWPF.Properties {
             }\r
         }\r
         \r
+        /// <summary>\r
+        ///   Looks up a localized string similar to Queue Paused.\r
+        /// </summary>\r
+        public static string Main_QueuePaused {\r
+            get {\r
+                return ResourceManager.GetString("Main_QueuePaused", resourceCulture);\r
+            }\r
+        }\r
+        \r
         /// <summary>\r
         ///   Looks up a localized string similar to Scan Cancelled..\r
         /// </summary>\r
@@ -1259,6 +1268,15 @@ namespace HandBrakeWPF.Properties {
             }\r
         }\r
         \r
+        /// <summary>\r
+        ///   Looks up a localized string similar to Queue Paused.  Warning, the drive you are encoding to is low on disk space. Please free up some space and press start to continue. You can also adjust the minimum space level in preferences..\r
+        /// </summary>\r
+        public static string PauseOnLowDiskspace {\r
+            get {\r
+                return ResourceManager.GetString("PauseOnLowDiskspace", resourceCulture);\r
+            }\r
+        }\r
+        \r
         /// <summary>\r
         ///   Looks up a localized string similar to Output: {0}.\r
         /// </summary>\r
@@ -1546,6 +1564,15 @@ namespace HandBrakeWPF.Properties {
             }\r
         }\r
         \r
+        /// <summary>\r
+        ///   Looks up a localized string similar to Queue Paused.\r
+        /// </summary>\r
+        public static string QueueViewModel_QueuePaused {\r
+            get {\r
+                return ResourceManager.GetString("QueueViewModel_QueuePaused", resourceCulture);\r
+            }\r
+        }\r
+        \r
         /// <summary>\r
         ///   Looks up a localized string similar to The Queue has been paused. The currently running job will run to completion and no further jobs will start..\r
         /// </summary>\r
index 1b263c8e98200b4fb1376f389d3a655e34f140af..6a67940adc7875e181e136821238b749b0f1bad1 100644 (file)
@@ -840,4 +840,13 @@ Your preset file will be archived and new one created. You will need to re-creat
     <value>{1}%, Pass {2} of {3}\r
 Remaining Time: {4}</value>\r
   </data>\r
+  <data name="PauseOnLowDiskspace" xml:space="preserve">\r
+    <value>Queue Paused.  Warning, the drive you are encoding to is low on disk space. Please free up some space and press start to continue. You can also adjust the minimum space level in preferences.</value>\r
+  </data>\r
+  <data name="Main_QueuePaused" xml:space="preserve">\r
+    <value>Queue Paused</value>\r
+  </data>\r
+  <data name="QueueViewModel_QueuePaused" xml:space="preserve">\r
+    <value>Queue Paused</value>\r
+  </data>\r
 </root>
\ No newline at end of file
index ffc9107bba48ac1854d8c7640a1f32a9f4038a1f..ead10cbf34daa60deac8903814d0f359a65c6fb1 100644 (file)
@@ -14,7 +14,7 @@ namespace HandBrakeWPF.Services.Queue.Interfaces
 \r
     using HandBrakeWPF.Services.Queue.Model;\r
 \r
-    using IEncode = HandBrakeWPF.Services.Encode.Interfaces.IEncode;\r
+    using IEncode = Encode.Interfaces.IEncode;\r
 \r
     /// <summary>\r
     /// The Queue Processor\r
@@ -44,12 +44,6 @@ namespace HandBrakeWPF.Services.Queue.Interfaces
         /// </summary>\r
         event EventHandler QueuePaused;\r
 \r
-        /// <summary>\r
-        /// Low Diskspace has been detected.\r
-        /// Checked before each job starts.\r
-        /// </summary>\r
-        event EventHandler LowDiskspaceDetected;\r
-\r
         #endregion\r
 \r
         #region Properties\r
index f0425b0c0e59a911a3765385a09d71b395a1a428..2292d18a28679f686da8a4aa977546d3f743f4e8 100644 (file)
@@ -17,9 +17,12 @@ namespace HandBrakeWPF.Services.Queue
     using System.Xml.Serialization;\r
 \r
     using HandBrake.ApplicationServices.Model;\r
+    using HandBrake.ApplicationServices.Services.Logging;\r
+    using HandBrake.ApplicationServices.Services.Logging.Model;\r
     using HandBrake.ApplicationServices.Utilities;\r
 \r
     using HandBrakeWPF.Factories;\r
+    using HandBrakeWPF.Properties;\r
     using HandBrakeWPF.Services.Encode.Factories;\r
     using HandBrakeWPF.Services.Encode.Model;\r
     using HandBrakeWPF.Services.Interfaces;\r
@@ -130,11 +133,6 @@ namespace HandBrakeWPF.Services.Queue
         /// </summary>\r
         public event EventHandler QueuePaused;\r
 \r
-        /// <summary>\r
-        /// The low diskspace detected.\r
-        /// </summary>\r
-        public event EventHandler LowDiskspaceDetected;\r
-\r
         #endregion\r
 \r
         #region Properties\r
@@ -478,8 +476,8 @@ namespace HandBrakeWPF.Services.Queue
         /// </summary>\r
         public void Pause()\r
         {\r
-            this.InvokeQueuePaused(EventArgs.Empty);\r
             this.IsProcessing = false;\r
+            this.InvokeQueuePaused(EventArgs.Empty);     \r
         }\r
 \r
         /// <summary>\r
@@ -501,17 +499,16 @@ namespace HandBrakeWPF.Services.Queue
             this.EncodeService.EncodeCompleted -= this.EncodeServiceEncodeCompleted;\r
             this.EncodeService.EncodeCompleted += this.EncodeServiceEncodeCompleted;\r
 \r
-            if (this.EncodeService.IsEncoding)\r
+            if (this.EncodeService.IsPasued)\r
             {\r
                 this.EncodeService.Resume();\r
+                this.IsProcessing = true;\r
             }\r
 \r
             if (!this.EncodeService.IsEncoding)\r
             {\r
                 this.ProcessNextJob();\r
             }\r
-\r
-            this.IsProcessing = true;\r
         }\r
 \r
         #endregion\r
@@ -535,14 +532,6 @@ namespace HandBrakeWPF.Services.Queue
             this.IsProcessing = false;\r
         }\r
 \r
-        /// <summary>\r
-        /// The on low diskspace detected.\r
-        /// </summary>\r
-        protected virtual void OnLowDiskspaceDetected()\r
-        {\r
-            this.LowDiskspaceDetected?.Invoke(this, EventArgs.Empty);\r
-        }\r
-\r
         /// <summary>\r
         /// After an encode is complete, move onto the next job.\r
         /// </summary>\r
@@ -644,22 +633,15 @@ namespace HandBrakeWPF.Services.Queue
             QueueTask job = this.GetNextJobForProcessing();\r
             if (job != null)\r
             {\r
-                if (this.userSettingService.GetUserSetting<bool>(UserSettingConstants.PauseOnLowDiskspace))\r
+                if (this.userSettingService.GetUserSetting<bool>(UserSettingConstants.PauseOnLowDiskspace) && !DriveUtilities.HasMinimumDiskSpace(job.Task.Destination, this.userSettingService.GetUserSetting<long>(UserSettingConstants.PauseOnLowDiskspaceLevel)))\r
                 {\r
-                    string drive = Path.GetPathRoot(job.Task.Destination);\r
-                    if (!string.IsNullOrEmpty(drive) && !drive.StartsWith("\\"))\r
-                    {\r
-                        DriveInfo c = new DriveInfo(drive);\r
-                        if (c.AvailableFreeSpace < this.userSettingService.GetUserSetting<long>(UserSettingConstants.PauseOnLowDiskspaceLevel))\r
-                        {\r
-                            job.Status = QueueItemStatus.Waiting;\r
-                            this.InvokeQueueChanged(EventArgs.Empty);\r
-                            this.OnLowDiskspaceDetected();\r
-                            return; // Don't start the next job.\r
-                        }\r
-                    }\r
+                    LogService.GetLogger().LogMessage(Resources.PauseOnLowDiskspace, LogMessageType.ScanOrEncode, LogLevel.Info);\r
+                    job.Status = QueueItemStatus.Waiting;\r
+                    this.Pause();\r
+                    return; // Don't start the next job.\r
                 }\r
 \r
+                this.IsProcessing = true;\r
                 this.InvokeJobProcessingStarted(new QueueProgressEventArgs(job));\r
                 this.EncodeService.Start(job.Task, job.Configuration);\r
             }\r
index d07056ef898cf1f71ad77f4b9db8e3ade18a170f..40bb2d5c05c4a2f31ee12dd55f508ffcefb5d190 100644 (file)
@@ -49,5 +49,20 @@ namespace HandBrakeWPF.Utilities
 \r
             return drives;\r
         }\r
+\r
+        public static bool HasMinimumDiskSpace(string destination, long minimumInBytes)\r
+        {\r
+            string drive = Path.GetPathRoot(destination);\r
+            if (!string.IsNullOrEmpty(drive) && !drive.StartsWith("\\"))\r
+            {\r
+                DriveInfo c = new DriveInfo(drive);\r
+                if (c.AvailableFreeSpace < minimumInBytes)\r
+                {\r
+                    return false;\r
+                }\r
+            }\r
+\r
+            return true;\r
+        }\r
     }\r
 }\r
index c8a59bbbc41715f4d0ed7e87f9bba564fe47db1a..5056f99a67178010d3a2bfce553cdd9c7bab095b 100644 (file)
@@ -205,6 +205,7 @@ namespace HandBrakeWPF.ViewModels
             this.scanService.ScanCompleted += this.ScanCompleted;\r
             this.scanService.ScanStatusChanged += this.ScanStatusChanged;\r
             this.queueProcessor.JobProcessingStarted += this.QueueProcessorJobProcessingStarted;\r
+            this.queueProcessor.QueuePaused += this.QueueProcessor_QueuePaused;\r
             this.queueProcessor.QueueCompleted += this.QueueCompleted;\r
             this.queueProcessor.QueueChanged += this.QueueChanged;\r
             this.queueProcessor.EncodeService.EncodeStatusChanged += this.EncodeStatusChanged;\r
@@ -1318,6 +1319,7 @@ namespace HandBrakeWPF.ViewModels
             this.queueProcessor.QueueCompleted -= this.QueueCompleted;\r
             this.queueProcessor.QueueChanged -= this.QueueChanged;\r
             this.queueProcessor.JobProcessingStarted -= this.QueueProcessorJobProcessingStarted;\r
+            this.queueProcessor.QueuePaused -= this.QueueProcessor_QueuePaused;\r
             this.queueProcessor.EncodeService.EncodeStatusChanged -= this.EncodeStatusChanged;\r
             this.userSettingService.SettingChanged -= this.UserSettingServiceSettingChanged;\r
         }\r
@@ -2528,6 +2530,20 @@ namespace HandBrakeWPF.ViewModels
                     }\r
 \r
                     this.ProgramStatusLabel = Resources.Main_QueueFinished + errorDesc;\r
+\r
+                    if (this.windowsSeven.IsWindowsSeven)\r
+                    {\r
+                        this.windowsSeven.SetTaskBarProgressToNoProgress();\r
+                    }\r
+                });\r
+        }\r
+\r
+        private void QueueProcessor_QueuePaused(object sender, EventArgs e)\r
+        {\r
+            Execute.OnUIThread(\r
+                () =>\r
+                {\r
+                    this.ProgramStatusLabel = Resources.Main_QueuePaused;\r
                     this.IsEncoding = false;\r
 \r
                     if (this.windowsSeven.IsWindowsSeven)\r
index 2267c1a447992d5a4c93a125ff8f5a541b021b71..0c984e032616129b1be433f81d608666381a0a8b 100644 (file)
@@ -459,6 +459,7 @@ namespace HandBrakeWPF.ViewModels
             this.queueProcessor.QueueCompleted += this.queueProcessor_QueueCompleted;\r
             this.queueProcessor.QueueChanged += this.QueueManager_QueueChanged;\r
             this.queueProcessor.JobProcessingStarted += this.QueueProcessorJobProcessingStarted;\r
+            this.queueProcessor.QueuePaused += this.QueueProcessor_QueuePaused;\r
         }\r
 \r
         public void Deactivate()\r
@@ -466,6 +467,7 @@ namespace HandBrakeWPF.ViewModels
             this.queueProcessor.QueueCompleted -= this.queueProcessor_QueueCompleted;\r
             this.queueProcessor.QueueChanged -= this.QueueManager_QueueChanged;\r
             this.queueProcessor.JobProcessingStarted -= this.QueueProcessorJobProcessingStarted;\r
+            this.queueProcessor.QueuePaused -= this.QueueProcessor_QueuePaused;\r
         }\r
 \r
         /// <summary>\r
@@ -480,7 +482,7 @@ namespace HandBrakeWPF.ViewModels
             this.queueProcessor.EncodeService.EncodeStatusChanged += this.EncodeService_EncodeStatusChanged;\r
             this.queueProcessor.EncodeService.EncodeCompleted += this.EncodeService_EncodeCompleted;\r
             this.queueProcessor.JobProcessingStarted += this.QueueProcessorJobProcessingStarted;\r
-            this.queueProcessor.LowDiskspaceDetected += this.QueueProcessor_LowDiskspaceDetected;\r
+            this.queueProcessor.QueuePaused += this.QueueProcessor_QueuePaused;\r
 \r
             this.JobsPending = string.Format(Resources.QueueViewModel_JobsPending, this.queueProcessor.Count);\r
             this.JobStatus = Resources.QueueViewModel_QueueReady;\r
@@ -501,7 +503,7 @@ namespace HandBrakeWPF.ViewModels
             this.queueProcessor.EncodeService.EncodeStatusChanged -= this.EncodeService_EncodeStatusChanged;\r
             this.queueProcessor.EncodeService.EncodeCompleted -= this.EncodeService_EncodeCompleted;\r
             this.queueProcessor.JobProcessingStarted -= this.QueueProcessorJobProcessingStarted;\r
-            this.queueProcessor.LowDiskspaceDetected -= this.QueueProcessor_LowDiskspaceDetected;\r
+            this.queueProcessor.QueuePaused -= this.QueueProcessor_QueuePaused;\r
 \r
             base.OnDeactivate(close);\r
         }\r
@@ -554,29 +556,6 @@ namespace HandBrakeWPF.ViewModels
             });\r
         }\r
 \r
-        /// <summary>\r
-        /// Detect Low Disk Space before starting new queue tasks.\r
-        /// </summary>\r
-        /// <param name="sender">Event invoker. </param>\r
-        /// <param name="e">Event Args.</param>\r
-        private void QueueProcessor_LowDiskspaceDetected(object sender, EventArgs e)\r
-        {\r
-            Execute.OnUIThreadAsync(\r
-                () =>\r
-                {\r
-                    this.queueProcessor.Pause();\r
-                    this.JobStatus = Resources.QueueViewModel_QueuePending;\r
-                    this.JobsPending = string.Format(Resources.QueueViewModel_JobsPending, this.queueProcessor.Count);\r
-                    this.IsQueueRunning = false;\r
-\r
-                    this.errorService.ShowMessageBox(\r
-                        Resources.MainViewModel_LowDiskSpaceWarning,\r
-                        Resources.MainViewModel_LowDiskSpace,\r
-                        MessageBoxButton.OK,\r
-                        MessageBoxImage.Warning);\r
-                });\r
-        }\r
-\r
         /// <summary>\r
         /// Handle the Queue Changed Event.\r
         /// </summary>\r
@@ -646,6 +625,13 @@ namespace HandBrakeWPF.ViewModels
             this.IsQueueRunning = true; \r
         }\r
 \r
+        private void QueueProcessor_QueuePaused(object sender, EventArgs e)\r
+        {\r
+            this.JobStatus = Resources.QueueViewModel_QueuePaused;\r
+            this.JobsPending = string.Format(Resources.QueueViewModel_JobsPending, this.queueProcessor.Count);\r
+            this.IsQueueRunning = false;\r
+        }\r
+\r
         #endregion\r
     }\r
 }
\ No newline at end of file