From: <an...@us...> - 2007-10-05 14:43:45
|
Revision: 975 http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=975&view=rev Author: and-81 Date: 2007-10-05 07:43:44 -0700 (Fri, 05 Oct 2007) Log Message: ----------- Modified Paths: -------------- trunk/plugins/IR Server Suite/Applications/Debug Client/MainForm.cs trunk/plugins/IR Server Suite/Applications/IR Blast/Program.cs trunk/plugins/IR Server Suite/Applications/IR Blast (No Window)/Program.cs trunk/plugins/IR Server Suite/Applications/IR Server/IR Server.csproj trunk/plugins/IR Server Suite/Applications/IR Server/Program.cs trunk/plugins/IR Server Suite/Applications/IR Server/Properties/AssemblyInfo.cs trunk/plugins/IR Server Suite/Applications/Translator/Forms/MacroEditor.cs trunk/plugins/IR Server Suite/Applications/Translator/Program.cs trunk/plugins/IR Server Suite/Common/IrssUtils/Common.cs trunk/plugins/IR Server Suite/Common/IrssUtils/SystemRegistry.cs trunk/plugins/IR Server Suite/IR Server Plugins/FusionRemote Receiver/FusionRemoteReceiver.cs trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/Advanced.cs trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/DriverVista.cs trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/MicrosoftMceTransceiver.cs trunk/plugins/IR Server Suite/IR Server Plugins/USB-UIRT Transceiver/UirtTransceiver.cs trunk/plugins/IR Server Suite/IR Server Plugins/WinLirc Transceiver/WinLirc Transceiver.cs trunk/plugins/IR Server Suite/IR Server Plugins/X10 Transceiver/X10Transceiver.cs trunk/plugins/IR Server Suite/IR Server Plugins/XBCDRC Receiver/XBCDRC Receiver.cs trunk/plugins/IR Server Suite/MediaPortal Plugins/MP Blast Zone Plugin/Forms/MacroEditor.cs trunk/plugins/IR Server Suite/MediaPortal Plugins/MP Blast Zone Plugin/MPBlastZonePlugin.cs trunk/plugins/IR Server Suite/MediaPortal Plugins/MP Control Plugin/Forms/MacroEditor.cs trunk/plugins/IR Server Suite/MediaPortal Plugins/MP Control Plugin/MPControlPlugin.cs trunk/plugins/IR Server Suite/MediaPortal Plugins/TV2 Blaster Plugin/Forms/MacroEditor.cs trunk/plugins/IR Server Suite/MediaPortal Plugins/TV2 Blaster Plugin/TV2BlasterPlugin.cs trunk/plugins/IR Server Suite/MediaPortal Plugins/TV3 Blaster Plugin/Forms/MacroEditor.cs trunk/plugins/IR Server Suite/MediaPortal Plugins/TV3 Blaster Plugin/TV3BlasterPlugin.cs trunk/plugins/MCEReplacement/Forms/MacroEditor.cs trunk/plugins/MCEReplacement/MCEReplacement.cs Added Paths: ----------- trunk/plugins/IR Server Suite/Applications/IR Server/IRServer.exe.manifest Modified: trunk/plugins/IR Server Suite/Applications/Debug Client/MainForm.cs =================================================================== --- trunk/plugins/IR Server Suite/Applications/Debug Client/MainForm.cs 2007-10-04 20:30:23 UTC (rev 974) +++ trunk/plugins/IR Server Suite/Applications/Debug Client/MainForm.cs 2007-10-05 14:43:44 UTC (rev 975) @@ -105,12 +105,12 @@ #region Variables - Client _client = null; + Client _client; string _serverHost = "localhost"; string _learnIRFilename = null; - bool _registered = false; + bool _registered; IRServerInfo _irServerInfo = new IRServerInfo(); Modified: trunk/plugins/IR Server Suite/Applications/IR Blast/Program.cs =================================================================== --- trunk/plugins/IR Server Suite/Applications/IR Blast/Program.cs 2007-10-04 20:30:23 UTC (rev 974) +++ trunk/plugins/IR Server Suite/Applications/IR Blast/Program.cs 2007-10-05 14:43:44 UTC (rev 975) @@ -21,9 +21,9 @@ #region Variables - static Client _client = null; + static Client _client; - static bool _registered = false; + static bool _registered; static string _serverHost = null; Modified: trunk/plugins/IR Server Suite/Applications/IR Blast (No Window)/Program.cs =================================================================== --- trunk/plugins/IR Server Suite/Applications/IR Blast (No Window)/Program.cs 2007-10-04 20:30:23 UTC (rev 974) +++ trunk/plugins/IR Server Suite/Applications/IR Blast (No Window)/Program.cs 2007-10-05 14:43:44 UTC (rev 975) @@ -22,9 +22,9 @@ #region Variables - static Client _client = null; + static Client _client; - static bool _registered = false; + static bool _registered; static string _serverHost = null; Modified: trunk/plugins/IR Server Suite/Applications/IR Server/IR Server.csproj =================================================================== --- trunk/plugins/IR Server Suite/Applications/IR Server/IR Server.csproj 2007-10-04 20:30:23 UTC (rev 974) +++ trunk/plugins/IR Server Suite/Applications/IR Server/IR Server.csproj 2007-10-05 14:43:44 UTC (rev 975) @@ -120,6 +120,9 @@ <ItemGroup> <Content Include="Icon.ico" /> <Content Include="Icon16.ico" /> + <Content Include="IRServer.exe.manifest"> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + </Content> </ItemGroup> <ItemGroup> <EmbeddedResource Include="Advanced.resx"> Added: trunk/plugins/IR Server Suite/Applications/IR Server/IRServer.exe.manifest =================================================================== --- trunk/plugins/IR Server Suite/Applications/IR Server/IRServer.exe.manifest (rev 0) +++ trunk/plugins/IR Server Suite/Applications/IR Server/IRServer.exe.manifest 2007-10-05 14:43:44 UTC (rev 975) @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="utf-8" ?> +<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" > + <assemblyIdentity version="1.0.3.4" processorArchitecture="X86" name="IRServer" type="win32" /> + <description>Provides multiple connections for local and network access to a remote control transceiver</description> + <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3"> + <security> + <requestedPrivileges> + <requestedExecutionLevel level="requireAdministrator" /> + </requestedPrivileges> + </security> + </trustInfo> +</assembly> Modified: trunk/plugins/IR Server Suite/Applications/IR Server/Program.cs =================================================================== --- trunk/plugins/IR Server Suite/Applications/IR Server/Program.cs 2007-10-04 20:30:23 UTC (rev 974) +++ trunk/plugins/IR Server Suite/Applications/IR Server/Program.cs 2007-10-05 14:43:44 UTC (rev 975) @@ -164,8 +164,23 @@ List<string> receivers = new List<string>(); foreach (IRServerPluginBase plugin in plugins) - if ((plugin is IRemoteReceiver || plugin is IKeyboardReceiver || plugin is IMouseReceiver) && plugin.Detect()) - receivers.Add(plugin.Name); + { + try + { + if ((plugin is IRemoteReceiver || plugin is IKeyboardReceiver || plugin is IMouseReceiver) && plugin.Detect()) + receivers.Add(plugin.Name); + } +#if TRACE + catch (Exception ex) + { + Trace.WriteLine("IRServer: " + ex.ToString()); + } +#else + catch + { + } +#endif + } if (receivers.Count > 0) return receivers.ToArray(); Modified: trunk/plugins/IR Server Suite/Applications/IR Server/Properties/AssemblyInfo.cs =================================================================== --- trunk/plugins/IR Server Suite/Applications/IR Server/Properties/AssemblyInfo.cs 2007-10-04 20:30:23 UTC (rev 974) +++ trunk/plugins/IR Server Suite/Applications/IR Server/Properties/AssemblyInfo.cs 2007-10-05 14:43:44 UTC (rev 975) @@ -2,7 +2,7 @@ using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -//using System.Security.Permissions; +using System.Security.Permissions; // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information @@ -39,4 +39,4 @@ [assembly: CLSCompliant(true)] -//[assembly: SecurityPermission(SecurityAction.RequestMinimum, UnmanagedCode = true)] +[assembly: SecurityPermission(SecurityAction.RequestMinimum, Unrestricted = true)] Modified: trunk/plugins/IR Server Suite/Applications/Translator/Forms/MacroEditor.cs =================================================================== --- trunk/plugins/IR Server Suite/Applications/Translator/Forms/MacroEditor.cs 2007-10-04 20:30:23 UTC (rev 974) +++ trunk/plugins/IR Server Suite/Applications/Translator/Forms/MacroEditor.cs 2007-10-05 14:43:44 UTC (rev 975) @@ -67,7 +67,11 @@ comboBoxCommands.Items.Add(Common.UITextHibernate); comboBoxCommands.Items.Add(Common.UITextReboot); comboBoxCommands.Items.Add(Common.UITextShutdown); - + + string[] macroList = Program.GetMacroList(true); + if (macroList != null && macroList.Length > 0) + comboBoxCommands.Items.AddRange(macroList); + string[] irList = Common.GetIRList(true); if (irList != null && irList.Length > 0) comboBoxCommands.Items.AddRange(irList); @@ -93,8 +97,13 @@ { writer.WriteStartElement("action"); - if (item.StartsWith(Common.CmdPrefixBlast)) + if (item.StartsWith(Common.CmdPrefixMacro)) { + writer.WriteAttributeString("command", Common.XmlTagMacro); + writer.WriteAttributeString("cmdproperty", item.Substring(Common.CmdPrefixMacro.Length)); + } + else if (item.StartsWith(Common.CmdPrefixBlast)) + { writer.WriteAttributeString("command", Common.XmlTagBlast); writer.WriteAttributeString("cmdproperty", item.Substring(Common.CmdPrefixBlast.Length)); } @@ -193,6 +202,10 @@ switch (item.Attributes["command"].Value) { + case Common.XmlTagMacro: + listBoxMacro.Items.Add(Common.CmdPrefixMacro + commandProperty); + break; + case Common.XmlTagBlast: listBoxMacro.Items.Add(Common.CmdPrefixBlast + commandProperty); break; @@ -332,6 +345,10 @@ if (blastCommand.ShowDialog(this) == DialogResult.OK) listBoxMacro.Items.Add(Common.CmdPrefixBlast + blastCommand.CommandString); } + else if (selected.StartsWith(Common.CmdPrefixMacro)) + { + listBoxMacro.Items.Add(selected); + } else { throw new ApplicationException(String.Format("Unknown command in macro command list \"{0}\"", selected)); Modified: trunk/plugins/IR Server Suite/Applications/Translator/Program.cs =================================================================== --- trunk/plugins/IR Server Suite/Applications/Translator/Program.cs 2007-10-04 20:30:23 UTC (rev 974) +++ trunk/plugins/IR Server Suite/Applications/Translator/Program.cs 2007-10-05 14:43:44 UTC (rev 975) @@ -33,13 +33,13 @@ #region Variables - static Client _client = null; + static Client _client; static Configuration _config; static string _learnIRFilename = null; - static bool _registered = false; + static bool _registered; static bool _firstConnection = true; @@ -52,6 +52,8 @@ //static Thread _focusWatcher; static IntPtr _currentForegroundWindow = IntPtr.Zero; + static List<string> _macroStack; + #endregion Variables #region Properties @@ -290,7 +292,7 @@ { UpdateForegroundWindow(); - //Program._mainForm.Focus(); + //_mainForm.Focus(); _notifyIcon.ContextMenuStrip.Show(Screen.PrimaryScreen.Bounds.Width / 4, Screen.PrimaryScreen.Bounds.Height / 4); @@ -433,13 +435,10 @@ { IntPtr result; Win32.SendMessageTimeout(hWnd, (int)msg, new IntPtr(wParam), new IntPtr(lParam), Win32.SendMessageTimeoutFlags.SMTO_ABORTIFHUNG, 1000, out result); + int lastError = Marshal.GetLastWin32Error(); - if (result == IntPtr.Zero) - { - int lastError = Marshal.GetLastWin32Error(); - if (lastError != 0) - throw new Win32Exception(lastError); - } + if (result == IntPtr.Zero && lastError != 0) + throw new Win32Exception(lastError); return true; } @@ -500,11 +499,11 @@ if (menuItem == null) return; - string fileName = Program.FolderMacros + menuItem.Text + Common.FileExtensionMacro; + string fileName = FolderMacros + menuItem.Text + Common.FileExtensionMacro; try { - Program.ProcessMacro(fileName); + ProcessMacro(fileName); } catch (Exception ex) { @@ -990,7 +989,6 @@ Win32.ExitWindowsEx(Win32.ExitWindows.ShutDown | Win32.ExitWindows.ForceIfHung, Win32.ShutdownReasons.FlagUserDefined); } - static void MapEvent(MappingEvent theEvent) { if (_inConfiguration) @@ -1023,108 +1021,162 @@ } } + static void MacroStackAdd(string fileName) + { + string lowerCasedFileName = fileName.ToLowerInvariant(); + + if (_macroStack == null) + { + _macroStack = new List<string>(); + } + else if (_macroStack.Contains(lowerCasedFileName)) + { + StringBuilder macroStackTrace = new StringBuilder(); + macroStackTrace.AppendLine("Macro infinite loop detected!"); + macroStackTrace.AppendLine(); + macroStackTrace.AppendLine("Stack trace:"); + + foreach (string macro in _macroStack) + { + if (macro.Equals(lowerCasedFileName)) + macroStackTrace.AppendLine(String.Format("--> {0}", macro)); + else + macroStackTrace.AppendLine(macro); + } + + macroStackTrace.AppendLine(String.Format("--> {0}", lowerCasedFileName)); + + throw new ApplicationException(macroStackTrace.ToString()); + } + + _macroStack.Add(lowerCasedFileName); + } + static void MacroStackRemove(string fileName) + { + string lowerCasedFileName = fileName.ToLowerInvariant(); + + if (_macroStack.Contains(lowerCasedFileName)) + _macroStack.Remove(lowerCasedFileName); + + if (_macroStack.Count == 0) + _macroStack = null; + } + /// <summary> /// Process the supplied Macro file. /// </summary> /// <param name="fileName">Macro file to process (absolute path).</param> internal static void ProcessMacro(string fileName) { - XmlDocument doc = new XmlDocument(); - doc.Load(fileName); + MacroStackAdd(fileName); - if (doc.DocumentElement.InnerText.Contains(Common.XmlTagBlast) && !_registered) - throw new ApplicationException("Cannot process Macro with Blast commands when not registered to an active IR Server"); + try + { + XmlDocument doc = new XmlDocument(); + doc.Load(fileName); - XmlNodeList commandSequence = doc.DocumentElement.SelectNodes("action"); - string commandProperty; - string commandName; + if (doc.DocumentElement.InnerText.Contains(Common.XmlTagBlast) && !_registered) + throw new ApplicationException("Cannot process Macro with Blast commands when not registered to an active IR Server"); - foreach (XmlNode item in commandSequence) - { - commandName = item.Attributes["command"].Value; - commandProperty = item.Attributes["cmdproperty"].Value; + XmlNodeList commandSequence = doc.DocumentElement.SelectNodes("action"); + string commandProperty; - switch (commandName) + foreach (XmlNode item in commandSequence) { - case Common.XmlTagBlast: - { - string[] commands = Common.SplitBlastCommand(commandProperty); - BlastIR(Common.FolderIRCommands + commands[0] + Common.FileExtensionIR, commands[1]); - break; - } + commandProperty = item.Attributes["cmdproperty"].Value; - case Common.XmlTagPause: - { - int sleep = int.Parse(commandProperty); - Thread.Sleep(sleep); - break; - } + switch (item.Attributes["command"].Value) + { + case Common.XmlTagMacro: + { + ProcessMacro(FolderMacros + commandProperty + Common.FileExtensionMacro); + break; + } - case Common.XmlTagRun: - { - string[] commands = Common.SplitRunCommand(commandProperty); - Common.ProcessRunCommand(commands); - break; - } + case Common.XmlTagBlast: + { + string[] commands = Common.SplitBlastCommand(commandProperty); + BlastIR(Common.FolderIRCommands + commands[0] + Common.FileExtensionIR, commands[1]); + break; + } - case Common.XmlTagSerial: - { - string[] commands = Common.SplitSerialCommand(commandProperty); - Common.ProcessSerialCommand(commands); - break; - } + case Common.XmlTagPause: + { + int sleep = int.Parse(commandProperty); + Thread.Sleep(sleep); + break; + } - case Common.XmlTagWindowMsg: - { - string[] commands = Common.SplitWindowMessageCommand(commandProperty); - Common.ProcessWindowMessageCommand(commands); - break; - } + case Common.XmlTagRun: + { + string[] commands = Common.SplitRunCommand(commandProperty); + Common.ProcessRunCommand(commands); + break; + } - case Common.XmlTagTcpMsg: - { - string[] commands = Common.SplitTcpMessageCommand(commandProperty); - Common.ProcessTcpMessageCommand(commands); - break; - } + case Common.XmlTagSerial: + { + string[] commands = Common.SplitSerialCommand(commandProperty); + Common.ProcessSerialCommand(commands); + break; + } - case Common.XmlTagKeys: - { - Common.ProcessKeyCommand(commandProperty); - break; - } + case Common.XmlTagWindowMsg: + { + string[] commands = Common.SplitWindowMessageCommand(commandProperty); + Common.ProcessWindowMessageCommand(commands); + break; + } - case Common.XmlTagEject: - { - Common.ProcessEjectCommand(commandProperty); - break; - } + case Common.XmlTagTcpMsg: + { + string[] commands = Common.SplitTcpMessageCommand(commandProperty); + Common.ProcessTcpMessageCommand(commands); + break; + } - case Common.XmlTagStandby: - { - Standby(); - break; - } + case Common.XmlTagKeys: + { + Common.ProcessKeyCommand(commandProperty); + break; + } - case Common.XmlTagHibernate: - { - Hibernate(); - break; - } + case Common.XmlTagEject: + { + Common.ProcessEjectCommand(commandProperty); + break; + } - case Common.XmlTagShutdown: - { - ShutDown(); - break; - } + case Common.XmlTagStandby: + { + Standby(); + break; + } - case Common.XmlTagReboot: - { - Reboot(); - break; - } + case Common.XmlTagHibernate: + { + Hibernate(); + break; + } + + case Common.XmlTagShutdown: + { + ShutDown(); + break; + } + + case Common.XmlTagReboot: + { + Reboot(); + break; + } + } } } + finally + { + MacroStackRemove(fileName); + } } /// <summary> Modified: trunk/plugins/IR Server Suite/Common/IrssUtils/Common.cs =================================================================== --- trunk/plugins/IR Server Suite/Common/IrssUtils/Common.cs 2007-10-04 20:30:23 UTC (rev 974) +++ trunk/plugins/IR Server Suite/Common/IrssUtils/Common.cs 2007-10-05 14:43:44 UTC (rev 975) @@ -1,6 +1,7 @@ using System; using System.Collections; using System.Collections.Generic; +using System.ComponentModel; using System.Diagnostics; using System.IO; using System.IO.Ports; @@ -115,6 +116,7 @@ #region XML Tags + public const string XmlTagMacro = "MACRO"; public const string XmlTagBlast = "BLAST"; public const string XmlTagPause = "PAUSE"; public const string XmlTagRun = "RUN"; @@ -427,7 +429,7 @@ int lastError = Marshal.GetLastWin32Error(); if (result == IntPtr.Zero) - Marshal.ThrowExceptionForHR(lastError); + throw new Win32Exception(lastError); } /// <summary> Modified: trunk/plugins/IR Server Suite/Common/IrssUtils/SystemRegistry.cs =================================================================== --- trunk/plugins/IR Server Suite/Common/IrssUtils/SystemRegistry.cs 2007-10-04 20:30:23 UTC (rev 974) +++ trunk/plugins/IR Server Suite/Common/IrssUtils/SystemRegistry.cs 2007-10-05 14:43:44 UTC (rev 975) @@ -70,7 +70,7 @@ if (String.IsNullOrEmpty(name)) throw new ArgumentNullException("name"); - Registry.SetValue(AutoRunPath, name, null); + Registry.SetValue(AutoRunPath, name, String.Empty, RegistryValueKind.String); } #endregion Methods Modified: trunk/plugins/IR Server Suite/IR Server Plugins/FusionRemote Receiver/FusionRemoteReceiver.cs =================================================================== --- trunk/plugins/IR Server Suite/IR Server Plugins/FusionRemote Receiver/FusionRemoteReceiver.cs 2007-10-04 20:30:23 UTC (rev 974) +++ trunk/plugins/IR Server Suite/IR Server Plugins/FusionRemote Receiver/FusionRemoteReceiver.cs 2007-10-05 14:43:44 UTC (rev 975) @@ -204,12 +204,19 @@ public override bool Detect() { - Guid hidGuid = new Guid(); - HidD_GetHidGuid(ref hidGuid); + try + { + Guid hidGuid = new Guid(); + HidD_GetHidGuid(ref hidGuid); - string devicePath = FindDevice(hidGuid, DeviceID); + string devicePath = FindDevice(hidGuid, DeviceID); - return (devicePath != null); + return (devicePath != null); + } + catch + { + return false; + } } public override bool Start() Modified: trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/Advanced.cs =================================================================== --- trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/Advanced.cs 2007-10-04 20:30:23 UTC (rev 974) +++ trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/Advanced.cs 2007-10-05 14:43:44 UTC (rev 975) @@ -12,18 +12,20 @@ namespace MicrosoftMceTransceiver { + [RegistryPermission(SecurityAction.Demand, + Read = "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\HidIr", + Write = "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\HidIr")] partial class Advanced : Form { #region Constants - const string HidIrRegKey = "SYSTEM\\CurrentControlSet\\Services\\HidIr"; + const string RegKey = "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\HidIr"; + const string RegValue = "Start"; - const string StartValue = "Start"; + const int SetEnabled = 3; + const int SetDisabled = 4; - const int HidIrEnabled = 3; - const int HidIrDisabled = 4; - #endregion Constants #region Constructor @@ -32,46 +34,42 @@ { InitializeComponent(); - using (RegistryKey regKey = Registry.LocalMachine.CreateSubKey(HidIrRegKey)) - { - if ((int)regKey.GetValue(StartValue, HidIrDisabled) == HidIrDisabled) - radioButtonDisabled.Checked = true; - else - radioButtonEnabled.Checked = true; - } + int currentValue = (int)Registry.GetValue(RegKey, RegValue, SetDisabled); + + if (currentValue == SetDisabled) + radioButtonDisabled.Checked = true; + else + radioButtonEnabled.Checked = true; } #endregion Constructor private void buttonOK_Click(object sender, EventArgs e) { - using (RegistryKey regKey = Registry.LocalMachine.CreateSubKey(HidIrRegKey)) - { - int currentValue = (int)regKey.GetValue(StartValue, HidIrDisabled); + int currentValue = (int)Registry.GetValue(RegKey, RegValue, SetDisabled); - bool changedValue = false; + bool changedValue = false; - if (radioButtonEnabled.Checked) + if (radioButtonEnabled.Checked) + { + if (currentValue == SetDisabled) { - if (currentValue == HidIrDisabled) - { - regKey.SetValue(StartValue, HidIrEnabled); - changedValue = true; - } + Registry.SetValue(RegKey, RegValue, SetEnabled, RegistryValueKind.DWord); + changedValue = true; } - else if (radioButtonDisabled.Checked) + } + else if (radioButtonDisabled.Checked) + { + if (currentValue != SetDisabled) { - if (currentValue != HidIrDisabled) - { - regKey.SetValue(StartValue, HidIrDisabled); - changedValue = true; - } + Registry.SetValue(RegKey, RegValue, SetDisabled, RegistryValueKind.DWord); + changedValue = true; } - - if (changedValue) - MessageBox.Show(this, "You must reboot for changes to take effect", "Reboot required", MessageBoxButtons.OK, MessageBoxIcon.Information); } + if (changedValue) + MessageBox.Show(this, "You must reboot for changes to take effect", "Reboot required", MessageBoxButtons.OK, MessageBoxIcon.Information); + this.Close(); } Modified: trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/DriverVista.cs =================================================================== --- trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/DriverVista.cs 2007-10-04 20:30:23 UTC (rev 974) +++ trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/DriverVista.cs 2007-10-05 14:43:44 UTC (rev 975) @@ -611,14 +611,14 @@ _learningCode = null; return status; } - + public override void Send(IrCode code, uint port) { byte[] data = DataPacket(code); TransmitIR(data, code.Carrier, port); } - + #endregion Driver overrides #region Implementation Modified: trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/MicrosoftMceTransceiver.cs =================================================================== --- trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/MicrosoftMceTransceiver.cs 2007-10-04 20:30:23 UTC (rev 974) +++ trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/MicrosoftMceTransceiver.cs 2007-10-05 14:43:44 UTC (rev 975) @@ -116,10 +116,17 @@ public override bool Detect() { - Guid deviceGuid; - string devicePath; + try + { + Guid deviceGuid; + string devicePath; - return FindDevice(out deviceGuid, out devicePath); + return FindDevice(out deviceGuid, out devicePath); + } + catch + { + return false; + } } public override bool Start() Modified: trunk/plugins/IR Server Suite/IR Server Plugins/USB-UIRT Transceiver/UirtTransceiver.cs =================================================================== --- trunk/plugins/IR Server Suite/IR Server Plugins/USB-UIRT Transceiver/UirtTransceiver.cs 2007-10-04 20:30:23 UTC (rev 974) +++ trunk/plugins/IR Server Suite/IR Server Plugins/USB-UIRT Transceiver/UirtTransceiver.cs 2007-10-05 14:43:44 UTC (rev 975) @@ -125,7 +125,9 @@ return true; } } - catch { } + catch + { + } return false; } Modified: trunk/plugins/IR Server Suite/IR Server Plugins/WinLirc Transceiver/WinLirc Transceiver.cs =================================================================== --- trunk/plugins/IR Server Suite/IR Server Plugins/WinLirc Transceiver/WinLirc Transceiver.cs 2007-10-04 20:30:23 UTC (rev 974) +++ trunk/plugins/IR Server Suite/IR Server Plugins/WinLirc Transceiver/WinLirc Transceiver.cs 2007-10-05 14:43:44 UTC (rev 975) @@ -46,7 +46,14 @@ public override bool Detect() { - return WinLircServer.IsServerRunning(); + try + { + return WinLircServer.IsServerRunning(); + } + catch + { + return false; + } } public override bool Start() Modified: trunk/plugins/IR Server Suite/IR Server Plugins/X10 Transceiver/X10Transceiver.cs =================================================================== --- trunk/plugins/IR Server Suite/IR Server Plugins/X10 Transceiver/X10Transceiver.cs 2007-10-04 20:30:23 UTC (rev 974) +++ trunk/plugins/IR Server Suite/IR Server Plugins/X10 Transceiver/X10Transceiver.cs 2007-10-05 14:43:44 UTC (rev 975) @@ -48,19 +48,18 @@ try { test = new X10Interface(); - if (test == null) - return false; + if (test != null) + return true; } catch { - return false; } finally { test = null; } - return true; + return false; } public override bool Start() Modified: trunk/plugins/IR Server Suite/IR Server Plugins/XBCDRC Receiver/XBCDRC Receiver.cs =================================================================== --- trunk/plugins/IR Server Suite/IR Server Plugins/XBCDRC Receiver/XBCDRC Receiver.cs 2007-10-04 20:30:23 UTC (rev 974) +++ trunk/plugins/IR Server Suite/IR Server Plugins/XBCDRC Receiver/XBCDRC Receiver.cs 2007-10-05 14:43:44 UTC (rev 975) @@ -204,12 +204,19 @@ public override bool Detect() { - Guid guid = new Guid(); - HidD_GetHidGuid(ref guid); + try + { + Guid guid = new Guid(); + HidD_GetHidGuid(ref guid); - string devicePath = FindDevice(guid); + string devicePath = FindDevice(guid); - return (devicePath != null); + return (devicePath != null); + } + catch + { + return false; + } } public override bool Start() Modified: trunk/plugins/IR Server Suite/MediaPortal Plugins/MP Blast Zone Plugin/Forms/MacroEditor.cs =================================================================== --- trunk/plugins/IR Server Suite/MediaPortal Plugins/MP Blast Zone Plugin/Forms/MacroEditor.cs 2007-10-04 20:30:23 UTC (rev 974) +++ trunk/plugins/IR Server Suite/MediaPortal Plugins/MP Blast Zone Plugin/Forms/MacroEditor.cs 2007-10-05 14:43:44 UTC (rev 975) @@ -73,9 +73,9 @@ comboBoxCommands.Items.Add(Common.UITextReboot); comboBoxCommands.Items.Add(Common.UITextShutdown); - string[] irList = Common.GetIRList(true); - if (irList != null && irList.Length > 0) - comboBoxCommands.Items.AddRange(irList); + string[] fileList = MPBlastZonePlugin.GetFileList(true); + if (fileList != null && fileList.Length > 0) + comboBoxCommands.Items.AddRange(fileList); } /// <summary> @@ -98,8 +98,13 @@ { writer.WriteStartElement("action"); - if (item.StartsWith(Common.CmdPrefixBlast)) + if (item.StartsWith(Common.CmdPrefixMacro)) { + writer.WriteAttributeString("command", Common.XmlTagMacro); + writer.WriteAttributeString("cmdproperty", item.Substring(Common.CmdPrefixMacro.Length)); + } + else if (item.StartsWith(Common.CmdPrefixBlast)) + { writer.WriteAttributeString("command", Common.XmlTagBlast); writer.WriteAttributeString("cmdproperty", item.Substring(Common.CmdPrefixBlast.Length)); } @@ -134,11 +139,11 @@ writer.WriteAttributeString("cmdproperty", item.Substring(Common.CmdPrefixPopup.Length)); } /* - else if (item.StartsWith(Common.CmdPrefixWindowState)) - { - writer.WriteAttributeString("command", Common.XmlTagWindowState); - writer.WriteAttributeString("cmdproperty", String.Empty); - } + else if (item.StartsWith(Common.CmdPrefixWindowState)) + { + writer.WriteAttributeString("command", Common.XmlTagWindowState); + writer.WriteAttributeString("cmdproperty", String.Empty); + } */ else if (item.StartsWith(Common.CmdPrefixFocus)) { @@ -210,6 +215,10 @@ switch (item.Attributes["command"].Value) { + case Common.XmlTagMacro: + listBoxMacro.Items.Add(Common.CmdPrefixMacro + commandProperty); + break; + case Common.XmlTagBlast: listBoxMacro.Items.Add(Common.CmdPrefixBlast + commandProperty); break; @@ -323,10 +332,10 @@ listBoxMacro.Items.Add(Common.CmdPrefixPopup + popupMessage.CommandString); } /* - else if (selected == Common.UITextWindowState) - { - listBoxMacro.Items.Add(Common.CmdPrefixWindowState); - } + else if (selected == Common.UITextWindowState) + { + listBoxMacro.Items.Add(Common.CmdPrefixWindowState); + } */ else if (selected == Common.UITextFocus) { @@ -363,6 +372,10 @@ if (blastCommand.ShowDialog(this) == DialogResult.OK) listBoxMacro.Items.Add(Common.CmdPrefixBlast + blastCommand.CommandString); } + else if (selected.StartsWith(Common.CmdPrefixMacro)) + { + listBoxMacro.Items.Add(selected); + } else { throw new ApplicationException(String.Format("Unknown command in macro command list \"{0}\"", selected)); Modified: trunk/plugins/IR Server Suite/MediaPortal Plugins/MP Blast Zone Plugin/MPBlastZonePlugin.cs =================================================================== --- trunk/plugins/IR Server Suite/MediaPortal Plugins/MP Blast Zone Plugin/MPBlastZonePlugin.cs 2007-10-04 20:30:23 UTC (rev 974) +++ trunk/plugins/IR Server Suite/MediaPortal Plugins/MP Blast Zone Plugin/MPBlastZonePlugin.cs 2007-10-05 14:43:44 UTC (rev 975) @@ -72,6 +72,8 @@ static IRServerInfo _irServerInfo = new IRServerInfo(); + static List<string> _macroStack; + #endregion Variables #region Properties @@ -505,180 +507,236 @@ } } + static void MacroStackAdd(string fileName) + { + string lowerCasedFileName = fileName.ToLowerInvariant(); + + if (_macroStack == null) + { + _macroStack = new List<string>(); + } + else if (_macroStack.Contains(lowerCasedFileName)) + { + StringBuilder macroStackTrace = new StringBuilder(); + macroStackTrace.AppendLine("Macro infinite loop detected!"); + macroStackTrace.AppendLine(); + macroStackTrace.AppendLine("Stack trace:"); + + foreach (string macro in _macroStack) + { + if (macro.Equals(lowerCasedFileName)) + macroStackTrace.AppendLine(String.Format("--> {0}", macro)); + else + macroStackTrace.AppendLine(macro); + } + + macroStackTrace.AppendLine(String.Format("--> {0}", lowerCasedFileName)); + + throw new ApplicationException(macroStackTrace.ToString()); + } + + _macroStack.Add(lowerCasedFileName); + } + static void MacroStackRemove(string fileName) + { + string lowerCasedFileName = fileName.ToLowerInvariant(); + + if (_macroStack.Contains(lowerCasedFileName)) + _macroStack.Remove(lowerCasedFileName); + + if (_macroStack.Count == 0) + _macroStack = null; + } + /// <summary> /// Process the supplied Macro file. /// </summary> /// <param name="fileName">Macro file to process (absolute path).</param> internal static void ProcessMacro(string fileName) { - XmlDocument doc = new XmlDocument(); - doc.Load(fileName); + MacroStackAdd(fileName); - XmlNodeList commandSequence = doc.DocumentElement.SelectNodes("action"); - string commandProperty; - string commandName; - - foreach (XmlNode item in commandSequence) + try { - commandName = item.Attributes["command"].Value; - commandProperty = item.Attributes["cmdproperty"].Value; + XmlDocument doc = new XmlDocument(); + doc.Load(fileName); - switch (commandName) + XmlNodeList commandSequence = doc.DocumentElement.SelectNodes("action"); + string commandProperty; + string commandName; + + foreach (XmlNode item in commandSequence) { - case Common.XmlTagBlast: - { - string[] commands = Common.SplitBlastCommand(commandProperty); - BlastIR(Common.FolderIRCommands + commands[0] + Common.FileExtensionIR, commands[1]); - break; - } + commandName = item.Attributes["command"].Value; + commandProperty = item.Attributes["cmdproperty"].Value; - case Common.XmlTagPause: - { - int sleep = int.Parse(commandProperty); - Thread.Sleep(sleep); - break; - } + switch (commandName) + { + case Common.XmlTagMacro: + { + ProcessMacro(FolderMacros + commandProperty + Common.FileExtensionMacro); + break; + } - case Common.XmlTagRun: - { - string[] commands = Common.SplitRunCommand(commandProperty); - Common.ProcessRunCommand(commands); - break; - } + case Common.XmlTagBlast: + { + string[] commands = Common.SplitBlastCommand(commandProperty); + BlastIR(Common.FolderIRCommands + commands[0] + Common.FileExtensionIR, commands[1]); + break; + } - case Common.XmlTagSerial: - { - string[] commands = Common.SplitSerialCommand(commandProperty); - Common.ProcessSerialCommand(commands); - break; - } + case Common.XmlTagPause: + { + int sleep = int.Parse(commandProperty); + Thread.Sleep(sleep); + break; + } - case Common.XmlTagGoto: - { - if (InConfiguration) - MessageBox.Show(commandProperty, "Go To Window", MessageBoxButtons.OK, MessageBoxIcon.Information); - else - MPCommands.ProcessGoTo(commandProperty, MP_BasicHome); - break; - } + case Common.XmlTagRun: + { + string[] commands = Common.SplitRunCommand(commandProperty); + Common.ProcessRunCommand(commands); + break; + } - case Common.XmlTagPopup: - { - string[] commands = Common.SplitPopupCommand(commandProperty); + case Common.XmlTagSerial: + { + string[] commands = Common.SplitSerialCommand(commandProperty); + Common.ProcessSerialCommand(commands); + break; + } - if (InConfiguration) - MessageBox.Show(commands[1], commands[0], MessageBoxButtons.OK, MessageBoxIcon.Information); - else - MPCommands.ShowNotifyDialog(commands[0], commands[1], int.Parse(commands[2])); + case Common.XmlTagGoto: + { + if (InConfiguration) + MessageBox.Show(commandProperty, "Go To Window", MessageBoxButtons.OK, MessageBoxIcon.Information); + else + MPCommands.ProcessGoTo(commandProperty, MP_BasicHome); + break; + } - break; - } + case Common.XmlTagPopup: + { + string[] commands = Common.SplitPopupCommand(commandProperty); - case Common.XmlTagWindowMsg: - { - string[] commands = Common.SplitWindowMessageCommand(commandProperty); - Common.ProcessWindowMessageCommand(commands); - break; - } + if (InConfiguration) + MessageBox.Show(commands[1], commands[0], MessageBoxButtons.OK, MessageBoxIcon.Information); + else + MPCommands.ShowNotifyDialog(commands[0], commands[1], int.Parse(commands[2])); - /* - case Common.XmlTagWindowState: - { - if (InConfiguration) - { - MessageBox.Show("Command to toggle the window state cannot be processed in configuration.", "Window State Toggle Command", MessageBoxButtons.OK, MessageBoxIcon.Information); - break; - } + break; + } - GUIMessage msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_SWITCH_FULL_WINDOWED, 0, 0, 0, 0, 0, null); - - if (GUIGraphicsContext.DX9Device.PresentationParameters.Windowed) - msg.Param1 = 1; - - GUIWindowManager.SendMessage(msg); - break; - } - */ - case Common.XmlTagFocus: - { - if (InConfiguration) + case Common.XmlTagWindowMsg: { - MessageBox.Show("Command to get focus cannot be processed in configuration.", "Get Focus Command", MessageBoxButtons.OK, MessageBoxIcon.Information); + string[] commands = Common.SplitWindowMessageCommand(commandProperty); + Common.ProcessWindowMessageCommand(commands); break; } - GUIGraphicsContext.ResetLastActivity(); - GUIMessage msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_GETFOCUS, 0, 0, 0, 0, 0, null); - GUIWindowManager.SendThreadMessage(msg); - break; - } + /* + case Common.XmlTagWindowState: + { + if (InConfiguration) + { + MessageBox.Show("Command to toggle the window state cannot be processed in configuration.", "Window State Toggle Command", MessageBoxButtons.OK, MessageBoxIcon.Information); + break; + } - case Common.XmlTagExit: - { - if (!InConfiguration) - GUIGraphicsContext.OnAction(new Action(Action.ActionType.ACTION_EXIT, 0, 0)); - break; - } + GUIMessage msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_SWITCH_FULL_WINDOWED, 0, 0, 0, 0, 0, null); - case Common.XmlTagStandby: - { - if (!InConfiguration) + if (GUIGraphicsContext.DX9Device.PresentationParameters.Windowed) + msg.Param1 = 1; + + GUIWindowManager.SendMessage(msg); + break; + } + */ + case Common.XmlTagFocus: { + if (InConfiguration) + { + MessageBox.Show("Command to get focus cannot be processed in configuration.", "Get Focus Command", MessageBoxButtons.OK, MessageBoxIcon.Information); + break; + } + GUIGraphicsContext.ResetLastActivity(); - // Stop all media before suspending or hibernating - g_Player.Stop(); + GUIMessage msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_GETFOCUS, 0, 0, 0, 0, 0, null); + GUIWindowManager.SendThreadMessage(msg); + break; + } - GUIMessage msg; + case Common.XmlTagExit: + { + if (!InConfiguration) + GUIGraphicsContext.OnAction(new Action(Action.ActionType.ACTION_EXIT, 0, 0)); + break; + } - if (_mpBasicHome) - msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_GOTO_WINDOW, 0, 0, 0, (int)GUIWindow.Window.WINDOW_SECOND_HOME, 0, null); - else - msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_GOTO_WINDOW, 0, 0, 0, (int)GUIWindow.Window.WINDOW_HOME, 0, null); + case Common.XmlTagStandby: + { + if (!InConfiguration) + { + GUIGraphicsContext.ResetLastActivity(); + // Stop all media before suspending or hibernating + g_Player.Stop(); - GUIWindowManager.SendThreadMessage(msg); + GUIMessage msg; - WindowsController.ExitWindows(RestartOptions.Suspend, true); + if (_mpBasicHome) + msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_GOTO_WINDOW, 0, 0, 0, (int)GUIWindow.Window.WINDOW_SECOND_HOME, 0, null); + else + msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_GOTO_WINDOW, 0, 0, 0, (int)GUIWindow.Window.WINDOW_HOME, 0, null); + + GUIWindowManager.SendThreadMessage(msg); + + WindowsController.ExitWindows(RestartOptions.Suspend, true); + } + break; } - break; - } - case Common.XmlTagHibernate: - { - if (!InConfiguration) + case Common.XmlTagHibernate: { - GUIGraphicsContext.ResetLastActivity(); - // Stop all media before suspending or hibernating - g_Player.Stop(); + if (!InConfiguration) + { + GUIGraphicsContext.ResetLastActivity(); + // Stop all media before suspending or hibernating + g_Player.Stop(); - GUIMessage msg; + GUIMessage msg; - if (_mpBasicHome) - msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_GOTO_WINDOW, 0, 0, 0, (int)GUIWindow.Window.WINDOW_SECOND_HOME, 0, null); - else - msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_GOTO_WINDOW, 0, 0, 0, (int)GUIWindow.Window.WINDOW_HOME, 0, null); + if (_mpBasicHome) + msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_GOTO_WINDOW, 0, 0, 0, (int)GUIWindow.Window.WINDOW_SECOND_HOME, 0, null); + else + msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_GOTO_WINDOW, 0, 0, 0, (int)GUIWindow.Window.WINDOW_HOME, 0, null); - GUIWindowManager.SendThreadMessage(msg); + GUIWindowManager.SendThreadMessage(msg); - WindowsController.ExitWindows(RestartOptions.Hibernate, true); + WindowsController.ExitWindows(RestartOptions.Hibernate, true); + } + break; } - break; - } - case Common.XmlTagReboot: - { - if (!InConfiguration) - GUIGraphicsContext.OnAction(new Action(Action.ActionType.ACTION_REBOOT, 0, 0)); - break; - } + case Common.XmlTagReboot: + { + if (!InConfiguration) + GUIGraphicsContext.OnAction(new Action(Action.ActionType.ACTION_REBOOT, 0, 0)); + break; + } - case Common.XmlTagShutdown: - { - if (!InConfiguration) - GUIGraphicsContext.OnAction(new Action(Action.ActionType.ACTION_SHUTDOWN, 0, 0)); - break; - } + case Common.XmlTagShutdown: + { + if (!InConfiguration) + GUIGraphicsContext.OnAction(new Action(Action.ActionType.ACTION_SHUTDOWN, 0, 0)); + break; + } + } } } + finally + { + MacroStackRemove(fileName); + } } /// <summary> Modified: trunk/plugins/IR Server Suite/MediaPortal Plugins/MP Control Plugin/Forms/MacroEditor.cs =================================================================== --- trunk/plugins/IR Server Suite/MediaPortal Plugins/MP Control Plugin/Forms/MacroEditor.cs 2007-10-04 20:30:23 UTC (rev 974) +++ trunk/plugins/IR Server Suite/MediaPortal Plugins/MP Control Plugin/Forms/MacroEditor.cs 2007-10-05 14:43:44 UTC (rev 975) @@ -77,9 +77,9 @@ comboBoxCommands.Items.Add(Common.UITextReboot); comboBoxCommands.Items.Add(Common.UITextShutdown); - string[] irList = Common.GetIRList(true); - if (irList != null && irList.Length > 0) - comboBoxCommands.Items.AddRange(irList); + string[] fileList = MPControlPlugin.GetFileList(true); + if (fileList != null && fileList.Length > 0) + comboBoxCommands.Items.AddRange(fileList); } /// <summary> @@ -102,8 +102,13 @@ { writer.WriteStartElement("action"); - if (item.StartsWith(Common.CmdPrefixBlast)) + if (item.StartsWith(Common.CmdPrefixMacro)) { + writer.WriteAttributeString("command", Common.XmlTagMacro); + writer.WriteAttributeString("cmdproperty", item.Substring(Common.CmdPrefixMacro.Length)); + } + else if (item.StartsWith(Common.CmdPrefixBlast)) + { writer.WriteAttributeString("command", Common.XmlTagBlast); writer.WriteAttributeString("cmdproperty", item.Substring(Common.CmdPrefixBlast.Length)); } @@ -158,11 +163,11 @@ writer.WriteAttributeString("cmdproperty", String.Empty); } /* - else if (item.StartsWith(Common.CmdPrefixWindowState)) - { - writer.WriteAttributeString("command", Common.XmlTagWindowState); - writer.WriteAttributeString("cmdproperty", String.Empty); - } + else if (item.StartsWith(Common.CmdPrefixWindowState)) + { + writer.WriteAttributeString("command", Common.XmlTagWindowState); + writer.WriteAttributeString("cmdproperty", String.Empty); + } */ else if (item.StartsWith(Common.CmdPrefixFocus)) { @@ -234,6 +239,10 @@ switch (item.Attributes["command"].Value) { + case Common.XmlTagMacro: + listBoxMacro.Items.Add(Common.CmdPrefixMacro + commandProperty); + break; + case Common.XmlTagBlast: listBoxMacro.Items.Add(Common.CmdPrefixBlast + commandProperty); break; @@ -389,10 +398,10 @@ listBoxMacro.Items.Add(Common.CmdPrefixInputLayer); } /* - else if (selected == Common.UITextWindowState) - { - listBoxMacro.Items.Add(Common.CmdPrefixWindowState); - } + else if (selected == Common.UITextWindowState) + { + listBoxMacro.Items.Add(Common.CmdPrefixWindowState); + } */ else if (selected == Common.UITextFocus) { @@ -429,6 +438,10 @@ if (blastCommand.ShowDialog(this) == DialogResult.OK) listBoxMacro.Items.Add(Common.CmdPrefixBlast + blastCommand.CommandString); } + else if (selected.StartsWith(Common.CmdPrefixMacro)) + { + listBoxMacro.Items.Add(selected); + } else { throw new ApplicationException(String.Format("Unknown command in macro command list \"{0}\"", selected)); Modified: trunk/plugins/IR Server Suite/MediaPortal Plugins/MP Control Plugin/MPControlPlugin.cs =================================================================== --- trunk/plugins/IR Server Suite/MediaPortal Plugins/MP Control Plugin/MPControlPlugin.cs 2007-10-04 20:30:23 UTC (rev 974) +++ trunk/plugins/IR Server Suite/MediaPortal Plugins/MP Control Plugin/MPControlPlugin.cs 2007-10-05 14:43:44 UTC (rev 975) @@ -53,12 +53,12 @@ #region Variables - static Client _client = null; + static Client _client; static string _serverHost; static string _learnIRFilename = null; - static bool _registered = false; + static bool _registered; static bool _logVerbose; static bool _requireFocus; @@ -97,6 +97,8 @@ static IRServerInfo _irServerInfo = new IRServerInfo(); + static List<string> _macroStack; + #endregion Variables #region Properties @@ -1045,281 +1047,337 @@ MapEvent(MappedEvent.MappingEvent.PC_Resume); } + static void MacroStackAdd(string fileName) + { + string lowerCasedFileName = fileName.ToLowerInvariant(); + + if (_macroStack == null) + { + _macroStack = new List<string>(); + } + else if (_macroStack.Contains(lowerCasedFileName)) + { + StringBuilder macroStackTrace = new StringBuilder(); + macroStackTrace.AppendLine("Macro infinite loop detected!"); + macroStackTrace.AppendLine(); + macroStackTrace.AppendLine("Stack trace:"); + + foreach (string macro in _macroStack) + { + if (macro.Equals(lowerCasedFileName)) + macroStackTrace.AppendLine(String.Format("--> {0}", macro)); + else + macroStackTrace.AppendLine(macro); + } + + macroStackTrace.AppendLine(String.Format("--> {0}", lowerCasedFileName)); + + throw new ApplicationException(macroStackTrace.ToString()); + } + + _macroStack.Add(lowerCasedFileName); + } + static void MacroStackRemove(string fileName) + { + string lowerCasedFileName = fileName.ToLowerInvariant(); + + if (_macroStack.Contains(lowerCasedFileName)) + _macroStack.Remove(lowerCasedFileName); + + if (_macroStack.Count == 0) + _macroStack = null; + } + /// <summary> /// Process the supplied Macro file. /// </summary> /// <param name="fileName">Macro file to process (absolute path).</param> internal static void ProcessMacro(string fileName) { - XmlDocument doc = new XmlDocument(); - doc.Load(fileName); + MacroStackAdd(fileName); - XmlNodeList commandSequence = doc.DocumentElement.SelectNodes("action"); - string commandProperty; - string commandName; - - foreach (XmlNode item in commandSequence) + try { - commandName = item.Attributes["command"].Value; - commandProperty = item.Attributes["cmdproperty"].Value; + XmlDocument doc = new XmlDocument(); + doc.Load(fileName); - switch (commandName) + XmlNodeList commandSequence = doc.DocumentElement.SelectNodes("action"); + string commandProperty; + string commandName; + + foreach (XmlNode item in commandSequence) { - case Common.XmlTagBlast: - { - string[] commands = Common.SplitBlastCommand(commandProperty); - BlastIR(Common.FolderIRCommands + commands[0] + Common.FileExtensionIR, commands[1]); - break; - } + commandName = item.Attributes["command"].Value; + commandProperty = item.Attributes["cmdproperty"].Value; - case Common.XmlTagPause: - { - int sleep = int.Parse(commandProperty); - Thread.Sleep(sleep); - break; - } + switch (commandName) + { + case Common.XmlTagMacro: + { + ProcessMacro(FolderMacros + commandProperty + Common.FileExtensionMacro); + break; + } - case Common.XmlTagRun: - { - string[] commands = Common.SplitRunCommand(commandProperty); - Common.ProcessRunCommand(commands); - break; - } + case Common.XmlTagBlast: + { + string[] commands = Common.SplitBlastCommand(commandProperty); + BlastIR(Common.FolderIRCommands + commands[0] + Common.FileExtensionIR, commands[1]); + break; + } - case Common.XmlTagSerial: - { - string[] commands = Common.SplitSerialCommand(commandProperty); - Common.ProcessSerialCommand(commands); - break; - } + case Common.XmlTagPause: + { + int sleep = int.Parse(commandProperty); + Thread.Sleep(sleep); + break; + } - case Common.XmlTagGoto: - { - if (InConfiguration) - MessageBox.Show(commandProperty, "Go To Window", MessageBoxButtons.OK, MessageBoxIcon.Information); - else - MPCommands.ProcessGoTo(commandProperty, MP_BasicHome); - break; - } + case Common.XmlTagRun: + { + string[] commands = Common.SplitRunCommand(commandProperty); + Common.ProcessRunCommand(commands); + break; + } - case Common.XmlTagPopup: - { - string[] commands = Common.SplitPopupCommand(commandProperty); + case Common.XmlTagSerial: + { + string[] commands = Common.SplitSerialCommand(commandProperty); + Common.ProcessSerialCommand(commands); + break; + } - if (InConfiguration) - MessageBox.Show(commands[1], commands[0], MessageBoxButtons.OK, MessageBoxIcon.Information); - else - MPCommands.ShowNotifyDialog(commands[0], commands[1], int.Parse(commands[2])); + case Common.XmlTagGoto: + { + if (InConfiguration) + MessageBox.Show(commandProperty, "Go To Window", MessageBoxButtons.OK, MessageBoxIcon.Information); + else + MPCommands.ProcessGoTo(commandProperty, MP_BasicHome); + break; + } - break; - } + case Common.XmlTagPopup: + { + string[] commands = Common.SplitPopupCommand(commandProperty); - case Common.XmlTagWindowMsg: - { - string[] commands = Common.SplitWindowMessageCommand(commandProperty); - Common.ProcessWindowMessageCommand(commands); - break; - } + if (InConfiguration) + MessageBox.Show(commands[1], commands[0], MessageBoxButtons.OK, MessageBoxIcon.Information); + else + MPCommands.ShowNotifyDialog(commands[0], commands[1], int.Parse(commands[2])); - case Common.XmlTagKeys: - { - if (InConfiguration) - MessageBox.Show(commandProperty, "Keystroke Command", MessageBoxButtons.OK, MessageBoxIcon.Information); - else - Common.ProcessKeyCommand(commandProperty); - break; - } + break; + } - case Common.XmlTagMultiMap: - { - if (InConfiguration) - ... [truncated message content] |