]> granicus.if.org Git - handbrake/commitdiff
WinGui: Add warning dialog on Destination Browse Button if disk space is low. Added...
authorScott <sr55.hb@outlook.com>
Tue, 10 Nov 2015 23:21:57 +0000 (23:21 +0000)
committerScott <sr55.hb@outlook.com>
Tue, 10 Nov 2015 23:21:57 +0000 (23:21 +0000)
Low Disk Space level is currently set at 10GB. Will add a preference to adjust this at a later point

12 files changed:
win/CS/HandBrakeWPF/Properties/Resources.Designer.cs
win/CS/HandBrakeWPF/Properties/Resources.resx
win/CS/HandBrakeWPF/Properties/ResourcesUI.Designer.cs
win/CS/HandBrakeWPF/Properties/ResourcesUI.resx
win/CS/HandBrakeWPF/Services/Queue/Interfaces/IQueueProcessor.cs
win/CS/HandBrakeWPF/Services/Queue/QueueProcessor.cs
win/CS/HandBrakeWPF/UserSettingConstants.cs
win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs
win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs
win/CS/HandBrakeWPF/ViewModels/QueueViewModel.cs
win/CS/HandBrakeWPF/Views/OptionsView.xaml
win/CS/HandBrakeWPF/defaultsettings.xml

index 52b7258f95d4f8a8fa803c5b779766be884f2457..6438431327fe8e23c4d24ba2266ca90a814db259 100644 (file)
@@ -951,6 +951,24 @@ namespace HandBrakeWPF.Properties {
             }\r
         }\r
         \r
+        /// <summary>\r
+        ///   Looks up a localized string similar to Low Disk Space.\r
+        /// </summary>\r
+        public static string MainViewModel_LowDiskSpace {\r
+            get {\r
+                return ResourceManager.GetString("MainViewModel_LowDiskSpace", resourceCulture);\r
+            }\r
+        }\r
+        \r
+        /// <summary>\r
+        ///   Looks up a localized string similar to Warning, you are running low on disk space. HandBrake will not be able to complete this encode if you run out of space. .\r
+        /// </summary>\r
+        public static string MainViewModel_LowDiskSpaceWarning {\r
+            get {\r
+                return ResourceManager.GetString("MainViewModel_LowDiskSpaceWarning", resourceCulture);\r
+            }\r
+        }\r
+        \r
         /// <summary>\r
         ///   Looks up a localized string similar to Are you sure you want to delete the preset: .\r
         /// </summary>\r
index ba36e3013450f41c4300840c0be35447bc56fe43..0ce417b62f4cef6183953a743795ef0c16b0e926 100644 (file)
@@ -733,4 +733,10 @@ Your old presets file was archived to:</value>
   <data name="Main_QueueFinishedErrors" xml:space="preserve">\r
     <value> with {0} errors detected.</value>\r
   </data>\r
+  <data name="MainViewModel_LowDiskSpace" xml:space="preserve">\r
+    <value>Low Disk Space</value>\r
+  </data>\r
+  <data name="MainViewModel_LowDiskSpaceWarning" xml:space="preserve">\r
+    <value>Warning, you are running low on disk space. HandBrake will not be able to complete this encode if you run out of space. </value>\r
+  </data>\r
 </root>
\ No newline at end of file
index 3bfe5da97c40a25cad88dad60582388d9e9a0675..defb16f34708fdd0301cf5c0d3d3e5a9eb68dd86 100644 (file)
@@ -1176,6 +1176,15 @@ namespace HandBrakeWPF.Properties {
             }\r
         }\r
         \r
+        /// <summary>\r
+        ///   Looks up a localized string similar to Pause queue if disk space is low before starting a job..\r
+        /// </summary>\r
+        public static string Options_PauseQueueOnLowDiskSpace {\r
+            get {\r
+                return ResourceManager.GetString("Options_PauseQueueOnLowDiskSpace", resourceCulture);\r
+            }\r
+        }\r
+        \r
         /// <summary>\r
         ///   Looks up a localized string similar to Prevent the system from sleeping while encoding.\r
         /// </summary>\r
index 1a5da42c9d391002a2355967764a2e22519150c2..7520641708b63219b94c968bdded3316bd0b917d 100644 (file)
   <data name="Options_ShowQueueInline" xml:space="preserve">\r
     <value>Show Queue in place of the tab controls when toggled on.</value>\r
   </data>\r
