Author: gedmurphy
Date: Tue Apr 22 04:12:01 2008
New Revision: 33095
URL:
http://svn.reactos.org/svn/reactos?rev=33095&view=rev
Log:
partially refactor the workings of the translator assembly to better handle multiple
messages
Modified:
trunk/tools/Message Translator/GUI/MainForm.cs
trunk/tools/Message Translator/MsgTrans.Library/BugCommand.cs
trunk/tools/Message Translator/MsgTrans.Library/Command.cs
trunk/tools/Message Translator/MsgTrans.Library/ErrorCommand.cs
trunk/tools/Message Translator/MsgTrans.Library/HresultCommand.cs
trunk/tools/Message Translator/MsgTrans.Library/MsgTrans.cs
trunk/tools/Message Translator/MsgTrans.Library/NtStatusCommand.cs
trunk/tools/Message Translator/MsgTrans.Library/WinerrorCommand.cs
trunk/tools/Message Translator/MsgTrans.Library/WmCommand.cs
Modified: trunk/tools/Message Translator/GUI/MainForm.cs
URL:
http://svn.reactos.org/svn/reactos/trunk/tools/Message%20Translator/GUI/Mai…
==============================================================================
--- trunk/tools/Message Translator/GUI/MainForm.cs [iso-8859-1] (original)
+++ trunk/tools/Message Translator/GUI/MainForm.cs [iso-8859-1] Tue Apr 22 04:12:01 2008
@@ -146,6 +146,12 @@
MessageOutput mo = new MessageOutput();
mo.MsgOut(null, ex.Message);
}
+ }
+
+ private void SendToTray()
+ {
+ Hide();
+ notifyIcon.Visible = true;
}
private string GetMessageType()
@@ -182,27 +188,33 @@
string message = msgType + " " + mainErrTxtBox.Text;
if (msgTran.ParseCommandMessage(null, message))
{
- if (msgType == msgTypes[0]) // error
+ foreach (Command cmd in msgTran.Messages)
{
- errorTypeValueLabel.Text = msgTran.Type;
- errorDecimalTxtBox.Text = msgTran.Number.ToString();
- errorHexTxtBox.Text = "0x" + msgTran.Hex;
- errorCodeTxtBox.Text = msgTran.Code;
- errorMessageTxtBox.Text = msgTran.Message;
- }
- else if (msgType == msgTypes[1]) // wm
- {
- wndmsgDecimalTxtBox.Text = msgTran.Number.ToString();
- wndmsgHexTxtBox.Text = "0x" + msgTran.Hex;
- wndmsgCodeTxtBox.Text = msgTran.Code;
- }
- else if (msgType == msgTypes[2]) // bug
- {
- bugLinkLabel.Text = "Click here for bug " +
msgTran.Number;
- bugLinkLabel.Links[0].LinkData = msgTran.BugUrl;
- bugLinkLabel.Links[0].Visited = false;
-
- SetBugurlPosition();
+ if (cmd.MsgType == MessageType.WinError ||
+ cmd.MsgType == MessageType.HResult ||
+ cmd.MsgType == MessageType.NTStatus ||
+ cmd.MsgType == MessageType.Custom)
+ {
+ errorTypeValueLabel.Text = cmd.MsgType.ToString();
+ errorDecimalTxtBox.Text = cmd.Number.ToString();
+ errorHexTxtBox.Text = "0x" + cmd.Hex;
+ errorCodeTxtBox.Text = cmd.Code;
+ errorMessageTxtBox.Text = cmd.Message;
+ }
+ else if (cmd.MsgType == MessageType.WinMsg)
+ {
+ wndmsgDecimalTxtBox.Text = cmd.Number.ToString();
+ wndmsgHexTxtBox.Text = "0x" + cmd.Hex;
+ wndmsgCodeTxtBox.Text = cmd.Code;
+ }
+ else if (cmd.MsgType == MessageType.BugUrl)
+ {
+ bugLinkLabel.Text = "Click here for bug " +
cmd.Number;
+ bugLinkLabel.Links[0].LinkData = cmd.Code;
+ bugLinkLabel.Links[0].Visited = false;
+
+ SetBugurlPosition();
+ }
}
}
}
@@ -227,8 +239,15 @@
optionsMinimizeChkBox.Checked = HideOnMin;
optionsRunStartChkBox.Checked = RunOnStart;
notifyIcon.Visible = false;
-
- toolTip.SetToolTip(mainErrTxtBox, Properties.Resources.tooltipErrMsg);
+ /*
+ if (HideOnMin)
+ {
+ // FIXME: hide correctly
+ this.WindowState = FormWindowState.Minimized;
+ SendToTray();
+ }*/
+
+ //toolTip.SetToolTip(mainErrTxtBox, Properties.Resources.tooltipErrMsg);
//toolTip.SetToolTip(mainWndMsgRadio, Properties.Resources.tooltipWndMsg);
//toolTip.SetToolTip(mainBugMsgRadio, Properties.Resources.tooltipBug);
//toolTip.SetToolTip(mainOptionsRadio, Properties.Resources.tooltipOpt);
@@ -243,13 +262,9 @@
private void MainForm_Resize(object sender, EventArgs e)
{
- if (FormWindowState.Minimized == WindowState)
- {
- if (HideOnMin)
- {
- Hide();
- notifyIcon.Visible = true;
- }
+ if (FormWindowState.Minimized == WindowState && HideOnMin)
+ {
+ SendToTray();
}
}
Modified: trunk/tools/Message Translator/MsgTrans.Library/BugCommand.cs
URL:
http://svn.reactos.org/svn/reactos/trunk/tools/Message%20Translator/MsgTran…
==============================================================================
--- trunk/tools/Message Translator/MsgTrans.Library/BugCommand.cs [iso-8859-1] (original)
+++ trunk/tools/Message Translator/MsgTrans.Library/BugCommand.cs [iso-8859-1] Tue Apr 22
04:12:01 2008
@@ -11,11 +11,6 @@
: base(msgTrans)
{
this.bugUrl = bugUrl;
- }
-
- public string BugUrl
- {
- get { return bugUrl; }
}
public override bool Handle(MessageContext context,
@@ -39,8 +34,14 @@
return false;
}
- MsgTrans.Number = np.Decimal;
- MsgTrans.BugUrl = String.Format(BugUrl, np.Decimal);
+ string url = String.Format(bugUrl, np.Decimal);
+
+ MsgType = MessageType.BugUrl;
+ Number = np.Decimal;
+ Hex = np.Hex;
+ Code = url;
+ Message = null;
+ MsgTrans.Messages.Add(this);
return true;
}
Modified: trunk/tools/Message Translator/MsgTrans.Library/Command.cs
URL:
http://svn.reactos.org/svn/reactos/trunk/tools/Message%20Translator/MsgTran…
==============================================================================
--- trunk/tools/Message Translator/MsgTrans.Library/Command.cs [iso-8859-1] (original)
+++ trunk/tools/Message Translator/MsgTrans.Library/Command.cs [iso-8859-1] Tue Apr 22
04:12:01 2008
@@ -6,18 +6,50 @@
public abstract class Command
{
protected MessageTranslator msgTrans = null;
+ private MessageType messageType;
+ private long number;
+ private string hex;
+ private string code;
+ private string message;
+
+ #region properties
+ public MessageType MsgType
+ {
+ get { return messageType; }
+ set { messageType = value; }
+ }
+ public long Number
+ {
+ get { return number; }
+ set { number = value; }
+ }
+ public string Hex
+ {
+ get { return hex; }
+ set { hex = value; }
+ }
+ public string Code
+ {
+ get { return code; }
+ set { code = value; }
+ }
+ public string Message
+ {
+ get { return message; }
+ set { message = value; }
+ }
+ public MessageTranslator MsgTrans
+ {
+ get { return msgTrans; }
+ }
+ #endregion
+
+ public abstract string[] AvailableCommands { get; }
public Command(MessageTranslator msgTrans)
{
this.msgTrans = msgTrans;
}
-
- public MessageTranslator MsgTrans
- {
- get { return msgTrans; }
- }
-
- public abstract string[] AvailableCommands { get; }
public abstract bool Handle(MessageContext context,
string commandName,
Modified: trunk/tools/Message Translator/MsgTrans.Library/ErrorCommand.cs
URL:
http://svn.reactos.org/svn/reactos/trunk/tools/Message%20Translator/MsgTran…
==============================================================================
--- trunk/tools/Message Translator/MsgTrans.Library/ErrorCommand.cs [iso-8859-1]
(original)
+++ trunk/tools/Message Translator/MsgTrans.Library/ErrorCommand.cs [iso-8859-1] Tue Apr
22 04:12:01 2008
@@ -1,6 +1,7 @@
using System;
using System.Xml;
using System.Collections;
+using System.Collections.Generic;
namespace MsgTrans.Library
{
@@ -9,6 +10,7 @@
private NtStatusCommand ntStatus;
private WinerrorCommand winerror;
private HResultCommand hresult;
+ private List<Command> errorCommands = new List<Command>();
public ErrorCommand(MessageTranslator msgTrans,
string ntstatusXml,
@@ -16,9 +18,9 @@
string hresultXml)
: base(msgTrans)
{
- this.ntStatus = new NtStatusCommand(msgTrans, ntstatusXml);
- this.winerror = new WinerrorCommand(msgTrans, winerrorXml);
- this.hresult = new HResultCommand(msgTrans, hresultXml);
+ ntStatus = new NtStatusCommand(msgTrans, ntstatusXml);
+ winerror = new WinerrorCommand(msgTrans, winerrorXml);
+ hresult = new HResultCommand(msgTrans, hresultXml);
}
public override string[] AvailableCommands
@@ -76,6 +78,20 @@
return code.ToString();
}
+ private void AddErrorCommand(MessageType msgType,
+ long dec,
+ string hex,
+ string code,
+ string msg)
+ {
+ MsgType = msgType;
+ Number = dec;
+ Hex = hex;
+ Code = code;
+ Message = msg;
+ MsgTrans.Messages.Add(this);
+ }
+
public override bool Handle(MessageContext context,
string commandName,
string parameters)
@@ -117,7 +133,11 @@
FormatSeverity(np.Decimal),
FormatFacility(np.Decimal),
FormatCode(np.Decimal));
- descriptions.Add(description);
+ AddErrorCommand(MessageType.Custom,
+ np.Decimal,
+ np.Hex,
+ description,
+ null);
}
// Reserved bit is set: HRESULT_FROM_NT(ntstatus)
else if (IsReserved(np.Decimal))
@@ -127,9 +147,14 @@
if (description == null)
description = status.ToString("X");
-
+
description = String.Format("HRESULT_FROM_NT({0})",
description);
- descriptions.Add(description);
+
+ AddErrorCommand(MessageType.Custom,
+ np.Decimal,
+ np.Hex,
+ description,
+ null);
}
// Win32 facility: HRESULT_FROM_WIN32(winerror)
else if (GetFacility(np.Decimal) == 7)
@@ -144,33 +169,49 @@
description = err.ToString("D");
description = String.Format("HRESULT_FROM_WIN32({0})",
description);
- descriptions.Add(description);
+
+ AddErrorCommand(MessageType.Custom,
+ np.Decimal,
+ np.Hex,
+ description,
+ null);
}
}
}
string winerrorDescription = winerror.GetWinerrorDescription(np.Decimal);
+ if (winerrorDescription != null)
+ {
+ string message = new
System.ComponentModel.Win32Exception(Convert.ToInt32(np.Decimal)).Message;
+
+ AddErrorCommand(MessageType.WinError,
+ np.Decimal,
+ np.Hex,
+ winerrorDescription,
+ message);
+ }
+
string ntstatusDescription = ntStatus.GetNtstatusDescription(np.Decimal);
+ if (ntstatusDescription != null)
+ {
+ AddErrorCommand(MessageType.NTStatus,
+ np.Decimal,
+ np.Hex,
+ ntstatusDescription,
+ null);
+ }
+
string hresultDescription = hresult.GetHresultDescription(np.Decimal);
-
- //FIXME: don't hardcode names here
- if (winerrorDescription != null)
- {
- descriptions.Add(winerrorDescription);
- MsgTrans.Type = "WinError";
- }
- else if (ntstatusDescription != null)
- {
- descriptions.Add(ntstatusDescription);
- MsgTrans.Type = "NTSTATUS";
- }
- else if (hresultDescription != null)
- {
- descriptions.Add(hresultDescription);
- MsgTrans.Type = "HRESULT";
- }
-
- if (descriptions.Count == 0)
+ if (hresultDescription != null)
+ {
+ AddErrorCommand(MessageType.HResult,
+ np.Decimal,
+ np.Hex,
+ hresultDescription,
+ null);
+ }
+
+ if (MsgTrans.Messages.Count == 0)
{
// Last chance heuristics: attempt to parse a 8-digit decimal as
hexadecimal
if (errorText.Length == 8)
@@ -180,37 +221,12 @@
}
MsgTrans.MsgOutput.MsgOut(context,
- String.Format("I don't know about Error
Code {0}.",
- originalErrorText));
+ String.Format("I don't know about
Error Code {0}.",
+ originalErrorText));
return false;
}
- else //if (descriptions.Count == 1) -- FIXME: implement multiple values
- {
- string description = (string)descriptions[0];
- MsgTrans.Code = description;
- MsgTrans.Number = np.Decimal;
- MsgTrans.Hex = np.Hex;
-
- MsgTrans.Message = string.Empty;
- if (winerrorDescription != null)
- {
- string message = new
System.ComponentModel.Win32Exception(Convert.ToInt32(np.Decimal)).Message;
- MsgTrans.Message = message;
- }
-
- return true;
- }/*
- else
- {
- MsgTrans.MsgOutput.MsgOut(context,
- String.Format("{0} could be:",
- originalErrorText));
-
- foreach(string description in descriptions)
- MsgTrans.MsgOutput.MsgOut(context, String.Format("\t{0}",
description));
-
- return true;
- }*/
+
+ return true;
}
public override string Help()
Modified: trunk/tools/Message Translator/MsgTrans.Library/HresultCommand.cs
URL:
http://svn.reactos.org/svn/reactos/trunk/tools/Message%20Translator/MsgTran…
==============================================================================
--- trunk/tools/Message Translator/MsgTrans.Library/HresultCommand.cs [iso-8859-1]
(original)
+++ trunk/tools/Message Translator/MsgTrans.Library/HresultCommand.cs [iso-8859-1] Tue Apr
22 04:12:01 2008
@@ -41,8 +41,8 @@
string description = GetHresultDescription(np.Decimal);
if (description != null)
{
- MsgTrans.Number = np.Decimal;
- MsgTrans.Code = description;
+ Number = np.Decimal;
+ Code = description;
return true;
}
else
Modified: trunk/tools/Message Translator/MsgTrans.Library/MsgTrans.cs
URL:
http://svn.reactos.org/svn/reactos/trunk/tools/Message%20Translator/MsgTran…
==============================================================================
--- trunk/tools/Message Translator/MsgTrans.Library/MsgTrans.cs [iso-8859-1] (original)
+++ trunk/tools/Message Translator/MsgTrans.Library/MsgTrans.cs [iso-8859-1] Tue Apr 22
04:12:01 2008
@@ -7,16 +7,46 @@
namespace MsgTrans.Library
{
+ // Summary:
+ // Specifies the type of message returned
+ public enum MessageType
+ {
+ // Summary:
+ // A Win32 error
+ WinError = 0,
+ //
+ // Summary:
+ // A HRESULT status code.
+ HResult = 1,
+ //
+ // Summary:
+ // An NTSTATUS status code
+ NTStatus = 2,
+ //
+ // Summary:
+ // a STOP/Bug Check code
+ BugCheck = 3,
+ //
+ // Summary:
+ // a Windows Message code
+ WinMsg = 4,
+ //
+ // Summary:
+ // a Bug Url
+ BugUrl = 5,
+ //
+ // Summary:
+ // a custom Check code
+ Custom = 6
+ }
+
public class MessageTranslator
{
private IMsgOutput msgOutput;
private List<Command> commands = new List<Command>();
- private string bugUrl;
+ private List<Command> messages = new List<Command>();
private string type;
- private long number;
- private string hex;
- private string code;
- private string message;
+
#region properties
public string Type
@@ -24,38 +54,13 @@
get { return type; }
set { type = value; }
}
- public long Number
- {
- get { return number; }
- set { number = value; }
- }
- public string Hex
- {
- get { return hex; }
- set { hex = value; }
- }
- public string Code
- {
- get { return code; }
- set { code = value; }
- }
- public string Message
- {
- get { return message; }
- set { message = value; }
- }
- public string BugUrl
- {
- get { return bugUrl; }
- set { bugUrl = value; }
- }
public IMsgOutput MsgOutput
{
get { return msgOutput; }
}
- public IList<Command> Commands
+ public IList<Command> Messages
{
- get { return commands; }
+ get { return messages; }
}
#endregion
Modified: trunk/tools/Message Translator/MsgTrans.Library/NtStatusCommand.cs
URL:
http://svn.reactos.org/svn/reactos/trunk/tools/Message%20Translator/MsgTran…
==============================================================================
--- trunk/tools/Message Translator/MsgTrans.Library/NtStatusCommand.cs [iso-8859-1]
(original)
+++ trunk/tools/Message Translator/MsgTrans.Library/NtStatusCommand.cs [iso-8859-1] Tue
Apr 22 04:12:01 2008
@@ -40,8 +40,8 @@
string description = GetNtstatusDescription(np.Decimal);
if (description != null)
{
- MsgTrans.Number = np.Decimal;
- MsgTrans.Code = description;
+ Number = np.Decimal;
+ Code = description;
return true;
}
else
Modified: trunk/tools/Message Translator/MsgTrans.Library/WinerrorCommand.cs
URL:
http://svn.reactos.org/svn/reactos/trunk/tools/Message%20Translator/MsgTran…
==============================================================================
--- trunk/tools/Message Translator/MsgTrans.Library/WinerrorCommand.cs [iso-8859-1]
(original)
+++ trunk/tools/Message Translator/MsgTrans.Library/WinerrorCommand.cs [iso-8859-1] Tue
Apr 22 04:12:01 2008
@@ -40,8 +40,8 @@
string description = GetWinerrorDescription(np.Decimal);
if (description != null)
{
- MsgTrans.Number = np.Decimal;
- MsgTrans.Code = description;
+ Number = np.Decimal;
+ Code = description;
return true;
}
else
Modified: trunk/tools/Message Translator/MsgTrans.Library/WmCommand.cs
URL:
http://svn.reactos.org/svn/reactos/trunk/tools/Message%20Translator/MsgTran…
==============================================================================
--- trunk/tools/Message Translator/MsgTrans.Library/WmCommand.cs [iso-8859-1] (original)
+++ trunk/tools/Message Translator/MsgTrans.Library/WmCommand.cs [iso-8859-1] Tue Apr 22
04:12:01 2008
@@ -30,32 +30,31 @@
}
NumberParser np = new NumberParser();
-
- string code;
- long num;
if (np.Parse(wmText))
{
- num = np.Decimal;
- code = GetWmDescription(np.Decimal);
+ Number = np.Decimal;
+ Hex = np.Hex;
+ Code = GetWmDescription(np.Decimal);
}
- else
+ else if ((Number = GetWmNumber(wmText)) != -1)
{
// Possibly in "wm <name>" form.
- num = GetWmNumber(wmText);
- code = wmText;
+ Hex = Number.ToString("X");
+ Code = wmText;
}
- if (code != null)
+ if (Code != null)
{
- MsgTrans.Number = num;
- MsgTrans.Hex = num.ToString("X");
- MsgTrans.Code = code;
+ MsgType = MessageType.WinMsg;
+ Message = null;
+ MsgTrans.Messages.Add(this);
+
return true;
}
else
{
MsgTrans.MsgOutput.MsgOut(context,
- String.Format("I don't know about
window message {0}.",
+ String.Format("I don't know about
window message: {0}.",
wmText));
return false;
}