diff options
Diffstat (limited to 'win/CS/HandBrake.ApplicationServices/Services')
-rw-r--r-- | win/CS/HandBrake.ApplicationServices/Services/Encode.cs | 74 | ||||
-rw-r--r-- | win/CS/HandBrake.ApplicationServices/Services/ScanService.cs | 94 |
2 files changed, 15 insertions, 153 deletions
diff --git a/win/CS/HandBrake.ApplicationServices/Services/Encode.cs b/win/CS/HandBrake.ApplicationServices/Services/Encode.cs index 4a6333da7..c7a00dda5 100644 --- a/win/CS/HandBrake.ApplicationServices/Services/Encode.cs +++ b/win/CS/HandBrake.ApplicationServices/Services/Encode.cs @@ -57,6 +57,11 @@ namespace HandBrake.ApplicationServices.Services /// </summary>
static readonly object fileWriterLock = new object();
+ /// <summary>
+ /// The Log File Header
+ /// </summary>
+ StringBuilder header = UtilityService.CreateCliLogHeader(null);
+
#endregion
/// <summary>
@@ -65,6 +70,7 @@ namespace HandBrake.ApplicationServices.Services public Encode()
{
this.EncodeStarted += this.EncodeEncodeStarted;
+ this.logBuffer = new StringBuilder();
GrowlCommunicator.Register();
}
@@ -104,20 +110,8 @@ namespace HandBrake.ApplicationServices.Services public string ActivityLog
{
get
- {
- if (this.IsEncoding == false)
- {
- try
- {
- ReadFile(); // Read the last log file back in if it exists
- }
- catch (Exception exc)
- {
- return exc.ToString();
- }
- }
-
- return string.IsNullOrEmpty(this.logBuffer.ToString()) ? "No log data available..." : this.logBuffer.ToString();
+ {
+ return string.IsNullOrEmpty(this.logBuffer.ToString()) ? header + "No log data available..." : header + this.logBuffer.ToString();
}
}
@@ -396,56 +390,6 @@ namespace HandBrake.ApplicationServices.Services }
/// <summary>
- /// Read the log file
- /// </summary>
- private void ReadFile()
- {
- logBuffer = new StringBuilder();
- lock (logBuffer)
- {
- // 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, 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
- {
- // Copy the log file.
- if (File.Exists(logFile))
- File.Copy(logFile, logFile2, true);
- else
- return;
-
- // Start the Reader
- // Only use text which continues on from the last read line
- using (StreamReader sr = new StreamReader(logFile2))
- {
- string line;
- int i = 1;
- while ((line = sr.ReadLine()) != null)
- {
- if (i > logFilePosition)
- {
- logBuffer.AppendLine(line);
- logFilePosition++;
- }
- i++;
- }
- sr.Close();
- }
- }
- catch (Exception exc)
- {
- logBuffer.Append(
- Environment.NewLine + "Unable to read Log file..." + Environment.NewLine + exc +
- Environment.NewLine);
- }
- }
- }
-
- /// <summary>
/// Setup the logging.
/// </summary>
/// <param name="encodeQueueTask">
@@ -466,9 +410,7 @@ namespace HandBrake.ApplicationServices.Services if (File.Exists(logFile2)) File.Delete(logFile2);
fileWriter = new StreamWriter(logFile) { AutoFlush = true };
-
fileWriter.WriteLine(UtilityService.CreateCliLogHeader(encodeQueueTask));
- logBuffer.AppendLine(UtilityService.CreateCliLogHeader(encodeQueueTask));
}
catch (Exception)
{
diff --git a/win/CS/HandBrake.ApplicationServices/Services/ScanService.cs b/win/CS/HandBrake.ApplicationServices/Services/ScanService.cs index 7064d9358..091b4478c 100644 --- a/win/CS/HandBrake.ApplicationServices/Services/ScanService.cs +++ b/win/CS/HandBrake.ApplicationServices/Services/ScanService.cs @@ -25,11 +25,6 @@ namespace HandBrake.ApplicationServices.Services #region Private Variables
/// <summary>
- /// A Lock object
- /// </summary>
- private static readonly object locker = new object();
-
- /// <summary>
/// The CLI data parser
/// </summary>
private Parser readData;
@@ -40,14 +35,14 @@ namespace HandBrake.ApplicationServices.Services private StringBuilder logBuffer;
/// <summary>
- /// The line number thats been read to in the log file
+ /// The Process belonging to the CLI
/// </summary>
- private int logFilePosition;
+ private Process hbProc;
/// <summary>
- /// The Process belonging to the CLI
+ /// The Log File Header
/// </summary>
- private Process hbProc;
+ StringBuilder header = UtilityService.CreateCliLogHeader(null);
#endregion
@@ -56,6 +51,7 @@ namespace HandBrake.ApplicationServices.Services /// </summary>
public ScanService()
{
+ this.logBuffer = new StringBuilder();
}
#region Events
@@ -96,16 +92,7 @@ namespace HandBrake.ApplicationServices.Services {
get
{
- if (IsScanning)
- return readData.Buffer.ToString();
-
- if (logBuffer == null)
- {
- ResetLogReader(false);
- ReadLastScanFile();
- }
-
- return logBuffer != null ? logBuffer.ToString() : string.Empty;
+ return string.IsNullOrEmpty(this.logBuffer.ToString()) ? header + "No log data available..." : header + this.logBuffer.ToString();
}
}
@@ -165,7 +152,7 @@ namespace HandBrake.ApplicationServices.Services this.ScanStared(this, new EventArgs());
}
- ResetLogReader(true);
+ logBuffer = new StringBuilder();
string handbrakeCLIPath = Path.Combine(Application.StartupPath, "HandBrakeCLI.exe");
string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) +
@@ -264,73 +251,6 @@ namespace HandBrake.ApplicationServices.Services }
/// <summary>
- /// Read the log file
- /// </summary>
- private void ReadLastScanFile()
- {
- lock (locker)
- {
- // 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, string.Format("last_scan_log{0}.txt", Init.InstanceId == 0 ? string.Empty : Init.InstanceId.ToString()));
- string logFile2 = Path.Combine(logDir, string.Format("tmp_appReadable_log{0}.txt", Init.InstanceId == 0 ? string.Empty : Init.InstanceId.ToString()));
-
- try
- {
- // Make sure the application readable log file does not already exist. FileCopy fill fail if it does.
- if (File.Exists(logFile2))
- File.Delete(logFile2);
-
- // Copy the log file.
- if (File.Exists(logFile))
- File.Copy(logFile, logFile2, true);
- else
- {
- ResetLogReader(true);
- return;
- }
-
- // Start the Reader
- // Only use text which continues on from the last read line
- StreamReader sr = new StreamReader(logFile2);
- string line;
- int i = 1;
- while ((line = sr.ReadLine()) != null)
- {
- if (i > logFilePosition)
- {
- logBuffer.AppendLine(line);
- logFilePosition++;
- }
- i++;
- }
- sr.Close();
- sr.Dispose();
- }
- catch (Exception exc)
- {
- ResetLogReader(true);
- }
- }
- }
-
- /// <summary>
- /// Reset the Log Reader
- /// </summary>
- /// <param name="addHeader">
- /// The add Header.
- /// </param>
- private void ResetLogReader(bool addHeader)
- {
- logFilePosition = 0;
- logBuffer = new StringBuilder();
- if (addHeader)
- logBuffer.AppendLine(UtilityService.CreateCliLogHeader(null));
- }
-
- /// <summary>
/// Fire an event when the scan process progresses
/// </summary>
/// <param name="sender">the sender</param>
|