summaryrefslogtreecommitdiffstats
path: root/win/CS
diff options
context:
space:
mode:
Diffstat (limited to 'win/CS')
-rw-r--r--win/CS/HandBrake.ApplicationServices/Interop/HandBrakeInstance.cs2
-rw-r--r--win/CS/HandBrake.ApplicationServices/Interop/HandBrakeInstanceManager.cs25
-rw-r--r--win/CS/HandBrakeWPF/Services/Encode/EncodeBase.cs18
-rw-r--r--win/CS/HandBrakeWPF/Services/Encode/Interfaces/IEncode.cs11
-rw-r--r--win/CS/HandBrakeWPF/Services/Encode/LibEncode.cs22
5 files changed, 46 insertions, 32 deletions
diff --git a/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeInstance.cs b/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeInstance.cs
index a862dc1e6..ca1a8367b 100644
--- a/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeInstance.cs
+++ b/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeInstance.cs
@@ -43,7 +43,7 @@ namespace HandBrake.ApplicationServices.Interop
/// <summary>
/// A wrapper for a HandBrake instance.
/// </summary>
- public class HandBrakeInstance : IHandBrakeInstance, IDisposable
+ public class HandBrakeInstance : IHandBrakeInstance, IDisposable
{
/// <summary>
/// The number of MS between status polls when scanning.
diff --git a/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeInstanceManager.cs b/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeInstanceManager.cs
index a74513f4a..5ceb70bdc 100644
--- a/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeInstanceManager.cs
+++ b/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeInstanceManager.cs
@@ -21,6 +21,7 @@ namespace HandBrake.ApplicationServices.Interop
{
private static HandBrakeInstance scanInstance;
private static HandBrakeInstance encodeInstance;
+ private static HandBrakeInstance previewInstance;
private static HandBrakeInstance masterInstance;
/// <summary>
@@ -89,6 +90,30 @@ namespace HandBrake.ApplicationServices.Interop
}
/// <summary>
+ /// The get encode instance.
+ /// </summary>
+ /// <param name="verbosity">
+ /// The verbosity.
+ /// </param>
+ /// <returns>
+ /// The <see cref="IHandBrakeInstance"/>.
+ /// </returns>
+ public static IHandBrakeInstance GetPreviewInstance(int verbosity)
+ {
+ if (previewInstance != null)
+ {
+ previewInstance.Dispose();
+ previewInstance = null;
+ }
+
+ HandBrakeInstance newInstance = new HandBrakeInstance();
+ newInstance.Initialize(verbosity);
+ previewInstance = newInstance;
+
+ return previewInstance;
+ }
+
+ /// <summary>
/// Gets the master instance.
/// </summary>
internal static IHandBrakeInstance MasterInstance
diff --git a/win/CS/HandBrakeWPF/Services/Encode/EncodeBase.cs b/win/CS/HandBrakeWPF/Services/Encode/EncodeBase.cs
index 4179ed3c7..9ae0398ee 100644
--- a/win/CS/HandBrakeWPF/Services/Encode/EncodeBase.cs
+++ b/win/CS/HandBrakeWPF/Services/Encode/EncodeBase.cs
@@ -11,6 +11,7 @@ namespace HandBrakeWPF.Services.Encode
{
using System;
using System.Diagnostics;
+ using System.Globalization;
using System.IO;
using System.Text;
@@ -188,18 +189,19 @@ namespace HandBrakeWPF.Services.Encode
/// <param name="configuration">
/// The configuration.
/// </param>
- public void ProcessLogs(string destination, HBConfiguration configuration)
+ public void ProcessLogs(string destination, bool isPreview, HBConfiguration configuration)
{
try
{
string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) +
"\\HandBrake\\logs";
- string tempLogFile = Path.Combine(logDir, string.Format("last_encode_log{0}.txt", GeneralUtilities.ProcessId));
+
+ string tempLogFile = Path.Combine(logDir, isPreview ? $"preview_encode_log{GeneralUtilities.ProcessId}.txt" : string.Format("last_encode_log{0}.txt", GeneralUtilities.ProcessId));
string encodeDestinationPath = Path.GetDirectoryName(destination);
string destinationFile = Path.GetFileName(destination);
string encodeLogFile = destinationFile + " " +
- DateTime.Now.ToString().Replace("/", "-").Replace(":", "-") + ".txt";
+ DateTime.Now.ToString(CultureInfo.InvariantCulture).Replace("/", "-").Replace(":", "-") + ".txt";
// Make sure the log directory exists.
if (!Directory.Exists(logDir))
@@ -232,12 +234,11 @@ namespace HandBrakeWPF.Services.Encode
/// <summary>
/// Setup the logging.
/// </summary>
- protected void SetupLogging()
+ protected void SetupLogging(bool isPreviewEncode)
{
this.ShutdownFileWriter();
string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";
- string logFile = Path.Combine(logDir, string.Format("last_encode_log{0}.txt", GeneralUtilities.ProcessId));
- string logFile2 = Path.Combine(logDir, string.Format("tmp_appReadable_log{0}.txt", GeneralUtilities.ProcessId));
+ string logFile = Path.Combine(logDir, isPreviewEncode ? $"preview_last_encode_log{GeneralUtilities.ProcessId}.txt" : $"last_encode_log{GeneralUtilities.ProcessId}.txt");
try
{
@@ -251,11 +252,6 @@ namespace HandBrakeWPF.Services.Encode
File.Delete(logFile);
}
- if (File.Exists(logFile2))
- {
- File.Delete(logFile2);
- }
-
lock (FileWriterLock)
{
this.fileWriter = new StreamWriter(logFile) { AutoFlush = true };
diff --git a/win/CS/HandBrakeWPF/Services/Encode/Interfaces/IEncode.cs b/win/CS/HandBrakeWPF/Services/Encode/Interfaces/IEncode.cs
index 1e81ed5ed..691df1500 100644
--- a/win/CS/HandBrakeWPF/Services/Encode/Interfaces/IEncode.cs
+++ b/win/CS/HandBrakeWPF/Services/Encode/Interfaces/IEncode.cs
@@ -104,16 +104,5 @@ namespace HandBrakeWPF.Services.Encode.Interfaces
/// Kill the process
/// </summary>
void Stop();
-
- /// <summary>
- /// Copy the log file to the desired destinations
- /// </summary>
- /// <param name="destination">
- /// The destination.
- /// </param>
- /// <param name="configuration">
- /// The configuration.
- /// </param>
- void ProcessLogs(string destination, HBConfiguration configuration);
}
} \ No newline at end of file
diff --git a/win/CS/HandBrakeWPF/Services/Encode/LibEncode.cs b/win/CS/HandBrakeWPF/Services/Encode/LibEncode.cs
index caf1eff1d..111c91c6e 100644
--- a/win/CS/HandBrakeWPF/Services/Encode/LibEncode.cs
+++ b/win/CS/HandBrakeWPF/Services/Encode/LibEncode.cs
@@ -17,6 +17,7 @@ namespace HandBrakeWPF.Services.Encode
using HandBrake.ApplicationServices.Interop.Interfaces;
using HandBrake.ApplicationServices.Model;
+ using HandBrakeWPF.Exceptions;
using HandBrakeWPF.Services.Encode.Factories;
using EncodeTask = HandBrakeWPF.Services.Encode.Model.EncodeTask;
@@ -34,6 +35,7 @@ namespace HandBrakeWPF.Services.Encode
private DateTime startTime;
private EncodeTask currentTask;
private HBConfiguration currentConfiguration;
+ private bool isPreviewInstance;
#endregion
@@ -55,6 +57,12 @@ namespace HandBrakeWPF.Services.Encode
{
try
{
+ // Sanity Checking and Setup
+ if (this.IsEncoding)
+ {
+ throw new GeneralApplicationException("HandBrake is already encoding a file.", "Please stop the current encode. If the problem persists, please restart HandBrake.", null);
+ }
+
// Setup
this.startTime = DateTime.Now;
this.currentTask = task;
@@ -64,18 +72,14 @@ namespace HandBrakeWPF.Services.Encode
// Setup the HandBrake Instance
HandBrakeUtils.MessageLogged += this.HandBrakeInstanceMessageLogged;
HandBrakeUtils.ErrorLogged += this.HandBrakeInstanceErrorLogged;
- this.instance = HandBrakeInstanceManager.GetEncodeInstance(configuration.Verbosity);
+ this.instance = task.IsPreviewEncode ? HandBrakeInstanceManager.GetPreviewInstance(configuration.Verbosity) : HandBrakeInstanceManager.GetEncodeInstance(configuration.Verbosity);
+
this.instance.EncodeCompleted += this.InstanceEncodeCompleted;
this.instance.EncodeProgress += this.InstanceEncodeProgress;
- // Sanity Checking and Setup
- if (this.IsEncoding)
- {
- throw new Exception("HandBrake is already encoding.");
- }
-
this.IsEncoding = true;
- this.SetupLogging();
+ this.isPreviewInstance = task.IsPreviewEncode;
+ this.SetupLogging(task.IsPreviewEncode);
// Verify the Destination Path Exists, and if not, create it.
this.VerifyEncodeDestinationPath(task);
@@ -246,7 +250,7 @@ namespace HandBrakeWPF.Services.Encode
HandBrakeUtils.ErrorLogged -= this.HandBrakeInstanceErrorLogged;
// Handling Log Data
- this.ProcessLogs(this.currentTask.Destination, this.currentConfiguration);
+ this.ProcessLogs(this.currentTask.Destination, this.isPreviewInstance, this.currentConfiguration);
// Cleanup
this.ShutdownFileWriter();