summaryrefslogtreecommitdiffstats
path: root/win/CS/HandBrake.ApplicationServices/Services
diff options
context:
space:
mode:
authorsr55 <[email protected]>2012-03-25 18:14:10 +0000
committersr55 <[email protected]>2012-03-25 18:14:10 +0000
commit479f2a8da44ee1237acdf187892e0bf2e77c5663 (patch)
tree7afe479dcc484fe8319019c2216e954c3e30a6cd /win/CS/HandBrake.ApplicationServices/Services
parent970ae1ed9f3c05fa4a8a4bc454892ef63278c721 (diff)
WinGuWinGui:(WPF) Remove some legacy queue code with the queue models and fix up some issues with the quality slider on the new video tab. Improve the User settings service code.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4542 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win/CS/HandBrake.ApplicationServices/Services')
-rw-r--r--win/CS/HandBrake.ApplicationServices/Services/Base/EncodeBase.cs2
-rw-r--r--win/CS/HandBrake.ApplicationServices/Services/QueueManager.cs4
-rw-r--r--win/CS/HandBrake.ApplicationServices/Services/QueueProcessor.cs10
-rw-r--r--win/CS/HandBrake.ApplicationServices/Services/UserSettingService.cs123
4 files changed, 60 insertions, 79 deletions
diff --git a/win/CS/HandBrake.ApplicationServices/Services/Base/EncodeBase.cs b/win/CS/HandBrake.ApplicationServices/Services/Base/EncodeBase.cs
index e2eacce72..d57f3a51f 100644
--- a/win/CS/HandBrake.ApplicationServices/Services/Base/EncodeBase.cs
+++ b/win/CS/HandBrake.ApplicationServices/Services/Base/EncodeBase.cs
@@ -366,7 +366,7 @@ namespace HandBrake.ApplicationServices.Services.Base
// Make sure the path exists, attempt to create it if it doesn't
try
{
- string path = Directory.GetParent(task.Destination ?? task.Task.Destination).ToString();
+ string path = Directory.GetParent(task.Task.Destination).ToString();
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
diff --git a/win/CS/HandBrake.ApplicationServices/Services/QueueManager.cs b/win/CS/HandBrake.ApplicationServices/Services/QueueManager.cs
index 7c60d1e86..1ce362449 100644
--- a/win/CS/HandBrake.ApplicationServices/Services/QueueManager.cs
+++ b/win/CS/HandBrake.ApplicationServices/Services/QueueManager.cs
@@ -154,8 +154,6 @@ namespace HandBrake.ApplicationServices.Services
{
lock (QueueLock)
{
- // Tag the job with an ID
- job.Id = lastJobId++;
queue.Add(job);
InvokeQueueChanged(EventArgs.Empty);
}
@@ -366,7 +364,7 @@ namespace HandBrake.ApplicationServices.Services
/// <returns>Whether or not the supplied destination is already in the queue.</returns>
public bool CheckForDestinationPathDuplicates(string destination)
{
- return this.queue.Any(checkItem => checkItem.Destination.Contains(destination.Replace("\\\\", "\\")));
+ return this.queue.Any(checkItem => checkItem.Task.Destination.Contains(destination.Replace("\\\\", "\\")));
}
/// <summary>
diff --git a/win/CS/HandBrake.ApplicationServices/Services/QueueProcessor.cs b/win/CS/HandBrake.ApplicationServices/Services/QueueProcessor.cs
index ce3a756ed..1deeb0d44 100644
--- a/win/CS/HandBrake.ApplicationServices/Services/QueueProcessor.cs
+++ b/win/CS/HandBrake.ApplicationServices/Services/QueueProcessor.cs
@@ -201,6 +201,12 @@ namespace HandBrake.ApplicationServices.Services
{
this.QueueManager.LastProcessedJob.Status = QueueItemStatus.Completed;
+ // Clear the completed item of the queue if the setting is set.
+ if (userSettingService.GetUserSetting<bool>(ASUserSettingConstants.ClearCompletedFromQueue))
+ {
+ this.QueueManager.ClearCompleted();
+ }
+
// Growl
if (userSettingService.GetUserSetting<bool>(ASUserSettingConstants.GrowlEncode))
GrowlCommunicator.Notify("Encode Completed",
@@ -218,12 +224,12 @@ namespace HandBrake.ApplicationServices.Services
}
// Handling Log Data
- this.EncodeService.ProcessLogs(this.QueueManager.LastProcessedJob.Destination);
+ this.EncodeService.ProcessLogs(this.QueueManager.LastProcessedJob.Task.Destination);
// Post-Processing
if (e.Successful)
{
- SendToApplication(this.QueueManager.LastProcessedJob.Destination);
+ SendToApplication(this.QueueManager.LastProcessedJob.Task.Destination);
}
// Move onto the next job.
diff --git a/win/CS/HandBrake.ApplicationServices/Services/UserSettingService.cs b/win/CS/HandBrake.ApplicationServices/Services/UserSettingService.cs
index d8e537bdc..c36b5ec49 100644
--- a/win/CS/HandBrake.ApplicationServices/Services/UserSettingService.cs
+++ b/win/CS/HandBrake.ApplicationServices/Services/UserSettingService.cs
@@ -6,9 +6,9 @@
namespace HandBrake.ApplicationServices.Services
{
using System;
- using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
+ using System.Linq;
using System.Windows.Forms;
using System.Xml.Serialization;
@@ -44,7 +44,7 @@ namespace HandBrake.ApplicationServices.Services
this.Load();
if (userSettings == null || userSettings.Count == 0)
{
- this.LoadDefaults();
+ this.userSettings = this.GetDefaults();
}
}
@@ -104,15 +104,25 @@ namespace HandBrake.ApplicationServices.Services
/// </summary>
private void Save()
{
- string directory = Path.GetDirectoryName(this.settingsFile);
- if (!string.IsNullOrEmpty(directory) && !Directory.Exists(directory))
+ try
{
- Directory.CreateDirectory(directory);
- }
+ string directory = Path.GetDirectoryName(this.settingsFile);
+ if (!string.IsNullOrEmpty(directory) && !Directory.Exists(directory))
+ {
+ Directory.CreateDirectory(directory);
+ }
- using (FileStream strm = new FileStream(this.settingsFile, FileMode.Create, FileAccess.Write))
+ using (FileStream strm = new FileStream(this.settingsFile, FileMode.Create, FileAccess.Write))
+ {
+ serializer.Serialize(strm, this.userSettings);
+ }
+ }
+ catch (Exception exc)
{
- serializer.Serialize(strm, this.userSettings);
+ throw new GeneralApplicationException(
+ "A problem occured when trying to save your preferences.",
+ "Any settings you changed may need to be reset the next time HandBrake launches.",
+ exc);
}
}
@@ -129,7 +139,16 @@ namespace HandBrake.ApplicationServices.Services
{
SerializableDictionary<string, object> data = (SerializableDictionary<string, object>)serializer.Deserialize(reader);
this.userSettings = data;
+
+ // Add any new settings
+ SerializableDictionary<string, object> defaults = this.GetDefaults();
+ foreach (var item in defaults.Where(item => !this.userSettings.Keys.Contains(item.Key)))
+ {
+ this.userSettings.Add(item.Key, item.Value);
+ }
}
+
+ this.Save();
}
}
catch (Exception exc)
@@ -144,76 +163,34 @@ namespace HandBrake.ApplicationServices.Services
/// <summary>
/// Load Default Settings
/// </summary>
- private void LoadDefaults()
+ /// <returns>
+ /// The get defaults.
+ /// </returns>
+ private SerializableDictionary<string, object> GetDefaults()
{
- string defaults = Path.Combine(Application.StartupPath, "defaultsettings.xml");
- if (File.Exists(defaults))
+ try
{
- using (StreamReader reader = new StreamReader(defaults))
+ string defaults = Path.Combine(Application.StartupPath, "defaultsettings.xml");
+ if (File.Exists(defaults))
{
- SerializableDictionary<string, object> data = (SerializableDictionary<string, object>)serializer.Deserialize(reader);
- this.userSettings = data;
+ using (StreamReader reader = new StreamReader(defaults))
+ {
+ return (SerializableDictionary<string, object>)serializer.Deserialize(reader);
+ }
}
- }
- }
- /// <summary>
- /// This is just a utility method for creating a defaults xml file. Don't use this!!!
- /// </summary>
- private void SetAllDefaults()
- {
- userSettings = new SerializableDictionary<string, object>();
- userSettings[ASUserSettingConstants.X264Step] = 0.25;
- userSettings[ASUserSettingConstants.Verbosity] = 1;
- userSettings[ASUserSettingConstants.WhenCompleteAction] = "Do Nothing";
- userSettings[ASUserSettingConstants.GrowlEncode] = false;
- userSettings[ASUserSettingConstants.GrowlQueue] = false;
- userSettings[ASUserSettingConstants.ProcessPriority] = "Below Normal";
- userSettings[ASUserSettingConstants.PreventSleep] = true;
- userSettings[ASUserSettingConstants.ShowCLI] = false;
- userSettings[ASUserSettingConstants.SaveLogToCopyDirectory] = false;
- userSettings[ASUserSettingConstants.SaveLogWithVideo] = false;
- userSettings[ASUserSettingConstants.DisableLibDvdNav] = false;
- userSettings[ASUserSettingConstants.SendFile] = false;
- userSettings[ASUserSettingConstants.MinScanDuration] = 10;
- userSettings[ASUserSettingConstants.HandBrakeBuild] = 0;
- userSettings[ASUserSettingConstants.HandBrakeVersion] = string.Empty;
- userSettings["updateStatus"] = true;
- userSettings["tooltipEnable"] = true;
- userSettings["defaultPreset"] = string.Empty;
- userSettings["skipversion"] = 0;
- userSettings["autoNaming"] = true;
- userSettings["autoNamePath"] = string.Empty;
- userSettings["appcast_i686"] = "http://handbrake.fr/appcast.i386.xml";
- userSettings["appcast_x64"] = "http://handbrake.fr/appcast_unstable.x86_64.xml";
- userSettings["autoNameFormat"] = "{source}-{title}";
- userSettings["VLC_Path"] = "C:\\Program Files\\VideoLAN\\vlc\\vlc.exe";
- userSettings["MainWindowMinimize"] = true;
- userSettings["QueryEditorTab"] = false;
- userSettings["presetNotification"] = false;
- userSettings["trayIconAlerts"] = true;
- userSettings["lastUpdateCheckDate"] = DateTime.Today;
- userSettings["daysBetweenUpdateCheck"] = 7;
- userSettings["useM4v"] = 0;
- userSettings["PromptOnUnmatchingQueries"] = true;
- userSettings["NativeLanguage"] = "Any";
- userSettings["DubMode"] = 255;
- userSettings["HandBrakeExeHash"] = string.Empty;
- userSettings["previewScanCount"] = 10;
- userSettings["clearOldLogs"] = true;
- userSettings["AutoNameTitleCase"] = true;
- userSettings["AutoNameRemoveUnderscore"] = true;
- userSettings["ActivityWindowLastMode"] = 0;
- userSettings["useClosedCaption"] = false;
- userSettings["batchMinDuration"] = "00:18:00";
- userSettings["batchMaxDuration"] = "02:30:00";
- userSettings["defaultPlayer"] = false;
- userSettings["SelectedLanguages"] = new StringCollection();
- userSettings["DubModeAudio"] = 0;
- userSettings["DubModeSubtitle"] = 0;
- userSettings["addOnlyOneAudioPerLanguage"] = true;
- userSettings["MinTitleLength"] = 10;
- userSettings["ShowAdvancedAudioPassthruOpts"] = false;
+ throw new GeneralApplicationException(
+ "User default settings file is missing. This install of HandBrake may be corrupted.",
+ "Try re-installing HandBrake.",
+ null);
+ }
+ catch (Exception exc)
+ {
+ throw new GeneralApplicationException(
+ "User default settings file is missing or inaccessible. This install of HandBrake may be corrupted.",
+ "Try re-installing HandBrake.",
+ exc);
+ }
}
}
}