summaryrefslogtreecommitdiffstats
path: root/win/C#/HandBrake.ApplicationServices/Services
diff options
context:
space:
mode:
authorsr55 <[email protected]>2010-07-15 20:15:08 +0000
committersr55 <[email protected]>2010-07-15 20:15:08 +0000
commit6c9b4d2c4cf5928bb2b472beca76c2edc4c41f03 (patch)
tree85ba020472dfb475f4db0424ed139da20fa6b64e /win/C#/HandBrake.ApplicationServices/Services
parent5c8cab7ea3c07e36b74bcb8c8198f8ef796e1530 (diff)
WinGui:
- Multiple instance support. Each instance has a unique id. id = 0 will use the standard log/queue files. id = 1,2...n will use standard file names but with the instance id added to the end. This means that each instance will have it's own queue. Queue is not shared between Instances If multiple queue files are found when starting up, it will offer to load them all in. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@3440 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win/C#/HandBrake.ApplicationServices/Services')
-rw-r--r--win/C#/HandBrake.ApplicationServices/Services/Encode.cs66
-rw-r--r--win/C#/HandBrake.ApplicationServices/Services/Queue.cs37
-rw-r--r--win/C#/HandBrake.ApplicationServices/Services/Scan.cs6
3 files changed, 45 insertions, 64 deletions
diff --git a/win/C#/HandBrake.ApplicationServices/Services/Encode.cs b/win/C#/HandBrake.ApplicationServices/Services/Encode.cs
index e5dc74cec..f0a2b1fe4 100644
--- a/win/C#/HandBrake.ApplicationServices/Services/Encode.cs
+++ b/win/C#/HandBrake.ApplicationServices/Services/Encode.cs
@@ -159,13 +159,13 @@ namespace HandBrake.ApplicationServices.Services
string handbrakeCLIPath = Path.Combine(Application.StartupPath, "HandBrakeCLI.exe");
ProcessStartInfo cliStart = new ProcessStartInfo(handbrakeCLIPath, encJob.Query)
- {
+ {
RedirectStandardOutput = true,
RedirectStandardError = enableLogging ? true : false,
UseShellExecute = false,
CreateNoWindow = !Settings.Default.showCliForInGuiEncodeStatus ? true : false
};
-
+
this.HbProcess = Process.Start(cliStart);
if (enableLogging)
@@ -213,8 +213,8 @@ namespace HandBrake.ApplicationServices.Services
}
catch (Exception exc)
{
- Main.ShowExceptiowWindow("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\nDetailed Error Information: error occured in runCli()",
+ Main.ShowExceptiowWindow("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\nDetailed Error Information: error occured in runCli()",
exc.ToString());
}
}
@@ -227,11 +227,7 @@ namespace HandBrake.ApplicationServices.Services
try
{
if (this.HbProcess != null) this.HbProcess.Kill();
-
- Process[] list = Process.GetProcessesByName("HandBrakeCLI");
- foreach (Process process in list)
- process.Kill();
- }
+ }
catch (Exception exc)
{
Main.ShowExceptiowWindow("Unable to stop HandBrakeCLI. It may not be running.", exc.ToString());
@@ -272,36 +268,12 @@ namespace HandBrake.ApplicationServices.Services
/// </param>
private static string CreateCliLogHeader(Job encJob)
{
- try
- {
- //string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) +
- // "\\HandBrake\\logs";
- //string logPath = Path.Combine(logDir, "last_encode_log.txt");
-
- //var reader = new StreamReader(File.Open(logPath, FileMode.Open, FileAccess.Read, FileShare.Read));
- //string log = reader.ReadToEnd();
- //reader.Close();
-
- //var writer = new StreamWriter(File.Create(logPath));
-
+ StringBuilder logHeader = new StringBuilder();
+ logHeader.AppendLine("# CLI Query: " + encJob.Query);
+ logHeader.AppendLine("# User Query: " + encJob.CustomQuery);
+ logHeader.AppendLine("-------------------------------------------");
- //writer.WriteLine("### CLI Query: " + encJob.Query);
- //writer.WriteLine("### User Query: " + encJob.CustomQuery);
- //writer.WriteLine("#########################################");
- //writer.WriteLine(log);
- //writer.Flush();
- //writer.Close();
- StringBuilder logHeader = new StringBuilder();
- logHeader.AppendLine("### CLI Query: " + encJob.Query);
- logHeader.AppendLine("### User Query: " + encJob.CustomQuery);
- logHeader.AppendLine("#########################################");
-
- return logHeader.ToString();
- }
- catch (Exception)
- {
- return string.Empty;
- }
+ return logHeader.ToString();
}
/// <summary>
@@ -317,7 +289,7 @@ namespace HandBrake.ApplicationServices.Services
{
string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) +
"\\HandBrake\\logs";
- string tempLogFile = Path.Combine(logDir, "last_encode_log.txt");
+ string tempLogFile = Path.Combine(logDir, string.Format("last_encode_log{0}.txt", Init.InstanceId));
string encodeDestinationPath = Path.GetDirectoryName(destination);
string destinationFile = Path.GetFileName(destination);
@@ -378,8 +350,8 @@ namespace HandBrake.ApplicationServices.Services
{
if (fileWriter != null)
fileWriter.Close();
- }
- catch(Exception exc)
+ }
+ catch (Exception exc)
{
Main.ShowExceptiowWindow("Unable to close the log file wrtier", exc.ToString());
}
@@ -399,8 +371,8 @@ namespace HandBrake.ApplicationServices.Services
// last_encode_log.txt is the primary log file. Since .NET can't read this file whilst the CLI is outputing to it (Not even in read only mode),
// we'll need to make a copy of it.
string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";
- string logFile = Path.Combine(logDir, "last_encode_log.txt");
- string logFile2 = Path.Combine(logDir, "tmp_appReadable_log.txt");
+ string logFile = Path.Combine(logDir, string.Format("last_encode_log{0}.txt", Init.InstanceId));
+ string logFile2 = Path.Combine(logDir, string.Format("tmp_appReadable_log{0}.txt", Init.InstanceId));
int logFilePosition = 0;
try
@@ -414,7 +386,7 @@ namespace HandBrake.ApplicationServices.Services
File.Copy(logFile, logFile2, true);
else
return;
-
+
// Start the Reader
// Only use text which continues on from the last read line
StreamReader sr = new StreamReader(logFile2);
@@ -445,8 +417,8 @@ namespace HandBrake.ApplicationServices.Services
private void SetupLogging(Job encodeJob)
{
string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";
- string logFile = Path.Combine(logDir, "last_encode_log.txt");
- string logFile2 = Path.Combine(logDir, "tmp_appReadable_log.txt");
+ string logFile = Path.Combine(logDir, string.Format("last_encode_log{0}.txt", Init.InstanceId));
+ string logFile2 = Path.Combine(logDir, string.Format("tmp_appReadable_log{0}.txt", Init.InstanceId));
try
{
@@ -493,7 +465,7 @@ namespace HandBrake.ApplicationServices.Services
catch (Exception exc)
{
Main.ShowExceptiowWindow("Unable to write log data...", exc.ToString());
- }
+ }
}
}
diff --git a/win/C#/HandBrake.ApplicationServices/Services/Queue.cs b/win/C#/HandBrake.ApplicationServices/Services/Queue.cs
index da32d2503..7ba1d9d31 100644
--- a/win/C#/HandBrake.ApplicationServices/Services/Queue.cs
+++ b/win/C#/HandBrake.ApplicationServices/Services/Queue.cs
@@ -104,7 +104,7 @@ namespace HandBrake.ApplicationServices.Services
this.LastEncode = job;
this.Remove(0); // Remove the item which we are about to pass out.
- this.WriteQueueStateToFile("hb_queue_recovery.xml");
+ this.SaveQueue();
return job;
}
@@ -140,7 +140,7 @@ namespace HandBrake.ApplicationServices.Services
};
this.queue.Add(newJob);
- this.WriteQueueStateToFile("hb_queue_recovery.xml");
+ this.SaveQueue();
if (this.QueueListChanged != null)
this.QueueListChanged(this, new EventArgs());
@@ -153,7 +153,7 @@ namespace HandBrake.ApplicationServices.Services
public void Remove(int index)
{
this.queue.RemoveAt(index);
- this.WriteQueueStateToFile("hb_queue_recovery.xml");
+ this.SaveQueue();
if (this.QueueListChanged != null)
this.QueueListChanged(this, new EventArgs());
@@ -186,7 +186,7 @@ namespace HandBrake.ApplicationServices.Services
queue.Insert((index - 1), item);
}
- WriteQueueStateToFile("hb_queue_recovery.xml"); // Update the queue recovery file
+ this.SaveQueue(); // Update the queue recovery file
if (this.QueueListChanged != null)
this.QueueListChanged(this, new EventArgs());
@@ -206,11 +206,22 @@ namespace HandBrake.ApplicationServices.Services
this.queue.Insert((index + 1), item);
}
- this.WriteQueueStateToFile("hb_queue_recovery.xml"); // Update the queue recovery file
+ this.SaveQueue(); // Update the queue recovery file
if (this.QueueListChanged != null)
this.QueueListChanged(this, new EventArgs());
}
+
+ /// <summary>
+ /// Save any updates to the main queue file.
+ /// </summary>
+ public void SaveQueue()
+ {
+ string file = Init.InstanceId == 0
+ ? "hb_queue_recovery.xml"
+ : string.Format("hb_queue_recovery{0}.xml", Init.InstanceId);
+ this.WriteQueueStateToFile(file);
+ }
/// <summary>
/// Writes the current state of the queue to a file.
@@ -218,9 +229,8 @@ namespace HandBrake.ApplicationServices.Services
/// <param name="file">The location of the file to write the queue to.</param>
public void WriteQueueStateToFile(string file)
{
- string appDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
- @"HandBrake\hb_queue_recovery.xml");
- string tempPath = file == "hb_queue_recovery.xml" ? appDataPath : file;
+ string appDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"HandBrake\");
+ string tempPath = file.Contains("hb_queue_recovery") ? appDataPath + file : file;
try
{
@@ -285,9 +295,8 @@ namespace HandBrake.ApplicationServices.Services
/// <param name="file">The location of the file to read the queue from.</param>
public void LoadQueueFromFile(string file)
{
- string appDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
- @"HandBrake\hb_queue_recovery.xml");
- string tempPath = file == "hb_queue_recovery.xml" ? appDataPath : file;
+ string appDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"HandBrake\");
+ string tempPath = file.Contains("hb_queue_recovery") ? appDataPath + file : file;
if (File.Exists(tempPath))
{
@@ -304,8 +313,8 @@ namespace HandBrake.ApplicationServices.Services
foreach (Job item in list)
this.queue.Add(item);
- if (file != "hb_queue_recovery.xml")
- this.WriteQueueStateToFile("hb_queue_recovery.xml");
+ if (!file.Contains("hb_queue_recovery"))
+ this.SaveQueue();
if (this.QueueListChanged != null)
this.QueueListChanged(this, new EventArgs());
@@ -378,7 +387,7 @@ namespace HandBrake.ApplicationServices.Services
while (this.Count != 0)
{
Job encJob = this.GetNextJob();
- this.WriteQueueStateToFile("hb_queue_recovery.xml"); // Update the queue recovery file
+ this.SaveQueue(); // Update the queue recovery file
Run(encJob, true);
diff --git a/win/C#/HandBrake.ApplicationServices/Services/Scan.cs b/win/C#/HandBrake.ApplicationServices/Services/Scan.cs
index 6aefa03fd..039cb3f3d 100644
--- a/win/C#/HandBrake.ApplicationServices/Services/Scan.cs
+++ b/win/C#/HandBrake.ApplicationServices/Services/Scan.cs
@@ -154,7 +154,7 @@ namespace HandBrake.ApplicationServices.Services
string handbrakeCLIPath = Path.Combine(Application.StartupPath, "HandBrakeCLI.exe");
string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) +
"\\HandBrake\\logs";
- string dvdInfoPath = Path.Combine(logDir, "last_scan_log.txt");
+ string dvdInfoPath = Path.Combine(logDir, string.Format("last_scan_log{0}.txt", Init.InstanceId));
// Make we don't pick up a stale last_encode_log.txt (and that we have rights to the file)
if (File.Exists(dvdInfoPath))
@@ -218,8 +218,8 @@ namespace HandBrake.ApplicationServices.Services
// we'll need to make a copy of it.
string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) +
"\\HandBrake\\logs";
- string logFile = Path.Combine(logDir, "last_scan_log.txt");
- string logFile2 = Path.Combine(logDir, "tmp_appReadable_log.txt");
+ string logFile = Path.Combine(logDir, string.Format("last_scan_log{0}.txt", Init.InstanceId));
+ string logFile2 = Path.Combine(logDir, string.Format("tmp_appReadable_log{0}.txt", Init.InstanceId));
try
{