+  <data name="Options_PauseQueueOnLowDiskSpace" xml:space="preserve">\r
+    <value>Pause queue if disk space is low before starting a job.</value>\r
+  </data>\r
 </root>
\ No newline at end of file
index d0bef608f7259674b188c14b6cf47805f3916aed..e148269ff77e1b85b0fe96efca993334b8e092f9 100644 (file)
@@ -44,6 +44,13 @@ namespace HandBrakeWPF.Services.Queue.Interfaces
         /// </summary>\r
         event EventHandler QueuePaused;\r
 \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 31fd7acee3911cdda26fab24914726c9616d4f6e..59b321d7ba8bc11c99d5c55dce5ba42a455af3b5 100644 (file)
@@ -14,8 +14,12 @@ namespace HandBrakeWPF.Services.Queue
     using System.ComponentModel;\r
     using System.IO;\r
     using System.Linq;\r
+    using System.Runtime.InteropServices.WindowsRuntime;\r
+    using System.Windows;\r
     using System.Xml.Serialization;\r
 \r
+    using HandBrakeWPF.Properties;\r
+    using HandBrakeWPF.Services.Interfaces;\r
     using HandBrakeWPF.Services.Queue.Model;\r
     using HandBrakeWPF.Utilities;\r
 \r
@@ -53,6 +57,9 @@ namespace HandBrakeWPF.Services.Queue
         /// </summary>\r
         private bool clearCompleted;\r
 \r
+        private readonly IUserSettingService userSettingService;\r
+        private readonly IErrorService errorService;\r
+\r
         #endregion\r
 \r
         #region Constructors and Destructors\r
@@ -63,11 +70,19 @@ namespace HandBrakeWPF.Services.Queue
         /// <param name="encodeService">\r
         /// The encode Service.\r
         /// </param>\r
+        /// <param name="userSettingService">\r
+        /// The user settings service.\r
+        /// </param>\r
+        /// <param name="errorService">\r
+        /// The Error Service.\r
+        /// </param>\r
         /// <exception cref="ArgumentNullException">\r
         /// Services are not setup\r
         /// </exception>\r
-        public QueueProcessor(IEncode encodeService)\r
+        public QueueProcessor(IEncode encodeService, IUserSettingService userSettingService, IErrorService errorService)\r
         {\r
+            this.userSettingService = userSettingService;\r
+            this.errorService = errorService;\r
             this.EncodeService = encodeService;\r
 \r
             // If this is the first instance, just use the main queue file, otherwise add the instance id to the filename.\r
@@ -125,6 +140,8 @@ namespace HandBrakeWPF.Services.Queue
         /// </summary>\r
         public event EventHandler QueuePaused;\r
 \r
+        public event EventHandler LowDiskspaceDetected;\r
+\r
         #endregion\r
 \r
         #region Properties\r
@@ -587,6 +604,11 @@ namespace HandBrakeWPF.Services.Queue
             this.IsProcessing = false;\r
         }\r
 \r
+        protected virtual void OnLowDiskspaceDetected()\r
+        {\r
+            this.LowDiskspaceDetected?.Invoke(this, EventArgs.Empty);\r
+        }\r
+        \r
         /// <summary>\r
         /// Run through all the jobs on the queue.\r
         /// </summary>\r
@@ -595,6 +617,22 @@ namespace HandBrakeWPF.Services.Queue
             QueueTask job = this.GetNextJobForProcessing();\r
             if (job != null)\r
             {\r
+                if (this.userSettingService.GetUserSetting<bool>(UserSettingConstants.PauseOnLowDiskspace))\r
+                {\r
+                    string drive = Path.GetPathRoot(job.Task.Destination);\r
+                    if (drive != null)\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
+                }\r
+\r
                 this.InvokeJobProcessingStarted(new QueueProgressEventArgs(job));\r
                 this.EncodeService.Start(job.Task, job.Configuration);\r
             }\r
@@ -609,5 +647,6 @@ namespace HandBrakeWPF.Services.Queue
         }\r
 \r
         #endregion\r
+\r
     }\r
 }
\ No newline at end of file
index 408f4061c59c202e62544104bf484978db4477f8..3956827bd2dca3e445fdce9b97805c802f70d878 100644 (file)
@@ -131,6 +131,16 @@ namespace HandBrakeWPF
         /// </summary>\r
         public const string PreventSleep = "PreventSleep";\r
 \r
