diff options
author | Scott <[email protected]> | 2015-11-10 23:21:57 +0000 |
---|---|---|
committer | Scott <[email protected]> | 2015-11-10 23:21:57 +0000 |
commit | 6b713adaa58a127a65a5e69a6507d894a4760884 (patch) | |
tree | 56a37c568826e3ab1503e6523b6ad1ebc5bacce9 /win/CS | |
parent | 6fd35381a879def5e76f99cded43a2a3c265c333 (diff) |
WinGui: Add warning dialog on Destination Browse Button if disk space is low. Added new Advanced Option in preferences that will force the queue to check for low disk space before starting each job and pause if necessary.
Low Disk Space level is currently set at 10GB. Will add a preference to adjust this at a later point
Diffstat (limited to 'win/CS')
-rw-r--r-- | win/CS/HandBrakeWPF/Properties/Resources.Designer.cs | 18 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/Properties/Resources.resx | 6 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/Properties/ResourcesUI.Designer.cs | 9 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/Properties/ResourcesUI.resx | 3 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/Services/Queue/Interfaces/IQueueProcessor.cs | 7 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/Services/Queue/QueueProcessor.cs | 41 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/UserSettingConstants.cs | 10 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs | 15 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs | 22 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/ViewModels/QueueViewModel.cs | 30 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/Views/OptionsView.xaml | 3 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/defaultsettings.xml | 16 |
12 files changed, 176 insertions, 4 deletions
diff --git a/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs b/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs index 52b7258f9..643843132 100644 --- a/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs +++ b/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs @@ -952,6 +952,24 @@ namespace HandBrakeWPF.Properties { }
/// <summary>
+ /// Looks up a localized string similar to Low Disk Space.
+ /// </summary>
+ public static string MainViewModel_LowDiskSpace {
+ get {
+ return ResourceManager.GetString("MainViewModel_LowDiskSpace", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// 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. .
+ /// </summary>
+ public static string MainViewModel_LowDiskSpaceWarning {
+ get {
+ return ResourceManager.GetString("MainViewModel_LowDiskSpaceWarning", resourceCulture);
+ }
+ }
+
+ /// <summary>
/// Looks up a localized string similar to Are you sure you want to delete the preset: .
/// </summary>
public static string MainViewModel_PresetRemove_AreYouSure {
diff --git a/win/CS/HandBrakeWPF/Properties/Resources.resx b/win/CS/HandBrakeWPF/Properties/Resources.resx index ba36e3013..0ce417b62 100644 --- a/win/CS/HandBrakeWPF/Properties/Resources.resx +++ b/win/CS/HandBrakeWPF/Properties/Resources.resx @@ -733,4 +733,10 @@ Your old presets file was archived to:</value> <data name="Main_QueueFinishedErrors" xml:space="preserve">
<value> with {0} errors detected.</value>
</data>
+ <data name="MainViewModel_LowDiskSpace" xml:space="preserve">
+ <value>Low Disk Space</value>
+ </data>
+ <data name="MainViewModel_LowDiskSpaceWarning" xml:space="preserve">
+ <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>
+ </data>
</root>
\ No newline at end of file diff --git a/win/CS/HandBrakeWPF/Properties/ResourcesUI.Designer.cs b/win/CS/HandBrakeWPF/Properties/ResourcesUI.Designer.cs index 3bfe5da97..defb16f34 100644 --- a/win/CS/HandBrakeWPF/Properties/ResourcesUI.Designer.cs +++ b/win/CS/HandBrakeWPF/Properties/ResourcesUI.Designer.cs @@ -1177,6 +1177,15 @@ namespace HandBrakeWPF.Properties { }
/// <summary>
+ /// Looks up a localized string similar to Pause queue if disk space is low before starting a job..
+ /// </summary>
+ public static string Options_PauseQueueOnLowDiskSpace {
+ get {
+ return ResourceManager.GetString("Options_PauseQueueOnLowDiskSpace", resourceCulture);
+ }
+ }
+
+ /// <summary>
/// Looks up a localized string similar to Prevent the system from sleeping while encoding.
/// </summary>
public static string Options_PreventSleep {
diff --git a/win/CS/HandBrakeWPF/Properties/ResourcesUI.resx b/win/CS/HandBrakeWPF/Properties/ResourcesUI.resx index 1a5da42c9..752064170 100644 --- a/win/CS/HandBrakeWPF/Properties/ResourcesUI.resx +++ b/win/CS/HandBrakeWPF/Properties/ResourcesUI.resx @@ -837,4 +837,7 @@ <data name="Options_ShowQueueInline" xml:space="preserve">
<value>Show Queue in place of the tab controls when toggled on.</value>
</data>
+ <data name="Options_PauseQueueOnLowDiskSpace" xml:space="preserve">
+ <value>Pause queue if disk space is low before starting a job.</value>
+ </data>
</root>
\ No newline at end of file diff --git a/win/CS/HandBrakeWPF/Services/Queue/Interfaces/IQueueProcessor.cs b/win/CS/HandBrakeWPF/Services/Queue/Interfaces/IQueueProcessor.cs index d0bef608f..e148269ff 100644 --- a/win/CS/HandBrakeWPF/Services/Queue/Interfaces/IQueueProcessor.cs +++ b/win/CS/HandBrakeWPF/Services/Queue/Interfaces/IQueueProcessor.cs @@ -44,6 +44,13 @@ namespace HandBrakeWPF.Services.Queue.Interfaces /// </summary>
event EventHandler QueuePaused;
+
+ /// <summary>
+ /// Low Diskspace has been detected.
+ /// Checked before each job starts.
+ /// </summary>
+ event EventHandler LowDiskspaceDetected;
+
#endregion
#region Properties
diff --git a/win/CS/HandBrakeWPF/Services/Queue/QueueProcessor.cs b/win/CS/HandBrakeWPF/Services/Queue/QueueProcessor.cs index 31fd7acee..59b321d7b 100644 --- a/win/CS/HandBrakeWPF/Services/Queue/QueueProcessor.cs +++ b/win/CS/HandBrakeWPF/Services/Queue/QueueProcessor.cs @@ -14,8 +14,12 @@ namespace HandBrakeWPF.Services.Queue using System.ComponentModel;
using System.IO;
using System.Linq;
+ using System.Runtime.InteropServices.WindowsRuntime;
+ using System.Windows;
using System.Xml.Serialization;
+ using HandBrakeWPF.Properties;
+ using HandBrakeWPF.Services.Interfaces;
using HandBrakeWPF.Services.Queue.Model;
using HandBrakeWPF.Utilities;
@@ -53,6 +57,9 @@ namespace HandBrakeWPF.Services.Queue /// </summary>
private bool clearCompleted;
+ private readonly IUserSettingService userSettingService;
+ private readonly IErrorService errorService;
+
#endregion
#region Constructors and Destructors
@@ -63,11 +70,19 @@ namespace HandBrakeWPF.Services.Queue /// <param name="encodeService">
/// The encode Service.
/// </param>
+ /// <param name="userSettingService">
+ /// The user settings service.
+ /// </param>
+ /// <param name="errorService">
+ /// The Error Service.
+ /// </param>
/// <exception cref="ArgumentNullException">
/// Services are not setup
/// </exception>
- public QueueProcessor(IEncode encodeService)
+ public QueueProcessor(IEncode encodeService, IUserSettingService userSettingService, IErrorService errorService)
{
+ this.userSettingService = userSettingService;
+ this.errorService = errorService;
this.EncodeService = encodeService;
// If this is the first instance, just use the main queue file, otherwise add the instance id to the filename.
@@ -125,6 +140,8 @@ namespace HandBrakeWPF.Services.Queue /// </summary>
public event EventHandler QueuePaused;
+ public event EventHandler LowDiskspaceDetected;
+
#endregion
#region Properties
@@ -587,6 +604,11 @@ namespace HandBrakeWPF.Services.Queue this.IsProcessing = false;
}
+ protected virtual void OnLowDiskspaceDetected()
+ {
+ this.LowDiskspaceDetected?.Invoke(this, EventArgs.Empty);
+ }
+
/// <summary>
/// Run through all the jobs on the queue.
/// </summary>
@@ -595,6 +617,22 @@ namespace HandBrakeWPF.Services.Queue QueueTask job = this.GetNextJobForProcessing();
if (job != null)
{
+ if (this.userSettingService.GetUserSetting<bool>(UserSettingConstants.PauseOnLowDiskspace))
+ {
+ string drive = Path.GetPathRoot(job.Task.Destination);
+ if (drive != null)
+ {
+ DriveInfo c = new DriveInfo(drive);
+ if (c.AvailableFreeSpace < this.userSettingService.GetUserSetting<long>(UserSettingConstants.PauseOnLowDiskspaceLevel))
+ {
+ job.Status = QueueItemStatus.Waiting;
+ this.InvokeQueueChanged(EventArgs.Empty);
+ this.OnLowDiskspaceDetected();
+ return; // Don't start the next job.
+ }
+ }
+ }
+
this.InvokeJobProcessingStarted(new QueueProgressEventArgs(job));
this.EncodeService.Start(job.Task, job.Configuration);
}
@@ -609,5 +647,6 @@ namespace HandBrakeWPF.Services.Queue }
#endregion
+
}
}
\ No newline at end of file diff --git a/win/CS/HandBrakeWPF/UserSettingConstants.cs b/win/CS/HandBrakeWPF/UserSettingConstants.cs index 408f4061c..3956827bd 100644 --- a/win/CS/HandBrakeWPF/UserSettingConstants.cs +++ b/win/CS/HandBrakeWPF/UserSettingConstants.cs @@ -132,6 +132,16 @@ namespace HandBrakeWPF public const string PreventSleep = "PreventSleep";
/// <summary>
+ /// Pause Queue on Low Disk Space
+ /// </summary>
+ public const string PauseOnLowDiskspace = "PauseOnLowDiskspace";
+
+ /// <summary>
+ /// Low Disk Space Warning Level in Bytes.
+ /// </summary>
+ public const string PauseOnLowDiskspaceLevel = "LowDiskSpaceWarningLevelInBytes";
+
+ /// <summary>
/// The remove punctuation.
/// </summary>
public const string RemovePunctuation = "RemovePunctuation";
diff --git a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs index bc6caa38a..20a779e43 100644 --- a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs @@ -1668,6 +1668,21 @@ namespace HandBrakeWPF.ViewModels this.Destination = saveFileDialog.FileName;
+ // Disk Space Check
+ string drive = Path.GetPathRoot(this.Destination);
+ if (drive != null)
+ {
+ DriveInfo c = new DriveInfo(drive);
+ if (c.AvailableFreeSpace < this.userSettingService.GetUserSetting<long>(UserSettingConstants.PauseOnLowDiskspaceLevel))
+ {
+ this.errorService.ShowMessageBox(
+ Resources.MainViewModel_LowDiskSpaceWarning,
+ Resources.MainViewModel_LowDiskSpace,
+ MessageBoxButton.OK,
+ MessageBoxImage.Warning);
+ }
+ }
+
// Set the Extension Dropdown. This will also set Mp4/m4v correctly.
if (!string.IsNullOrEmpty(saveFileDialog.FileName))
{
diff --git a/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs index 3e37a8a85..3176070d0 100644 --- a/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs @@ -88,6 +88,7 @@ namespace HandBrakeWPF.ViewModels private bool disableQuickSyncDecoding;
private bool isClScaling;
private bool showQueueInline;
+ private bool pauseOnLowDiskspace;
#endregion
@@ -587,6 +588,23 @@ namespace HandBrakeWPF.ViewModels }
/// <summary>
+ /// Gets or sets a value indicating whether HandBrake should pause on low disk space.
+ /// </summary>
+ public bool PauseOnLowDiskspace
+ {
+ get
+ {
+ return this.pauseOnLowDiskspace;
+ }
+
+ set
+ {
+ this.pauseOnLowDiskspace = value;
+ this.NotifyOfPropertyChange(() => this.PauseOnLowDiskspace);
+ }
+ }
+
+ /// <summary>
/// Gets or sets PriorityLevelOptions.
/// </summary>
public BindingList<string> PriorityLevelOptions
@@ -1222,7 +1240,8 @@ namespace HandBrakeWPF.ViewModels this.SelectedPriority = userSettingService.GetUserSetting<string>(UserSettingConstants.ProcessPriority);
this.PreventSleep = userSettingService.GetUserSetting<bool>(UserSettingConstants.PreventSleep);
-
+ this.PauseOnLowDiskspace = userSettingService.GetUserSetting<bool>(UserSettingConstants.PauseOnLowDiskspace);
+
// Log Verbosity Level
this.logVerbosityOptions.Clear();
this.logVerbosityOptions.Add(0);
@@ -1312,6 +1331,7 @@ namespace HandBrakeWPF.ViewModels /* System and Logging */
userSettingService.SetUserSetting(UserSettingConstants.ProcessPriority, this.SelectedPriority);
userSettingService.SetUserSetting(UserSettingConstants.PreventSleep, this.PreventSleep);
+ userSettingService.SetUserSetting(UserSettingConstants.PauseOnLowDiskspace, this.PauseOnLowDiskspace);
userSettingService.SetUserSetting(UserSettingConstants.Verbosity, this.SelectedVerbosity);
userSettingService.SetUserSetting(UserSettingConstants.SaveLogWithVideo, this.CopyLogToEncodeDirectory);
userSettingService.SetUserSetting(UserSettingConstants.SaveLogToCopyDirectory, this.CopyLogToSepcficedLocation);
diff --git a/win/CS/HandBrakeWPF/ViewModels/QueueViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/QueueViewModel.cs index 8167c1953..e3dccd32c 100644 --- a/win/CS/HandBrakeWPF/ViewModels/QueueViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/QueueViewModel.cs @@ -396,8 +396,9 @@ namespace HandBrakeWPF.ViewModels this.queueProcessor.QueueCompleted += this.queueProcessor_QueueCompleted;
this.queueProcessor.QueueChanged += this.QueueManager_QueueChanged;
this.queueProcessor.EncodeService.EncodeStatusChanged += this.EncodeService_EncodeStatusChanged;
- this.queueProcessor.EncodeService.EncodeCompleted += EncodeService_EncodeCompleted;
+ this.queueProcessor.EncodeService.EncodeCompleted += this.EncodeService_EncodeCompleted;
this.queueProcessor.JobProcessingStarted += this.QueueProcessorJobProcessingStarted;
+ this.queueProcessor.LowDiskspaceDetected += this.QueueProcessor_LowDiskspaceDetected;
this.JobsPending = string.Format(Resources.QueueViewModel_JobsPending, this.queueProcessor.Count);
this.JobStatus = Resources.QueueViewModel_QueueReady;
@@ -416,8 +417,10 @@ namespace HandBrakeWPF.ViewModels this.queueProcessor.QueueCompleted -= this.queueProcessor_QueueCompleted;
this.queueProcessor.QueueChanged -= this.QueueManager_QueueChanged;
this.queueProcessor.EncodeService.EncodeStatusChanged -= this.EncodeService_EncodeStatusChanged;
- this.queueProcessor.EncodeService.EncodeCompleted -= EncodeService_EncodeCompleted;
+ this.queueProcessor.EncodeService.EncodeCompleted -= this.EncodeService_EncodeCompleted;
this.queueProcessor.JobProcessingStarted -= this.QueueProcessorJobProcessingStarted;
+ this.queueProcessor.LowDiskspaceDetected -= this.QueueProcessor_LowDiskspaceDetected;
+
base.OnDeactivate(close);
}
@@ -449,6 +452,29 @@ namespace HandBrakeWPF.ViewModels }
/// <summary>
+ /// Detect Low Disk Space before starting new queue tasks.
+ /// </summary>
+ /// <param name="sender">Event invoker. </param>
+ /// <param name="e">Event Args.</param>
+ private void QueueProcessor_LowDiskspaceDetected(object sender, EventArgs e)
+ {
+ Execute.OnUIThreadAsync(
+ () =>
+ {
+ this.queueProcessor.Pause();
+ this.JobStatus = Resources.QueueViewModel_QueuePending;
+ this.JobsPending = string.Format(Resources.QueueViewModel_JobsPending, this.queueProcessor.Count);
+ this.IsEncoding = false;
+
+ this.errorService.ShowMessageBox(
+ Resources.MainViewModel_LowDiskSpaceWarning,
+ Resources.MainViewModel_LowDiskSpace,
+ MessageBoxButton.OK,
+ MessageBoxImage.Warning);
+ });
+ }
+
+ /// <summary>
/// Handle the Queue Changed Event.
/// </summary>
/// <param name="sender">
diff --git a/win/CS/HandBrakeWPF/Views/OptionsView.xaml b/win/CS/HandBrakeWPF/Views/OptionsView.xaml index 1cde94b01..9766618d3 100644 --- a/win/CS/HandBrakeWPF/Views/OptionsView.xaml +++ b/win/CS/HandBrakeWPF/Views/OptionsView.xaml @@ -253,6 +253,9 @@ <StackPanel Orientation="Vertical" Margin="20,0,0,0">
<CheckBox Content="{x:Static Properties:ResourcesUI.Options_PreventSleep}" IsChecked="{Binding PreventSleep}" />
+ <CheckBox Content="{x:Static Properties:ResourcesUI.Options_PauseQueueOnLowDiskSpace}"
+ IsChecked="{Binding PauseOnLowDiskspace}" />
+
<StackPanel Orientation="Horizontal" Margin="0,10,0,0">
<TextBlock Text="{x:Static Properties:ResourcesUI.Options_PreviewScanCount}" VerticalAlignment="Center" Width="250" />
<ComboBox Name="numberOfPreviews" ItemsSource="{Binding PreviewPicturesToScan}" SelectedItem="{Binding SelectedPreviewCount}" Width="120" />
diff --git a/win/CS/HandBrakeWPF/defaultsettings.xml b/win/CS/HandBrakeWPF/defaultsettings.xml index 224923acf..cd7284a2b 100644 --- a/win/CS/HandBrakeWPF/defaultsettings.xml +++ b/win/CS/HandBrakeWPF/defaultsettings.xml @@ -456,4 +456,20 @@ <anyType xmlns:q1="http://www.w3.org/2001/XMLSchema" d4p1:type="q1:boolean" xmlns:d4p1="http://www.w3.org/2001/XMLSchema-instance">false</anyType>
</value>
</item>
+ <item>
+ <key>
+ <string>PauseOnLowDiskspace</string>
+ </key>
+ <value>
+ <anyType xmlns:q1="http://www.w3.org/2001/XMLSchema" d4p1:type="q1:boolean" xmlns:d4p1="http://www.w3.org/2001/XMLSchema-instance">false</anyType>
+ </value>
+ </item>
+ <item>
+ <key>
+ <string>LowDiskSpaceWarningLevelInBytes</string>
+ </key>
+ <value>
+ <anyType xmlns:q1="http://www.w3.org/2001/XMLSchema" d4p1:type="q1:long" xmlns:d4p1="http://www.w3.org/2001/XMLSchema-instance">10000000000</anyType>
+ </value>
+ </item>
</dictionary>
\ No newline at end of file |