diff options
-rw-r--r-- | win/C#/Functions/Encode.cs | 6 | ||||
-rw-r--r-- | win/C#/Functions/Main.cs | 28 | ||||
-rw-r--r-- | win/C#/Functions/QueryParser.cs | 46 | ||||
-rw-r--r-- | win/C#/HandBrakeCS.csproj | 17 | ||||
-rw-r--r-- | win/C#/Queue/QueueHandler.cs (renamed from win/C#/Functions/Queue.cs) | 115 | ||||
-rw-r--r-- | win/C#/Queue/QueueItem.cs | 50 | ||||
-rw-r--r-- | win/C#/frmMain.cs | 12 | ||||
-rw-r--r-- | win/C#/frmQueue.cs | 42 |
8 files changed, 163 insertions, 153 deletions
diff --git a/win/C#/Functions/Encode.cs b/win/C#/Functions/Encode.cs index 0445392d0..471acb586 100644 --- a/win/C#/Functions/Encode.cs +++ b/win/C#/Functions/Encode.cs @@ -133,7 +133,7 @@ namespace Handbrake.Functions /// if this feature is enabled in options.
/// </summary>
/// <param name="query"></param>
- public void copyLog(string query)
+ public void copyLog(string query, string destination)
{
// The user may wish to do something with the log.
if (Properties.Settings.Default.saveLog == "Checked")
@@ -143,7 +143,7 @@ namespace Handbrake.Functions if (Properties.Settings.Default.saveLogWithVideo == "Checked")
{
- string[] destName = parsed.Destination.Split('\\');
+ string[] destName = destination.Split('\\');
string destinationFile = "";
for (int i = 0; i < destName.Length - 1; i++)
{
@@ -156,7 +156,7 @@ namespace Handbrake.Functions }
else if (Properties.Settings.Default.saveLogPath != String.Empty)
{
- string[] destName = parsed.Destination.Split('\\');
+ string[] destName = destination.Split('\\');
string dest = destName[destName.Length - 1];
string filename = DateTime.Now.ToString().Replace("/", "-").Replace(":", "-") + " " + dest + ".txt";
string useDefinedLogPath = Path.Combine(Properties.Settings.Default.saveLogPath, filename);
diff --git a/win/C#/Functions/Main.cs b/win/C#/Functions/Main.cs index f8600d3e9..0a202b15d 100644 --- a/win/C#/Functions/Main.cs +++ b/win/C#/Functions/Main.cs @@ -13,11 +13,16 @@ using System.IO; using System.Drawing;
using System.Diagnostics;
using System.Text.RegularExpressions;
+using System.Collections.Generic;
+using System.Xml.Serialization;
namespace Handbrake.Functions
{
class Main
{
+ // Private Variables
+ private static XmlSerializer ser = new XmlSerializer(typeof(List<Queue.QueueItem>));
+
/// <summary>
/// Calculate the duration of the selected title and chapters
/// </summary>
@@ -361,28 +366,21 @@ namespace Handbrake.Functions {
try
{
- string tempPath = Path.Combine(Path.GetTempPath(), "hb_queue_recovery.dat");
- using (StreamReader reader = new StreamReader(tempPath))
+ string tempPath = Path.Combine(Path.GetTempPath(), "hb_queue_recovery.xml");
+ if (File.Exists(tempPath))
{
- string queue_item = reader.ReadLine();
- if (queue_item == null)
- {
- reader.Close();
- reader.Dispose();
- return false;
- }
- else // There exists an item in the recovery queue file, so try and recovr it.
+ using (FileStream strm = new FileStream(tempPath, FileMode.Open, FileAccess.Read))
{
- reader.Close();
- reader.Dispose();
- return true;
+ List<Queue.QueueItem> list = ser.Deserialize(strm) as List<Queue.QueueItem>;
+ if (list.Count != 0)
+ return true;
}
}
+ return false;
}
catch (Exception)
{
- // Keep quiet about the error.
- return false;
+ return false; // Keep quiet about the error.
}
}
diff --git a/win/C#/Functions/QueryParser.cs b/win/C#/Functions/QueryParser.cs index 3e8b18ebe..b2d2ee661 100644 --- a/win/C#/Functions/QueryParser.cs +++ b/win/C#/Functions/QueryParser.cs @@ -19,20 +19,6 @@ namespace Handbrake.Functions #region Varibles
#region Source
-
- private string q_source;
- /// <summary>
- /// Returns a String
- /// Full path of the source.
- /// </summary>
- public string Source
- {
- get
- {
- return this.q_source;
- }
- }
-
private int q_dvdTitle;
/// <summary>
/// Returns an Integer
@@ -74,20 +60,6 @@ namespace Handbrake.Functions #endregion
#region Destination
-
- private string q_destination;
- /// <summary>
- /// Returns a String
- /// Full path of the destination.
- /// </summary>
- public string Destination
- {
- get
- {
- return this.q_destination;
- }
- }
-
private string q_format;
/// <summary>
/// Returns a String
@@ -811,16 +783,16 @@ namespace Handbrake.Functions QueryParser thisQuery = new QueryParser();
#region Regular Expressions
+ // Useful Destination Finder
+ //Regex r1 = new Regex(@"(-i)(?:\s\"")([a-zA-Z0-9?';!^%&*()_\-:\\\s\.]+)(?:\"")");
+ //Match source = r1.Match(input.Replace('"', '\"'));
+
//Source
- Regex r1 = new Regex(@"(-i)(?:\s\"")([a-zA-Z0-9_\-:\\\s\.]+)(?:\"")");
- Match source = r1.Match(input.Replace('"', '\"'));
Match title = Regex.Match(input, @"-t ([0-9]*)");
Match chapters = Regex.Match(input, @"-c ([0-9-]*)");
Match format = Regex.Match(input, @"-f ([a-z0-9a-z0-9a-z0-9]*)");
//Destination
- Regex r2 = new Regex(@"(-o)(?:\s\"")([a-zA-Z0-9_\-:\\\s\.]+)(?:\"")");
- Match destination = r2.Match(input.Replace('"', '\"'));
Match videoEncoder = Regex.Match(input, @"-e ([a-zA-Z0-9]*)");
//Picture Settings Tab
@@ -896,12 +868,9 @@ namespace Handbrake.Functions #region Set Varibles
try
{
-
#region Source Tab
-
- thisQuery.q_source = source.ToString().Replace("-i ", "").Replace("\"", "");
if (title.Success != false)
- thisQuery.q_dvdTitle = int.Parse(title.ToString().Replace("-t ", ""));
+ thisQuery.q_dvdTitle = int.Parse(title.ToString().Replace("-t ", ""));
if (chapters.Success != false)
{
@@ -923,11 +892,8 @@ namespace Handbrake.Functions #endregion
#region Destination
- thisQuery.q_destination = destination.ToString().Replace("-o ", "").Replace("\"", "");
-
- string videoEncoderConvertion;
- videoEncoderConvertion = videoEncoder.ToString().Replace("-e ", "");
+ string videoEncoderConvertion = videoEncoder.ToString().Replace("-e ", "");
switch (videoEncoderConvertion)
{
case "ffmpeg":
diff --git a/win/C#/HandBrakeCS.csproj b/win/C#/HandBrakeCS.csproj index df5258c1d..64d5d69ec 100644 --- a/win/C#/HandBrakeCS.csproj +++ b/win/C#/HandBrakeCS.csproj @@ -90,12 +90,6 @@ <PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<ItemGroup>
- <Reference Include="PresentationCore">
- <RequiredTargetFramework>3.0</RequiredTargetFramework>
- </Reference>
- <Reference Include="PresentationFramework">
- <RequiredTargetFramework>3.0</RequiredTargetFramework>
- </Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Deployment" />
@@ -103,13 +97,7 @@ <Reference Include="System.Drawing" />
<Reference Include="System.Messaging" />
<Reference Include="System.Windows.Forms" />
- <Reference Include="System.Xml" />
- <Reference Include="UIAutomationProvider">
- <RequiredTargetFramework>3.0</RequiredTargetFramework>
- </Reference>
- <Reference Include="WindowsBase">
- <RequiredTargetFramework>3.0</RequiredTargetFramework>
- </Reference>
+ <Reference Include="System.XML" />
</ItemGroup>
<ItemGroup>
<Compile Include="frmActivityWindow.cs">
@@ -166,7 +154,7 @@ <Compile Include="Functions\Main.cs" />
<Compile Include="Presets\preset.cs" />
<Compile Include="Presets\PresetsHandler.cs" />
- <Compile Include="Functions\Queue.cs" />
+ <Compile Include="Queue\QueueHandler.cs" />
<Compile Include="Functions\AppcastReader.cs" />
<Compile Include="Functions\Encode.cs" />
<Compile Include="Functions\QueryParser.cs" />
@@ -250,6 +238,7 @@ <Compile Include="frmSplashScreen.Designer.cs">
<DependentUpon>frmSplashScreen.cs</DependentUpon>
</Compile>
+ <Compile Include="Queue\QueueItem.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="handbrakepineapple.ico" />
diff --git a/win/C#/Functions/Queue.cs b/win/C#/Queue/QueueHandler.cs index 3afca7d3e..6810dec5f 100644 --- a/win/C#/Functions/Queue.cs +++ b/win/C#/Queue/QueueHandler.cs @@ -4,16 +4,18 @@ using System.Text; using System.Collections;
using System.IO;
using System.Windows.Forms;
+using System.Xml.Serialization;
-namespace Handbrake.Functions
+namespace Handbrake.Queue
{
public class Queue
{
- ArrayList queue = new ArrayList();
- ArrayList lastQuery;
+ private static XmlSerializer ser = new XmlSerializer(typeof(List<QueueItem>));
+ List<QueueItem> queue = new List<QueueItem>();
int id = 0; // Unique identifer number for each job
+ private QueueItem lastItem;
- public ArrayList getQueue()
+ public List<QueueItem> getQueue()
{
return queue;
}
@@ -22,24 +24,35 @@ namespace Handbrake.Functions /// Get's the next CLI query for encoding
/// </summary>
/// <returns>String</returns>
- public String getNextItemForEncoding()
+ public string getNextItemForEncoding()
{
- Object query = queue[0];
- lastQuery = (ArrayList)query;
+ QueueItem job = queue[0];
+ String query = job.Query;
+ lastItem = job;
remove(0); // Remove the item which we are about to pass out.
- return lastQuery[1].ToString();
+ return query;
+ }
+
+ /// <summary>
+ /// Get the last query that was returned by getNextItemForEncoding()
+ /// </summary>
+ /// <returns></returns>
+ public QueueItem getLastQuery()
+ {
+ return lastItem;
}
/// <summary>
/// Add's a new item to the queue
/// </summary>
/// <param name="query">String</param>
- public void add(string query)
+ public void add(string query, string source, string destination)
{
- // Creates a new job with a unique identifer and cli query
- ArrayList newJob = new ArrayList();
- newJob.Add(id);
- newJob.Add(query);
+ QueueItem newJob = new QueueItem();
+ newJob.Id = id;
+ newJob.Query = query;
+ newJob.Source = source;
+ newJob.Destination = destination;
id++;
// Adds the job to the queue
@@ -67,15 +80,6 @@ namespace Handbrake.Functions }
/// <summary>
- /// Get's the last query to be selected for encoding by getNextItemForEncoding()
- /// </summary>
- /// <returns>String</returns>
- public string getLastQuery()
- {
- return lastQuery[1].ToString();
- }
-
- /// <summary>
/// Move an item with an index x, up in the queue
/// </summary>
/// <param name="index">Int</param>
@@ -83,7 +87,7 @@ namespace Handbrake.Functions {
if (index != 0)
{
- ArrayList item = (ArrayList)queue[index];
+ QueueItem item = (QueueItem)queue[index];
queue.Insert((index - 1), item);
queue.RemoveAt((index + 1));
@@ -98,7 +102,7 @@ namespace Handbrake.Functions {
if (index != queue.Count - 1)
{
- ArrayList item = (ArrayList)queue[index];
+ QueueItem item = (QueueItem)queue[index];
queue.Insert((index + 2), item);
queue.RemoveAt((index));
@@ -106,31 +110,30 @@ namespace Handbrake.Functions }
/// <summary>
- /// Writes the current queue to disk. hb_queue_recovery.dat
+ /// Writes the current queue to disk. hb_queue_recovery.xml
/// This function is called after getNextItemForEncoding()
/// </summary>
public void write2disk(string file)
{
+ string tempPath = "";
+ if (file == "hb_queue_recovery.xml")
+ tempPath = Path.Combine(Path.GetTempPath(), "hb_queue_recovery.xml");
+ else
+ tempPath = file;
+
try
{
- string tempPath = "";
- if (file == "hb_queue_recovery.dat")
- tempPath = Path.Combine(Path.GetTempPath(), "hb_queue_recovery.dat");
- else
- tempPath = file;
- using (StreamWriter writer = new StreamWriter(tempPath))
+ using (FileStream strm = new FileStream(tempPath, FileMode.Create, FileAccess.Write))
{
- foreach (ArrayList item in queue)
- {
- writer.WriteLine(item[1].ToString());
- }
- writer.Close();
- writer.Dispose();
+ ser.Serialize(strm, queue);
+ strm.Close();
+ strm.Dispose();
}
}
catch (Exception)
{
- // Any Errors will be out of diskspace/permissions problems. Don't report them as they'll annoy the user.
+ // Any Errors will be out of diskspace/permissions problems.
+ // Don't report them as they'll annoy the user.
}
}
@@ -141,9 +144,9 @@ namespace Handbrake.Functions public void writeBatchScript(string file)
{
string queries = "";
- foreach (ArrayList queue_item in queue)
+ foreach (QueueItem queue_item in queue)
{
- string q_item = queue_item[1].ToString();
+ string q_item = queue_item.Query;
string fullQuery = '"' + Application.StartupPath.ToString() + "\\HandBrakeCLI.exe" + '"' + q_item;
if (queries == string.Empty)
@@ -174,33 +177,29 @@ namespace Handbrake.Functions }
/// <summary>
- /// Recover the queue from hb_queue_recovery.dat
+ /// Recover the queue from hb_queue_recovery.xml
/// </summary>
public void recoverQueue(string file)
{
- try
+ string tempPath = "";
+ if (file == "hb_queue_recovery.xml")
+ tempPath = Path.Combine(Path.GetTempPath(), "hb_queue_recovery.xml");
+ else
+ tempPath = file;
+
+ if (File.Exists(tempPath))
{
- string tempPath = "";
- if (file == "hb_queue_recovery.dat")
- tempPath = Path.Combine(Path.GetTempPath(), "hb_queue_recovery.dat");
- else
- tempPath = file;
- using (StreamReader reader = new StreamReader(tempPath))
+ using (FileStream strm = new FileStream(tempPath, FileMode.Open, FileAccess.Read))
{
- string queue_item = reader.ReadLine();
-
- while (queue_item != null)
+ if (strm.Length != 0)
{
- this.add(queue_item);
- queue_item = reader.ReadLine();
+ List<QueueItem> list = ser.Deserialize(strm) as List<QueueItem>;
+
+ foreach (QueueItem item in list)
+ queue.Add(item);
}
}
}
- catch (Exception exc)
- {
- MessageBox.Show("HandBrake was unable to recover the queue. \nError Information:" + exc.ToString(), "Queue Recovery Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
}
-
}
}
diff --git a/win/C#/Queue/QueueItem.cs b/win/C#/Queue/QueueItem.cs new file mode 100644 index 000000000..1639b168b --- /dev/null +++ b/win/C#/Queue/QueueItem.cs @@ -0,0 +1,50 @@ +using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Handbrake.Queue
+{
+ public class QueueItem
+ {
+ private int id;
+ private string query;
+ private string source;
+ private string destination;
+
+ /// <summary>
+ /// Get or Set the job id.
+ /// </summary>
+ public int Id
+ {
+ get { return id; }
+ set { this.id = value; }
+ }
+
+ /// <summary>
+ /// Get or Set the query string.
+ /// </summary>
+ public string Query
+ {
+ get { return query; }
+ set { this.query = value; }
+ }
+
+ /// <summary>
+ /// Get or set the source file of encoding
+ /// </summary>
+ public string Source
+ {
+ get { return source; }
+ set { this.source = value; }
+ }
+
+ /// <summary>
+ /// Get or set the destination for the file to be encoded.
+ /// </summary>
+ public string Destination
+ {
+ get { return destination; }
+ set { this.destination = value; }
+ }
+ }
+}
diff --git a/win/C#/frmMain.cs b/win/C#/frmMain.cs index 149664600..59ae27ba2 100644 --- a/win/C#/frmMain.cs +++ b/win/C#/frmMain.cs @@ -25,7 +25,7 @@ namespace Handbrake // Objects which may be used by one or more other objects
Functions.Main hb_common_func = new Functions.Main();
Functions.Encode cliObj = new Functions.Encode();
- Functions.Queue encodeQueue = new Functions.Queue();
+ Queue.Queue encodeQueue = new Queue.Queue();
Presets.PresetsHandler presetHandler = new Presets.PresetsHandler();
Parsing.Title selectedTitle;
@@ -184,11 +184,11 @@ namespace Handbrake DialogResult result = MessageBox.Show("HandBrake has detected unfinished items on the queue from the last time the application was launched. Would you like to recover these?", "Queue Recovery Possible", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.Yes)
- encodeQueue.recoverQueue("hb_queue_recovery.dat"); // Start Recovery
+ encodeQueue.recoverQueue("hb_queue_recovery.xml"); // Start Recovery
else
{
// Remove the Queue recovery file if the user doesn't want to recovery the last queue.
- string queuePath = Path.Combine(Path.GetTempPath(), "hb_queue_recovery.dat");
+ string queuePath = Path.Combine(Path.GetTempPath(), "hb_queue_recovery.xml");
if (File.Exists(queuePath))
File.Delete(queuePath);
}
@@ -397,8 +397,8 @@ namespace Handbrake if (rtf_query.Text != "")
query = rtf_query.Text;
- encodeQueue.add(query);
- encodeQueue.write2disk("hb_queue_recovery.dat"); // Writes the queue to the recovery file, just incase the GUI crashes.
+ encodeQueue.add(query, text_source.Text, text_destination.Text);
+ encodeQueue.write2disk("hb_queue_recovery.xml"); // Writes the queue to the recovery file, just incase the GUI crashes.
queueWindow.setQueue(encodeQueue);
queueWindow.Show();
@@ -1919,7 +1919,7 @@ namespace Handbrake // After the encode is done, we may want to shutdown, suspend etc.
cliObj.addCLIQueryToLog((string)state);
- cliObj.copyLog((string)state); // Make a copy of the log in the users desired location if necessary
+ cliObj.copyLog((string)state, text_destination.Text); // Make a copy of the log in the users desired location if necessary
cliObj.afterEncodeAction();
}
}
diff --git a/win/C#/frmQueue.cs b/win/C#/frmQueue.cs index 88acf24e9..765c940b7 100644 --- a/win/C#/frmQueue.cs +++ b/win/C#/frmQueue.cs @@ -26,7 +26,7 @@ namespace Handbrake Functions.Encode cliObj = new Functions.Encode();
Boolean cancel = false;
Process hbProc = null;
- Functions.Queue queue;
+ Queue.Queue queue;
frmMain mainWindow = null;
public frmQueue(frmMain main)
@@ -39,11 +39,20 @@ namespace Handbrake /// Initializes the Queue list with the Arraylist from the Queue class
/// </summary>
/// <param name="qw"></param>
- public void setQueue(Functions.Queue qw)
+ public void setQueue(Queue.Queue qw)
{
queue = qw;
redrawQueue();
lbl_encodesPending.Text = list_queue.Items.Count + " encode(s) pending";
+
+ // Recalculate the progress bar, but only if the queue has already started.
+ if (progressBar.Value != 0)
+ {
+ progressBar.Value = 0;
+ progressBar.Step = 100 / queue.count();
+ progressBar.PerformStep();
+ lbl_progressValue.Text = string.Format("{0} %", progressBar.Value);
+ }
}
/// <summary>
@@ -62,10 +71,10 @@ namespace Handbrake private void redrawQueue()
{
list_queue.Items.Clear();
- ArrayList theQueue = queue.getQueue();
- foreach (ArrayList queue_item in theQueue)
+ List<Queue.QueueItem> theQueue = queue.getQueue();
+ foreach (Queue.QueueItem queue_item in theQueue)
{
- string q_item = queue_item[1].ToString();
+ string q_item = queue_item.Query;
Functions.QueryParser parsed = Functions.QueryParser.Parse(q_item);
// Get the DVD Title
@@ -89,8 +98,8 @@ namespace Handbrake ListViewItem item = new ListViewItem();
item.Text = title; // Title
item.SubItems.Add(chapters); // Chapters
- item.SubItems.Add(parsed.Source); // Source
- item.SubItems.Add(parsed.Destination); // Destination
+ item.SubItems.Add(queue_item.Source); // Source
+ item.SubItems.Add(queue_item.Destination); // Destination
item.SubItems.Add(parsed.VideoEncoder); // Video
item.SubItems.Add(parsed.AudioEncoder1); // Audio
@@ -139,7 +148,7 @@ namespace Handbrake while (queue.count() != 0)
{
string query = queue.getNextItemForEncoding();
- queue.write2disk("hb_queue_recovery.dat"); // Update the queue recovery file
+ queue.write2disk("hb_queue_recovery.xml"); // Update the queue recovery file
setEncValue();
updateUIElements();
@@ -148,7 +157,7 @@ namespace Handbrake hbProc.WaitForExit();
cliObj.addCLIQueryToLog(query);
- cliObj.copyLog(query);
+ cliObj.copyLog(query, queue.getLastQuery().Destination);
hbProc.Close();
hbProc.Dispose();
@@ -255,9 +264,9 @@ namespace Handbrake }
// found query is a global varible
- Functions.QueryParser parsed = Functions.QueryParser.Parse(queue.getLastQuery());
- lbl_source.Text = parsed.Source;
- lbl_dest.Text = parsed.Destination;
+ Functions.QueryParser parsed = Functions.QueryParser.Parse(queue.getLastQuery().Query);
+ lbl_source.Text = queue.getLastQuery().Source;
+ lbl_dest.Text = queue.getLastQuery().Destination;
if (parsed.DVDTitle == 0)
@@ -295,7 +304,7 @@ namespace Handbrake int selected = list_queue.SelectedIndices[0];
queue.moveUp(selected);
- queue.write2disk("hb_queue_recovery.dat"); // Update the queue recovery file
+ queue.write2disk("hb_queue_recovery.xml"); // Update the queue recovery file
redrawQueue();
if (selected - 1 > 0)
@@ -313,7 +322,7 @@ namespace Handbrake int selected = list_queue.SelectedIndices[0];
queue.moveDown(list_queue.SelectedIndices[0]);
- queue.write2disk("hb_queue_recovery.dat"); // Update the queue recovery file
+ queue.write2disk("hb_queue_recovery.xml"); // Update the queue recovery file
redrawQueue();
if (selected +1 < list_queue.Items.Count)
@@ -329,7 +338,7 @@ namespace Handbrake if (list_queue.SelectedIndices.Count != 0)
{
queue.remove(list_queue.SelectedIndices[0]);
- queue.write2disk("hb_queue_recovery.dat"); // Update the queue recovery file
+ queue.write2disk("hb_queue_recovery.xml"); // Update the queue recovery file
redrawQueue();
lbl_encodesPending.Text = list_queue.Items.Count + " encode(s) pending";
}
@@ -373,7 +382,7 @@ namespace Handbrake if (list_queue.SelectedIndices.Count != 0)
{
queue.remove(list_queue.SelectedIndices[0]);
- queue.write2disk("hb_queue_recovery.dat"); // Update the queue recovery file
+ queue.write2disk("hb_queue_recovery.xml"); // Update the queue recovery file
redrawQueue();
}
}
@@ -393,6 +402,5 @@ namespace Handbrake base.OnClosing(e);
}
-
}
}
\ No newline at end of file |