From 561aa6ec3b4f018a4e76d1a57c7ffd6f0e7ded70 Mon Sep 17 00:00:00 2001 From: sr55 Date: Sat, 17 Jul 2010 22:25:01 +0000 Subject: WinGui: - Some tweaks to the Logging code. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@3445 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- win/C#/Functions/System.cs | 57 --------------------- .../Functions/Logging.cs | 49 ++++++++++++++++++ .../Functions/System.cs | 58 ++++++++++++++++++++++ .../HandBrake.ApplicationServices.csproj | 2 + win/C#/HandBrake.ApplicationServices/Init.cs | 14 +++++- win/C#/HandBrake.ApplicationServices/Model/Job.cs | 2 +- .../Services/Encode.cs | 20 +------- .../HandBrake.ApplicationServices/Services/Scan.cs | 4 +- win/C#/HandBrakeCS.csproj | 1 - win/C#/Program.cs | 3 +- win/C#/frmActivityWindow.cs | 46 ----------------- win/C#/frmOptions.cs | 3 +- 12 files changed, 132 insertions(+), 127 deletions(-) delete mode 100644 win/C#/Functions/System.cs create mode 100644 win/C#/HandBrake.ApplicationServices/Functions/Logging.cs create mode 100644 win/C#/HandBrake.ApplicationServices/Functions/System.cs (limited to 'win') diff --git a/win/C#/Functions/System.cs b/win/C#/Functions/System.cs deleted file mode 100644 index fb830fb8d..000000000 --- a/win/C#/Functions/System.cs +++ /dev/null @@ -1,57 +0,0 @@ -/* System.cs $ - This file is part of the HandBrake source code. - Homepage: . - It may be used under the terms of the GNU General Public License. */ - -namespace Handbrake.Functions -{ - using System.Windows.Forms; - using Microsoft.Win32; - - /// - /// The System Information. - /// - public class SystemInfo - { - /// - /// Gets the total physical ram in a system - /// - /// The total memory in the system - public static uint TotalPhysicalMemory - { - get - { - Win32.MEMORYSTATUS memStatus = new Win32.MEMORYSTATUS(); - Win32.GlobalMemoryStatus(ref memStatus); - - uint memoryInfo = memStatus.dwTotalPhys; - memoryInfo = memoryInfo / 1024 / 1024; - - return memoryInfo; - } - } - - /// - /// Gets the number of CPU Cores - /// - /// Object - public static object GetCpuCount - { - get - { - RegistryKey regKey = Registry.LocalMachine; - regKey = regKey.OpenSubKey("HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0"); - return regKey == null ? 0 : regKey.GetValue("ProcessorNameString"); - } - } - - /// - /// Gets the System screen size information. - /// - /// System.Windows.Forms.Scree - public static Screen ScreenBounds - { - get { return Screen.PrimaryScreen; } - } - } -} \ No newline at end of file diff --git a/win/C#/HandBrake.ApplicationServices/Functions/Logging.cs b/win/C#/HandBrake.ApplicationServices/Functions/Logging.cs new file mode 100644 index 000000000..aba92dbbe --- /dev/null +++ b/win/C#/HandBrake.ApplicationServices/Functions/Logging.cs @@ -0,0 +1,49 @@ +/* Logging.cs $ + This file is part of the HandBrake source code. + Homepage: . + It may be used under the terms of the GNU General Public License. */ + +namespace HandBrake.ApplicationServices.Functions +{ + using System; + using System.IO; + using System.Text; + using System.Windows.Forms; + + using HandBrake.ApplicationServices.Model; + + /// + /// The System Information. + /// + public class Logging + { + /// + /// Add the CLI Query to the Log File. + /// + /// + /// The Encode Job Object + /// + public static string CreateCliLogHeader(Job encJob) + { + StringBuilder logHeader = new StringBuilder(); + + logHeader.AppendLine(String.Format("# {0}", Init.HandBrakeGuiVersionString)); + logHeader.AppendLine(String.Format("# Running: {0}", Environment.OSVersion)); + logHeader.AppendLine(String.Format("# CPU: {0}", SystemInfo.GetCpuCount)); + logHeader.AppendLine(String.Format("# Ram: {0} MB", SystemInfo.TotalPhysicalMemory)); + logHeader.AppendLine(String.Format("# Screen: {0}x{1}", SystemInfo.ScreenBounds.Bounds.Width, SystemInfo.ScreenBounds.Bounds.Height)); + logHeader.AppendLine(String.Format("# Temp Dir: {0}", Path.GetTempPath())); + logHeader.AppendLine(String.Format("# Install Dir: {0}", Application.StartupPath)); + logHeader.AppendLine(String.Format("# Data Dir: {0}\n", Application.UserAppDataPath)); + + if (encJob != null) + { + logHeader.AppendLine(String.Format("# CLI Query: {0}", encJob.Query)); + logHeader.AppendLine(String.Format("# User Query: {0}", encJob.CustomQuery)); + } + logHeader.AppendLine("-------------------------------------------"); + + return logHeader.ToString(); + } + } +} \ No newline at end of file diff --git a/win/C#/HandBrake.ApplicationServices/Functions/System.cs b/win/C#/HandBrake.ApplicationServices/Functions/System.cs new file mode 100644 index 000000000..b2ee6edfe --- /dev/null +++ b/win/C#/HandBrake.ApplicationServices/Functions/System.cs @@ -0,0 +1,58 @@ +/* System.cs $ + This file is part of the HandBrake source code. + Homepage: . + It may be used under the terms of the GNU General Public License. */ + +namespace HandBrake.ApplicationServices.Functions +{ + using System.Windows.Forms; + + using Microsoft.Win32; + + /// + /// The System Information. + /// + public class SystemInfo + { + /// + /// Gets the total physical ram in a system + /// + /// The total memory in the system + public static uint TotalPhysicalMemory + { + get + { + Win32.MEMORYSTATUS memStatus = new Win32.MEMORYSTATUS(); + Win32.GlobalMemoryStatus(ref memStatus); + + uint memoryInfo = memStatus.dwTotalPhys; + memoryInfo = memoryInfo / 1024 / 1024; + + return memoryInfo; + } + } + + /// + /// Gets the number of CPU Cores + /// + /// Object + public static object GetCpuCount + { + get + { + RegistryKey regKey = Registry.LocalMachine; + regKey = regKey.OpenSubKey("HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0"); + return regKey == null ? 0 : regKey.GetValue("ProcessorNameString"); + } + } + + /// + /// Gets the System screen size information. + /// + /// System.Windows.Forms.Scree + public static Screen ScreenBounds + { + get { return Screen.PrimaryScreen; } + } + } +} \ No newline at end of file diff --git a/win/C#/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj b/win/C#/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj index 148ba78db..bc6c04db0 100644 --- a/win/C#/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj +++ b/win/C#/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj @@ -78,8 +78,10 @@ frmExceptionWindow.cs + + diff --git a/win/C#/HandBrake.ApplicationServices/Init.cs b/win/C#/HandBrake.ApplicationServices/Init.cs index 7f1e1ed72..d279a0b11 100644 --- a/win/C#/HandBrake.ApplicationServices/Init.cs +++ b/win/C#/HandBrake.ApplicationServices/Init.cs @@ -16,6 +16,9 @@ namespace HandBrake.ApplicationServices /// /// Setup the Settings used by the applicaiton with this library /// + /// + /// The version / name of the application that's using this DLL. + /// /// /// The Instance ID /// @@ -49,11 +52,12 @@ namespace HandBrake.ApplicationServices /// /// Prevent the system from sleeping /// - public static void SetupSettings(int instanceId, string completionOption, bool disableDvdNav, + public static void SetupSettings(string versionString, int instanceId, string completionOption, bool disableDvdNav, bool growlEncode, bool growlQueue, string processPriority, string saveLogPath, bool saveLogToSpecifiedPath, bool saveLogWithVideo, bool showCliForInGuiEncodeStatus, bool preventSleep) { InstanceId = instanceId; + HandBrakeGuiVersionString = versionString; Properties.Settings.Default.CompletionOption = completionOption; Properties.Settings.Default.disableDvdNav = disableDvdNav; Properties.Settings.Default.growlEncode = growlEncode; @@ -79,6 +83,14 @@ namespace HandBrake.ApplicationServices return Assembly.GetExecutingAssembly().GetName().Version; } + /// + /// The instance ID used by the Main Applicaiton + /// public static int InstanceId; + + /// + /// The Applicaiton that uses this DLL can pass in it's version string. + /// + public static string HandBrakeGuiVersionString; } } diff --git a/win/C#/HandBrake.ApplicationServices/Model/Job.cs b/win/C#/HandBrake.ApplicationServices/Model/Job.cs index 9d4b37510..536069153 100644 --- a/win/C#/HandBrake.ApplicationServices/Model/Job.cs +++ b/win/C#/HandBrake.ApplicationServices/Model/Job.cs @@ -8,7 +8,7 @@ namespace HandBrake.ApplicationServices.Model /// /// The job. /// - public struct Job + public class Job { /// /// Gets or sets the job ID. diff --git a/win/C#/HandBrake.ApplicationServices/Services/Encode.cs b/win/C#/HandBrake.ApplicationServices/Services/Encode.cs index 9ef1b2c9c..c21d83722 100644 --- a/win/C#/HandBrake.ApplicationServices/Services/Encode.cs +++ b/win/C#/HandBrake.ApplicationServices/Services/Encode.cs @@ -260,22 +260,6 @@ namespace HandBrake.ApplicationServices.Services } /* Helpers */ - /// - /// Add the CLI Query to the Log File. - /// - /// - /// The Encode Job Object - /// - private static string CreateCliLogHeader(Job encJob) - { - StringBuilder logHeader = new StringBuilder(); - logHeader.AppendLine("# CLI Query: " + encJob.Query); - logHeader.AppendLine("# User Query: " + encJob.CustomQuery); - logHeader.AppendLine("-------------------------------------------"); - - return logHeader.ToString(); - } - /// /// Save a copy of the log to the users desired location or a default location /// if this feature is enabled in options. @@ -430,8 +414,8 @@ namespace HandBrake.ApplicationServices.Services fileWriter = new StreamWriter(logFile) { AutoFlush = true }; - fileWriter.WriteLine(CreateCliLogHeader(encodeJob)); - logBuffer.AppendLine(CreateCliLogHeader(encodeJob)); + fileWriter.WriteLine(Logging.CreateCliLogHeader(encodeJob)); + logBuffer.AppendLine(Logging.CreateCliLogHeader(encodeJob)); } catch (Exception exc) { diff --git a/win/C#/HandBrake.ApplicationServices/Services/Scan.cs b/win/C#/HandBrake.ApplicationServices/Services/Scan.cs index 039cb3f3d..04c35e36f 100644 --- a/win/C#/HandBrake.ApplicationServices/Services/Scan.cs +++ b/win/C#/HandBrake.ApplicationServices/Services/Scan.cs @@ -191,10 +191,11 @@ namespace HandBrake.ApplicationServices.Services // Write the Buffer out to file. StreamWriter scanLog = new StreamWriter(dvdInfoPath); + scanLog.WriteLine(Logging.CreateCliLogHeader(null)); scanLog.Write(this.readData.Buffer); scanLog.Flush(); scanLog.Close(); - logBuffer = readData.Buffer; + logBuffer.AppendLine(this.readData.Buffer.ToString()); IsScanning = false; @@ -268,6 +269,7 @@ namespace HandBrake.ApplicationServices.Services { logFilePosition = 0; logBuffer = new StringBuilder(); + logBuffer.AppendLine(Logging.CreateCliLogHeader(null)); } /// diff --git a/win/C#/HandBrakeCS.csproj b/win/C#/HandBrakeCS.csproj index 76042e21b..0a947594b 100644 --- a/win/C#/HandBrakeCS.csproj +++ b/win/C#/HandBrakeCS.csproj @@ -272,7 +272,6 @@ - diff --git a/win/C#/Program.cs b/win/C#/Program.cs index f54a775f9..1c428c874 100644 --- a/win/C#/Program.cs +++ b/win/C#/Program.cs @@ -91,7 +91,8 @@ namespace Handbrake /// private static void InitializeApplicationServices() { - Init.SetupSettings(InstanceId, Settings.Default.CompletionOption, Settings.Default.noDvdNav, + string versionId = String.Format("Windows GUI {1} {0}", Settings.Default.hb_build, Settings.Default.hb_version); + Init.SetupSettings(versionId, InstanceId, Settings.Default.CompletionOption, Settings.Default.noDvdNav, Settings.Default.growlEncode, Settings.Default.growlQueue, Settings.Default.processPriority, Settings.Default.saveLogPath, Settings.Default.saveLogToSpecifiedPath, Settings.Default.saveLogWithVideo, Settings.Default.showCliForInGuiEncodeStatus, Settings.Default.preventSleep); diff --git a/win/C#/frmActivityWindow.cs b/win/C#/frmActivityWindow.cs index d890a7834..62799e926 100644 --- a/win/C#/frmActivityWindow.cs +++ b/win/C#/frmActivityWindow.cs @@ -12,7 +12,6 @@ namespace Handbrake using System.Text; using System.Threading; using System.Windows.Forms; - using Functions; using HandBrake.ApplicationServices.Services.Interfaces; @@ -231,7 +230,6 @@ namespace Handbrake appendText.AppendFormat("Waiting for the log to be generated ...\n"); position = 0; ClearWindowText(); - PrintLogHeader(); return appendText; } @@ -247,7 +245,6 @@ namespace Handbrake appendText.AppendFormat("Waiting for the log to be generated ...\n"); position = 0; ClearWindowText(); - PrintLogHeader(); return appendText; } @@ -342,48 +339,6 @@ namespace Handbrake } } - /// - /// Display the log header - /// - private void PrintLogHeader() - { - try - { - if (IsHandleCreated) - { - if (rtf_actLog.InvokeRequired) - { - IAsyncResult invoked = BeginInvoke(new SetTextClearCallback(PrintLogHeader)); - EndInvoke(invoked); - } - else - { - lock (rtf_actLog) - { - // Print the log header. This function will be re-implimented later. Do not delete. - StringBuilder header = new StringBuilder(); - - header.Append(String.Format("### Windows GUI {1} {0} \n", Properties.Settings.Default.hb_build, Properties.Settings.Default.hb_version)); - header.Append(String.Format("### Running: {0} \n###\n", Environment.OSVersion)); - header.Append(String.Format("### CPU: {0} \n", SystemInfo.GetCpuCount)); - header.Append(String.Format("### Ram: {0} MB \n", SystemInfo.TotalPhysicalMemory)); - header.Append(String.Format("### Screen: {0}x{1} \n", SystemInfo.ScreenBounds.Bounds.Width, SystemInfo.ScreenBounds.Bounds.Height)); - header.Append(String.Format("### Temp Dir: {0} \n", Path.GetTempPath())); - header.Append(String.Format("### Install Dir: {0} \n", Application.StartupPath)); - header.Append(String.Format("### Data Dir: {0} \n", Application.UserAppDataPath)); - header.Append("#########################################\n\n"); - - rtf_actLog.AppendText(header.ToString()); - } - } - } - } - catch (Exception) - { - return; - } - } - /// /// Reset Everything /// @@ -393,7 +348,6 @@ namespace Handbrake windowTimer.Dispose(); position = 0; ClearWindowText(); - PrintLogHeader(); windowTimer = new Timer(new TimerCallback(LogMonitor), null, 1000, 1000); } diff --git a/win/C#/frmOptions.cs b/win/C#/frmOptions.cs index 7ca71dc30..4475d9071 100644 --- a/win/C#/frmOptions.cs +++ b/win/C#/frmOptions.cs @@ -473,7 +473,8 @@ namespace Handbrake /// private static void UpdateApplicationServicesSettings() { - Init.SetupSettings(Program.InstanceId, Settings.Default.CompletionOption, Settings.Default.noDvdNav, + string versionId = String.Format("Windows GUI {1} {0}", Settings.Default.hb_build, Settings.Default.hb_version); + Init.SetupSettings(versionId, Program.InstanceId, Settings.Default.CompletionOption, Settings.Default.noDvdNav, Settings.Default.growlEncode, Settings.Default.growlQueue, Settings.Default.processPriority, Settings.Default.saveLogPath, Settings.Default.saveLogToSpecifiedPath, Settings.Default.saveLogWithVideo, Settings.Default.showCliForInGuiEncodeStatus, Settings.Default.preventSleep); -- cgit v1.2.3