diff options
author | sr55 <[email protected]> | 2010-02-27 18:19:28 +0000 |
---|---|---|
committer | sr55 <[email protected]> | 2010-02-27 18:19:28 +0000 |
commit | 477178a22e1508361828e11593e6bf2be6770c85 (patch) | |
tree | 68976637f6bc7361bb04618005b382818b65ce8b | |
parent | da04bbd1b4b264b3d4c419b721699e658d50e545 (diff) |
WinGui:
- Moved the Activity Log Code out of the Activity window into the Encode and Scan services. They now provide the log data. (Some duplicate code here will need to be refactored into a base class later)
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@3144 b64f7644-9d1e-0410-96f1-a4d463321fa5
-rw-r--r-- | win/C#/Controls/x264Panel.cs | 4 | ||||
-rw-r--r-- | win/C#/HandBrakeCS.5.0.ReSharper | 4 | ||||
-rw-r--r-- | win/C#/HandBrakeCS.csproj | 1 | ||||
-rw-r--r-- | win/C#/frmActivityWindow.cs | 231 | ||||
-rw-r--r-- | win/C#/frmMain.Designer.cs | 1 | ||||
-rw-r--r-- | win/C#/frmMain.cs | 28 |
6 files changed, 116 insertions, 153 deletions
diff --git a/win/C#/Controls/x264Panel.cs b/win/C#/Controls/x264Panel.cs index 27809415a..a33879632 100644 --- a/win/C#/Controls/x264Panel.cs +++ b/win/C#/Controls/x264Panel.cs @@ -142,8 +142,8 @@ namespace Handbrake.Controls /// Input: String. - Single X264 Option. Name only
/// Output: String - Single X264 Option. Name only. Changed to standard format
/// </summary>
- /// <param name="cleanOptNameString"></param>
- /// <returns></returns>
+ /// <param name="cleanOptNameString">a string of x264 options to clean</param>
+ /// <returns>A string containing standardized x264 option names</returns>
private static string X264_StandardizeOptNames(string cleanOptNameString)
{
string input = cleanOptNameString;
diff --git a/win/C#/HandBrakeCS.5.0.ReSharper b/win/C#/HandBrakeCS.5.0.ReSharper index ede9d3f57..a3d96d833 100644 --- a/win/C#/HandBrakeCS.5.0.ReSharper +++ b/win/C#/HandBrakeCS.5.0.ReSharper @@ -88,7 +88,9 @@ <EventHandlerPatternLong>$object$_On$event$</EventHandlerPatternLong>
<EventHandlerPatternShort>$event$Handler</EventHandlerPatternShort>
<PredefinedRule Inspect="True" Prefix="" Suffix="" Style="AaBb" ElementKind="MethodPropertyEvent" />
- <PredefinedRule Inspect="True" Prefix="" Suffix="" Style="AaBb" ElementKind="TypesAndNamespaces" />
+ <PredefinedRule Inspect="True" Prefix="" Suffix="" Style="AaBb" ElementKind="TypesAndNamespaces">
+ <ExtraRule Prefix="frm" Suffix="" Style="AaBb" />
+ </PredefinedRule>
<PredefinedRule Inspect="True" Prefix="I" Suffix="" Style="AaBb" ElementKind="Interfaces" />
<PredefinedRule Inspect="True" Prefix="T" Suffix="" Style="AaBb" ElementKind="TypeParameters" />
<PredefinedRule Inspect="True" Prefix="" Suffix="" Style="aaBb" ElementKind="Locals" />
diff --git a/win/C#/HandBrakeCS.csproj b/win/C#/HandBrakeCS.csproj index f4902e3e1..701316b78 100644 --- a/win/C#/HandBrakeCS.csproj +++ b/win/C#/HandBrakeCS.csproj @@ -164,6 +164,7 @@ <Compile Include="Controls\x264Panel.Designer.cs">
<DependentUpon>x264Panel.cs</DependentUpon>
</Compile>
+ <Compile Include="Model\ActivityLogMode.cs" />
<Compile Include="Services\Encode.cs" />
<Compile Include="frmPreview.cs">
<SubType>Form</SubType>
diff --git a/win/C#/frmActivityWindow.cs b/win/C#/frmActivityWindow.cs index 70f62d5e9..e3468927e 100644 --- a/win/C#/frmActivityWindow.cs +++ b/win/C#/frmActivityWindow.cs @@ -13,6 +13,8 @@ namespace Handbrake using System.Threading;
using System.Windows.Forms;
using Functions;
+ using Model;
+ using Services;
using Timer = System.Threading.Timer;
/// <summary>
@@ -26,19 +28,24 @@ namespace Handbrake private int position;
/// <summary>
- /// The previous mode
+ /// A Timer for this window
/// </summary>
- private string lastMode;
+ private Timer windowTimer;
/// <summary>
- /// The current mode
+ /// The Encode Object
/// </summary>
- private string currentMode;
+ private Encode encode;
/// <summary>
- /// A Timer for this window
+ /// The Scan Object
/// </summary>
- private Timer windowTimer;
+ private Scan scan;
+
+ /// <summary>
+ /// The Type of log that the window is currently dealing with
+ /// </summary>
+ private ActivityLogMode mode;
/// <summary>
/// Initializes a new instance of the <see cref="frmActivityWindow"/> class.
@@ -46,15 +53,20 @@ namespace Handbrake /// <param name="mode">
/// The mode.
/// </param>
- public frmActivityWindow(string mode)
+ /// <param name="encode">
+ /// The encode.
+ /// </param>
+ /// <param name="scan">
+ /// The scan.
+ /// </param>
+ public frmActivityWindow(ActivityLogMode mode, Encode encode, Scan scan)
{
InitializeComponent();
- position = 0;
- if (mode == "scan")
- SetScanMode();
- else
- SetEncodeMode();
+ this.encode = encode;
+ this.scan = scan;
+ this.mode = mode;
+ this.position = 0;
}
/// <summary>
@@ -73,32 +85,16 @@ namespace Handbrake // Public
/// <summary>
- /// Gets or sets SetLogFile.
- /// </summary>
- public string SetLogFile
- {
- get { return string.IsNullOrEmpty(currentMode) ? string.Empty : currentMode; }
- set { currentMode = value; }
- }
-
- /// <summary>
/// Set the window to scan mode
/// </summary>
- public void SetScanMode()
- {
- Reset();
- SetLogFile = "last_scan_log.txt";
- this.Text = "Activity Window (Scan Log)";
- }
-
- /// <summary>
- /// Set the window to encode mode
- /// </summary>
- public void SetEncodeMode()
+ /// <param name="setMode">
+ /// The set Mode.
+ /// </param>
+ public void SetMode(ActivityLogMode setMode)
{
Reset();
- SetLogFile = "last_encode_log.txt";
- this.Text = "Activity Window (Enocde Log)";
+ this.mode = setMode;
+ this.Text = mode == ActivityLogMode.Scan ? "Activity Window (Scan Log)" : "Activity Window (Enocde Log)";
}
// Logging
@@ -125,116 +121,79 @@ namespace Handbrake /// </param>
private void LogMonitor(object n)
{
- if (SetLogFile != lastMode) Reset();
-
- // Perform the window update
- switch (SetLogFile)
- {
- case "last_scan_log.txt":
- AppendWindowText(ReadFile("last_scan_log.txt"));
- lastMode = "last_scan_log.txt";
- break;
- case "last_encode_log.txt":
- AppendWindowText(ReadFile("last_encode_log.txt"));
- lastMode = "last_encode_log.txt";
- break;
- }
+ AppendWindowText(GetLog());
}
/// <summary>
- /// Read the log file
+ /// New Code for getting the Activity log from the Services rather than reading a file.
/// </summary>
- /// <param name="file">
- /// The file.
- /// </param>
/// <returns>
- /// A string builder containing the log data
+ /// The StringBuilder containing a log
/// </returns>
- private StringBuilder ReadFile(string file)
+ private StringBuilder GetLog()
{
StringBuilder appendText = new StringBuilder();
- lock (this)
+
+ if (this.mode == ActivityLogMode.Scan)
{
- // 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, file);
- string logFile2 = Path.Combine(logDir, "tmp_appReadable_log.txt");
-
- try
+ if (scan == null || scan.ActivityLog == string.Empty)
{
- // 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
- {
- appendText.AppendFormat("Waiting for the log file to be generated ...\n");
- position = 0;
- ClearWindowText();
- PrintLogHeader();
- return appendText;
- }
-
+ appendText.AppendFormat("Waiting for the log to be generated ...\n");
+ position = 0;
+ ClearWindowText();
+ PrintLogHeader();
+ return appendText;
+ }
- // TODO This is just Experimental Code. Just ignore it.
- ////if (encode.ActivityLog == null)
- ////{
- //// appendText.AppendFormat("Waiting for the log file to be generated ...\n");
- //// position = 0;
- //// ClearWindowText();
- //// PrintLogHeader();
- //// return appendText;
- ////}
-
- ////using (StringReader reader = new StringReader(encode.ActivityLog))
- ////{
- //// string line;
- //// int i = 1;
- //// while ((line = reader.ReadLine()) != null)
- //// {
- //// if (i > position)
- //// {
- //// appendText.AppendLine(line);
- //// position++;
- //// }
- //// i++;
- //// }
-
- ////}
-
- // 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 > position)
- {
- appendText.AppendLine(line);
- position++;
- }
- i++;
- }
- sr.Close();
- sr.Dispose();
+ using (StringReader reader = new StringReader(scan.ActivityLog))
+ {
+ LogReader(reader, appendText);
}
- catch (Exception)
+ }
+ else
+ {
+ if (encode == null || encode.ActivityLog == string.Empty)
{
- Reset();
- appendText = new StringBuilder();
- appendText.AppendLine("\nThe Log file is currently in use. Waiting for the log file to become accessible ...\n");
+ appendText.AppendFormat("Waiting for the log to be generated ...\n");
+ position = 0;
+ ClearWindowText();
+ PrintLogHeader();
+ return appendText;
+ }
+
+ using (StringReader reader = new StringReader(encode.ActivityLog))
+ {
+ LogReader(reader, appendText);
}
}
return appendText;
}
/// <summary>
+ /// Reads the log data from a Scan or Encode object
+ /// </summary>
+ /// <param name="reader">
+ /// The reader.
+ /// </param>
+ /// <param name="appendText">
+ /// The append text.
+ /// </param>
+ private void LogReader(StringReader reader, StringBuilder appendText)
+ {
+ string line;
+ int i = 1;
+ while ((line = reader.ReadLine()) != null)
+ {
+ if (i > position)
+ {
+ appendText.AppendLine(line);
+ position++;
+ }
+ i++;
+ }
+ }
+
+ /// <summary>
/// Append text to the RTF box
/// </summary>
/// <param name="text">
@@ -308,15 +267,15 @@ namespace Handbrake // Print the log header. This function will be re-implimented later. Do not delete.
StringBuilder header = new StringBuilder();
- header.AppendLine(String.Format("### Windows GUI {1} {0} \n", Properties.Settings.Default.hb_build, Properties.Settings.Default.hb_version));
- header.AppendLine(String.Format("### Running: {0} \n###\n", Environment.OSVersion));
- header.AppendLine(String.Format("### CPU: {0} \n", SystemInfo.GetCpuCount));
- header.AppendLine(String.Format("### Ram: {0} MB \n", SystemInfo.TotalPhysicalMemory));
- header.AppendLine(String.Format("### Screen: {0}x{1} \n", SystemInfo.ScreenBounds.Bounds.Width, SystemInfo.ScreenBounds.Bounds.Height));
- header.AppendLine(String.Format("### Temp Dir: {0} \n", Path.GetTempPath()));
- header.AppendLine(String.Format("### Install Dir: {0} \n", Application.StartupPath));
- header.AppendLine(String.Format("### Data Dir: {0} \n", Application.UserAppDataPath));
- header.AppendLine("#########################################\n\n");
+ 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());
}
@@ -407,7 +366,7 @@ namespace Handbrake /// </param>
private void BtnScanLogClick(object sender, EventArgs e)
{
- SetScanMode();
+ SetMode(ActivityLogMode.Scan);
}
/// <summary>
@@ -421,7 +380,7 @@ namespace Handbrake /// </param>
private void BtnEncodeLogClick(object sender, EventArgs e)
{
- SetEncodeMode();
+ SetMode(ActivityLogMode.Encode);
}
// Overrides
diff --git a/win/C#/frmMain.Designer.cs b/win/C#/frmMain.Designer.cs index 618902549..dad2201f2 100644 --- a/win/C#/frmMain.Designer.cs +++ b/win/C#/frmMain.Designer.cs @@ -1077,6 +1077,7 @@ namespace Handbrake this.x264Panel.Name = "x264Panel";
this.x264Panel.Size = new System.Drawing.Size(720, 306);
this.x264Panel.TabIndex = 0;
+ this.x264Panel.X264Query = " -x ";
//
// tab_query
//
diff --git a/win/C#/frmMain.cs b/win/C#/frmMain.cs index 5ec925973..e4f6c05be 100644 --- a/win/C#/frmMain.cs +++ b/win/C#/frmMain.cs @@ -34,12 +34,13 @@ namespace Handbrake private frmActivityWindow ActivityWindow;
private Form splash;
public string sourcePath;
- private string lastAction;
+ private ActivityLogMode lastAction;
private SourceType selectedSourceType;
private string dvdDrivePath;
private string dvdDriveLabel;
private Preset CurrentlySelectedPreset;
private DVD currentSource;
+ private Scan SourceScan = new Scan();
// Delegates **********************************************************
private delegate void UpdateWindowHandler();
@@ -337,7 +338,7 @@ namespace Handbrake private void encodeStarted(object sender, EventArgs e)
{
- lastAction = "encode";
+ lastAction = ActivityLogMode.Encode;
SetEncodeStarted();
// Experimental HBProc Process Monitoring.
@@ -385,7 +386,7 @@ namespace Handbrake private void mnu_encodeLog_Click(object sender, EventArgs e)
{
- frmActivityWindow dvdInfoWindow = new frmActivityWindow(lastAction);
+ frmActivityWindow dvdInfoWindow = new frmActivityWindow(lastAction, encodeQueue, SourceScan);
dvdInfoWindow.Show();
}
@@ -850,10 +851,10 @@ namespace Handbrake SetEncodeStarted(); // Encode is running, so setup the GUI appropriately
encodeQueue.Start(); // Start The Queue Encoding Process
- lastAction = "encode"; // Set the last action to encode - Used for activity window.
+ lastAction = ActivityLogMode.Encode; // Set the last action to encode - Used for activity window.
}
if (ActivityWindow != null)
- ActivityWindow.SetEncodeMode();
+ ActivityWindow.SetMode(ActivityLogMode.Encode);
this.Focus();
}
@@ -924,18 +925,18 @@ namespace Handbrake private void btn_ActivityWindow_Click(object sender, EventArgs e)
{
if (ActivityWindow == null || !ActivityWindow.IsHandleCreated)
- ActivityWindow = new frmActivityWindow(lastAction);
+ ActivityWindow = new frmActivityWindow(lastAction, encodeQueue, SourceScan);
else
switch (lastAction)
{
- case "scan":
- ActivityWindow.SetScanMode();
+ case ActivityLogMode.Scan:
+ ActivityWindow.SetMode(ActivityLogMode.Scan);
break;
- case "encode":
- ActivityWindow.SetEncodeMode();
+ case ActivityLogMode.Encode:
+ ActivityWindow.SetMode(ActivityLogMode.Encode);
break;
default:
- ActivityWindow.SetEncodeMode();
+ ActivityWindow.SetMode(ActivityLogMode.Encode);
break;
}
@@ -1011,7 +1012,7 @@ namespace Handbrake private void SelectSource(string file)
{
Check_ChapterMarkers.Enabled = true;
- lastAction = "scan";
+ lastAction = ActivityLogMode.Scan;
sourcePath = string.Empty;
if (file == string.Empty) // Must have a file or path
@@ -1630,7 +1631,6 @@ namespace Handbrake #region Source Scan
public bool isScanning { get; set; }
- private Scan SourceScan;
private void StartScan(string filename, int title)
{
@@ -1650,7 +1650,7 @@ namespace Handbrake mnu_killCLI.Visible = true;
if (ActivityWindow != null)
- ActivityWindow.SetScanMode();
+ ActivityWindow.SetMode(ActivityLogMode.Scan);
// Start the Scan
try
|