Low Disk Space level is currently set at 10GB. Will add a preference to adjust this at a later point
}\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
<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
}\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
<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
/// </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
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
/// </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
/// <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
/// </summary>\r
public event EventHandler QueuePaused;\r
\r
+ public event EventHandler LowDiskspaceDetected;\r
+\r
#endregion\r
\r
#region Properties\r
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
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
}\r
\r
#endregion\r
+\r
}\r
}
\ No newline at end of file
/// </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
\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
private bool disableQuickSyncDecoding;\r
private bool isClScaling;\r
private bool showQueueInline;\r
+ private bool pauseOnLowDiskspace;\r
\r
#endregion\r
\r
}\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
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
/* 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
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
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
});\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
\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
<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