From 6b713adaa58a127a65a5e69a6507d894a4760884 Mon Sep 17 00:00:00 2001 From: Scott Date: Tue, 10 Nov 2015 23:21:57 +0000 Subject: 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 --- .../HandBrakeWPF/Properties/Resources.Designer.cs | 18 ++++++++++ win/CS/HandBrakeWPF/Properties/Resources.resx | 6 ++++ .../Properties/ResourcesUI.Designer.cs | 9 +++++ win/CS/HandBrakeWPF/Properties/ResourcesUI.resx | 3 ++ .../Services/Queue/Interfaces/IQueueProcessor.cs | 7 ++++ .../HandBrakeWPF/Services/Queue/QueueProcessor.cs | 41 +++++++++++++++++++++- win/CS/HandBrakeWPF/UserSettingConstants.cs | 10 ++++++ win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs | 15 ++++++++ win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs | 22 +++++++++++- win/CS/HandBrakeWPF/ViewModels/QueueViewModel.cs | 30 ++++++++++++++-- win/CS/HandBrakeWPF/Views/OptionsView.xaml | 3 ++ win/CS/HandBrakeWPF/defaultsettings.xml | 16 +++++++++ 12 files changed, 176 insertions(+), 4 deletions(-) (limited to 'win/CS') 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 @@ -951,6 +951,24 @@ namespace HandBrakeWPF.Properties { } } + /// + /// Looks up a localized string similar to Low Disk Space. + /// + public static string MainViewModel_LowDiskSpace { + get { + return ResourceManager.GetString("MainViewModel_LowDiskSpace", resourceCulture); + } + } + + /// + /// 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. . + /// + public static string MainViewModel_LowDiskSpaceWarning { + get { + return ResourceManager.GetString("MainViewModel_LowDiskSpaceWarning", resourceCulture); + } + } + /// /// Looks up a localized string similar to Are you sure you want to delete the preset: . /// 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: with {0} errors detected. + + Low Disk Space + + + Warning, you are running low on disk space. HandBrake will not be able to complete this encode if you run out of space. + \ 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 @@ -1176,6 +1176,15 @@ namespace HandBrakeWPF.Properties { } } + /// + /// Looks up a localized string similar to Pause queue if disk space is low before starting a job.. + /// + public static string Options_PauseQueueOnLowDiskSpace { + get { + return ResourceManager.GetString("Options_PauseQueueOnLowDiskSpace", resourceCulture); + } + } + /// /// Looks up a localized string similar to Prevent the system from sleeping while encoding. /// 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 @@ Show Queue in place of the tab controls when toggled on. + + Pause queue if disk space is low before starting a job. + \ 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 /// event EventHandler QueuePaused; + + /// + /// Low Diskspace has been detected. + /// Checked before each job starts. + /// + 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 /// private bool clearCompleted; + private readonly IUserSettingService userSettingService; + private readonly IErrorService errorService; + #endregion #region Constructors and Destructors @@ -63,11 +70,19 @@ namespace HandBrakeWPF.Services.Queue /// /// The encode Service. /// + /// + /// The user settings service. + /// + /// + /// The Error Service. + /// /// /// Services are not setup /// - 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 /// 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); + } + /// /// Run through all the jobs on the queue. /// @@ -595,6 +617,22 @@ namespace HandBrakeWPF.Services.Queue QueueTask job = this.GetNextJobForProcessing(); if (job != null) { + if (this.userSettingService.GetUserSetting(UserSettingConstants.PauseOnLowDiskspace)) + { + string drive = Path.GetPathRoot(job.Task.Destination); + if (drive != null) + { + DriveInfo c = new DriveInfo(drive); + if (c.AvailableFreeSpace < this.userSettingService.GetUserSetting(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 @@ -131,6 +131,16 @@ namespace HandBrakeWPF /// public const string PreventSleep = "PreventSleep"; + /// + /// Pause Queue on Low Disk Space + /// + public const string PauseOnLowDiskspace = "PauseOnLowDiskspace"; + + /// + /// Low Disk Space Warning Level in Bytes. + /// + public const string PauseOnLowDiskspaceLevel = "LowDiskSpaceWarningLevelInBytes"; + /// /// The remove punctuation. /// 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(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 @@ -586,6 +587,23 @@ namespace HandBrakeWPF.ViewModels } } + /// + /// Gets or sets a value indicating whether HandBrake should pause on low disk space. + /// + public bool PauseOnLowDiskspace + { + get + { + return this.pauseOnLowDiskspace; + } + + set + { + this.pauseOnLowDiskspace = value; + this.NotifyOfPropertyChange(() => this.PauseOnLowDiskspace); + } + } + /// /// Gets or sets PriorityLevelOptions. /// @@ -1222,7 +1240,8 @@ namespace HandBrakeWPF.ViewModels this.SelectedPriority = userSettingService.GetUserSetting(UserSettingConstants.ProcessPriority); this.PreventSleep = userSettingService.GetUserSetting(UserSettingConstants.PreventSleep); - + this.PauseOnLowDiskspace = userSettingService.GetUserSetting(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); } @@ -448,6 +451,29 @@ namespace HandBrakeWPF.ViewModels }); } + /// + /// Detect Low Disk Space before starting new queue tasks. + /// + /// Event invoker. + /// Event Args. + 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); + }); + } + /// /// Handle the Queue Changed Event. /// 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 @@ + + 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 @@ false + + + PauseOnLowDiskspace + + + false + + + + + LowDiskSpaceWarningLevelInBytes + + + 10000000000 + + \ No newline at end of file -- cgit v1.2.3