+        /// <summary>\r
+        /// Pause Queue on Low Disk Space\r
+        /// </summary>\r
+        public const string PauseOnLowDiskspace = "PauseOnLowDiskspace";\r
+\r
+        /// <summary>\r
+        /// Low Disk Space Warning Level in Bytes.\r
+        /// </summary>\r
+        public const string PauseOnLowDiskspaceLevel = "LowDiskSpaceWarningLevelInBytes";\r
+\r
         /// <summary>\r
         /// The remove punctuation.\r
         /// </summary>\r
index bc6caa38a478414d684cbf2638f86b8753399432..20a779e4344d4f1f6091bcb147da22f0b6457ecd 100644 (file)
@@ -1668,6 +1668,21 @@ namespace HandBrakeWPF.ViewModels
 \r
                 this.Destination = saveFileDialog.FileName;\r
 \r
+                // Disk Space Check\r
+                string drive = Path.GetPathRoot(this.Destination);\r
+                if (drive != null)\r
+                {\r
+                    DriveInfo c = new DriveInfo(drive);\r
+                    if (c.AvailableFreeSpace < this.userSettingService.GetUserSetting<long>(UserSettingConstants.PauseOnLowDiskspaceLevel))\r
+                    {\r
+                        this.errorService.ShowMessageBox(\r
+                            Resources.MainViewModel_LowDiskSpaceWarning,\r
+                            Resources.MainViewModel_LowDiskSpace,\r
+                            MessageBoxButton.OK,\r
+                            MessageBoxImage.Warning);\r
+                    }\r
+                }\r
+\r
                 // Set the Extension Dropdown. This will also set Mp4/m4v correctly.\r
                 if (!string.IsNullOrEmpty(saveFileDialog.FileName))\r
                 {\r
index 3e37a8a852b952346ba57c3bbadc65bfec85583d..3176070d029026b93fba91a4d8f0aaff7b542811 100644 (file)
@@ -88,6 +88,7 @@ namespace HandBrakeWPF.ViewModels
         private bool disableQuickSyncDecoding;\r
         private bool isClScaling;\r
         private bool showQueueInline;\r
+        private bool pauseOnLowDiskspace;\r
 \r
         #endregion\r
 \r
@@ -586,6 +587,23 @@ namespace HandBrakeWPF.ViewModels
             }\r
         }\r
 \r
+        /// <summary>\r
+        /// Gets or sets a value indicating whether HandBrake should pause on low disk space.\r
+        /// </summary>\r
+        public bool PauseOnLowDiskspace\r
+        {\r
+            get\r
+            {\r
+                return this.pauseOnLowDiskspace;\r
+            }\r
+\r
+            set\r
+            {\r
+                this.pauseOnLowDiskspace = value;\r
+                this.NotifyOfPropertyChange(() => this.PauseOnLowDiskspace);\r
+            }\r
+        }  \r
+\r
         /// <summary>\r
         /// Gets or sets PriorityLevelOptions.\r
         /// </summary>\r
@@ -1222,7 +1240,8 @@ namespace HandBrakeWPF.ViewModels
             this.SelectedPriority = userSettingService.GetUserSetting<string>(UserSettingConstants.ProcessPriority);\r
 \r
             this.PreventSleep = userSettingService.GetUserSetting<bool>(UserSettingConstants.PreventSleep);\r
-\r
+            this.PauseOnLowDiskspace = userSettingService.GetUserSetting<bool>(UserSettingConstants.PauseOnLowDiskspace);\r
+            \r
             // Log Verbosity Level\r
             this.logVerbosityOptions.Clear();\r
             this.logVerbosityOptions.Add(0);\r
@@ -1312,6 +1331,7 @@ namespace HandBrakeWPF.ViewModels
             /* System and Logging */\r
             userSettingService.SetUserSetting(UserSettingConstants.ProcessPriority, this.SelectedPriority);\r
             userSettingService.SetUserSetting(UserSettingConstants.PreventSleep, this.PreventSleep);\r
+            userSettingService.SetUserSetting(UserSettingConstants.PauseOnLowDiskspace, this.PauseOnLowDiskspace);\r
             userSettingService.SetUserSetting(UserSettingConstants.Verbosity, this.SelectedVerbosity);\r
             userSettingService.SetUserSetting(UserSettingConstants.SaveLogWithVideo, this.CopyLogToEncodeDirectory);\r
             userSettingService.SetUserSetting(UserSettingConstants.SaveLogToCopyDirectory, this.CopyLogToSepcficedLocation);\r
