summaryrefslogtreecommitdiffstats
path: root/win/C#
diff options
context:
space:
mode:
Diffstat (limited to 'win/C#')
-rw-r--r--win/C#/EncodeQueue/Encode.cs191
-rw-r--r--win/C#/EncodeQueue/EncodeAndQueueHandler.cs (renamed from win/C#/EncodeQueue/QueueHandler.cs)259
-rw-r--r--win/C#/Functions/Main.cs167
-rw-r--r--win/C#/HandBrakeCS.csproj3
-rw-r--r--win/C#/Properties/Settings.Designer.cs12
-rw-r--r--win/C#/Properties/Settings.settings3
-rw-r--r--win/C#/app.config3
-rw-r--r--win/C#/frmAbout.Designer.cs29
-rw-r--r--win/C#/frmAbout.cs4
-rw-r--r--win/C#/frmActivityWindow.cs37
-rw-r--r--win/C#/frmMain.cs14
-rw-r--r--win/C#/frmPreview.cs2
-rw-r--r--win/C#/frmQueue.cs6
13 files changed, 354 insertions, 376 deletions
diff --git a/win/C#/EncodeQueue/Encode.cs b/win/C#/EncodeQueue/Encode.cs
deleted file mode 100644
index 83ebc986b..000000000
--- a/win/C#/EncodeQueue/Encode.cs
+++ /dev/null
@@ -1,191 +0,0 @@
-/* Encode.cs $
-
- This file is part of the HandBrake source code.
- Homepage: <http://handbrake.fr>.
- It may be used under the terms of the GNU General Public License. */
-
-using System;
-using System.Diagnostics;
-using System.Windows.Forms;
-using System.IO;
-using Handbrake.Functions;
-
-namespace Handbrake.EncodeQueue
-{
- public class Encode
- {
- public Process hbProcess { get; set; }
- public int processID { get; set; }
- public IntPtr processHandle { get; set; }
- public Boolean isEncoding { get; set; }
- public String currentQuery { get; set; }
-
- /// <summary>
- /// Execute a HandBrakeCLI process.
- /// </summary>
- /// <param name="query">The CLI Query</param>
- public void runCli(string query)
- {
- try
- {
- string handbrakeCLIPath = Path.Combine(Application.StartupPath, "HandBrakeCLI.exe");
- string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";
- string logPath = Path.Combine(logDir, "last_encode_log.txt");
- string strCmdLine = String.Format(@" CMD /c """"{0}"" {1} 2>""{2}"" """, handbrakeCLIPath, query, logPath);
-
- ProcessStartInfo cliStart = new ProcessStartInfo("CMD.exe", strCmdLine);
- if (Properties.Settings.Default.enocdeStatusInGui)
- {
- cliStart.RedirectStandardOutput = true;
- cliStart.UseShellExecute = false;
- }
- if (Properties.Settings.Default.cli_minimized)
- cliStart.WindowStyle = ProcessWindowStyle.Minimized;
-
- Process[] before = Process.GetProcesses(); // Get a list of running processes before starting.
- hbProcess = Process.Start(cliStart);
- processID = Main.getCliProcess(before);
- isEncoding = true;
- currentQuery = query;
- if (hbProcess != null)
- processHandle = hbProcess.MainWindowHandle; // Set the process Handle
-
- // Set the process Priority
- Process hbCliProcess = null;
- if (processID != -1)
- hbCliProcess = Process.GetProcessById(processID);
-
- if (hbCliProcess != null)
- switch (Properties.Settings.Default.processPriority)
- {
- case "Realtime":
- hbCliProcess.PriorityClass = ProcessPriorityClass.RealTime;
- break;
- case "High":
- hbCliProcess.PriorityClass = ProcessPriorityClass.High;
- break;
- case "Above Normal":
- hbCliProcess.PriorityClass = ProcessPriorityClass.AboveNormal;
- break;
- case "Normal":
- hbCliProcess.PriorityClass = ProcessPriorityClass.Normal;
- break;
- case "Low":
- hbCliProcess.PriorityClass = ProcessPriorityClass.Idle;
- break;
- default:
- hbCliProcess.PriorityClass = ProcessPriorityClass.BelowNormal;
- break;
- }
- }
- catch (Exception exc)
- {
- MessageBox.Show("It would appear that HandBrakeCLI has not started correctly. You should take a look at the Activity log as it may indicate the reason why.\n\n Detailed Error Information: error occured in runCli()\n\n" + exc, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
-
- }
-
- /// <summary>
- /// Kill the CLI process
- /// </summary>
- public void closeCLI()
- {
- hbProcess.Kill();
- }
-
- /// <summary>
- /// Perform an action after an encode. e.g a shutdown, standby, restart etc.
- /// </summary>
- public void afterEncodeAction()
- {
- isEncoding = false;
- currentQuery = String.Empty;
- // Do something whent he encode ends.
- switch (Properties.Settings.Default.CompletionOption)
- {
- case "Shutdown":
- Process.Start("Shutdown", "-s -t 60");
- break;
- case "Log Off":
- Win32.ExitWindowsEx(0, 0);
- break;
- case "Suspend":
- Application.SetSuspendState(PowerState.Suspend, true, true);
- break;
- case "Hibernate":
- Application.SetSuspendState(PowerState.Hibernate, true, true);
- break;
- case "Lock System":
- Win32.LockWorkStation();
- break;
- case "Quit HandBrake":
- Application.Exit();
- break;
- default:
- break;
- }
- }
-
- /// <summar>
- /// Append the CLI query to the start of the log file.
- /// </summary>
- /// <param name="query"></param>
- public void addCLIQueryToLog(string query)
- {
- string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";
- string logPath = Path.Combine(logDir, "last_encode_log.txt");
-
- StreamReader reader = new StreamReader(File.Open(logPath, FileMode.Open, FileAccess.Read, FileShare.Read));
- String log = reader.ReadToEnd();
- reader.Close();
-
- StreamWriter writer = new StreamWriter(File.Create(logPath));
-
- writer.Write("### CLI Query: " + query + "\n\n");
- writer.Write("#########################################\n\n");
- writer.WriteLine(log);
- writer.Flush();
- writer.Close();
- }
-
- /// <summary>
- /// Save a copy of the log to the users desired location or a default location
- /// if this feature is enabled in options.
- /// </summary>
- /// <param name="destination"></param>
- public void copyLog(string destination)
- {
- try
- {
- string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";
- string tempLogFile = Path.Combine(logDir, "last_encode_log.txt");
-
- string encodeDestinationPath = Path.GetDirectoryName(destination);
- String destinationFile = Path.GetFileName(destination);
- string encodeLogFile = destinationFile + " " + DateTime.Now.ToString().Replace("/", "-").Replace(":", "-") + ".txt";
-
- // Make sure the log directory exists.
- if (!Directory.Exists(logDir))
- Directory.CreateDirectory(logDir);
-
- // Copy the Log to HandBrakes log folder in the users applciation data folder.
- File.Copy(tempLogFile, Path.Combine(logDir, encodeLogFile));
-
- // Save a copy of the log file in the same location as the enocde.
- if (Properties.Settings.Default.saveLogWithVideo)
- File.Copy(tempLogFile, Path.Combine(encodeDestinationPath, encodeLogFile));
-
- // Save a copy of the log file to a user specified location
- if (Directory.Exists(Properties.Settings.Default.saveLogPath))
- if (Properties.Settings.Default.saveLogPath != String.Empty && Properties.Settings.Default.saveLogToSpecifiedPath)
- File.Copy(tempLogFile, Path.Combine(Properties.Settings.Default.saveLogPath, encodeLogFile));
- }
- catch (Exception exc)
- {
- MessageBox.Show("Something went a bit wrong trying to copy your log file.\nError Information:\n\n" + exc, "Error",
- MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
-
- }
-} \ No newline at end of file
diff --git a/win/C#/EncodeQueue/QueueHandler.cs b/win/C#/EncodeQueue/EncodeAndQueueHandler.cs
index d183af0c5..09d1f1419 100644
--- a/win/C#/EncodeQueue/QueueHandler.cs
+++ b/win/C#/EncodeQueue/EncodeAndQueueHandler.cs
@@ -7,45 +7,22 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
+using System.Diagnostics;
using System.IO;
using System.Threading;
using System.Windows.Forms;
using System.Xml.Serialization;
+using Handbrake.Functions;
namespace Handbrake.EncodeQueue
{
- /// <summary>
- /// Provides a handler for encoding jobs and a queue of those jobs.
- /// </summary>
- public class QueueHandler
+ public class EncodeAndQueueHandler
{
- public Encode encodeHandler = new Encode();
private static XmlSerializer serializer = new XmlSerializer(typeof(List<Job>));
private List<Job> queue = new List<Job>();
private int nextJobId;
- /// <summary>
- /// Gets the number of items in the queue.
- /// </summary>
- public int Count
- {
- get { return queue.Count; }
- }
-
- /// <summary>
- /// Gets the last encode that was processed.
- /// </summary>
- /// <returns></returns>
- public Job LastEncode { get; set; }
-
- /// <summary>
- /// Gets the current state of the encode queue.
- /// </summary>
- public ReadOnlyCollection<Job> CurrentQueue
- {
- get { return queue.AsReadOnly(); }
- }
-
+ #region Event Handlers
/// <summary>
/// Fires when an encode job has been started.
/// </summary>
@@ -65,9 +42,9 @@ namespace Handbrake.EncodeQueue
/// Fires when the entire encode queue has completed.
/// </summary>
public event EventHandler QueueCompleted;
+ #endregion
- #region Queue Handling
-
+ #region Queue
/// <summary>
/// Gets and removes the next job in the queue.
/// </summary>
@@ -84,6 +61,23 @@ namespace Handbrake.EncodeQueue
}
/// <summary>
+ /// Gets the current state of the encode queue.
+ /// </summary>
+ public ReadOnlyCollection<Job> CurrentQueue
+ {
+ get { return queue.AsReadOnly(); }
+ }
+
+ /// <summary>
+ /// Gets the number of items in the queue.
+ /// </summary>
+ public int Count
+ {
+ get { return queue.Count; }
+ }
+
+
+ /// <summary>
/// Adds an item to the queue.
/// </summary>
/// <param name="query">The query that will be passed to the HandBrake CLI.</param>
@@ -252,15 +246,23 @@ namespace Handbrake.EncodeQueue
#region Encoding
- public bool PauseRequested { get; private set; }
- public bool IsEncoding { get; private set; }
+ /// <summary>
+ /// Gets the last encode that was processed.
+ /// </summary>
+ /// <returns></returns>
+ public Job LastEncode { get; set; }
+
+ /// <summary>
+ /// Request Pause
+ /// </summary>
+ public Boolean PauseRequested { get; private set; }
/// <summary>
/// Starts encoding the first job in the queue and continues encoding until all jobs
/// have been encoded.
/// </summary>
public void StartEncodeQueue()
- {
+ {
if (this.Count != 0)
{
if (PauseRequested)
@@ -297,7 +299,7 @@ namespace Handbrake.EncodeQueue
/// </summary>
public void EndEncodeJob()
{
- encodeHandler.closeCLI();
+ closeCLI();
}
private void startProcess(object state)
@@ -308,18 +310,20 @@ namespace Handbrake.EncodeQueue
string query = GetNextJob().Query;
WriteQueueStateToFile("hb_queue_recovery.xml"); // Update the queue recovery file
- encodeHandler.runCli(query);
+ runCli(query);
if (NewJobStarted != null)
NewJobStarted(this, new EventArgs());
- encodeHandler.hbProcess.WaitForExit();
+ hbProcess.WaitForExit();
- encodeHandler.addCLIQueryToLog(query);
- encodeHandler.copyLog(LastEncode.Destination);
+ addCLIQueryToLog(query);
+ copyLog(LastEncode.Destination);
- encodeHandler.hbProcess.Close();
- encodeHandler.hbProcess.Dispose();
+ hbProcess.Close();
+ hbProcess.Dispose();
+
+ isEncoding = false;
if (CurrentJobCompleted != null)
CurrentJobCompleted(this, new EventArgs());
@@ -334,9 +338,184 @@ namespace Handbrake.EncodeQueue
QueueCompleted(this, new EventArgs());
// After the encode is done, we may want to shutdown, suspend etc.
- encodeHandler.afterEncodeAction();
+ afterEncodeAction();
}
#endregion
+
+ #region CLI and Log Handling
+ public Process hbProcess { get; set; }
+ public int processID { get; set; }
+ public IntPtr processHandle { get; set; }
+ public String currentQuery { get; set; }
+ public Boolean isEncoding { get; set; }
+
+ /// <summary>
+ /// Execute a HandBrakeCLI process.
+ /// </summary>
+ /// <param name="query">The CLI Query</param>
+ public void runCli(string query)
+ {
+ try
+ {
+ string handbrakeCLIPath = Path.Combine(Application.StartupPath, "HandBrakeCLI.exe");
+ string logPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs", "last_encode_log.txt");
+ string strCmdLine = String.Format(@" /C """"{0}"" {1} 2>""{2}"" """, handbrakeCLIPath, query, logPath);
+ ProcessStartInfo cliStart = new ProcessStartInfo("CMD.exe", strCmdLine);
+
+ if (Properties.Settings.Default.enocdeStatusInGui)
+ {
+ cliStart.RedirectStandardOutput = true;
+ cliStart.UseShellExecute = false;
+ }
+ if (Properties.Settings.Default.cli_minimized)
+ cliStart.WindowStyle = ProcessWindowStyle.Minimized;
+
+ Process[] before = Process.GetProcesses(); // Get a list of running processes before starting.
+ hbProcess = Process.Start(cliStart);
+ processID = Main.getCliProcess(before);
+ isEncoding = true;
+ currentQuery = query;
+ if (hbProcess != null)
+ processHandle = hbProcess.MainWindowHandle; // Set the process Handle
+
+ // Set the process Priority
+ Process hbCliProcess = null;
+ if (processID != -1)
+ hbCliProcess = Process.GetProcessById(processID);
+
+ if (hbCliProcess != null)
+ switch (Properties.Settings.Default.processPriority)
+ {
+ case "Realtime":
+ hbCliProcess.PriorityClass = ProcessPriorityClass.RealTime;
+ break;
+ case "High":
+ hbCliProcess.PriorityClass = ProcessPriorityClass.High;
+ break;
+ case "Above Normal":
+ hbCliProcess.PriorityClass = ProcessPriorityClass.AboveNormal;
+ break;
+ case "Normal":
+ hbCliProcess.PriorityClass = ProcessPriorityClass.Normal;
+ break;
+ case "Low":
+ hbCliProcess.PriorityClass = ProcessPriorityClass.Idle;
+ break;
+ default:
+ hbCliProcess.PriorityClass = ProcessPriorityClass.BelowNormal;
+ break;
+ }
+ }
+ catch (Exception exc)
+ {
+ MessageBox.Show("It would appear that HandBrakeCLI has not started correctly. You should take a look at the Activity log as it may indicate the reason why.\n\n Detailed Error Information: error occured in runCli()\n\n" + exc, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+
+ }
+
+ /// <summary>
+ /// Kill the CLI process
+ /// </summary>
+ public void closeCLI()
+ {
+ hbProcess.Kill();
+ isEncoding = false;
+ }
+
+ /// <summary>
+ /// Perform an action after an encode. e.g a shutdown, standby, restart etc.
+ /// </summary>
+ public void afterEncodeAction()
+ {
+ isEncoding = false;
+ currentQuery = String.Empty;
+ // Do something whent he encode ends.
+ switch (Properties.Settings.Default.CompletionOption)
+ {
+ case "Shutdown":
+ Process.Start("Shutdown", "-s -t 60");
+ break;
+ case "Log Off":
+ Win32.ExitWindowsEx(0, 0);
+ break;
+ case "Suspend":
+ Application.SetSuspendState(PowerState.Suspend, true, true);
+ break;
+ case "Hibernate":
+ Application.SetSuspendState(PowerState.Hibernate, true, true);
+ break;
+ case "Lock System":
+ Win32.LockWorkStation();
+ break;
+ case "Quit HandBrake":
+ Application.Exit();
+ break;
+ default:
+ break;
+ }
+ }
+
+ /// <summar>
+ /// Append the CLI query to the start of the log file.
+ /// </summary>
+ /// <param name="query"></param>
+ public void addCLIQueryToLog(string query)
+ {
+ string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";
+ string logPath = Path.Combine(logDir, "last_encode_log.txt");
+
+ StreamReader reader = new StreamReader(File.Open(logPath, FileMode.Open, FileAccess.Read, FileShare.Read));
+ String log = reader.ReadToEnd();
+ reader.Close();
+
+ StreamWriter writer = new StreamWriter(File.Create(logPath));
+
+ writer.Write("### CLI Query: " + query + "\n\n");
+ writer.Write("#########################################\n\n");
+ writer.WriteLine(log);
+ writer.Flush();
+ writer.Close();
+ }
+
+ /// <summary>
+ /// Save a copy of the log to the users desired location or a default location
+ /// if this feature is enabled in options.
+ /// </summary>
+ /// <param name="destination"></param>
+ public void copyLog(string destination)
+ {
+ try
+ {
+ string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";
+ string tempLogFile = Path.Combine(logDir, "last_encode_log.txt");
+
+ string encodeDestinationPath = Path.GetDirectoryName(destination);
+ String destinationFile = Path.GetFileName(destination);
+ string encodeLogFile = destinationFile + " " + DateTime.Now.ToString().Replace("/", "-").Replace(":", "-") + ".txt";
+
+ // Make sure the log directory exists.
+ if (!Directory.Exists(logDir))
+ Directory.CreateDirectory(logDir);
+
+ // Copy the Log to HandBrakes log folder in the users applciation data folder.
+ File.Copy(tempLogFile, Path.Combine(logDir, encodeLogFile));
+
+ // Save a copy of the log file in the same location as the enocde.
+ if (Properties.Settings.Default.saveLogWithVideo)
+ File.Copy(tempLogFile, Path.Combine(encodeDestinationPath, encodeLogFile));
+
+ // Save a copy of the log file to a user specified location
+ if (Directory.Exists(Properties.Settings.Default.saveLogPath))
+ if (Properties.Settings.Default.saveLogPath != String.Empty && Properties.Settings.Default.saveLogToSpecifiedPath)
+ File.Copy(tempLogFile, Path.Combine(Properties.Settings.Default.saveLogPath, encodeLogFile));
+ }
+ catch (Exception exc)
+ {
+ MessageBox.Show("Something went a bit wrong trying to copy your log file.\nError Information:\n\n" + exc, "Error",
+ MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ #endregion
}
} \ No newline at end of file
diff --git a/win/C#/Functions/Main.cs b/win/C#/Functions/Main.cs
index 075bdfa9f..987876e56 100644
--- a/win/C#/Functions/Main.cs
+++ b/win/C#/Functions/Main.cs
@@ -25,122 +25,75 @@ namespace Handbrake.Functions
/// <summary>
/// Calculate the duration of the selected title and chapters
/// </summary>
- public static TimeSpan calculateDuration(string chapter_start, string chapter_end, Parsing.Title selectedTitle)
+ public static TimeSpan calculateDuration(int chapterStart, int chapterEnd, Parsing.Title selectedTitle)
{
- TimeSpan Duration = TimeSpan.FromSeconds(0.0);
-
- // Get the durations between the 2 chapter points and add them together.
- if (chapter_start != "Auto" && chapter_end != "Auto")
+ TimeSpan duration = TimeSpan.FromSeconds(0.0);
+ chapterStart++; chapterEnd++;
+ if (chapterStart != 0 && chapterEnd != 0 && chapterEnd <= selectedTitle.Chapters.Count)
{
- int start_chapter, end_chapter;
- int.TryParse(chapter_start, out start_chapter);
- int.TryParse(chapter_end, out end_chapter);
-
- int position = start_chapter - 1;
-
- if (start_chapter <= end_chapter)
- {
- if (end_chapter > selectedTitle.Chapters.Count)
- end_chapter = selectedTitle.Chapters.Count;
-
- while (position != end_chapter)
- {
- TimeSpan dur = selectedTitle.Chapters[position].Duration;
- Duration = Duration + dur;
- position++;
- }
- }
+ for (int i = chapterStart; i <= chapterEnd; i++)
+ duration += selectedTitle.Chapters[i - 1].Duration;
}
- return Duration;
+
+ return duration;
}
/// <summary>
/// Select the longest title in the DVD title dropdown menu on frmMain
/// </summary>
- public static Parsing.Title selectLongestTitle(ComboBox drp_dvdtitle)
+ public static Parsing.Title selectLongestTitle(Parsing.DVD thisDvd)
{
- int current_largest = 0;
- Parsing.Title title2Select;
-
- // Check if there are titles in the DVD title dropdown menu and make sure, it's not just "Automatic"
- if (drp_dvdtitle.Items[0].ToString() != "Automatic")
- title2Select = (Parsing.Title)drp_dvdtitle.Items[0];
- else
- title2Select = null;
+ TimeSpan longestDurationFound = TimeSpan.FromSeconds(0.0);
+ Parsing.Title returnTitle = null;
- // So, If there are titles in the DVD Title dropdown menu, lets select the longest.
- if (title2Select != null)
+ foreach (Parsing.Title item in thisDvd.Titles)
{
- foreach (Parsing.Title x in drp_dvdtitle.Items)
+ if (item.Duration > longestDurationFound)
{
- string title = x.ToString();
- if (title != "Automatic")
- {
- string[] y = title.Split(' ');
- string time = y[1].Replace("(", "").Replace(")", "");
- string[] z = time.Split(':');
-
- int hours = int.Parse(z[0]) * 60 * 60;
- int minutes = int.Parse(z[1]) * 60;
- int seconds = int.Parse(z[2]);
- int total_sec = hours + minutes + seconds;
-
- if (current_largest == 0)
- {
- current_largest = hours + minutes + seconds;
- title2Select = x;
- }
- else
- {
- if (total_sec > current_largest)
- {
- current_largest = total_sec;
- title2Select = x;
- }
- }
- }
+ returnTitle = item;
+ longestDurationFound = item.Duration;
}
}
- return title2Select;
+ return returnTitle;
}
/// <summary>
/// Set's up the DataGridView on the Chapters tab (frmMain)
/// </summary>
- public static DataGridView chapterNaming(DataGridView data_chpt, string chapter_end)
+ public static DataGridView chapterNaming(DataGridView dataChpt, string chapterEnd)
{
int i = 0, finish = 0;
- if (chapter_end != "Auto")
- int.TryParse(chapter_end, out finish);
+ if (chapterEnd != "Auto")
+ int.TryParse(chapterEnd, out finish);
while (i < finish)
{
- int n = data_chpt.Rows.Add();
- data_chpt.Rows[n].Cells[0].Value = (i + 1);
- data_chpt.Rows[n].Cells[1].Value = "Chapter " + (i + 1);
- data_chpt.Rows[n].Cells[0].ValueType = typeof(int);
- data_chpt.Rows[n].Cells[1].ValueType = typeof(string);
+ int n = dataChpt.Rows.Add();
+ dataChpt.Rows[n].Cells[0].Value = (i + 1);
+ dataChpt.Rows[n].Cells[1].Value = "Chapter " + (i + 1);
+ dataChpt.Rows[n].Cells[0].ValueType = typeof(int);
+ dataChpt.Rows[n].Cells[1].ValueType = typeof(string);
i++;
}
- return data_chpt;
+ return dataChpt;
}
/// <summary>
/// Function which generates the filename and path automatically based on
/// the Source Name, DVD title and DVD Chapters
/// </summary>
- public static string autoName(ComboBox drp_dvdtitle, string chapter_start, string chatper_end, string source, string dest, int format)
+ public static string autoName(ComboBox drpDvdtitle, string chapter_start, string chatper_end, string source, string dest, int format)
{
string AutoNamePath = string.Empty;
- if (drp_dvdtitle.Text != "Automatic")
+ if (drpDvdtitle.Text != "Automatic")
{
// Get the Source Name
string sourceName = Path.GetFileNameWithoutExtension(source);
// Get the Selected Title Number
- string[] titlesplit = drp_dvdtitle.Text.Split(' ');
+ string[] titlesplit = drpDvdtitle.Text.Split(' ');
string dvdTitle = titlesplit[0].Replace("Automatic", "");
// Get the Chapter Start and Chapter End Numbers
@@ -151,25 +104,25 @@ namespace Handbrake.Functions
combinedChapterTag = chapterStart + "-" + chapterFinish;
// Get the destination filename.
- string destination_filename;
+ string destinationFilename;
if (Properties.Settings.Default.autoNameFormat != "")
{
- destination_filename = Properties.Settings.Default.autoNameFormat;
- destination_filename = destination_filename.Replace("{source}", sourceName).Replace("{title}", dvdTitle).Replace("{chapters}", combinedChapterTag);
+ destinationFilename = Properties.Settings.Default.autoNameFormat;
+ destinationFilename = destinationFilename.Replace("{source}", sourceName).Replace("{title}", dvdTitle).Replace("{chapters}", combinedChapterTag);
}
else
- destination_filename = sourceName + "_T" + dvdTitle + "_C" + combinedChapterTag;
+ destinationFilename = sourceName + "_T" + dvdTitle + "_C" + combinedChapterTag;
// Add the appropriate file extension
if (format == 0)
{
if (Properties.Settings.Default.useM4v)
- destination_filename += ".m4v";
+ destinationFilename += ".m4v";
else
- destination_filename += ".mp4";
+ destinationFilename += ".mp4";
}
else if (format == 1)
- destination_filename += ".mkv";
+ destinationFilename += ".mkv";
// Now work out the path where the file will be stored.
// First case: If the destination box doesn't already contain a path, make one.
@@ -177,14 +130,14 @@ namespace Handbrake.Functions
{
// If there is an auto name path, use it...
if (Properties.Settings.Default.autoNamePath.Trim() != "" && Properties.Settings.Default.autoNamePath.Trim() != "Click 'Browse' to set the default location")
- AutoNamePath = Path.Combine(Properties.Settings.Default.autoNamePath, destination_filename);
+ AutoNamePath = Path.Combine(Properties.Settings.Default.autoNamePath, destinationFilename);
else // ...otherwise, output to the source directory
AutoNamePath = null;
}
else // Otherwise, use the path that is already there.
{
// Use the path and change the file extension to match the previous destination
- AutoNamePath = Path.Combine(Path.GetDirectoryName(dest), destination_filename);
+ AutoNamePath = Path.Combine(Path.GetDirectoryName(dest), destinationFilename);
AutoNamePath = Path.ChangeExtension(AutoNamePath, Path.GetExtension(dest));
}
}
@@ -222,6 +175,7 @@ namespace Handbrake.Functions
{
line = stdOutput.ReadLine() ?? "";
Match m = Regex.Match(line, @"HandBrake ([0-9.]*)(svn[0-9M]*) \([0-9]*\)");
+ Match platform = Regex.Match(line, @"- ([A-Za-z0-9\s ]*) -");
if (m.Success)
{
@@ -231,6 +185,9 @@ namespace Handbrake.Functions
Properties.Settings.Default.hb_build = int.Parse(arr[1]);
Properties.Settings.Default.hb_version = arr[0];
}
+ if (platform.Success)
+ Properties.Settings.Default.hb_platform = platform.Value.Replace("-", "").Trim();
+
if (cliProcess.TotalProcessorTime.Seconds > 10) // Don't wait longer than 10 seconds.
{
Process cli = Process.GetProcessById(cliProcess.Id);
@@ -286,34 +243,36 @@ namespace Handbrake.Functions
// avoiding any previous instances of HandBrakeCLI.exe in before.
// Kill the current process.
- Process[] hbProcesses = Process.GetProcessesByName("HandBrakeCLI");
+ DateTime startTime = DateTime.Now;
+ TimeSpan duration;
- // Another hack. We maybe need to wait a few seconds for HandBrakeCLI to launch
- if (hbProcesses.Length == 0)
+ Process[] hbProcesses = Process.GetProcessesByName("HandBrakeCLI");
+ while (hbProcesses.Length == 0)
{
- Thread.Sleep(2000);
hbProcesses = Process.GetProcessesByName("HandBrakeCLI");
+ duration = DateTime.Now - startTime;
+ if (duration.Seconds > 5 && hbProcesses.Length == 0) // Make sure we don't wait forever if the process doesn't start
+ return -1;
}
Process hbProcess = null;
- if (hbProcesses.Length > 0)
- foreach (Process process in hbProcesses)
+ foreach (Process process in hbProcesses)
+ {
+ Boolean found = false;
+ // Check if the current CLI instance was running before we started the current one
+ foreach (Process bprocess in before)
{
- Boolean found = false;
- // Check if the current CLI instance was running before we started the current one
- foreach (Process bprocess in before)
- {
- if (process.Id == bprocess.Id)
- found = true;
- }
+ if (process.Id == bprocess.Id)
+ found = true;
+ }
- // If it wasn't running before, we found the process we want.
- if (!found)
- {
- hbProcess = process;
- break;
- }
+ // If it wasn't running before, we found the process we want.
+ if (!found)
+ {
+ hbProcess = process;
+ break;
}
+ }
if (hbProcess != null)
return hbProcess.Id;
@@ -333,9 +292,7 @@ namespace Handbrake.Functions
foreach (FileInfo file in logFiles)
{
if (!file.Name.Contains("last_scan_log") && !file.Name.Contains("last_encode_log") && !file.Name.Contains("tmp_appReadable_log.txt"))
- {
File.Delete(file.FullName);
- }
}
}
}
diff --git a/win/C#/HandBrakeCS.csproj b/win/C#/HandBrakeCS.csproj
index fda90e513..13d5e1073 100644
--- a/win/C#/HandBrakeCS.csproj
+++ b/win/C#/HandBrakeCS.csproj
@@ -198,9 +198,8 @@
<Compile Include="Presets\Import.cs" />
<Compile Include="Presets\preset.cs" />
<Compile Include="Presets\PresetsHandler.cs" />
- <Compile Include="EncodeQueue\QueueHandler.cs" />
+ <Compile Include="EncodeQueue\EncodeAndQueueHandler.cs" />
<Compile Include="Functions\AppcastReader.cs" />
- <Compile Include="EncodeQueue\Encode.cs" />
<Compile Include="Functions\QueryParser.cs" />
<Compile Include="Parsing\AudioTrack.cs" />
<Compile Include="Parsing\Chapter.cs" />
diff --git a/win/C#/Properties/Settings.Designer.cs b/win/C#/Properties/Settings.Designer.cs
index f1cc044f0..4cf46354c 100644
--- a/win/C#/Properties/Settings.Designer.cs
+++ b/win/C#/Properties/Settings.Designer.cs
@@ -441,5 +441,17 @@ namespace Handbrake.Properties {
this["DubAudio"] = value;
}
}
+
+ [global::System.Configuration.UserScopedSettingAttribute()]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Configuration.DefaultSettingValueAttribute("")]
+ public string hb_platform {
+ get {
+ return ((string)(this["hb_platform"]));
+ }
+ set {
+ this["hb_platform"] = value;
+ }
+ }
}
}
diff --git a/win/C#/Properties/Settings.settings b/win/C#/Properties/Settings.settings
index ebd6f44f2..0f9c5ffb0 100644
--- a/win/C#/Properties/Settings.settings
+++ b/win/C#/Properties/Settings.settings
@@ -107,5 +107,8 @@
<Setting Name="DubAudio" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
+ <Setting Name="hb_platform" Type="System.String" Scope="User">
+ <Value Profile="(Default)" />
+ </Setting>
</Settings>
</SettingsFile> \ No newline at end of file
diff --git a/win/C#/app.config b/win/C#/app.config
index eb64a36bb..5a00d0c97 100644
--- a/win/C#/app.config
+++ b/win/C#/app.config
@@ -112,6 +112,9 @@
<setting name="DubAudio" serializeAs="String">
<value>False</value>
</setting>
+ <setting name="hb_platform" serializeAs="String">
+ <value />
+ </setting>
</Handbrake.Properties.Settings>
</userSettings>
<startup><supportedRuntime version="v2.0.50727"/></startup></configuration>
diff --git a/win/C#/frmAbout.Designer.cs b/win/C#/frmAbout.Designer.cs
index bcf01c8bb..c4fbce802 100644
--- a/win/C#/frmAbout.Designer.cs
+++ b/win/C#/frmAbout.Designer.cs
@@ -39,7 +39,7 @@ namespace Handbrake
this.label1 = new System.Windows.Forms.Label();
this.lbl_HBBuild = new System.Windows.Forms.Label();
this.PictureBox1 = new System.Windows.Forms.PictureBox();
- this.button1 = new System.Windows.Forms.Button();
+ this.btn_close = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.PictureBox1)).BeginInit();
this.SuspendLayout();
//
@@ -72,7 +72,7 @@ namespace Handbrake
this.lbl_HBBuild.Location = new System.Drawing.Point(125, 33);
this.lbl_HBBuild.Margin = new System.Windows.Forms.Padding(3, 1, 3, 3);
this.lbl_HBBuild.Name = "lbl_HBBuild";
- this.lbl_HBBuild.Size = new System.Drawing.Size(152, 13);
+ this.lbl_HBBuild.Size = new System.Drawing.Size(224, 13);
this.lbl_HBBuild.TabIndex = 32;
this.lbl_HBBuild.Text = "{Version}";
this.lbl_HBBuild.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
@@ -90,24 +90,25 @@ namespace Handbrake
this.PictureBox1.TabIndex = 33;
this.PictureBox1.TabStop = false;
//
- // button1
+ // btn_close
//
- this.button1.DialogResult = System.Windows.Forms.DialogResult.OK;
- this.button1.Location = new System.Drawing.Point(274, 82);
- this.button1.Name = "button1";
- this.button1.Size = new System.Drawing.Size(75, 23);
- this.button1.TabIndex = 35;
- this.button1.Text = "OK";
- this.button1.UseVisualStyleBackColor = true;
+ this.btn_close.DialogResult = System.Windows.Forms.DialogResult.OK;
+ this.btn_close.Location = new System.Drawing.Point(274, 82);
+ this.btn_close.Name = "btn_close";
+ this.btn_close.Size = new System.Drawing.Size(75, 23);
+ this.btn_close.TabIndex = 35;
+ this.btn_close.Text = "OK";
+ this.btn_close.UseVisualStyleBackColor = true;
+ this.btn_close.Click += new System.EventHandler(this.btn_close_Click);
//
// frmAbout
//
- this.AcceptButton = this.button1;
+ this.AcceptButton = this.btn_close;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.CancelButton = this.button1;
+ this.CancelButton = this.btn_close;
this.ClientSize = new System.Drawing.Size(363, 117);
- this.Controls.Add(this.button1);
+ this.Controls.Add(this.btn_close);
this.Controls.Add(this.label1);
this.Controls.Add(this.PictureBox1);
this.Controls.Add(this.lbl_HBBuild);
@@ -134,6 +135,6 @@ namespace Handbrake
internal System.Windows.Forms.Label label1;
internal System.Windows.Forms.Label lbl_HBBuild;
internal System.Windows.Forms.PictureBox PictureBox1;
- private System.Windows.Forms.Button button1;
+ private System.Windows.Forms.Button btn_close;
}
} \ No newline at end of file
diff --git a/win/C#/frmAbout.cs b/win/C#/frmAbout.cs
index e43706f73..a35779a35 100644
--- a/win/C#/frmAbout.cs
+++ b/win/C#/frmAbout.cs
@@ -14,14 +14,12 @@ namespace Handbrake
public frmAbout()
{
InitializeComponent();
- lbl_HBBuild.Text = Properties.Settings.Default.hb_version + " " + Properties.Settings.Default.hb_build;
+ lbl_HBBuild.Text = Properties.Settings.Default.hb_version + " (" + Properties.Settings.Default.hb_build + ") - " + Properties.Settings.Default.hb_platform;
}
private void btn_close_Click(object sender, EventArgs e)
{
this.Close();
}
-
-
}
} \ No newline at end of file
diff --git a/win/C#/frmActivityWindow.cs b/win/C#/frmActivityWindow.cs
index c308990e0..84f9bddd5 100644
--- a/win/C#/frmActivityWindow.cs
+++ b/win/C#/frmActivityWindow.cs
@@ -20,7 +20,7 @@ namespace Handbrake
delegate void SetTextCallback(string text);
String read_file;
Thread monitor;
- QueueHandler encodeQueue;
+ EncodeAndQueueHandler encodeQueue;
int position; // Position in the arraylist reached by the current log output in the rtf box.
string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";
private frmMain mainWin;
@@ -28,16 +28,15 @@ namespace Handbrake
/// <summary>
/// This window should be used to display the RAW output of the handbrake CLI which is produced during an encode.
/// </summary>
- public frmActivityWindow(string file, QueueHandler eh, frmMain mw)
+ public frmActivityWindow(string file, EncodeAndQueueHandler eh, frmMain mw)
{
InitializeComponent();
rtf_actLog.Text = string.Empty;
encodeQueue = eh;
- read_file = file;
position = 0;
mainWin = mw;
-
+
// When the window closes, we want to abort the monitor thread.
this.Disposed += new EventHandler(forceQuit);
@@ -45,15 +44,33 @@ namespace Handbrake
displayLogHeader();
if (file == "last_scan_log.txt")
- txt_log.Text = "Scan Log";
- else if (file == "last_encode_log.txt")
- txt_log.Text = "Encode Log";
+ setLogView(true);
+ else
+ setLogView(false);
// Start a new thread which will montior and keep the log window up to date if required/
startLogThread(read_file);
}
/// <summary>
+ /// Set the file which the log window is viewing.
+ /// </summary>
+ /// <param name="scan"></param>
+ public void setLogView(Boolean scan)
+ {
+ if (scan)
+ {
+ txt_log.Text = "Scan Log";
+ read_file = "last_scan_log.txt";
+ }
+ else
+ {
+ read_file = "last_encode_log.txt";
+ txt_log.Text = "Encode Log";
+ }
+ }
+
+ /// <summary>
/// Displays the Log header
/// </summary>
private void displayLogHeader()
@@ -68,7 +85,7 @@ namespace Handbrake
rtf_actLog.AppendText(String.Format("### Install Dir: {0} \n", Application.StartupPath));
rtf_actLog.AppendText(String.Format("### Data Dir: {0} \n", Application.UserAppDataPath));
rtf_actLog.AppendText("#########################################\n\n");
- if (encodeQueue.IsEncoding && encodeQueue.LastEncode.Query != String.Empty)
+ if (encodeQueue.isEncoding && encodeQueue.LastEncode.Query != String.Empty)
{
rtf_actLog.AppendText("### CLI Query: " + encodeQueue.LastEncode.Query + "\n\n");
rtf_actLog.AppendText("#########################################\n\n");
@@ -114,7 +131,7 @@ namespace Handbrake
updateTextFromThread();
while (true)
{
- if (encodeQueue.IsEncoding || mainWin.isScanning)
+ if (encodeQueue.isEncoding || mainWin.isScanning)
updateTextFromThread();
else
{
@@ -304,7 +321,7 @@ namespace Handbrake
#endregion
#region System Information
-
+
/// <summary>
/// Returns the total physical ram in a system
diff --git a/win/C#/frmMain.cs b/win/C#/frmMain.cs
index 62e0bc698..f385b1507 100644
--- a/win/C#/frmMain.cs
+++ b/win/C#/frmMain.cs
@@ -22,7 +22,7 @@ namespace Handbrake
public partial class frmMain : Form
{
// Objects which may be used by one or more other objects *************
- QueueHandler encodeQueue = new QueueHandler();
+ EncodeAndQueueHandler encodeQueue = new EncodeAndQueueHandler();
PresetsHandler presetHandler = new PresetsHandler();
QueryGenerator queryGen = new QueryGenerator();
@@ -650,7 +650,7 @@ namespace Handbrake
encodeQueue.RequestPause();
// Allow the CLI to exit cleanly
- Win32.SetForegroundWindow((int)encodeQueue.encodeHandler.processHandle);
+ Win32.SetForegroundWindow((int)encodeQueue.processHandle);
SendKeys.Send("^C");
// Update the GUI
@@ -1004,7 +1004,7 @@ namespace Handbrake
drop_chapterFinish.Text = c_start.ToString();
}
- lbl_duration.Text = Main.calculateDuration(drop_chapterStart.Text, drop_chapterFinish.Text, selectedTitle).ToString();
+ lbl_duration.Text = Main.calculateDuration(drop_chapterStart.SelectedIndex, drop_chapterFinish.SelectedIndex, selectedTitle).ToString();
// Run the Autonaming function
if (Properties.Settings.Default.autoNaming)
@@ -1035,7 +1035,7 @@ namespace Handbrake
drop_chapterFinish.Text = c_start.ToString();
}
- lbl_duration.Text = Main.calculateDuration(drop_chapterStart.Text, drop_chapterFinish.Text, selectedTitle).ToString();
+ lbl_duration.Text = Main.calculateDuration(drop_chapterStart.SelectedIndex, drop_chapterFinish.SelectedIndex, selectedTitle).ToString();
// Run the Autonaming function
if (Properties.Settings.Default.autoNaming)
@@ -1469,7 +1469,7 @@ namespace Handbrake
// Now select the longest title
if (thisDVD.Titles.Count != 0)
- drp_dvdtitle.SelectedItem = Main.selectLongestTitle(drp_dvdtitle);
+ drp_dvdtitle.SelectedItem = Main.selectLongestTitle(thisDVD);
// Enable the creation of chapter markers if the file is an image of a dvd.
if (sourcePath.ToLower().Contains(".iso") || sourcePath.ToLower().Contains("VIDEO_TS"))
@@ -1696,7 +1696,7 @@ namespace Handbrake
protected override void OnFormClosing(FormClosingEventArgs e)
{
// If currently encoding, the queue isn't paused, and there are queue items to process, prompt to confirm close.
- if ((encodeQueue.IsEncoding) && (!encodeQueue.PauseRequested) && (encodeQueue.Count > 0))
+ if ((encodeQueue.isEncoding) && (!encodeQueue.PauseRequested) && (encodeQueue.Count > 0))
{
DialogResult result = MessageBox.Show("HandBrake has queue items to process. Closing HandBrake will not stop the current encoding, but will stop processing the queue.\n\nDo you want to close HandBrake?",
"Close HandBrake?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
@@ -1713,7 +1713,7 @@ namespace Handbrake
{
try
{
- Parser encode = new Parser(encodeQueue.encodeHandler.hbProcess.StandardOutput.BaseStream);
+ Parser encode = new Parser(encodeQueue.hbProcess.StandardOutput.BaseStream);
encode.OnEncodeProgress += encodeOnEncodeProgress;
while (!encode.EndOfStream)
{
diff --git a/win/C#/frmPreview.cs b/win/C#/frmPreview.cs
index c1f2e73a9..96ef4a87d 100644
--- a/win/C#/frmPreview.cs
+++ b/win/C#/frmPreview.cs
@@ -15,7 +15,7 @@ namespace Handbrake
{
QueryGenerator hb_common_func = new QueryGenerator();
- Encode process = new Encode();
+ EncodeAndQueueHandler process = new EncodeAndQueueHandler();
private delegate void UpdateUIHandler();
String currently_playing = "";
readonly frmMain mainWindow;
diff --git a/win/C#/frmQueue.cs b/win/C#/frmQueue.cs
index d52545b0b..e110a470e 100644
--- a/win/C#/frmQueue.cs
+++ b/win/C#/frmQueue.cs
@@ -16,9 +16,9 @@ namespace Handbrake
public partial class frmQueue : Form
{
private delegate void UpdateHandler();
- private QueueHandler queue;
+ private EncodeAndQueueHandler queue;
- public frmQueue(QueueHandler q)
+ public frmQueue(EncodeAndQueueHandler q)
{
InitializeComponent();
@@ -81,7 +81,7 @@ namespace Handbrake
MessageBox.Show("Encoding restarted", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
- if (!queue.IsEncoding)
+ if (!queue.isEncoding)
queue.StartEncodeQueue();
}