From: <an...@us...> - 2007-02-10 06:48:55
|
Revision: 107 http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=107&view=rev Author: and-81 Date: 2007-02-09 22:48:49 -0800 (Fri, 09 Feb 2007) Log Message: ----------- Modified Paths: -------------- trunk/plugins/MCEReplacement/AssemblyInfo.cs trunk/plugins/MCEReplacement/ExternalChannelConfig.cs trunk/plugins/MCEReplacement/Forms/ExternalChannels.cs trunk/plugins/MCEReplacement/Forms/ExternalProgram.Designer.cs trunk/plugins/MCEReplacement/Forms/MacroEditor.cs trunk/plugins/MCEReplacement/Forms/SetupForm.Designer.cs trunk/plugins/MCEReplacement/Forms/SetupForm.cs trunk/plugins/MCEReplacement/Forms/StbSetup.cs trunk/plugins/MCEReplacement/MCEReplacement.cs trunk/plugins/MCEReplacement/MCEReplacement.csproj trunk/plugins/MCEReplacement/MappedEvent.cs trunk/plugins/MCEReplacement/MceIrApi.cs trunk/plugins/MCEReplacement/Util.cs trunk/plugins/MCEReplacement/Win32.cs trunk/plugins/MCEReplacementTray/MceIrApi.cs trunk/plugins/MCEReplacementTray/Program.cs trunk/plugins/MCEReplacementTray/Properties/AssemblyInfo.cs trunk/plugins/MCEReplacementTray/Setup.Designer.cs trunk/plugins/MCEReplacementTray/Setup.cs trunk/plugins/MCEReplacementTray/Tray.cs trunk/plugins/MessagePlugin/AssemblyInfo.cs trunk/plugins/MessagePlugin/MessagePlugin.cs trunk/plugins/TV3ExtChannelChanger/AssemblyInfo.cs trunk/plugins/TV3ExtChannelChanger/ExternalChannelConfig.cs trunk/plugins/TV3ExtChannelChanger/Forms/ExternalChannels.cs trunk/plugins/TV3ExtChannelChanger/Forms/ExternalProgram.Designer.cs trunk/plugins/TV3ExtChannelChanger/Forms/PluginSetup.Designer.cs trunk/plugins/TV3ExtChannelChanger/Forms/SerialCommand.cs trunk/plugins/TV3ExtChannelChanger/Forms/StbSetup.cs trunk/plugins/TV3ExtChannelChanger/TV3ExtChannelChanger.cs trunk/plugins/TV3ExtChannelChanger/Util.cs trunk/plugins/TV3ExtChannelChanger/Win32.cs trunk/plugins/TV3MceBlaster/AssemblyInfo.cs trunk/plugins/TV3MceBlaster/ExternalChannelConfig.cs trunk/plugins/TV3MceBlaster/Forms/ExternalChannels.cs trunk/plugins/TV3MceBlaster/Forms/ExternalProgram.Designer.cs trunk/plugins/TV3MceBlaster/Forms/MacroEditor.cs trunk/plugins/TV3MceBlaster/Forms/PluginSetup.Designer.cs trunk/plugins/TV3MceBlaster/Forms/PluginSetup.cs trunk/plugins/TV3MceBlaster/Forms/SerialCommand.cs trunk/plugins/TV3MceBlaster/Forms/StbSetup.cs trunk/plugins/TV3MceBlaster/MceIrApi.cs trunk/plugins/TV3MceBlaster/TV3MceBlaster.cs trunk/plugins/TV3MceBlaster/Util.cs trunk/plugins/TV3MceBlaster/Win32.cs trunk/plugins/XBCDRC/AssemblyInfo.cs trunk/plugins/XBCDRC/XBCDRC Plugin.csproj trunk/plugins/XBCDRC/XBCDRCPlugin.cs Added Paths: ----------- trunk/plugins/MCEReplacement/Mouse.cs Modified: trunk/plugins/MCEReplacement/AssemblyInfo.cs =================================================================== --- trunk/plugins/MCEReplacement/AssemblyInfo.cs 2007-02-09 15:00:57 UTC (rev 106) +++ trunk/plugins/MCEReplacement/AssemblyInfo.cs 2007-02-10 06:48:49 UTC (rev 107) @@ -1,6 +1,8 @@ +using System; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; +using System.Security.Permissions; // // General Information about an assembly is controlled through the following @@ -16,6 +18,11 @@ [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + // // Version information for an assembly consists of the following four values: // @@ -58,4 +65,7 @@ [assembly: AssemblyDelaySign(false)] [assembly: AssemblyKeyFile("")] [assembly: AssemblyKeyName("")] -[assembly: ComVisibleAttribute(false)] + +[assembly: CLSCompliant(true)] + +[assembly: SecurityPermission(SecurityAction.RequestMinimum, UnmanagedCode = true)] Modified: trunk/plugins/MCEReplacement/ExternalChannelConfig.cs =================================================================== --- trunk/plugins/MCEReplacement/ExternalChannelConfig.cs 2007-02-09 15:00:57 UTC (rev 106) +++ trunk/plugins/MCEReplacement/ExternalChannelConfig.cs 2007-02-10 06:48:49 UTC (rev 107) @@ -14,7 +14,7 @@ #region Variables - string _filename; + string _fileName; int _pauseTime = 250; bool _sendSelect = false; @@ -34,9 +34,9 @@ #region Properties - public string Filename + public string FileName { - get { return _filename; } + get { return _fileName; } } public int PauseTime @@ -105,11 +105,11 @@ #region Constructor - public ExternalChannelConfig(string filename) + public ExternalChannelConfig(string fileName) { - _filename = filename; + _fileName = fileName; - if (!File.Exists(_filename)) + if (!File.Exists(_fileName)) { for (int i = 0; i < 10; i++) Digits[i] = ""; @@ -121,7 +121,7 @@ try { - file = new FileStream(_filename, FileMode.Open, FileAccess.Read, FileShare.Read); + file = new FileStream(_fileName, FileMode.Open, FileAccess.Read, FileShare.Read); XmlDocument doc = new XmlDocument(); doc.Load(file); @@ -161,7 +161,7 @@ try { - file = new FileStream(_filename, FileMode.Create, FileAccess.Write, FileShare.Read); + file = new FileStream(_fileName, FileMode.Create, FileAccess.Write, FileShare.Read); XmlTextWriter writer = new XmlTextWriter(file, System.Text.Encoding.UTF8); writer.Formatting = Formatting.Indented; Modified: trunk/plugins/MCEReplacement/Forms/ExternalChannels.cs =================================================================== --- trunk/plugins/MCEReplacement/Forms/ExternalChannels.cs 2007-02-09 15:00:57 UTC (rev 106) +++ trunk/plugins/MCEReplacement/Forms/ExternalChannels.cs 2007-02-10 06:48:49 UTC (rev 107) @@ -11,9 +11,6 @@ using System.Windows.Forms; using System.Xml; -using MediaPortal.GUI.Library; -using MediaPortal.Util; - namespace MediaPortal.Plugins { @@ -192,21 +189,36 @@ ProcessExternalChannelProgram(setup.SelectCommand.Substring(MCEReplacement.RunCommandPrefix.Length), -1, channel, setup.ExtBlastPort); if (setup.DoubleChannelSelect) + { + if (setup.PauseTime > 0) + Thread.Sleep(setup.PauseTime); + ProcessExternalChannelProgram(setup.SelectCommand.Substring(MCEReplacement.RunCommandPrefix.Length), -1, channel, setup.ExtBlastPort); + } } else if (setup.SelectCommand.StartsWith(MCEReplacement.SerialCommandPrefix)) { ProcessSerialCommand(setup.SelectCommand.Substring(MCEReplacement.SerialCommandPrefix.Length), -1, channel, setup.ExtBlastPort); if (setup.DoubleChannelSelect) + { + if (setup.PauseTime > 0) + Thread.Sleep(setup.PauseTime); + ProcessSerialCommand(setup.SelectCommand.Substring(MCEReplacement.SerialCommandPrefix.Length), -1, channel, setup.ExtBlastPort); + } } else { MCEReplacement.ProcessCommand(setup.SelectCommand, setup.ExtBlastPort, setup.ExtBlastSpeed); if (setup.DoubleChannelSelect) - MCEReplacement.ProcessCommand(setup.SelectCommand, setup.ExtBlastPort, setup.ExtBlastSpeed); + { + if (setup.PauseTime > 0) + Thread.Sleep(setup.PauseTime); + + MCEReplacement.ProcessCommand(setup.SelectCommand, setup.ExtBlastPort, setup.ExtBlastSpeed); + } } } } @@ -221,7 +233,7 @@ { string quickSetup = comboBoxQuickSetup.Text; - if (quickSetup.Length == 0) + if (String.IsNullOrEmpty(quickSetup)) return; _tvCardStbSetups[tabControlTVCards.SelectedIndex].SetToXml(quickSetup); Modified: trunk/plugins/MCEReplacement/Forms/ExternalProgram.Designer.cs =================================================================== --- trunk/plugins/MCEReplacement/Forms/ExternalProgram.Designer.cs 2007-02-09 15:00:57 UTC (rev 106) +++ trunk/plugins/MCEReplacement/Forms/ExternalProgram.Designer.cs 2007-02-10 06:48:49 UTC (rev 107) @@ -99,7 +99,7 @@ this.labelStartup.Name = "labelStartup"; this.labelStartup.Size = new System.Drawing.Size(288, 16); this.labelStartup.TabIndex = 3; - this.labelStartup.Text = "Startup Folder:"; + this.labelStartup.Text = "Start in folder:"; this.labelStartup.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; // // textBoxStartup @@ -180,7 +180,7 @@ this.checkBoxShellExecute.Name = "checkBoxShellExecute"; this.checkBoxShellExecute.Size = new System.Drawing.Size(184, 21); this.checkBoxShellExecute.TabIndex = 12; - this.checkBoxShellExecute.Text = "Startup using ShellExecute"; + this.checkBoxShellExecute.Text = "Start using ShellExecute"; this.checkBoxShellExecute.UseVisualStyleBackColor = true; // // buttonTest Modified: trunk/plugins/MCEReplacement/Forms/MacroEditor.cs =================================================================== --- trunk/plugins/MCEReplacement/Forms/MacroEditor.cs 2007-02-09 15:00:57 UTC (rev 106) +++ trunk/plugins/MCEReplacement/Forms/MacroEditor.cs 2007-02-10 06:48:49 UTC (rev 107) @@ -60,13 +60,13 @@ comboBoxCommands.Items.AddRange(MCEReplacement.GetIRList()); } - void WriteToFile(string filename) + void WriteToFile(string fileName) { FileStream file = null; try { - file = new FileStream(MCEReplacement.AppDataFolder + filename + MCEReplacement.MacroExtension, FileMode.Create, FileAccess.Write, FileShare.Read); + file = new FileStream(MCEReplacement.AppDataFolder + fileName + MCEReplacement.MacroExtension, FileMode.Create, FileAccess.Write, FileShare.Read); XmlTextWriter writer = new XmlTextWriter(file, System.Text.Encoding.UTF8); writer.Formatting = Formatting.Indented; @@ -145,13 +145,13 @@ if (file != null) file.Close(); } - void ReadFromFile(string filename) + void ReadFromFile(string fileName) { FileStream file = null; try { - file = new FileStream(MCEReplacement.AppDataFolder + filename + MCEReplacement.MacroExtension, FileMode.Open, FileAccess.Read, FileShare.Read); + file = new FileStream(MCEReplacement.AppDataFolder + fileName + MCEReplacement.MacroExtension, FileMode.Open, FileAccess.Read, FileShare.Read); XmlDocument doc = new XmlDocument(); doc.Load(file); @@ -339,20 +339,20 @@ private void buttonTest_Click(object sender, EventArgs e) { - string filename = textBoxName.Text.Trim().ToUpperInvariant(); + string fileName = textBoxName.Text.Trim().ToUpperInvariant(); - if (filename.Length == 0) + if (fileName.Length == 0) { MessageBox.Show(this, "You must supply a name for this macro", "Name missing", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } - if (!filename.StartsWith(MCEReplacement.MacroFolder)) - filename = MCEReplacement.MacroFolder + filename; + if (!fileName.StartsWith(MCEReplacement.MacroFolder)) + fileName = MCEReplacement.MacroFolder + fileName; - WriteToFile(filename); + WriteToFile(fileName); - if (!MCEReplacement.ProcessCommand(filename, _blastPort, _blastSpeed)) + if (!MCEReplacement.ProcessCommand(fileName, _blastPort, _blastSpeed)) MessageBox.Show(this, "Check the log files for details", "Test failed", MessageBoxButtons.OK, MessageBoxIcon.Error); } @@ -364,18 +364,18 @@ private void buttonOK_Click(object sender, EventArgs e) { - string filename = textBoxName.Text.Trim().ToUpperInvariant(); + string fileName = textBoxName.Text.Trim().ToUpperInvariant(); - if (filename.Length == 0) + if (fileName.Length == 0) { MessageBox.Show(this, "You must supply a name for this macro", "Name missing", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } - if (!filename.StartsWith(MCEReplacement.MacroFolder)) - filename = MCEReplacement.MacroFolder + filename; + if (!fileName.StartsWith(MCEReplacement.MacroFolder)) + fileName = MCEReplacement.MacroFolder + fileName; - WriteToFile(filename); + WriteToFile(fileName); this.DialogResult = DialogResult.OK; this.Close(); Modified: trunk/plugins/MCEReplacement/Forms/SetupForm.Designer.cs =================================================================== --- trunk/plugins/MCEReplacement/Forms/SetupForm.Designer.cs 2007-02-09 15:00:57 UTC (rev 106) +++ trunk/plugins/MCEReplacement/Forms/SetupForm.Designer.cs 2007-02-10 06:48:49 UTC (rev 107) @@ -310,7 +310,7 @@ this.checkBoxMCERemote.Size = new System.Drawing.Size(184, 24); this.checkBoxMCERemote.TabIndex = 3; this.checkBoxMCERemote.Text = "Enable MCE remote"; - this.toolTips.SetToolTip(this.checkBoxMCERemote, "Enable the plugin\'s MCE remote mapping"); + this.toolTips.SetToolTip(this.checkBoxMCERemote, "Enable MCE remote button mapping"); this.checkBoxMCERemote.UseVisualStyleBackColor = true; // // checkBoxMessageMode Modified: trunk/plugins/MCEReplacement/Forms/SetupForm.cs =================================================================== --- trunk/plugins/MCEReplacement/Forms/SetupForm.cs 2007-02-09 15:00:57 UTC (rev 106) +++ trunk/plugins/MCEReplacement/Forms/SetupForm.cs 2007-02-10 06:48:49 UTC (rev 107) @@ -4,7 +4,7 @@ using System.Data; using System.Drawing; using System.IO; -using System.Security; +using System.Runtime.InteropServices; using System.Security.Permissions; using System.Text; using System.Windows.Forms; @@ -103,7 +103,7 @@ comboBoxCommands.Items.AddRange(MCEReplacement.GetFileList()); comboBoxEvents.Items.Clear(); - foreach (string eventType in Enum.GetNames(typeof(MappedEvent.Events))) + foreach (string eventType in Enum.GetNames(typeof(MappedEvent.MappingEvent))) if (eventType != "None") comboBoxEvents.Items.Add(eventType); @@ -131,9 +131,11 @@ try { + HandleRef handleRef = new HandleRef(this, this.Handle); + do { - registered = MceIrApi.RegisterEvents(this.Handle); + registered = MceIrApi.RegisterEvents(handleRef); if (!registered) { @@ -174,13 +176,14 @@ MessageBox.Show(this, ex.Message, "MCE Replacement Plugin Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } + private void SetupForm_FormClosing(object sender, FormClosingEventArgs e) { if (MceIrApi.InUse) MceIrApi.UnregisterEvents(); } - [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)] + [SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)] override protected void WndProc(ref Message m) { // Handle Suspend & Resume ... @@ -193,14 +196,14 @@ case Win32.PBT_APMQUERYSUSPEND: case Win32.PBT_APMQUERYSTANDBY: //case Win32.PBT_APMSUSPEND: - MceIrApi.Suspend(); + MCEReplacement.OnSuspend(); break; //case Win32.PBT_APMRESUMECRITICAL: //case Win32.PBT_APMRESUMESUSPEND: //case Win32.PBT_APMRESUMESTANDBY: case Win32.PBT_APMRESUMEAUTOMATIC: - MceIrApi.Resume(); + MCEReplacement.OnResume(); break; } } @@ -244,16 +247,16 @@ if (listBoxIR.SelectedIndex != -1) { string command = (string)listBoxIR.SelectedItem; - string filename = MCEReplacement.AppDataFolder + command + MCEReplacement.IRExtension; + string fileName = MCEReplacement.AppDataFolder + command + MCEReplacement.IRExtension; - if (File.Exists(filename)) + if (File.Exists(fileName)) { LearnIR learnIR = new LearnIR(false, command, BlastPort, BlastSpeed); learnIR.ShowDialog(this); } else { - MessageBox.Show(this, "File not found: " + filename, "File missing", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + MessageBox.Show(this, "File not found: " + fileName, "File missing", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); RefreshIRList(); } } @@ -263,16 +266,16 @@ if (listBoxMacro.SelectedIndex != -1) { string command = (string)listBoxMacro.SelectedItem; - string filename = MCEReplacement.AppDataFolder + command + MCEReplacement.MacroExtension; + string fileName = MCEReplacement.AppDataFolder + command + MCEReplacement.MacroExtension; - if (File.Exists(filename)) + if (File.Exists(fileName)) { MacroEditor macroEditor = new MacroEditor(false, command, BlastPort, BlastSpeed); macroEditor.ShowDialog(this); } else { - MessageBox.Show(this, "File not found: " + filename, "File missing", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + MessageBox.Show(this, "File not found: " + fileName, "File missing", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); RefreshMacroList(); } } @@ -403,15 +406,15 @@ if (listBoxIR.SelectedIndex != -1) { string file = (string)listBoxIR.SelectedItem; - string filename = MCEReplacement.AppDataFolder + file + MCEReplacement.IRExtension; - if (File.Exists(filename)) + string fileName = MCEReplacement.AppDataFolder + file + MCEReplacement.IRExtension; + if (File.Exists(fileName)) { if (MessageBox.Show(this, "Are you sure you want to delete \"" + file + "\"?", "Confirm delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) - File.Delete(filename); + File.Delete(fileName); } else { - MessageBox.Show(this, "File not found: " + filename, "File missing", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + MessageBox.Show(this, "File not found: " + fileName, "File missing", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } RefreshIRList(); @@ -445,15 +448,15 @@ if (listBoxMacro.SelectedIndex != -1) { string file = (string)listBoxMacro.SelectedItem; - string filename = MCEReplacement.AppDataFolder + file + MCEReplacement.MacroExtension; - if (File.Exists(filename)) + string fileName = MCEReplacement.AppDataFolder + file + MCEReplacement.MacroExtension; + if (File.Exists(fileName)) { if (MessageBox.Show(this, "Are you sure you want to delete \"" + file + "\"?", "Confirm delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) - File.Delete(filename); + File.Delete(fileName); } else { - MessageBox.Show(this, "File not found: " + filename, "File missing", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + MessageBox.Show(this, "File not found: " + fileName, "File missing", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } RefreshMacroList(); Modified: trunk/plugins/MCEReplacement/Forms/StbSetup.cs =================================================================== --- trunk/plugins/MCEReplacement/Forms/StbSetup.cs 2007-02-09 15:00:57 UTC (rev 106) +++ trunk/plugins/MCEReplacement/Forms/StbSetup.cs 2007-02-10 06:48:49 UTC (rev 107) @@ -210,16 +210,16 @@ return; } - string filename = MCEReplacement.AppDataFolder + MCEReplacement.STBFolder + xmlFile + ".xml"; + string fileName = String.Format("{0}{1}{2}.xml", MCEReplacement.AppDataFolder, MCEReplacement.STBFolder, xmlFile); - if (!File.Exists(filename)) + if (!File.Exists(fileName)) return; FileStream file = null; try { - file = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read); + file = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read); XmlDocument doc = new XmlDocument(); doc.Load(file); @@ -229,7 +229,7 @@ string temp; for (int i = 0; i < 10; i++) { - temp = Util.GetXmlString(nodeList, "Digit" + i.ToString(), ""); + temp = Util.GetXmlString(nodeList, String.Format("Digit{0}", i), ""); if (temp.EndsWith(MCEReplacement.IRExtension)) temp = MCEReplacement.STBFolder + temp; Modified: trunk/plugins/MCEReplacement/MCEReplacement.cs =================================================================== --- trunk/plugins/MCEReplacement/MCEReplacement.cs 2007-02-09 15:00:57 UTC (rev 106) +++ trunk/plugins/MCEReplacement/MCEReplacement.cs 2007-02-10 06:48:49 UTC (rev 107) @@ -5,6 +5,7 @@ using System.Drawing; using System.IO; using System.IO.Ports; +using System.Runtime.InteropServices; using System.Text; using System.Threading; using System.Windows.Forms; @@ -97,10 +98,16 @@ static InputHandler _defaultInputHandler; static List<InputHandler> _multiInputHandlers; + static ExternalChannelConfig[] _externalChannelConfigs; + + static bool _inConfiguration = false; + + static bool _mpBasicHome; + static bool _mpMCERemote; + static string _mpSerialUirPort; + SendMessageHandler _sendMessageHandler; - static ExternalChannelConfig[] _externalChannelConfigs = null; - int[] _mceRemoteMap = null; int[] _differentRemoteMap = null; @@ -108,12 +115,6 @@ bool _mouseModeLeftHeld = false; bool _mouseModeMiddleHeld = false; - static bool _mpBasicHome; - static bool _mpMCERemote; - static string _mpSerialUirPort; - - static bool _inConfiguration = false; - #endregion Variables #region Properties @@ -235,6 +236,12 @@ get { return _externalChannelConfigs; } } + public static bool InConfiguration + { + get { return _inConfiguration; } + set { _inConfiguration = value; } + } + // MediaPortal Settings public static bool MP_BasicHome { @@ -249,19 +256,16 @@ get { return _mpSerialUirPort; } } - public static bool InConfiguration - { - get { return _inConfiguration; } - set { _inConfiguration = value; } - } - #endregion Properties #region IPlugin methods + //[SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)] public void Start() { Log.Info("MCEReplacement: Starting ({0})", Version); + + Log.Debug("MCEReplacement: Platform is {0}", (IntPtr.Size == 4 ? "32-bit" : "64-bit")); // Load basic settings LoadSettings(); @@ -320,8 +324,10 @@ try { // Register with MceIrApi to receive remote button presses - IntPtr hWnd = Application.OpenForms["D3DApp"].Handle; - if (MceIrApi.RegisterEvents(hWnd)) + Form mpForm = Application.OpenForms["D3DApp"]; + HandleRef handleRef = new HandleRef(mpForm, mpForm.Handle); + + if (MceIrApi.RegisterEvents(handleRef)) { if (LogVerbose) Log.Debug("MCEReplacement: MceIrApi enabled"); @@ -344,7 +350,7 @@ { LoadEventMappings(); - MapEvent(MappedEvent.Events.MediaPortal_Start); + MapEvent(MappedEvent.MappingEvent.MediaPortal_Start); } // Register with MediaPortal to receive GUI Messages ... @@ -357,13 +363,15 @@ if (LogVerbose) Log.Info("MCEReplacement: Started"); } + + //[SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)] public void Stop() { if (LogVerbose) Log.Info("MCEReplacement: Stopping"); if (EventMapperEnabled) - MapEvent(MappedEvent.Events.MediaPortal_Stop); + MapEvent(MappedEvent.MappingEvent.MediaPortal_Stop); if (ControlExternalEnabled || EventMapperEnabled) GUIWindowManager.Receivers -= _sendMessageHandler; @@ -429,6 +437,7 @@ #region IPluginReceiver methods + //[SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)] public bool WndProc(ref Message msg) { // Handle Suspend & Resume ... @@ -463,9 +472,9 @@ if (RequireFocus && !GUIGraphicsContext.HasFocus) return true; - int lParam = msg.LParam.ToInt32(); - int keyCode = lParam & 0xFFFF; - int repeatCount = lParam >> 16; + int longParam = msg.LParam.ToInt32(); + int keyCode = longParam & 0xFFFF; + int repeatCount = longParam >> 16; int button = -1; @@ -557,9 +566,9 @@ // The plugin just maps it through the input handler. if (MessageModeEnabled && msg.Msg == Win32.WM_APP && msg.WParam.ToInt32() == MessageModeCommand) { - int lParam = msg.LParam.ToInt32(); - int button = lParam & 0xFFFF; - int repeatCount = lParam >> 16; + int longParam = msg.LParam.ToInt32(); + int button = longParam & 0xFFFF; + int repeatCount = longParam >> 16; if (MultiMappingEnabled && button == MultiMappingButton) { @@ -620,13 +629,13 @@ notifyMessage = "Mouse Mode is now OFF"; if (_mouseModeLeftHeld) - Win32.MouseEvent((uint)Win32.MouseEventFlags.LEFTUP, 0, 0, 0, 0); + Mouse.Button(Mouse.MouseEvents.LeftUp); if (_mouseModeRightHeld) - Win32.MouseEvent((uint)Win32.MouseEventFlags.RIGHTUP, 0, 0, 0, 0); + Mouse.Button(Mouse.MouseEvents.RightUp); if (_mouseModeMiddleHeld) - Win32.MouseEvent((uint)Win32.MouseEventFlags.MIDDLEUP, 0, 0, 0, 0); + Mouse.Button(Mouse.MouseEvents.MiddleUp); _mouseModeLeftHeld = false; _mouseModeRightHeld = false; @@ -642,8 +651,8 @@ } else if (MouseModeActive) { - int x = Cursor.Position.X; - int y = Cursor.Position.Y; + //int x = Cursor.Position.X; + //int y = Cursor.Position.Y; int distance = MouseModeStep; if (MouseModeAcceleration) @@ -652,19 +661,23 @@ switch ((RemoteButton)button) { case RemoteButton.Up: - Cursor.Position = new Point(x, y - distance); + //Cursor.Position = new Point(x, y - distance); + Mouse.Move(0, -distance, false); return true; case RemoteButton.Down: - Cursor.Position = new Point(x, y + distance); + //Cursor.Position = new Point(x, y + distance); + Mouse.Move(0, distance, false); return true; case RemoteButton.Left: - Cursor.Position = new Point(x - distance, y); + //Cursor.Position = new Point(x - distance, y); + Mouse.Move(-distance, 0, false); return true; case RemoteButton.Right: - Cursor.Position = new Point(x + distance, y); + //Cursor.Position = new Point(x + distance, y); + Mouse.Move(distance, 0, false); return true; case RemoteButton.Replay: // Left Single-Click @@ -672,20 +685,20 @@ return true; if (_mouseModeLeftHeld) - Win32.MouseEvent((uint)Win32.MouseEventFlags.LEFTUP, 0, 0, 0, 0); + Mouse.Button(Mouse.MouseEvents.LeftUp); if (_mouseModeRightHeld) - Win32.MouseEvent((uint)Win32.MouseEventFlags.RIGHTUP, 0, 0, 0, 0); + Mouse.Button(Mouse.MouseEvents.RightUp); if (_mouseModeMiddleHeld) - Win32.MouseEvent((uint)Win32.MouseEventFlags.MIDDLEUP, 0, 0, 0, 0); + Mouse.Button(Mouse.MouseEvents.MiddleUp); _mouseModeLeftHeld = false; _mouseModeRightHeld = false; _mouseModeMiddleHeld = false; - Win32.MouseEvent((uint)Win32.MouseEventFlags.LEFTDOWN, 0, 0, 0, 0); - Win32.MouseEvent((uint)Win32.MouseEventFlags.LEFTUP, 0, 0, 0, 0); + Mouse.Button(Mouse.MouseEvents.LeftDown); + Mouse.Button(Mouse.MouseEvents.LeftUp); return true; case RemoteButton.Skip: // Right Single-Click @@ -693,20 +706,20 @@ return true; if (_mouseModeLeftHeld) - Win32.MouseEvent((uint)Win32.MouseEventFlags.LEFTUP, 0, 0, 0, 0); + Mouse.Button(Mouse.MouseEvents.LeftUp); if (_mouseModeRightHeld) - Win32.MouseEvent((uint)Win32.MouseEventFlags.RIGHTUP, 0, 0, 0, 0); + Mouse.Button(Mouse.MouseEvents.RightUp); if (_mouseModeMiddleHeld) - Win32.MouseEvent((uint)Win32.MouseEventFlags.MIDDLEUP, 0, 0, 0, 0); + Mouse.Button(Mouse.MouseEvents.MiddleUp); _mouseModeLeftHeld = false; _mouseModeRightHeld = false; _mouseModeMiddleHeld = false; - Win32.MouseEvent((uint)Win32.MouseEventFlags.RIGHTDOWN, 0, 0, 0, 0); - Win32.MouseEvent((uint)Win32.MouseEventFlags.RIGHTUP, 0, 0, 0, 0); + Mouse.Button(Mouse.MouseEvents.RightDown); + Mouse.Button(Mouse.MouseEvents.RightUp); return true; case RemoteButton.Play: // Middle Single-Click @@ -714,20 +727,20 @@ return true; if (_mouseModeLeftHeld) - Win32.MouseEvent((uint)Win32.MouseEventFlags.LEFTUP, 0, 0, 0, 0); + Mouse.Button(Mouse.MouseEvents.LeftUp); if (_mouseModeRightHeld) - Win32.MouseEvent((uint)Win32.MouseEventFlags.RIGHTUP, 0, 0, 0, 0); + Mouse.Button(Mouse.MouseEvents.RightUp); if (_mouseModeMiddleHeld) - Win32.MouseEvent((uint)Win32.MouseEventFlags.MIDDLEUP, 0, 0, 0, 0); + Mouse.Button(Mouse.MouseEvents.MiddleUp); _mouseModeLeftHeld = false; _mouseModeRightHeld = false; _mouseModeMiddleHeld = false; - Win32.MouseEvent((uint)Win32.MouseEventFlags.MIDDLEDOWN, 0, 0, 0, 0); - Win32.MouseEvent((uint)Win32.MouseEventFlags.MIDDLEUP, 0, 0, 0, 0); + Mouse.Button(Mouse.MouseEvents.MiddleDown); + Mouse.Button(Mouse.MouseEvents.MiddleUp); return true; case RemoteButton.Ok: // Double-Click (Left) @@ -735,36 +748,36 @@ return true; if (_mouseModeLeftHeld) - Win32.MouseEvent((uint)Win32.MouseEventFlags.LEFTUP, 0, 0, 0, 0); + Mouse.Button(Mouse.MouseEvents.LeftUp); if (_mouseModeRightHeld) - Win32.MouseEvent((uint)Win32.MouseEventFlags.RIGHTUP, 0, 0, 0, 0); + Mouse.Button(Mouse.MouseEvents.RightUp); if (_mouseModeMiddleHeld) - Win32.MouseEvent((uint)Win32.MouseEventFlags.MIDDLEUP, 0, 0, 0, 0); + Mouse.Button(Mouse.MouseEvents.MiddleUp); _mouseModeLeftHeld = false; _mouseModeRightHeld = false; _mouseModeMiddleHeld = false; - Win32.MouseEvent((uint)Win32.MouseEventFlags.LEFTDOWN, 0, 0, 0, 0); - Win32.MouseEvent((uint)Win32.MouseEventFlags.LEFTUP, 0, 0, 0, 0); + Mouse.Button(Mouse.MouseEvents.LeftDown); + Mouse.Button(Mouse.MouseEvents.LeftUp); - Win32.MouseEvent((uint)Win32.MouseEventFlags.LEFTDOWN, 0, 0, 0, 0); - Win32.MouseEvent((uint)Win32.MouseEventFlags.LEFTUP, 0, 0, 0, 0); + Mouse.Button(Mouse.MouseEvents.LeftDown); + Mouse.Button(Mouse.MouseEvents.LeftUp); return true; case RemoteButton.Back: // Left Click & Hold if (_mouseModeRightHeld) - Win32.MouseEvent((uint)Win32.MouseEventFlags.RIGHTUP, 0, 0, 0, 0); + Mouse.Button(Mouse.MouseEvents.RightUp); if (_mouseModeMiddleHeld) - Win32.MouseEvent((uint)Win32.MouseEventFlags.MIDDLEUP, 0, 0, 0, 0); + Mouse.Button(Mouse.MouseEvents.MiddleUp); if (_mouseModeLeftHeld) - Win32.MouseEvent((uint)Win32.MouseEventFlags.LEFTUP, 0, 0, 0, 0); + Mouse.Button(Mouse.MouseEvents.LeftUp); else - Win32.MouseEvent((uint)Win32.MouseEventFlags.LEFTDOWN, 0, 0, 0, 0); + Mouse.Button(Mouse.MouseEvents.LeftDown); _mouseModeLeftHeld = !_mouseModeLeftHeld; _mouseModeRightHeld = false; @@ -773,15 +786,15 @@ case RemoteButton.Info: // Right Click & Hold if (_mouseModeLeftHeld) - Win32.MouseEvent((uint)Win32.MouseEventFlags.LEFTUP, 0, 0, 0, 0); + Mouse.Button(Mouse.MouseEvents.LeftUp); if (_mouseModeMiddleHeld) - Win32.MouseEvent((uint)Win32.MouseEventFlags.MIDDLEUP, 0, 0, 0, 0); + Mouse.Button(Mouse.MouseEvents.MiddleUp); if (_mouseModeRightHeld) - Win32.MouseEvent((uint)Win32.MouseEventFlags.RIGHTUP, 0, 0, 0, 0); + Mouse.Button(Mouse.MouseEvents.RightUp); else - Win32.MouseEvent((uint)Win32.MouseEventFlags.RIGHTDOWN, 0, 0, 0, 0); + Mouse.Button(Mouse.MouseEvents.RightDown); _mouseModeRightHeld = !_mouseModeRightHeld; _mouseModeLeftHeld = false; @@ -790,15 +803,15 @@ case RemoteButton.Stop: // Middle Click & Hold if (_mouseModeLeftHeld) - Win32.MouseEvent((uint)Win32.MouseEventFlags.LEFTUP, 0, 0, 0, 0); + Mouse.Button(Mouse.MouseEvents.LeftUp); if (_mouseModeRightHeld) - Win32.MouseEvent((uint)Win32.MouseEventFlags.RIGHTUP, 0, 0, 0, 0); + Mouse.Button(Mouse.MouseEvents.RightUp); if (_mouseModeMiddleHeld) - Win32.MouseEvent((uint)Win32.MouseEventFlags.MIDDLEUP, 0, 0, 0, 0); + Mouse.Button(Mouse.MouseEvents.MiddleUp); else - Win32.MouseEvent((uint)Win32.MouseEventFlags.MIDDLEDOWN, 0, 0, 0, 0); + Mouse.Button(Mouse.MouseEvents.MiddleDown); _mouseModeMiddleHeld = !_mouseModeMiddleHeld; _mouseModeLeftHeld = false; @@ -806,11 +819,11 @@ return true; case RemoteButton.ChannelUp: // Scroll Up - Win32.MouseEvent((uint)Win32.MouseEventFlags.SCROLL, 0, 0, (uint)120, 0); + Mouse.Scroll(Mouse.ScrollDir.Up); return true; case RemoteButton.ChannelDown: // Scroll Down - Win32.MouseEvent((uint)Win32.MouseEventFlags.SCROLL, 0, 0, unchecked((uint)-120), 0); + Mouse.Scroll(Mouse.ScrollDir.Down); return true; } } @@ -1022,7 +1035,7 @@ /// <param name="msg">MediaPortal Message to run through the event mapper</param> static void MapEvent(GUIMessage msg) { - MappedEvent.Events eventType = MappedEvent.GetEventType(msg.Message); + MappedEvent.MappingEvent eventType = MappedEvent.GetEventType(msg.Message); foreach (MappedEvent mappedEvent in EventMappings) { @@ -1086,7 +1099,7 @@ continue; if (LogVerbose) - Log.Info("MCEReplacement: Event Mapper - Event \"{0}\"", Enum.GetName(typeof(MappedEvent.Events), eventType)); + Log.Info("MCEReplacement: Event Mapper - Event \"{0}\"", Enum.GetName(typeof(MappedEvent.MappingEvent), eventType)); string command = mappedEvent.Command; @@ -1105,7 +1118,7 @@ /// Run the event mapper over the supplied MappedEvent type /// </summary> /// <param name="msg">MappedEvent to run through the event mapper</param> - static void MapEvent(MappedEvent.Events eventType) + static void MapEvent(MappedEvent.MappingEvent eventType) { foreach (MappedEvent mappedEvent in EventMappings) { @@ -1115,7 +1128,7 @@ continue; if (LogVerbose) - Log.Info("MCEReplacement: Event Mapper - Event \"{0}\"", Enum.GetName(typeof(MappedEvent.Events), eventType)); + Log.Info("MCEReplacement: Event Mapper - Event \"{0}\"", Enum.GetName(typeof(MappedEvent.MappingEvent), eventType)); string command = mappedEvent.Command; @@ -1301,26 +1314,24 @@ return ProcessSerialCommand(commands); } - static bool BlastIR(string filename, MceIrApi.BlasterPort port, MceIrApi.BlasterSpeed speed) + static bool BlastIR(string fileName, MceIrApi.BlasterPort port, MceIrApi.BlasterSpeed speed) { FileStream file = null; try { - file = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read); + file = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read); if (file.Length == 0) { - Log.Error("MCEReplacement: IR file \"{0}\" has no data, possible IR learn failure", filename); + Log.Error("MCEReplacement: IR file \"{0}\" has no data, possible IR learn failure", fileName); file.Close(); return false; } - IntPtr fileHandle = file.SafeFileHandle.DangerousGetHandle(); - - if (!MceIrApi.CheckFile(fileHandle)) + if (!MceIrApi.CheckFile(file.SafeFileHandle)) { - Log.Error("MCEReplacement: Bad IR file \"{0}\"", filename); + Log.Error("MCEReplacement: Bad IR file \"{0}\"", fileName); file.Close(); return false; } @@ -1329,7 +1340,7 @@ MceIrApi.SetBlasterSpeed(speed); MceIrApi.SetBlasterType(BlastType); - if (MceIrApi.PlaybackFromFile(fileHandle)) + if (MceIrApi.PlaybackFromFile(file.SafeFileHandle)) { if (LogVerbose) Log.Info("MCEReplacement: Blast successful"); @@ -1343,7 +1354,7 @@ Log.Error("MCEReplacement: BlastIR() {0}", ex.Message); } - Log.Error("MCEReplacement: Failed to blast IR file \"{0}\"", filename); + Log.Error("MCEReplacement: Failed to blast IR file \"{0}\"", fileName); if (file != null) file.Close(); @@ -1351,7 +1362,7 @@ return false; } - static bool ProcessMacro(string filename, MceIrApi.BlasterPort port, MceIrApi.BlasterSpeed speed) + static bool ProcessMacro(string fileName, MceIrApi.BlasterPort port, MceIrApi.BlasterSpeed speed) { FileStream file = null; @@ -1360,7 +1371,7 @@ try { - file = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read); + file = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read); XmlDocument doc = new XmlDocument(); doc.Load(file); @@ -1378,7 +1389,7 @@ if (!BlastIR(AppDataFolder + commandProperty + IRExtension, macroPort, macroSpeed)) { file.Close(); - Log.Error("MCEReplacement: Error blasting \"{0}\" in \"{1}\"", commandProperty, filename); + Log.Error("MCEReplacement: Error blasting \"{0}\" in \"{1}\"", commandProperty, fileName); return false; } break; @@ -1400,14 +1411,14 @@ if (commands == null) { file.Close(); - Log.Error("MCEReplacement: Error processing Run \"{0}\" in \"{1}\"", commandProperty, filename); + Log.Error("MCEReplacement: Error processing Run \"{0}\" in \"{1}\"", commandProperty, fileName); return false; } if (!ProcessRunCommand(commands)) { file.Close(); - Log.Error("MCEReplacement: Error executing Run in \"{0}\"", filename); + Log.Error("MCEReplacement: Error executing Run in \"{0}\"", fileName); return false; } break; @@ -1420,14 +1431,14 @@ if (commands == null) { file.Close(); - Log.Error("MCEReplacement: Error processing Serial Command \"{0}\" in \"{1}\"", commandProperty, filename); + Log.Error("MCEReplacement: Error processing Serial Command \"{0}\" in \"{1}\"", commandProperty, fileName); return false; } if (!ProcessSerialCommand(commands)) { file.Close(); - Log.Error("MCEReplacement: Error executing Serial Command in \"{0}\"", filename); + Log.Error("MCEReplacement: Error executing Serial Command in \"{0}\"", fileName); return false; } break; @@ -1449,7 +1460,7 @@ if (commands == null) { file.Close(); - Log.Error("MCEReplacement: Error processing Popup Command \"{0}\" in \"{1}\"", commandProperty, filename); + Log.Error("MCEReplacement: Error processing Popup Command \"{0}\" in \"{1}\"", commandProperty, fileName); return false; } @@ -1479,7 +1490,7 @@ if (commands == null) { file.Close(); - Log.Error("MCEReplacement: Error processing Message Command \"{0}\" in \"{1}\"", commandProperty, filename); + Log.Error("MCEReplacement: Error processing Message Command \"{0}\" in \"{1}\"", commandProperty, fileName); return false; } @@ -1499,7 +1510,7 @@ else if (!ProcessKeyCommand(commandProperty)) { file.Close(); - Log.Error("MCEReplacement: Error executing Key Command in \"{0}\"", filename); + Log.Error("MCEReplacement: Error executing Key Command in \"{0}\"", fileName); return false; } @@ -1593,8 +1604,8 @@ /// </summary> public static void OnSuspend() { - if (EventMapperEnabled) - MapEvent(MappedEvent.Events.PC_Suspend); + if (!InConfiguration && EventMapperEnabled) + MapEvent(MappedEvent.MappingEvent.PC_Suspend); if (MceIrApi.InUse) { @@ -1618,8 +1629,8 @@ MceIrApi.Resume(); } - if (EventMapperEnabled) - MapEvent(MappedEvent.Events.PC_Resume); + if (!InConfiguration && EventMapperEnabled) + MapEvent(MappedEvent.MappingEvent.PC_Resume); } /// <summary> @@ -1629,6 +1640,12 @@ /// <returns>Returns string[] of command elements</returns> public static string[] SplitRunCommand(string runCommand) { + if (String.IsNullOrEmpty(runCommand)) + { + Log.Error("MCEReplacement: Invalid run command"); + return null; + } + string[] commands = runCommand.Split(new char[] { '|' }); if (commands.Length != 7) @@ -1647,24 +1664,30 @@ /// <param name="command">An array of arguments for the method /// (the output of SplitRunCommand)</param> /// <returns>success</returns> - public static bool ProcessRunCommand(string[] command) + public static bool ProcessRunCommand(string[] commands) { + if (commands == null) + { + Log.Error("MCEReplacement: Invalid run command"); + return false; + } + try { Process process = new Process(); - process.StartInfo.FileName = command[0]; - process.StartInfo.WorkingDirectory = command[1]; - process.StartInfo.Arguments = command[2]; - process.StartInfo.WindowStyle = (ProcessWindowStyle)Enum.Parse(typeof(ProcessWindowStyle), command[3]); - process.StartInfo.CreateNoWindow = bool.Parse(command[4]); - process.StartInfo.UseShellExecute = bool.Parse(command[5]); + process.StartInfo.FileName = commands[0]; + process.StartInfo.WorkingDirectory = commands[1]; + process.StartInfo.Arguments = commands[2]; + process.StartInfo.WindowStyle = (ProcessWindowStyle)Enum.Parse(typeof(ProcessWindowStyle), commands[3]); + process.StartInfo.CreateNoWindow = bool.Parse(commands[4]); + process.StartInfo.UseShellExecute = bool.Parse(commands[5]); if (LogVerbose) - Log.Info("MCEReplacement: Launching program {0}", command[0]); + Log.Info("MCEReplacement: Launching program {0}", commands[0]); process.Start(); - if (bool.Parse(command[6])) // Wait for exit + if (bool.Parse(commands[6])) // Wait for exit process.WaitForExit(); } catch (Exception ex) @@ -1683,6 +1706,12 @@ /// <returns>Returns string[] of command elements</returns> public static string[] SplitSerialCommand(string serialCommand) { + if (String.IsNullOrEmpty(serialCommand)) + { + Log.Error("MCEReplacement: Invalid serial command"); + return null; + } + string[] commands = serialCommand.Split(new char[] { '|' }); if (commands.Length != 6) @@ -1704,6 +1733,12 @@ /// <returns>success</returns> public static bool ProcessSerialCommand(string[] commands) { + if (commands == null) + { + Log.Error("MCEReplacement: Invalid serial command"); + return false; + } + SerialPort serialPort = null; if (LogVerbose) @@ -1748,41 +1783,47 @@ /// <returns>success</returns> public static bool ProcessCommand(string command, MceIrApi.BlasterPort port, MceIrApi.BlasterSpeed speed) { + if (String.IsNullOrEmpty(command)) + { + Log.Error("MCEReplacement: Invalid command"); + return false; + } + if (command.StartsWith(MacroFolder)) // Macro { - string filename = AppDataFolder + command + MacroExtension; - if (File.Exists(filename)) + string fileName = AppDataFolder + command + MacroExtension; + if (File.Exists(fileName)) { - return ProcessMacro(filename, port, speed); + return ProcessMacro(fileName, port, speed); } else { - Log.Error("MCEReplacement: Macro file missing \"{0}\"", filename); + Log.Error("MCEReplacement: Macro file missing \"{0}\"", fileName); return false; } } else if (command.StartsWith(IRFolder)) // IR Code { - string filename = AppDataFolder + command + IRExtension; - if (File.Exists(filename)) + string fileName = AppDataFolder + command + IRExtension; + if (File.Exists(fileName)) { - return BlastIR(filename, port, speed); + return BlastIR(fileName, port, speed); } else { - Log.Error("MCEReplacement: IR file missing \"{0}\"", filename); + Log.Error("MCEReplacement: IR file missing \"{0}\"", fileName); return false; } } else if (command.StartsWith(STBFolder)) // STB Command { - string filename = AppDataFolder + command; - if (File.Exists(filename)) + string fileName = AppDataFolder + command; + if (File.Exists(fileName)) { - if (filename.EndsWith(IRExtension)) // IR Command - return BlastIR(filename, port, speed); - else if (filename.EndsWith(MacroExtension)) // Macro - return ProcessMacro(filename, port, speed); + if (fileName.EndsWith(IRExtension)) // IR Command + return BlastIR(fileName, port, speed); + else if (fileName.EndsWith(MacroExtension)) // Macro + return ProcessMacro(fileName, port, speed); else { Log.Error("MCEReplacement: Invalid STB Command \"{0}\"", command); @@ -1791,7 +1832,7 @@ } else { - Log.Error("MCEReplacement: STB file missing \"{0}\"", filename); + Log.Error("MCEReplacement: STB file missing \"{0}\"", fileName); return false; } } @@ -1860,6 +1901,12 @@ /// <returns>Returns string[] of command elements</returns> public static string[] SplitMessageCommand(string messageCommand) { + if (String.IsNullOrEmpty(messageCommand)) + { + Log.Error("MCEReplacement: Invalid message command"); + return null; + } + string[] commands = messageCommand.Split(new char[] { '|' }); if (commands.Length != 4) @@ -1880,13 +1927,19 @@ /// <returns>success</returns> public static bool ProcessMessageCommand(string[] commands) { + if (commands == null) + { + Log.Error("MCEReplacement: Invalid message command"); + return false; + } + try { - IntPtr hWnd = IntPtr.Zero; + IntPtr windowHandle = IntPtr.Zero; if (commands[0] == "*") { - hWnd = Win32.GetForegroundWindow(); + windowHandle = Win32.GetForegroundWindow(); } else { @@ -1895,7 +1948,7 @@ try { if (proc.MainModule.FileName == commands[0]) - hWnd = proc.MainWindowHandle; + windowHandle = proc.MainWindowHandle; } catch { @@ -1903,19 +1956,20 @@ } } - if (hWnd == IntPtr.Zero) + if (windowHandle == IntPtr.Zero) { Log.Warn("MCEReplacement: No target found for Message Command"); return false; } int msg = int.Parse(commands[1]); - int wParam = int.Parse(commands[2]); - int lParam = int.Parse(commands[3]); + IntPtr wordParam = new IntPtr(int.Parse(commands[2])); + IntPtr longParam = new IntPtr(int.Parse(commands[3])); - Win32.SendMessage(hWnd, msg, wParam, lParam); + Win32.SendMessage(windowHandle, msg, wordParam, longParam); - Log.Info("MCEReplacement: Message Sent({0}, {1}, {2}, {3})", hWnd.ToString(), msg, wParam, lParam); + if (LogVerbose) + Log.Info("MCEReplacement: Message Sent({0}, {1}, {2}, {3})", commands[0], msg, wordParam, longParam); return true; } @@ -1933,11 +1987,17 @@ /// <returns>Returns string[] of command elements</returns> public static string[] SplitPopupCommand(string popupCommand) { + if (String.IsNullOrEmpty(popupCommand)) + { + Log.Error("MCEReplacement: Invalid popup command"); + return null; + } + string[] commands = popupCommand.Split(new char[] { '|' }); if (commands.Length != 3) { - Log.Error("MCEReplacement: Popup command structure is invalid: {0}", popupCommand); + Log.Error("MCEReplacement: Popup Command structure is invalid: {0}", popupCommand); return null; } @@ -1951,16 +2011,31 @@ /// <returns>Success</returns> public static bool ProcessGoTo(string screen) { - GUIWindow.Window window = (GUIWindow.Window)Enum.Parse(typeof(GUIWindow.Window), "WINDOW_" + screen); + if (String.IsNullOrEmpty(screen)) + { + Log.Error("MCEReplacement: Invalid goto command"); + return false; + } - if (window == GUIWindow.Window.WINDOW_HOME && MP_BasicHome) - window = GUIWindow.Window.WINDOW_SECOND_HOME; + try + { + GUIWindow.Window window = (GUIWindow.Window)Enum.Parse(typeof(GUIWindow.Window), "WINDOW_" + screen); - if (LogVerbose) - Log.Info("MCEReplacement: Go To Window \"{0}\"", Enum.GetName(typeof(GUIWindow.Window), window)); + if (window == GUIWindow.Window.WINDOW_HOME && MP_BasicHome) + window = GUIWindow.Window.WINDOW_SECOND_HOME; - GUIGraphicsContext.ResetLastActivity(); - GUIWindowManager.SendThreadMessage(new GUIMessage(GUIMessage.MessageType.GUI_MSG_GOTO_WINDOW, 0, 0, 0, (int)window, 0, null)); + if (LogVerbose) + Log.Info("MCEReplacement: Go To Window \"{0}\"", Enum.GetName(typeof(GUIWindow.Window), window)); + + GUIGraphicsContext.ResetLastActivity(); + GUIWindowManager.SendThreadMessage(new GUIMessage(GUIMessage.MessageType.GUI_MSG_GOTO_WINDOW, 0, 0, 0, (int)window, 0, null)); + } + catch (Exception ex) + { + Log.Error("MCEReplacement: Error processing Goto Command \"{0}\" - {1}", screen, ex.Message); + return false; + } + return true; } @@ -1971,13 +2046,19 @@ /// <returns>Success</returns> public static bool ProcessKeyCommand(string command) { + if (String.IsNullOrEmpty(command)) + { + Log.Error("MCEReplacement: Invalid key command"); + return false; + } + try { SendKeys.SendWait(command); } catch (Exception ex) { - Log.Error("MCEReplacement: {0}", ex.Message); + Log.Error("MCEReplacement: Error processing Key Command \"{0}\"", ex.Message); return false; } @@ -1991,15 +2072,14 @@ /// <returns>bool value shows success</returns> public static bool LearnIRCommand(string blastCommand) { - string filename = AppDataFolder + blastCommand + IRExtension; + string fileName = AppDataFolder + blastCommand + IRExtension; FileStream file = null; bool status = false; try { - file = new FileStream(filename, FileMode.Create, FileAccess.Write, FileShare.Read); - - status = MceIrApi.RecordToFile(file.SafeFileHandle.DangerousGetHandle(), LearnTimeout); + file = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.Read); + status = MceIrApi.RecordToFile(file.SafeFileHandle, LearnTimeout); } catch (Exception ex) { @@ -2071,6 +2151,17 @@ /// <returns>Modified string with escape codes processed</returns> public static string ReplaceEscapeCodes(string input) { + if (input == null) + { + Log.Error("MCEReplacement: Null escape code string"); + return ""; + } + else if (input.Length == 0) + { + Log.Warn("MCEReplacement: Empty escape code string"); + return ""; + } + bool inEscapeCode = false; bool inHexCode = false; byte hexParsed; @@ -2128,7 +2219,7 @@ if (byte.TryParse(hexCode.ToString(), System.Globalization.NumberStyles.HexNumber, null, out hexParsed)) output.Append((char)hexParsed); else - Log.Error("MCEReplacement: ReplaceEscapeCodes() - Bad Hex Code"); + Log.Error("MCEReplacement: Bad Hex Code \"{0}\"", hexCode.ToString()); inHexCode = false; break; Modified: trunk/plugins/MCEReplacement/MCEReplacement.csproj =================================================================== --- trunk/plugins/MCEReplacement/MCEReplacement.csproj 2007-02-09 15:00:57 UTC (rev 106) +++ trunk/plugins/MCEReplacement/MCEReplacement.csproj 2007-02-10 06:48:49 UTC (rev 107) @@ -13,6 +13,9 @@ <StartupObject> </StartupObject> <RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent> + <SignAssembly>false</SignAssembly> + <AssemblyOriginatorKeyFile> + </AssemblyOriginatorKeyFile> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <DebugSymbols>false</DebugSymbols> @@ -150,6 +153,7 @@ <Compile Include="MappedEvent.cs" /> <Compile Include="MceIrApi.cs" /> <Compile Include="MCEReplacement.cs" /> + <Compile Include="Mouse.cs" /> <Compile Include="Util.cs" /> <Compile Include="Win32.cs" /> </ItemGroup> Modified: trunk/plugins/MCEReplacement/MappedEvent.cs =================================================================== --- trunk/plugins/MCEReplacement/MappedEvent.cs 2007-02-09 15:00:57 UTC (rev 106) +++ trunk/plugins/MCEReplacement/MappedEvent.cs 2007-02-10 06:48:49 UTC (rev 107) @@ -18,7 +18,7 @@ /// <summary> /// A list of events that can be mapped in the Event Mapper /// </summary> - public enum Events + public enum MappingEvent { None, //Time_Schedule, @@ -114,77 +114,78 @@ /// </summary> /// <param name="messageType">MediaPortal GUIMessage.MessageType</param> /// <returns></returns> - public static Events GetEventType(GUIMessage.MessageType messageType) + [CLSCompliant(false)] + public static MappingEvent GetEventType(GUIMessage.MessageType messageType) { switch (messageType) { case GUIMessage.MessageType.GUI_MSG_CD_INSERTED: - return Events.CD_Inserted; + return MappingEvent.CD_Inserted; case GUIMessage.MessageType.GUI_MSG_CD_REMOVED: - return Events.CD_Ejected; + return MappingEvent.CD_Ejected; case GUIMessage.MessageType.GUI_MSG_FILE_DOWNLOADED: - return Events.File_Downloaded; + return MappingEvent.File_Downloaded; case GUIMessage.MessageType.GUI_MSG_FILE_DOWNLOADING: - return Events.File_Downloading; + return MappingEvent.File_Downloading; case GUIMessage.MessageType.GUI_MSG_LOSTFOCUS: - return Events.Focus_Lost; + return MappingEvent.Focus_Lost; case GUIMessage.MessageType.GUI_MSG_MSN_CLOSECONVERSATION: - return Events.MSN_Close_Conversation; + return MappingEvent.MSN_Close_Conversation; case GUIMessage.MessageType.GUI_MSG_MSN_MESSAGE: - return Events.MSN_Message; + return MappingEvent.MSN_Message; case GUIMessage.MessageType.GUI_MSG_MSN_STATUS_MESSAGE: - return Events.MSN_Status_Message; + return MappingEvent.MSN_Status_Message; case GUIMessage.MessageType.GUI_MSG_PLAY_AUDIO_CD: - return Events.Play_Audio_CD; + return MappingEvent.Play_Audio_CD; case GUIMessage.MessageType.GUI_MSG_PLAY_FILE: - return Events.Play_File; + return MappingEvent.Play_File; case GUIMessage.MessageType.GUI_MSG_PLAY_ITEM: - return Events.Play_Item; + return MappingEvent.Play_Item; case GUIMessage.MessageType.GUI_MSG_PLAY_RADIO_STATION: - return Events.Play_Radio_Station; + return MappingEvent.Play_Radio_Station; case GUIMessage.MessageType.GUI_MSG_PLAYBACK_ENDED: - return Events.Playback_Ended; + return MappingEvent.Playback_Ended; case GUIMessage.MessageType.GUI_MSG_PLAYBACK_STARTED: - return Events.Playback_Started; + return MappingEvent.Playback_Started; case GUIMessage.MessageType.GUI_MSG_PLAYBACK_STOPPED: - return Events.Playback_Stopped; + return MappingEvent.Playback_Stopped; case GUIMessage.MessageType.GUI_MSG_RECORD: - return Events.Record; + return MappingEvent.Record; case GUIMessage.MessageType.GUI_MSG_RECORDER_ABOUT_TO_START_RECORDING: - return Events.About_To_Record; + return MappingEvent.About_To_Record; case GUIMessage.MessageType.GUI_MSG_RECORDER_START: - return Events.Recorder_Start; + return MappingEvent.Recorder_Start; case GUIMessage.MessageType.GUI_MSG_RECORDER_STOP: - return Events.Recorder_Stop; + return MappingEvent.Recorder_Stop; case GUIMessage.MessageType.GUI_MSG_RECORDER_STOP_RADIO: - return Events.Recorder_Stop_Radio; + return MappingEvent.Recorder_Stop_Radio; case GUIMessage.MessageType.GUI_MSG_RECORDER_STOP_TIMESHIFT: - return Events.Recorder_Stop_Timeshift; + return MappingEvent.Recorder_Stop_Timeshift; case GUIMessage.MessageType.GUI_MSG_RECORDER_STOP_TV: - return Events.Recorder_Stop_TV; + return MappingEvent.Recorder_Stop_TV; case GUIMessage.Messag... [truncated message content] |