summaryrefslogtreecommitdiffstats
path: root/win/C#/HandBrake.ApplicationServices
diff options
context:
space:
mode:
Diffstat (limited to 'win/C#/HandBrake.ApplicationServices')
-rw-r--r--win/C#/HandBrake.ApplicationServices/Init.cs12
-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
4 files changed, 51 insertions, 70 deletions
diff --git a/win/C#/HandBrake.ApplicationServices/Init.cs b/win/C#/HandBrake.ApplicationServices/Init.cs
index c8f15c3fd..7f1e1ed72 100644
--- a/win/C#/HandBrake.ApplicationServices/Init.cs
+++ b/win/C#/HandBrake.ApplicationServices/Init.cs
@@ -16,8 +16,8 @@ namespace HandBrake.ApplicationServices
/// <summary>
/// Setup the Settings used by the applicaiton with this library
/// </summary>
- /// <param name="cli_minimized">
- /// The cli_minimized.
+ /// <param name="instanceId">
+ /// The Instance ID
/// </param>
/// <param name="completionOption">
/// The completion option.
@@ -25,9 +25,6 @@ namespace HandBrake.ApplicationServices
/// <param name="disableDvdNav">
/// The disable dvd nav.
/// </param>
- /// <param name="enocdeStatusInGui">
- /// The enocde status in gui.
- /// </param>
/// <param name="growlEncode">
/// The growl encode.
/// </param>
@@ -52,10 +49,11 @@ namespace HandBrake.ApplicationServices
/// <param name="preventSleep">
/// Prevent the system from sleeping
/// </param>
- public static void SetupSettings(string completionOption, bool disableDvdNav,
+ public static void SetupSettings(int instanceId, string completionOption, bool disableDvdNav,
bool growlEncode, bool growlQueue, string processPriority, string saveLogPath, bool saveLogToSpecifiedPath,
bool saveLogWithVideo, bool showCliForInGuiEncodeStatus, bool preventSleep)
{
+ InstanceId = instanceId;
Properties.Settings.Default.CompletionOption = completionOption;
Properties.Settings.Default.disableDvdNav = disableDvdNav;
Properties.Settings.Default.growlEncode = growlEncode;
@@ -80,5 +78,7 @@ namespace HandBrake.ApplicationServices
{
return Assembly.GetExecutingAssembly().GetName().Version;
}
+
+ public static int InstanceId;
}
}
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
{