X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=win%2FC%23%2FfrmActivityWindow.cs;h=613a1a4c2c31a912d16abb5fa1f0940996703642;hb=4f0019f03c2e85e8634150ff0c9a31bee6d35ce5;hp=879dd54a5198e3e6cd2386aa0d01cbe389645d29;hpb=d571d3e6a3bb4bbeda35cac674f697a253a11e94;p=handbrake-jp%2Fhandbrake-jp-git.git
diff --git a/win/C#/frmActivityWindow.cs b/win/C#/frmActivityWindow.cs
index 879dd54a..613a1a4c 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;
///
@@ -20,43 +22,59 @@ namespace Handbrake
///
public partial class frmActivityWindow : Form
{
+ /* Private Variables */
+
///
/// The current position in the log file
///
private int position;
///
- /// The previous mode
+ /// A Timer for this window
///
- private string lastMode;
+ private Timer windowTimer;
///
- /// The current mode
+ /// The Encode Object
///
- private string currentMode;
+ private Encode encode;
///
- /// A Timer for this window
+ /// The Scan Object
///
- private Timer windowTimer;
+ private ScanService scan;
+
+ ///
+ /// The Type of log that the window is currently dealing with
+ ///
+ private ActivityLogMode mode;
+
+ /* Constructor */
///
/// Initializes a new instance of the class.
///
- ///
- /// The mode.
+ ///
+ /// The encode.
+ ///
+ ///
+ /// The scan.
///
- public frmActivityWindow(string mode)
+ public frmActivityWindow(Encode encode, ScanService scan)
{
InitializeComponent();
- position = 0;
- if (mode == "scan")
- SetScanMode();
- else
- SetEncodeMode();
+ this.encode = encode;
+ this.scan = scan;
+ this.position = 0;
+
+ // Listen for Scan and Encode Starting Events
+ scan.ScanStared += scan_ScanStared;
+ encode.EncodeStarted += encode_EncodeStarted;
}
+ /* Delegates */
+
///
/// A callback function for updating the ui
///
@@ -70,41 +88,106 @@ namespace Handbrake
///
private delegate void SetTextClearCallback();
- // Public
+ ///
+ /// Set mode callback
+ ///
+ ///
+ /// The set mode.
+ ///
+ private delegate void SetModeCallback(ActivityLogMode setMode);
+
+ /* Private Methods */
///
- /// Gets or sets SetLogFile.
+ /// Set the window to scan mode
///
- public string SetLogFile
+ ///
+ /// The set Mode.
+ ///
+ private void SetMode(ActivityLogMode setMode)
{
- get { return string.IsNullOrEmpty(currentMode) ? string.Empty : currentMode; }
- set { currentMode = value; }
+ if (IsHandleCreated)
+ {
+ if (rtf_actLog.InvokeRequired)
+ {
+ IAsyncResult invoked = BeginInvoke(new SetModeCallback(SetMode), new object[] {setMode});
+ EndInvoke(invoked);
+ }
+ else
+ {
+ Reset();
+ this.mode = setMode;
+
+ Array values = Enum.GetValues(typeof(ActivityLogMode));
+ Properties.Settings.Default.ActivityWindowLastMode = (int) values.GetValue(Convert.ToInt32(setMode));
+ Properties.Settings.Default.Save();
+
+ this.Text = mode == ActivityLogMode.Scan
+ ? "Activity Window (Scan Log)"
+ : "Activity Window (Encode Log)";
+
+ if (mode == ActivityLogMode.Scan)
+ {
+ scan.ScanCompleted += stopWindowRefresh;
+ encode.EncodeEnded -= stopWindowRefresh;
+ }
+ else
+ {
+ scan.ScanCompleted -= stopWindowRefresh;
+ encode.EncodeEnded += stopWindowRefresh;
+ }
+
+ // Start a fresh window timer
+ windowTimer = new Timer(new TimerCallback(LogMonitor), null, 1000, 1000);
+ }
+ }
}
///
- /// Set the window to scan mode
+ /// On Window load, start a new timer
///
- public void SetScanMode()
+ ///
+ /// The sender.
+ ///
+ ///
+ /// The e.
+ ///
+ private void NewActivityWindow_Load(object sender, EventArgs e)
{
- Reset();
- SetLogFile = "last_scan_log.txt";
- this.Text = "Activity Window (Scan Log)";
+ ActivityLogMode activitLogMode = (ActivityLogMode) Enum.ToObject(typeof(ActivityLogMode), Properties.Settings.Default.ActivityWindowLastMode);
+ SetMode(activitLogMode);
}
///
- /// Set the window to encode mode
+ /// Set the Log window to encode mode when an encode starts.
///
- public void SetEncodeMode()
+ ///
+ /// The sender.
+ ///
+ ///
+ /// The e.
+ ///
+ private void encode_EncodeStarted(object sender, EventArgs e)
{
- Reset();
- SetLogFile = "last_encode_log.txt";
- this.Text = "Activity Window (Enocde Log)";
+ SetMode(ActivityLogMode.Encode);
}
- // Logging
+ ///
+ /// Set the log widow to scan mode when a scan starts
+ ///
+ ///
+ /// The sender.
+ ///
+ ///
+ /// The e.
+ ///
+ private void scan_ScanStared(object sender, EventArgs e)
+ {
+ SetMode(ActivityLogMode.Scan);
+ }
///
- /// On Window load, start a new timer
+ /// Stop refreshing the window when no scanning or encoding is happening.
///
///
/// The sender.
@@ -112,9 +195,10 @@ namespace Handbrake
///
/// The e.
///
- private void NewActivityWindow_Load(object sender, EventArgs e)
+ private void stopWindowRefresh(object sender, EventArgs e)
{
- windowTimer = new Timer(new TimerCallback(LogMonitor), null, 1000, 1000);
+ windowTimer.Dispose();
+ LogMonitor(null);
}
///
@@ -125,89 +209,79 @@ namespace Handbrake
///
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());
}
///
- /// Read the log file
+ /// New Code for getting the Activity log from the Services rather than reading a file.
///
- ///
- /// The file.
- ///
///
- /// A string builder containing the log data
+ /// The StringBuilder containing a log
///
- 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;
+ }
- // 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;
}
///
+ /// Reads the log data from a Scan or Encode object
+ ///
+ ///
+ /// The reader.
+ ///
+ ///
+ /// The append text.
+ ///
+ 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++;
+ }
+ }
+
+ ///
/// Append text to the RTF box
///
///
@@ -227,6 +301,12 @@ namespace Handbrake
else
lock (rtf_actLog)
rtf_actLog.AppendText(text.ToString());
+
+ // Stop the refresh process if log has finished.
+ if (text.ToString().Contains("HandBrake has Exited"))
+ {
+ windowTimer.Dispose();
+ }
}
}
catch (Exception)
@@ -281,15 +361,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());
}
@@ -315,7 +395,7 @@ namespace Handbrake
windowTimer = new Timer(new TimerCallback(LogMonitor), null, 1000, 1000);
}
- // Menus and Buttons
+ /* Menus and Buttons */
///
/// Copy log to clipboard
@@ -380,7 +460,7 @@ namespace Handbrake
///
private void BtnScanLogClick(object sender, EventArgs e)
{
- SetScanMode();
+ SetMode(ActivityLogMode.Scan);
}
///
@@ -394,10 +474,10 @@ namespace Handbrake
///
private void BtnEncodeLogClick(object sender, EventArgs e)
{
- SetEncodeMode();
+ SetMode(ActivityLogMode.Encode);
}
- // Overrides
+ /* Overrides */
///
/// override onclosing
@@ -407,6 +487,12 @@ namespace Handbrake
///
protected override void OnClosing(CancelEventArgs e)
{
+ scan.ScanStared -= scan_ScanStared;
+ encode.EncodeStarted -= encode_EncodeStarted;
+
+ scan.ScanCompleted -= stopWindowRefresh;
+ encode.EncodeEnded -= stopWindowRefresh;
+
windowTimer.Dispose();
e.Cancel = true;
this.Dispose();