summaryrefslogtreecommitdiffstats
path: root/win/CS/HandBrake.ApplicationServices
diff options
context:
space:
mode:
Diffstat (limited to 'win/CS/HandBrake.ApplicationServices')
-rw-r--r--win/CS/HandBrake.ApplicationServices/Services/Base/EncodeBase.cs6
-rw-r--r--win/CS/HandBrake.ApplicationServices/Services/Interfaces/IQueueProcessor.cs5
-rw-r--r--win/CS/HandBrake.ApplicationServices/Services/QueueProcessor.cs10
-rw-r--r--win/CS/HandBrake.ApplicationServices/Services/ScanService.cs2
-rw-r--r--win/CS/HandBrake.ApplicationServices/Utilities/GeneralUtilities.cs64
5 files changed, 30 insertions, 57 deletions
diff --git a/win/CS/HandBrake.ApplicationServices/Services/Base/EncodeBase.cs b/win/CS/HandBrake.ApplicationServices/Services/Base/EncodeBase.cs
index 8cca6e7e5..8ef67b28d 100644
--- a/win/CS/HandBrake.ApplicationServices/Services/Base/EncodeBase.cs
+++ b/win/CS/HandBrake.ApplicationServices/Services/Base/EncodeBase.cs
@@ -213,7 +213,7 @@ namespace HandBrake.ApplicationServices.Services.Base
{
string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) +
"\\HandBrake\\logs";
- string tempLogFile = Path.Combine(logDir, string.Format("last_encode_log{0}.txt", GeneralUtilities.GetInstanceCount));
+ string tempLogFile = Path.Combine(logDir, string.Format("last_encode_log{0}.txt", GeneralUtilities.ProcessId));
string encodeDestinationPath = Path.GetDirectoryName(destination);
string destinationFile = Path.GetFileName(destination);
@@ -259,8 +259,8 @@ namespace HandBrake.ApplicationServices.Services.Base
{
ShutdownFileWriter();
string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";
- string logFile = Path.Combine(logDir, string.Format("last_encode_log{0}.txt", GeneralUtilities.GetInstanceCount));
- string logFile2 = Path.Combine(logDir, string.Format("tmp_appReadable_log{0}.txt", GeneralUtilities.GetInstanceCount));
+ 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));
try
{
diff --git a/win/CS/HandBrake.ApplicationServices/Services/Interfaces/IQueueProcessor.cs b/win/CS/HandBrake.ApplicationServices/Services/Interfaces/IQueueProcessor.cs
index c9285ebfe..0a952e516 100644
--- a/win/CS/HandBrake.ApplicationServices/Services/Interfaces/IQueueProcessor.cs
+++ b/win/CS/HandBrake.ApplicationServices/Services/Interfaces/IQueueProcessor.cs
@@ -154,11 +154,6 @@ namespace HandBrake.ApplicationServices.Services.Interfaces
void Remove(QueueTask job);
/// <summary>
- /// Temp workaround until this can be fixed properly.
- /// </summary>
- void ResetInstanceId();
-
- /// <summary>
/// Reset a Queued Item from Error or Completed to Waiting
/// </summary>
/// <param name="job">
diff --git a/win/CS/HandBrake.ApplicationServices/Services/QueueProcessor.cs b/win/CS/HandBrake.ApplicationServices/Services/QueueProcessor.cs
index 0b3290839..7aefd285f 100644
--- a/win/CS/HandBrake.ApplicationServices/Services/QueueProcessor.cs
+++ b/win/CS/HandBrake.ApplicationServices/Services/QueueProcessor.cs
@@ -75,7 +75,7 @@ namespace HandBrake.ApplicationServices.Services
this.EncodeService = encodeService;
// If this is the first instance, just use the main queue file, otherwise add the instance id to the filename.
- this.queueFile = string.Format("hb_queue_recovery{0}.xml", GeneralUtilities.GetInstanceCount);
+ this.queueFile = string.Format("hb_queue_recovery{0}.xml", GeneralUtilities.ProcessId);
}
#endregion
@@ -331,14 +331,6 @@ namespace HandBrake.ApplicationServices.Services
}
/// <summary>
- /// Temp workaround until this can be fixed properly.
- /// </summary>
- public void ResetInstanceId()
- {
- this.queueFile = string.Format("hb_queue_recovery{0}.xml", GeneralUtilities.GetInstanceCount);
- }
-
- /// <summary>
/// Reset a Queued Item from Error or Completed to Waiting
/// </summary>
/// <param name="job">
diff --git a/win/CS/HandBrake.ApplicationServices/Services/ScanService.cs b/win/CS/HandBrake.ApplicationServices/Services/ScanService.cs
index bb4ec44c6..e7c7a2852 100644
--- a/win/CS/HandBrake.ApplicationServices/Services/ScanService.cs
+++ b/win/CS/HandBrake.ApplicationServices/Services/ScanService.cs
@@ -246,7 +246,7 @@ namespace HandBrake.ApplicationServices.Services
"\\HandBrake\\logs";
string dvdInfoPath = Path.Combine(
logDir,
- string.Format("last_scan_log{0}.txt", GeneralUtilities.GetInstanceCount));
+ string.Format("last_scan_log{0}.txt", GeneralUtilities.ProcessId));
if (!Directory.Exists(logDir))
{
diff --git a/win/CS/HandBrake.ApplicationServices/Utilities/GeneralUtilities.cs b/win/CS/HandBrake.ApplicationServices/Utilities/GeneralUtilities.cs
index bebdc734d..378898c05 100644
--- a/win/CS/HandBrake.ApplicationServices/Utilities/GeneralUtilities.cs
+++ b/win/CS/HandBrake.ApplicationServices/Utilities/GeneralUtilities.cs
@@ -14,14 +14,12 @@ namespace HandBrake.ApplicationServices.Utilities
using System.Diagnostics;
using System.Globalization;
using System.IO;
+ using System.Linq;
using System.Text;
+ using System.Text.RegularExpressions;
using System.Windows.Forms;
- using Caliburn.Micro;
-
using HandBrake.ApplicationServices.Model;
- using HandBrake.ApplicationServices.Services;
- using HandBrake.ApplicationServices.Services.Interfaces;
/// <summary>
/// A Set of Static Utilites
@@ -33,12 +31,7 @@ namespace HandBrake.ApplicationServices.Utilities
/// <summary>
/// The Default Log Directory
/// </summary>
- private static readonly string LogDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) +
- "\\HandBrake\\logs";
- /// <summary>
- /// The Instance ID
- /// </summary>
- private static int instanceId = 0;
+ private static readonly string LogDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";
#endregion
@@ -47,23 +40,11 @@ namespace HandBrake.ApplicationServices.Utilities
/// <summary>
/// Gets the number of HandBrake instances running.
/// </summary>
- public static string GetInstanceCount
- {
- get
- {
- return instanceId == 0 ? string.Empty : instanceId.ToString(CultureInfo.InvariantCulture);
- }
- }
-
- /// <summary>
- /// Gets a value indicating whether HandBrake is running in multi instance mode
- /// </summary>
- /// <returns>True if the UI has another instance running</returns>
- public static bool IsMultiInstance
+ public static int ProcessId
{
get
{
- return Process.GetProcessesByName("HandBrake").Length > 1 ? true : false;
+ return Process.GetCurrentProcess().Id;
}
}
@@ -85,19 +66,16 @@ namespace HandBrake.ApplicationServices.Utilities
var info = new DirectoryInfo(LogDir);
FileInfo[] logFiles = info.GetFiles("*.txt");
- // Delete Them
+ // Delete old and excessivly large files (> ~50MB).
foreach (FileInfo file in logFiles)
{
if (file.LastWriteTime < DateTime.Now.AddDays(-daysToKeep))
{
- if (!file.Name.Contains("last_scan_log.txt") && !file.Name.Contains("last_encode_log.txt"))
- {
- File.Delete(file.FullName);
- }
- else if (file.Length > 104857600)
- {
- File.Delete(file.FullName);
- }
+ File.Delete(file.FullName);
+ }
+ else if (file.Length > 50000000)
+ {
+ File.Delete(file.FullName);
}
}
}
@@ -118,7 +96,7 @@ namespace HandBrake.ApplicationServices.Utilities
public static StringBuilder CreateCliLogHeader(string version, int build)
{
var logHeader = new StringBuilder();
-
+
logHeader.AppendLine(String.Format("HandBrake {0} {1}", version, build));
logHeader.AppendLine(String.Format("OS: {0}", Environment.OSVersion));
logHeader.AppendLine(String.Format("CPU: {0}", SystemInfo.GetCpuCount));
@@ -161,8 +139,8 @@ namespace HandBrake.ApplicationServices.Utilities
drives.Add(
new DriveInformation
{
- Id = id,
- VolumeLabel = curDrive.VolumeLabel,
+ Id = id,
+ VolumeLabel = curDrive.VolumeLabel,
RootDirectory = curDrive.RootDirectory.ToString()
});
id++;
@@ -188,12 +166,20 @@ namespace HandBrake.ApplicationServices.Utilities
}
/// <summary>
- /// Set the Instance ID
+ /// The find hand brake instance ids.
/// </summary>
- public static void SetInstanceId()
+ /// <param name="id">
+ /// The id.
+ /// </param>
+ /// <returns>
+ /// The <see cref="bool"/>. True if it's a running HandBrake instance.
+ /// </returns>
+ public static bool IsPidACurrentHandBrakeInstance(int id)
{
- instanceId = Process.GetProcessesByName("HandBrake").Length;
+ List<int> ids = Process.GetProcessesByName("HandBrake").Select(process => process.Id).ToList();
+ return ids.Contains(id);
}
+
#endregion
}
} \ No newline at end of file