index 8167c19538a4ed6df9f979b6c891c93b3a032672..e3dccd32c0c1d73db871c7ab0a550867d0033e96 100644 (file)
@@ -396,8 +396,9 @@ namespace HandBrakeWPF.ViewModels
             this.queueProcessor.QueueCompleted += this.queueProcessor_QueueCompleted;\r
             this.queueProcessor.QueueChanged += this.QueueManager_QueueChanged;\r
             this.queueProcessor.EncodeService.EncodeStatusChanged += this.EncodeService_EncodeStatusChanged;\r
-            this.queueProcessor.EncodeService.EncodeCompleted += EncodeService_EncodeCompleted;\r
+            this.queueProcessor.EncodeService.EncodeCompleted += this.EncodeService_EncodeCompleted;\r
             this.queueProcessor.JobProcessingStarted += this.QueueProcessorJobProcessingStarted;\r
+            this.queueProcessor.LowDiskspaceDetected += this.QueueProcessor_LowDiskspaceDetected;\r
 \r
             this.JobsPending = string.Format(Resources.QueueViewModel_JobsPending, this.queueProcessor.Count);\r
             this.JobStatus = Resources.QueueViewModel_QueueReady;\r
@@ -416,8 +417,10 @@ namespace HandBrakeWPF.ViewModels
             this.queueProcessor.QueueCompleted -= this.queueProcessor_QueueCompleted;\r
             this.queueProcessor.QueueChanged -= this.QueueManager_QueueChanged;\r
             this.queueProcessor.EncodeService.EncodeStatusChanged -= this.EncodeService_EncodeStatusChanged;\r
-            this.queueProcessor.EncodeService.EncodeCompleted -= EncodeService_EncodeCompleted;\r
+            this.queueProcessor.EncodeService.EncodeCompleted -= this.EncodeService_EncodeCompleted;\r
             this.queueProcessor.JobProcessingStarted -= this.QueueProcessorJobProcessingStarted;\r
+            this.queueProcessor.LowDiskspaceDetected -= this.QueueProcessor_LowDiskspaceDetected;\r
+\r
 \r
             base.OnDeactivate(close);\r
         }\r
@@ -448,6 +451,29 @@ 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.IsEncoding = 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
index 1cde94b01456a865df0cc6b32b6b7423347e151d..9766618d3dc178e50a8d8d095a84c9f5259781f0 100644 (file)
 \r
                         <StackPanel Orientation="Vertical" Margin="20,0,0,0">\r
                             <CheckBox Content="{x:Static Properties:ResourcesUI.Options_PreventSleep}" IsChecked="{Binding PreventSleep}" />\r
+                            <CheckBox Content="{x:Static Properties:ResourcesUI.Options_PauseQueueOnLowDiskSpace}" \r
+                                      IsChecked="{Binding PauseOnLowDiskspace}" />\r
+\r
                             <StackPanel Orientation="Horizontal" Margin="0,10,0,0">\r
                                 <TextBlock Text="{x:Static Properties:ResourcesUI.Options_PreviewScanCount}" VerticalAlignment="Center" Width="250" />\r
                                 <ComboBox Name="numberOfPreviews" ItemsSource="{Binding PreviewPicturesToScan}" SelectedItem="{Binding SelectedPreviewCount}" Width="120" />\r
index 224923acf9e1dfe7538e317b7e36ce7aa5d76f2a..cd7284a2b33d0b4c8786ae3eebd6be22db64c3e8 100644 (file)
       <anyType xmlns:q1="http://www.w3.org/2001/XMLSchema" d4p1:type="q1:boolean" xmlns:d4p1="http://www.w3.org/2001/XMLSchema-instance">false</anyType>\r
     </value>\r
   </item>\r
+  <item>\r
+    <key>\r
+      <string>PauseOnLowDiskspace</string>\r
+    </key>\r
+    <value>\r
+      <anyType xmlns:q1="http://www.w3.org/2001/XMLSchema" d4p1:type="q1:boolean" xmlns:d4p1="http://www.w3.org/2001/XMLSchema-instance">false</anyType>\r
+    </value>\r
+  </item>\r
+  <item>\r
+    <key>\r
+      <string>LowDiskSpaceWarningLevelInBytes</string>\r
+    </key>\r
+    <value>\r
+      <anyType xmlns:q1="http://www.w3.org/2001/XMLSchema" d4p1:type="q1:long" xmlns:d4p1="http://www.w3.org/2001/XMLSchema-instance">10000000000</anyType>\r
+    </value>\r
+  </item>\r
 </dictionary>
\ No newline at end of file