EncodeTask task = CreateEncodeTaskObject(mainWindow);\r
QueueTask queueTask = new QueueTask(query)\r
{\r
- Source = task.Source,\r
- Destination = task.Destination,\r
- Title = mainWindow.GetTitle(),\r
CustomQuery = (mainWindow.rtf_query.Text != string.Empty) || isCustom,\r
Task = task,\r
Query = query,\r
/// Preview Scan Count\r
/// </summary>\r
public const string PreviewScanCount = "previewScanCount";\r
+\r
+ /// <summary>\r
+ /// Clear completed items from the queue automatically.\r
+ /// </summary>\r
+ public const string ClearCompletedFromQueue = "ClearCompletedFromQueue";\r
}\r
}\r
/// </summary>\r
public bool CustomQuery { get; set; }\r
\r
- /// <summary>\r
- /// Gets or sets Destination.\r
- /// </summary>\r
- public string Destination { get; set; }\r
-\r
- /// <summary>\r
- /// Gets or sets the job ID.\r
- /// </summary>\r
- public int Id { get; set; }\r
-\r
- /// <summary>\r
- /// Gets a value indicating whether or not this instance is empty.\r
- /// </summary>\r
- public bool IsEmpty\r
- {\r
- get\r
- {\r
- return this.Id == 0 && string.IsNullOrEmpty(this.Query) && string.IsNullOrEmpty(this.Task.Source) &&\r
- string.IsNullOrEmpty(this.Task.Destination);\r
- }\r
- }\r
-\r
/// <summary>\r
/// Gets or sets the query string.\r
/// </summary>\r
public string Query { get; set; }\r
\r
- /// <summary>\r
- /// Gets or sets Source.\r
- /// </summary>\r
- public string Source { get; set; }\r
-\r
/// <summary>\r
/// Gets or sets Status.\r
/// </summary>\r
/// </summary>\r
public EncodeTask Task { get; set; }\r
\r
- /// <summary>\r
- /// Gets or sets Title.\r
- /// </summary>\r
- public int Title { get; set; }\r
-\r
#endregion\r
}\r
}
\ No newline at end of file
// Make sure the path exists, attempt to create it if it doesn't\r
try\r
{\r
- string path = Directory.GetParent(task.Destination ?? task.Task.Destination).ToString();\r
+ string path = Directory.GetParent(task.Task.Destination).ToString();\r
if (!Directory.Exists(path))\r
{\r
Directory.CreateDirectory(path);\r
{\r
lock (QueueLock)\r
{\r
- // Tag the job with an ID\r
- job.Id = lastJobId++;\r
queue.Add(job);\r
InvokeQueueChanged(EventArgs.Empty);\r
}\r
/// <returns>Whether or not the supplied destination is already in the queue.</returns>\r
public bool CheckForDestinationPathDuplicates(string destination)\r
{\r
- return this.queue.Any(checkItem => checkItem.Destination.Contains(destination.Replace("\\\\", "\\")));\r
+ return this.queue.Any(checkItem => checkItem.Task.Destination.Contains(destination.Replace("\\\\", "\\")));\r
}\r
\r
/// <summary>\r
{\r
this.QueueManager.LastProcessedJob.Status = QueueItemStatus.Completed;\r
\r
+ // Clear the completed item of the queue if the setting is set.\r
+ if (userSettingService.GetUserSetting<bool>(ASUserSettingConstants.ClearCompletedFromQueue))\r
+ {\r
+ this.QueueManager.ClearCompleted();\r
+ }\r
+\r
// Growl\r
if (userSettingService.GetUserSetting<bool>(ASUserSettingConstants.GrowlEncode))\r
GrowlCommunicator.Notify("Encode Completed",\r
}\r
\r
// Handling Log Data \r
- this.EncodeService.ProcessLogs(this.QueueManager.LastProcessedJob.Destination);\r
+ this.EncodeService.ProcessLogs(this.QueueManager.LastProcessedJob.Task.Destination);\r
\r
// Post-Processing\r
if (e.Successful)\r
{\r
- SendToApplication(this.QueueManager.LastProcessedJob.Destination);\r
+ SendToApplication(this.QueueManager.LastProcessedJob.Task.Destination);\r
}\r
\r
// Move onto the next job.\r
namespace HandBrake.ApplicationServices.Services\r
{\r
using System;\r
- using System.Collections.Generic;\r
using System.Collections.Specialized;\r
using System.IO;\r
+ using System.Linq;\r
using System.Windows.Forms;\r
using System.Xml.Serialization;\r
\r
this.Load();\r
if (userSettings == null || userSettings.Count == 0)\r
{\r
- this.LoadDefaults();\r
+ this.userSettings = this.GetDefaults();\r
}\r
}\r
\r
/// </summary>\r
private void Save()\r
{\r
- string directory = Path.GetDirectoryName(this.settingsFile);\r
- if (!string.IsNullOrEmpty(directory) && !Directory.Exists(directory))\r
+ try\r
{\r
- Directory.CreateDirectory(directory);\r
- }\r
+ string directory = Path.GetDirectoryName(this.settingsFile);\r
+ if (!string.IsNullOrEmpty(directory) && !Directory.Exists(directory))\r
+ {\r
+ Directory.CreateDirectory(directory);\r
+ }\r
\r
- using (FileStream strm = new FileStream(this.settingsFile, FileMode.Create, FileAccess.Write))\r
+ using (FileStream strm = new FileStream(this.settingsFile, FileMode.Create, FileAccess.Write))\r
+ {\r
+ serializer.Serialize(strm, this.userSettings);\r
+ }\r
+ }\r
+ catch (Exception exc)\r
{\r
- serializer.Serialize(strm, this.userSettings);\r
+ throw new GeneralApplicationException(\r
+ "A problem occured when trying to save your preferences.",\r
+ "Any settings you changed may need to be reset the next time HandBrake launches.",\r
+ exc);\r
}\r
}\r
\r
{\r
SerializableDictionary<string, object> data = (SerializableDictionary<string, object>)serializer.Deserialize(reader);\r
this.userSettings = data;\r
+\r
+ // Add any new settings\r
+ SerializableDictionary<string, object> defaults = this.GetDefaults();\r
+ foreach (var item in defaults.Where(item => !this.userSettings.Keys.Contains(item.Key)))\r
+ {\r
+ this.userSettings.Add(item.Key, item.Value);\r
+ }\r
}\r
+\r
+ this.Save();\r
}\r
}\r
catch (Exception exc)\r
/// <summary>\r
/// Load Default Settings\r
/// </summary>\r
- private void LoadDefaults()\r
+ /// <returns>\r
+ /// The get defaults.\r
+ /// </returns>\r
+ private SerializableDictionary<string, object> GetDefaults()\r
{\r
- string defaults = Path.Combine(Application.StartupPath, "defaultsettings.xml");\r
- if (File.Exists(defaults))\r
+ try\r
{\r
- using (StreamReader reader = new StreamReader(defaults))\r
+ string defaults = Path.Combine(Application.StartupPath, "defaultsettings.xml");\r
+ if (File.Exists(defaults))\r
{\r
- SerializableDictionary<string, object> data = (SerializableDictionary<string, object>)serializer.Deserialize(reader);\r
- this.userSettings = data;\r
+ using (StreamReader reader = new StreamReader(defaults))\r
+ {\r
+ return (SerializableDictionary<string, object>)serializer.Deserialize(reader);\r
+ }\r
}\r
- }\r
- }\r
\r
- /// <summary>\r
- /// This is just a utility method for creating a defaults xml file. Don't use this!!!\r
- /// </summary>\r
- private void SetAllDefaults()\r
- {\r
- userSettings = new SerializableDictionary<string, object>();\r
- userSettings[ASUserSettingConstants.X264Step] = 0.25;\r
- userSettings[ASUserSettingConstants.Verbosity] = 1;\r
- userSettings[ASUserSettingConstants.WhenCompleteAction] = "Do Nothing";\r
- userSettings[ASUserSettingConstants.GrowlEncode] = false;\r
- userSettings[ASUserSettingConstants.GrowlQueue] = false;\r
- userSettings[ASUserSettingConstants.ProcessPriority] = "Below Normal";\r
- userSettings[ASUserSettingConstants.PreventSleep] = true;\r
- userSettings[ASUserSettingConstants.ShowCLI] = false;\r
- userSettings[ASUserSettingConstants.SaveLogToCopyDirectory] = false;\r
- userSettings[ASUserSettingConstants.SaveLogWithVideo] = false;\r
- userSettings[ASUserSettingConstants.DisableLibDvdNav] = false;\r
- userSettings[ASUserSettingConstants.SendFile] = false;\r
- userSettings[ASUserSettingConstants.MinScanDuration] = 10;\r
- userSettings[ASUserSettingConstants.HandBrakeBuild] = 0;\r
- userSettings[ASUserSettingConstants.HandBrakeVersion] = string.Empty;\r
- userSettings["updateStatus"] = true;\r
- userSettings["tooltipEnable"] = true;\r
- userSettings["defaultPreset"] = string.Empty;\r
- userSettings["skipversion"] = 0;\r
- userSettings["autoNaming"] = true;\r
- userSettings["autoNamePath"] = string.Empty;\r
- userSettings["appcast_i686"] = "http://handbrake.fr/appcast.i386.xml";\r
- userSettings["appcast_x64"] = "http://handbrake.fr/appcast_unstable.x86_64.xml";\r
- userSettings["autoNameFormat"] = "{source}-{title}";\r
- userSettings["VLC_Path"] = "C:\\Program Files\\VideoLAN\\vlc\\vlc.exe";\r
- userSettings["MainWindowMinimize"] = true;\r
- userSettings["QueryEditorTab"] = false;\r
- userSettings["presetNotification"] = false;\r
- userSettings["trayIconAlerts"] = true;\r
- userSettings["lastUpdateCheckDate"] = DateTime.Today;\r
- userSettings["daysBetweenUpdateCheck"] = 7;\r
- userSettings["useM4v"] = 0;\r
- userSettings["PromptOnUnmatchingQueries"] = true;\r
- userSettings["NativeLanguage"] = "Any";\r
- userSettings["DubMode"] = 255;\r
- userSettings["HandBrakeExeHash"] = string.Empty;\r
- userSettings["previewScanCount"] = 10;\r
- userSettings["clearOldLogs"] = true;\r
- userSettings["AutoNameTitleCase"] = true;\r
- userSettings["AutoNameRemoveUnderscore"] = true;\r
- userSettings["ActivityWindowLastMode"] = 0;\r
- userSettings["useClosedCaption"] = false;\r
- userSettings["batchMinDuration"] = "00:18:00";\r
- userSettings["batchMaxDuration"] = "02:30:00";\r
- userSettings["defaultPlayer"] = false;\r
- userSettings["SelectedLanguages"] = new StringCollection();\r
- userSettings["DubModeAudio"] = 0;\r
- userSettings["DubModeSubtitle"] = 0;\r
- userSettings["addOnlyOneAudioPerLanguage"] = true;\r
- userSettings["MinTitleLength"] = 10;\r
- userSettings["ShowAdvancedAudioPassthruOpts"] = false;\r
+ throw new GeneralApplicationException(\r
+ "User default settings file is missing. This install of HandBrake may be corrupted.",\r
+ "Try re-installing HandBrake.",\r
+ null);\r
+ }\r
+ catch (Exception exc)\r
+ {\r
+ throw new GeneralApplicationException(\r
+ "User default settings file is missing or inaccessible. This install of HandBrake may be corrupted.",\r
+ "Try re-installing HandBrake.",\r
+ exc);\r
+ }\r
}\r
}\r
}\r
// Create the Queue Task and Start Processing\r
QueueTask task = new QueueTask(null)\r
{\r
- Destination = this.CurrentTask.Destination,\r
Task = this.CurrentTask,\r
Query = QueryGeneratorUtility.GenerateQuery(this.CurrentTask),\r
CustomQuery = false\r
using System;\r
using System.Collections.Generic;\r
using System.ComponentModel.Composition;\r
+ using System.Globalization;\r
\r
using Caliburn.Micro;\r
\r
this.ShowPeakFramerate = true;\r
if (this.Task.FramerateMode == FramerateMode.VFR)\r
{\r
- this.Task.FramerateMode = FramerateMode.PFR; \r
- } \r
+ this.Task.FramerateMode = FramerateMode.PFR;\r
+ }\r
this.Task.Framerate = double.Parse(value);\r
}\r
\r
{\r
return;\r
}\r
- \r
+\r
this.SelectedVideoEncoder = preset.Task.VideoEncoder;\r
- this.SelectedFramerate = preset.Task.Framerate.ToString();\r
+ if (preset.Task.Framerate.HasValue)\r
+ {\r
+ this.SelectedFramerate = preset.Task.Framerate.Value.ToString(CultureInfo.InvariantCulture);\r
+ }\r
+\r
+ this.IsConstantQuantity = preset.Task.VideoEncodeRateType == VideoEncodeRateType.ConstantQuality;\r
+\r
switch (preset.Task.FramerateMode)\r
{\r
case FramerateMode.CFR:\r
this.ShowPeakFramerate = true;\r
break;\r
}\r
- \r
- // TODO Compute RF\r
- this.RF = 20;\r
+\r
+ double cqStep = userSettingService.GetUserSetting<double>(ASUserSettingConstants.X264Step);\r
+ double rfValue = 0;\r
+ switch (this.SelectedVideoEncoder)\r
+ {\r
+ case VideoEncoder.FFMpeg:\r
+ case VideoEncoder.FFMpeg2:\r
+ int cq;\r
+ if (preset.Task.Quality.HasValue)\r
+ {\r
+ int.TryParse(preset.Task.Quality.Value.ToString(CultureInfo.InvariantCulture), out cq);\r
+ this.RF = 32 - cq;\r
+ }\r
+ break;\r
+ case VideoEncoder.X264:\r
+ \r
+ double multiplier = 1.0 / cqStep;\r
+ if (preset.Task.Quality.HasValue)\r
+ {\r
+ rfValue = preset.Task.Quality.Value * multiplier;\r
+ }\r
+\r
+ this.RF = this.QualityMax - (int)Math.Round(rfValue, 0);\r
+\r
+ break;\r
+\r
+ case VideoEncoder.Theora:\r
+ if (preset.Task.Quality.HasValue)\r
+ {\r
+ this.RF = (int)preset.Task.Quality.Value;\r
+ }\r
+ break;\r
+ }\r
\r
this.Task.TwoPass = preset.Task.TwoPass;\r
this.Task.TurboFirstPass = preset.Task.TurboFirstPass;\r
<string>appcast_x64</string>\r
</key>\r
<value>\r
- <anyType xmlns:q1="http://www.w3.org/2001/XMLSchema" d4p1:type="q1:string" xmlns:d4p1="http://www.w3.org/2001/XMLSchema-instance">http://handbrake.fr/appcast_unstable.x86_64.xml</anyType>\r
+ <anyType xmlns:q1="http://www.w3.org/2001/XMLSchema" d4p1:type="q1:string" xmlns:d4p1="http://www.w3.org/2001/XMLSchema-instance">http://handbrake.fr/appcast.86_64.xml</anyType>\r
</value>\r
</item>\r
<item>\r
<anyType xmlns:q1="http://www.w3.org/2001/XMLSchema" d4p1:type="q1:string" xmlns:d4p1="http://www.w3.org/2001/XMLSchema-instance">MinGW i686</anyType>\r
</value>\r
</item>\r
+ <item>\r
+ <key>\r
+ <string>ClearCompletedFromQueue</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
</dictionary>
\ No newline at end of file
<string>appcast_x64</string>\r
</key>\r
<value>\r
- <anyType xmlns:q1="http://www.w3.org/2001/XMLSchema" d4p1:type="q1:string" xmlns:d4p1="http://www.w3.org/2001/XMLSchema-instance">http://handbrake.fr/appcast_unstable.x86_64.xml</anyType>\r
+ <anyType xmlns:q1="http://www.w3.org/2001/XMLSchema" d4p1:type="q1:string" xmlns:d4p1="http://www.w3.org/2001/XMLSchema-instance">http://handbrake.fr/appcast.86_64.xml</anyType>\r
</value>\r
</item>\r
<item>\r
<anyType xmlns:q1="http://www.w3.org/2001/XMLSchema" d4p1:type="q1:string" xmlns:d4p1="http://www.w3.org/2001/XMLSchema-instance">MinGW i686</anyType>\r
</value>\r
</item>\r
+ <item>\r
+ <key>\r
+ <string>ClearCompletedFromQueue</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
</dictionary>
\ No newline at end of file
this.AudioSettings.LoadTracks(preset);\r
\r
// Set the destination path);\r
- this.text_destination.Text = queueEdit.Destination;\r
+ this.text_destination.Text = queueEdit.Task.Destination;\r
\r
// The x264 widgets will need updated, so do this now:\r
x264Panel.StandardizeOptString();\r
\r
// Scan\r
queueEdit = job; // Nasty but will do for now. TODO\r
- StartScan(job.Source, job.Title);\r
+ StartScan(job.Task.Source, job.Task.Title);\r
}\r
\r
#endregion\r
int duration;\r
int.TryParse(endPoint.Text, out duration);\r
string query = QueryGenerator.GeneratePreviewQuery(this.mainWindow, duration, startPoint.Text);\r
- QueueTask task = new QueueTask(query) { Destination = this.mainWindow.text_destination.Text };\r
+ QueueTask task = new QueueTask(query) { Task = { Destination = this.mainWindow.text_destination.Text } };\r
ThreadPool.QueueUserWorkItem(this.CreatePreview, task);\r
}\r
\r
{ Tag = queueItem, Text = EnumHelper<QueueItemStatus>.GetDescription(queueItem.Status) };\r
item.SubItems.Add(title);\r
item.SubItems.Add(chapters); // Chapters\r
- item.SubItems.Add(queueItem.Source); // Source\r
- item.SubItems.Add(queueItem.Destination); // Destination\r
+ item.SubItems.Add(queueItem.Task.Source); // Source\r
+ item.SubItems.Add(queueItem.Task.Destination); // Destination\r
item.SubItems.Add(EnumHelper<VideoEncoder>.GetDisplay(parsed.VideoEncoder));\r
\r
// Display The Audio Track Information\r
\r
// found query is a global varible \r
lbl_encodeStatus.Text = "Encoding ...";\r
- lbl_source.Text = queue.QueueManager.LastProcessedJob.Source + "(Title: " + title + " Chapters: " + chapterlbl + ")";\r
- lbl_dest.Text = queue.QueueManager.LastProcessedJob.Destination;\r
+ lbl_source.Text = queue.QueueManager.LastProcessedJob.Task.Source + "(Title: " + title + " Chapters: " + chapterlbl + ")";\r
+ lbl_dest.Text = queue.QueueManager.LastProcessedJob.Task.Destination;\r
lbl_encodeOptions.Text = string.Format("Video: {0}, Audio: {1}\nx264 Options: {2}",\r
EnumHelper<VideoEncoder>.GetDisplay(parsed.VideoEncoder),\r
audio, \r