public static bool HasKeyMapped(int iWindow, Key key)
 {
   string strSoundFile;
   int wAction = GetActionCode(iWindow, key, out strSoundFile);
   if (wAction == 0)
   {
     return false;
   }
   return true;
 }
Пример #2
0
    /// <summary>
    /// Evaluates the button number, gets its mapping and executes the action
    /// </summary>
    /// <param name="btnCode">Button code (ref: XML file)</param>
    /// <param name="processID">Process-ID for close/kill commands</param>
    private bool DoMapAction(string btnCode, int processID)
    {
      if (!_isLoaded) // No mapping loaded
      {
        Log.Info("Map: No button mapping loaded");
        return false;
      }
      Mapping map = null;
      map = GetMapping(btnCode);
      if (map == null)
        return false;

      Log.Debug("{0} / {1} / {2} / {3}", map.Condition, map.ConProperty, map.Command, map.CmdProperty);

      Action action;
      if (map.Sound != string.Empty) // && !g_Player.Playing)
        Util.Utils.PlaySound(map.Sound, false, true);
      if (map.Focus && !GUIGraphicsContext.HasFocus)
      {
        GUIGraphicsContext.ResetLastActivity();
        GUIMessage msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_GETFOCUS, 0, 0, 0, 0, 0, null);
        GUIWindowManager.SendThreadMessage(msg);
        return true;
      }
      switch (map.Command)
      {
        case "ACTION": // execute Action x
          Key key = new Key(map.CmdKeyChar, map.CmdKeyCode);

          Log.Debug("Executing: key {0} / {1} / Action: {2} / {3}", map.CmdKeyChar, map.CmdKeyCode, map.CmdProperty,
                   ((Action.ActionType) Convert.ToInt32(map.CmdProperty)).ToString());

          action = new Action(key, (Action.ActionType) Convert.ToInt32(map.CmdProperty), 0, 0);
          GUIGraphicsContext.OnAction(action);
          break;
        case "KEY": // send Key x
          SendKeys.SendWait(map.CmdProperty);
          break;
        case "WINDOW": // activate Window x
          GUIGraphicsContext.ResetLastActivity();
          GUIMessage msg;
          if ((Convert.ToInt32(map.CmdProperty) == (int) GUIWindow.Window.WINDOW_HOME) ||
              (Convert.ToInt32(map.CmdProperty) == (int) GUIWindow.Window.WINDOW_SECOND_HOME))
          {
            if (_basicHome)
              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);
          }
          else
            msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_GOTO_WINDOW, 0, 0, 0, Convert.ToInt32(map.CmdProperty),
                                 0, null);

          GUIWindowManager.SendThreadMessage(msg);
          break;
        case "TOGGLE": // toggle Layer 1/2
          if (_currentLayer == 1)
            _currentLayer = 2;
          else
            _currentLayer = 1;
          break;
        case "POWER": // power down commands

          if ((map.CmdProperty == "STANDBY") || (map.CmdProperty == "HIBERNATE"))
          {
            GUIGraphicsContext.ResetLastActivity();

            //Stop all media before suspending or hibernating
            if (g_Player.Playing)
            {
              GUIWindowManager.SendThreadCallbackAndWait(StopPlayback, 0, 0, null);
            }

            // this is all handled in mediaportal.cs - OnSuspend          
            /*
            if (_basicHome)
              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);             
            */
          }

          switch (map.CmdProperty)
          {
            case "EXIT":
              action = new Action(Action.ActionType.ACTION_EXIT, 0, 0);
              GUIGraphicsContext.OnAction(action);
              break;
            case "REBOOT":
              action = new Action(Action.ActionType.ACTION_REBOOT, 0, 0);
              GUIGraphicsContext.OnAction(action);
              break;
            case "SHUTDOWN":
              action = new Action(Action.ActionType.ACTION_SHUTDOWN, 0, 0);
              GUIGraphicsContext.OnAction(action);
              break;
            case "STANDBY":
              // we need a slow standby (force=false), in order to have the onsuspend method being called on mediportal.cs
              // this is needed in order to have "ShowLastActiveModule" working correctly.
              // also using force=true results in a silent non critical D3DERR_DEVICELOST exception when resuming from powerstate.
              MPControlPlugin.OnSuspend();
              WindowsController.ExitWindows(RestartOptions.Suspend, false);
              break;
            case "HIBERNATE":
              // we need a slow hibernation (force=false), in order to have the onsuspend method being called on mediportal.cs
              // this is needed in order to have "ShowLastActiveModule" working correctly.
              // also using force=true results in a silent non critical D3DERR_DEVICELOST exception when resuming from powerstate.
              MPControlPlugin.OnSuspend();
              WindowsController.ExitWindows(RestartOptions.Hibernate, false);
              break;
          }
          break;
        case "PROCESS":
          {
            GUIGraphicsContext.ResetLastActivity();
            if (processID > 0)
            {
              Process proc = Process.GetProcessById(processID);
              if (null != proc)
                switch (map.CmdProperty)
                {
                  case "CLOSE":
                    proc.CloseMainWindow();
                    break;
                  case "KILL":
                    proc.Kill();
                    break;
                }
            }
          }
          break;
        case "BLAST":
          MPControlPlugin.ProcessCommand(map.CmdProperty, true);
          break;
        default:
          return false;
      }
      return true;
    }
 /// <summary>
 /// Translates a window, key combination to an Action.
 /// </summary>
 /// <param name="iWindow">The window that received the key action.</param>
 /// <param name="key">The key that caused the key action.</param>
 /// <param name="action">The Action that is initialized by this method.</param>
 /// <returns>True if the translation was successful, false if not.</returns>
 public static bool GetAction(int iWindow, Key key, ref Action action)
 {
   // try to get the action from the current window
   if (key == null)
   {
     return false;
   }
   string strSoundFile;
   int wAction = GetActionCode(iWindow, key, out strSoundFile);
   // if it's invalid, try to get it from the global map
   if (wAction == 0)
   {
     wAction = GetActionCode(-1, key, out strSoundFile);
   }
   if (wAction == 0)
   {
     return false;
   }
   // Now fill our action structure
   action.wID = (Action.ActionType)wAction;
   action.m_key = key;
   action.m_SoundFileName = strSoundFile;
   return true;
 }
    /// <summary>
    /// Gets the action based on a window key combination
    /// </summary>
    /// <param name="wWindow">The window id.</param>
    /// <param name="key">The key.</param>
    /// <returns>The action if it is found in the map, 0 if not.</returns>
    private static int GetActionCode(int wWindow, Key key, out string strSoundFile)
    {
      strSoundFile = "";
      if (key == null)
      {
        return 0;
      }
      for (int iw = 0; iw < mapWindows.Count; ++iw)
      {
        WindowMap window = (WindowMap)mapWindows[iw];
        if (window.iWindow == wWindow)
        {
          for (int ib = 0; ib < window.mapButtons.Count; ib++)
          {
            button but = (button)window.mapButtons[ib];

            if (but.eKeyChar == key.KeyChar && key.KeyChar > 0)
            {
              strSoundFile = but.m_strSoundFile;
              return (int)but.eAction;
            }
            if (but.eKeyCode == key.KeyCode && key.KeyCode > 0)
            {
              strSoundFile = but.m_strSoundFile;
              return (int)but.eAction;
            }
          }
          return 0;
        }
      }
      return 0;
    }
Пример #5
0
 public static void RefreshMadVrVideo()
 {
   if (GUIGraphicsContext.VideoRenderer == GUIGraphicsContext.VideoRendererType.madVR &&
       GUIGraphicsContext.Vmr9Active)
   {
     // TODO find a better way to restore madVR rendering (right now i send an 'X' to force refresh a current window)
     var key = new Key(120, 0);
     var action = new Action(key, Action.ActionType.ACTION_KEY_PRESSED, 0, 0);
     if (ActionTranslator.GetAction(GUIWindowManager.ActiveWindowEx, key, ref action))
     {
       GUIGraphicsContext.OnAction(action);
       action = new Action(key, Action.ActionType.ACTION_KEY_PRESSED, 0, 0);
       GUIGraphicsContext.OnAction(action);
     }
     key = new Key(120, 0);
     action = new Action(key, Action.ActionType.ACTION_KEY_PRESSED, 0, 0);
     if (ActionTranslator.GetAction(GUIWindowManager.ActiveWindowEx, key, ref action))
     {
       GUIGraphicsContext.OnAction(action);
       action = new Action(key, Action.ActionType.ACTION_KEY_PRESSED, 0, 0);
       GUIGraphicsContext.OnAction(action);
     }
   }
 }
Пример #6
0
    /// <summary>
    /// Evaluates the button number, gets its mapping and executes the action
    /// </summary>
    /// <param name="btnCode">Button code (ref: XML file)</param>
    /// <param name="processID">Process-ID for close/kill commands</param>
    private bool DoMapAction(string btnCode, int processID)
    {
      if (!_isLoaded) // No mapping loaded
      {
        Log.Info("Map: No button mapping loaded");
        return false;
      }
      Mapping map = null;
      map = GetMapping(btnCode);
      if (map == null)
      {
        return false;
      }
#if DEBUG
      Log.Info("{0} / {1} / {2} / {3}", map.Condition, map.ConProperty, map.Command, map.CmdProperty);
#endif
      Action action;
      if (map.Sound != string.Empty)
      {
        Util.Utils.PlaySound(map.Sound, false, true);
      }
      if (map.Focus && !GUIGraphicsContext.HasFocus)
      {
        GUIGraphicsContext.ResetLastActivity();
        GUIMessage msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_GETFOCUS, 0, 0, 0, 0, 0, null);
        //GUIWindowManager.SendThreadMessage(msg);
        GUIGraphicsContext.SendMessage(msg);
        return true;
      }
      switch (map.Command)
      {
        case "ACTION": // execute Action x
          Key key = new Key(map.CmdKeyChar, map.CmdKeyCode);
#if DEBUG
          Log.Info("Executing: key {0} / {1} / Action: {2} / {3}", map.CmdKeyChar, map.CmdKeyCode, map.CmdProperty,
                   ((Action.ActionType)Convert.ToInt32(map.CmdProperty)).ToString());
#endif
          action = new Action(key, (Action.ActionType)Convert.ToInt32(map.CmdProperty), 0, 0);
          GUIGraphicsContext.OnAction(action);
          break;
        case "KEY": // send Key x
          SendKeys.SendWait(map.CmdProperty);
          break;
        case "WINDOW": // activate Window x
          GUIGraphicsContext.ResetLastActivity();
          GUIMessage msg;
          if ((Convert.ToInt32(map.CmdProperty) == (int)GUIWindow.Window.WINDOW_HOME) ||
              (Convert.ToInt32(map.CmdProperty) == (int)GUIWindow.Window.WINDOW_SECOND_HOME))
          {
            if (_basicHome)
            {
              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);
            }
          }
          else
          {
            msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_GOTO_WINDOW, 0, 0, 0, Convert.ToInt32(map.CmdProperty),
                                 0, null);
          }

          GUIWindowManager.SendThreadMessage(msg);
          break;
        case "TOGGLE": // toggle Layer 1/2
          if (_currentLayer == 1)
          {
            _currentLayer = 2;
          }
          else
          {
            _currentLayer = 1;
          }
          break;
        case "POWER": // power down commands

          if ((map.CmdProperty == "STANDBY") || (map.CmdProperty == "HIBERNATE"))
          {
            GUIGraphicsContext.ResetLastActivity();
          }

          switch (map.CmdProperty)
          {
            case "EXIT":
              action = new Action(Action.ActionType.ACTION_EXIT, 0, 0);
              GUIGraphicsContext.OnAction(action);
              break;
            case "REBOOT":
              action = new Action(Action.ActionType.ACTION_REBOOT, 0, 0);
              GUIGraphicsContext.OnAction(action);
              break;
            case "SHUTDOWN":
              action = new Action(Action.ActionType.ACTION_SHUTDOWN, 0, 0);
              GUIGraphicsContext.OnAction(action);
              break;
            case "STANDBY":
              action = new Action(Action.ActionType.ACTION_SUSPEND, 1, 0); //1 = ignore prompt
              GUIGraphicsContext.OnAction(action);
              break;
            case "HIBERNATE":
              action = new Action(Action.ActionType.ACTION_HIBERNATE, 1, 0); //1 = ignore prompt
              GUIGraphicsContext.OnAction(action);
              break;
          }
          break;
        case "PROCESS":
          {
            GUIGraphicsContext.ResetLastActivity();
            if (processID > 0)
            {
              Process proc = Process.GetProcessById(processID);
              if (null != proc)
              {
                switch (map.CmdProperty)
                {
                  case "CLOSE":
                    proc.CloseMainWindow();
                    break;
                  case "KILL":
                    proc.Kill();
                    break;
                }
              }
            }
          }
          break;
        default:
          return false;
      }
      return true;
    }
Пример #7
0
    private void CommandPropChanged()
    {
      if ((string) comboBoxCmdProperty.SelectedItem == "Key Pressed")
        textBoxKeyChar.Enabled = textBoxKeyCode.Enabled = true;
      else
      {
        textBoxKeyChar.Enabled = textBoxKeyCode.Enabled = false;
        textBoxKeyChar.Text = textBoxKeyCode.Text = String.Empty;
      }

      TreeNode node = getNode("COMMAND");
      Data data = (Data) node.Tag;
      switch ((string) data.Parameter)
      {
        case "ACTION":
          if ((string) comboBoxCmdProperty.SelectedItem != "Key Pressed")
          {
            node.Tag = new Data("COMMAND", "ACTION",
                                (int)
                                Enum.Parse(typeof (Action.ActionType),
                                           GetActionName((string) comboBoxCmdProperty.SelectedItem)));
            node.Text = "Action \"" + (string) comboBoxCmdProperty.SelectedItem + "\"";
          }
          else
          {
            textBoxKeyChar.Text = "0";
            textBoxKeyCode.Text = "0";
            Key key = new Key(Convert.ToInt32(textBoxKeyChar.Text), Convert.ToInt32(textBoxKeyCode.Text));
            node.Tag = new Data("COMMAND", "KEY", key);
            node.Text = String.Format("Key Pressed: {0} [{1}]", textBoxKeyChar.Text, textBoxKeyCode.Text);
          }
          break;
        case "WINDOW":
          {
            int windowID;
            try
            {
              windowID = (int) Enum.Parse(typeof (GUIWindow.Window), GetWindowName(comboBoxCmdProperty.Text));
            }
            catch
            {
              windowID = Convert.ToInt32(comboBoxCmdProperty.Text);
            }

            node.Tag = new Data("COMMAND", "WINDOW", windowID);
            node.Text = "Window \"" + comboBoxCmdProperty.Text + "\"";
            break;
          }
        case "POWER":
          node.Tag = new Data("COMMAND", "POWER",
                              _nativePowerList[Array.IndexOf(_powerList, (string) comboBoxCmdProperty.SelectedItem)]);
          node.Text = (string) comboBoxCmdProperty.SelectedItem;
          break;
        case "PROCESS":
          node.Tag = new Data("COMMAND", "PROCESS",
                              _nativeProcessList[Array.IndexOf(_processList, (string) comboBoxCmdProperty.SelectedItem)]);
          node.Text = (string) comboBoxCmdProperty.SelectedItem;
          break;
        case "BLAST":
          {
            string text = (string) comboBoxCmdProperty.SelectedItem;
            if (text.StartsWith(IrssUtils.Common.CmdPrefixBlast, StringComparison.InvariantCultureIgnoreCase))
            {
              BlastCommand blastCommand = new BlastCommand(
                MPControlPlugin.BlastIR,
                IrssUtils.Common.FolderIRCommands,
                MPControlPlugin.TransceiverInformation.Ports,
                text.Substring(IrssUtils.Common.CmdPrefixBlast.Length));

              if (blastCommand.ShowDialog(this) == DialogResult.OK)
              {
                string command = IrssUtils.Common.CmdPrefixBlast + blastCommand.CommandString;
                node.Tag = new Data("COMMAND", "BLAST", command);
                node.Text = command;
              }
            }
            else if (text.StartsWith(IrssUtils.Common.CmdPrefixMacro, StringComparison.InvariantCultureIgnoreCase))
            {
              node.Tag = new Data("COMMAND", "BLAST", text);
              node.Text = text;
            }
            break;
          }
      }
      ((Data) node.Tag).Focus = checkBoxGainFocus.Checked;
      _changedSettings = true;
    }
 private void textBoxKeyChar_KeyUp(object sender, KeyEventArgs e)
 {
   var keyChar = textBoxKeyChar.Text;
   var keyCode = textBoxKeyCode.Text;
   var node = getNode("COMMAND");
   if (keyChar == string.Empty)
   {
     keyChar = "0";
   }
   if (keyCode == string.Empty)
   {
     keyCode = "0";
   }
   var key = new Key(Convert.ToInt32(keyChar), Convert.ToInt32(keyCode));
   node.Tag = new NodeData("COMMAND", "KEY", key);
   node.Text = string.Format("Key Pressed: {0} [{1}]", keyChar, keyCode);
   ((NodeData) node.Tag).Focus = checkBoxGainFocus.Checked;
   changedSettings = true;
 }
Пример #9
0
    protected void RenderKey(float timePassed, float fX, float fY, Key key, long keyColor, long textColor)
    {
      if (key.xKey == Xkey.XK_NULL)
      {
        return;
      }

      string strKey = GetChar(key.xKey);
      string name = (key.name.Length == 0) ? strKey : key.name;

      int width = key.dwWidth;
      GUIGraphicsContext.ScaleHorizontal(ref width);

      float x = fX;
      float y = fY;
      float z = fX + width;
      float w = fY + _keyHeightScaled;

      float nw = width;
      float nh = _keyHeightScaled;

      key.button.SetPosition((int)x, (int)y);
      key.button.Width = (int)nw;
      key.button.Height = (int)nh;
      key.button.ColourDiffuse = keyColor;
      key.button.Focus = key.inFocus;

      // Draw the key text. If key name is, use a slightly smaller font.
      float textWidth = 0;
      float textHeight = 0;
      float positionX = (x + z) / 2.0f;
      float positionY = (y + w) / 2.0f;

      if (key.name.Length > 1 && Char.IsUpper(key.name[1]))
      {
        _fontNamedKey.GetTextExtent(name, ref textWidth, ref textHeight);
        positionX -= (textWidth / 2);
        positionY -= (textHeight / 2);

        key.button.Label = name;
        key.button.FontName = _namedKeyFont;
        key.button.TextAlignment = GUIControl.Alignment.ALIGN_CENTER;
        key.button.TextVAlignment = GUIControl.VAlignment.ALIGN_MIDDLE;
        key.button.TextColorNoFocus = textColor;
        key.button.TextColor = textColor;
      }
      else
      {
        _fontCharKey.GetTextExtent(name, ref textWidth, ref textHeight);
        positionX -= (textWidth / 2);
        positionY -= (textHeight / 2);

        key.button.Label = name;
        key.button.FontName = _charKeyFont;
        key.button.TextAlignment = GUIControl.Alignment.ALIGN_CENTER;
        key.button.TextVAlignment = GUIControl.VAlignment.ALIGN_MIDDLE;
        key.button.TextColor = textColor;
        key.button.TextColorNoFocus = textColor;
      }
      key.button.Render(timePassed);
    }
Пример #10
0
 private void textBoxKeyChar_KeyUp(object sender, KeyEventArgs e)
 {
   string keyChar = textBoxKeyChar.Text;
   string keyCode = textBoxKeyCode.Text;
   TreeNode node = getNode("COMMAND");
   if (String.IsNullOrEmpty(keyChar))
     keyChar = "0";
   if (String.IsNullOrEmpty(keyCode))
     keyCode = "0";
   Key key = new Key(Convert.ToInt32(keyChar), Convert.ToInt32(keyCode));
   node.Tag = new Data("COMMAND", "KEY", key);
   node.Text = String.Format("Key Pressed: {0} [{1}]", keyChar, keyCode);
   ((Data) node.Tag).Focus = checkBoxGainFocus.Checked;
   _changedSettings = true;
 }
Пример #11
0
 protected void ChangeKey(int iBoard, int iRow, int iKey, Key newkey)
 {
   ArrayList board = (ArrayList)_keyboardList[iBoard];
   ArrayList row = (ArrayList)board[iRow];
   row[iKey] = newkey;
 }
Пример #12
0
        public MainWindow()
        {
            // get ID of windowplugin belonging to this setup
            // enter your own unique code
            GetID = Constants.PlugInInfo.ID;

            try
            {
                settings = new AnimePluginSettings();

                imageHelper = new ImageDownloader();
                imageHelper.Init();

                listPoster = new AsyncImageResource();
                listPoster.Property = "#Anime3.GroupSeriesPoster";
                listPoster.Delay = artworkDelay;

                fanartTexture = new AsyncImageResource();
                fanartTexture.Property = "#Anime3.Fanart.1";
                fanartTexture.Delay = artworkDelay;

                GroupFilterQuickSorts = new Dictionary<int, QuickSort>();

                //searching
                searchTimer = new System.Timers.Timer();
                searchTimer.AutoReset = true;
                searchTimer.Interval = settings.FindTimeout_s * 1000;
                searchTimer.Elapsed += new System.Timers.ElapsedEventHandler(searchTimer_Elapsed);

                //set the search key sound to the same sound for the REMOTE_1 key
                Key key = new Key('1', (int)Keys.D1);
                MediaPortal.GUI.Library.Action action = new MediaPortal.GUI.Library.Action();
                ActionTranslator.GetAction(GetID, key, ref action);
                searchSound = action.SoundFileName;

                // timer for automatic updates
                autoUpdateTimer = new System.Timers.Timer();
                autoUpdateTimer.AutoReset = true;
                autoUpdateTimer.Interval = 5 * 60 * 1000; // 5 minutes * 60 seconds
                autoUpdateTimer.Elapsed += new System.Timers.ElapsedEventHandler(autoUpdateTimer_Elapsed);

                downloadImagesWorker.DoWork += new DoWorkEventHandler(downloadImagesWorker_DoWork);

                this.OnToggleWatched += new OnToggleWatchedHandler(MainWindow_OnToggleWatched);

                g_Player.PlayBackEnded += new g_Player.EndedHandler(g_Player_PlayBackEnded);
            }
            catch (Exception ex)
            {
                BaseConfig.MyAnimeLog.Write(ex.ToString());
                throw;
            }
        }
Пример #13
0
    /// <summary>
    /// Try and map a WndProc message to an action regardless of whether the remote is stopped or not (will still ignore if it's disabled)
    /// </summary>
    /// <param name="msg"></param>
    /// <returns></returns>
    public static Action MapToAction(Message msg)
    {
      Action result = null;
      Log.Info(string.Format("WndProc message to be processed {0}, appCommand {1}, LParam {2}, WParam {3}", msg.Msg, Win32.Macro.GET_APPCOMMAND_LPARAM(msg.LParam), msg.LParam, msg.WParam));
      foreach (var device in Devices)
      {
        var mapping = device.GetMapping(msg);
        if (mapping != null)
        {
          switch (mapping.Command)
          {
            case "ACTION": // execute Action x
              Key key = new Key(mapping.CmdKeyChar, mapping.CmdKeyCode);
              Log.Info("MappingToAction: key {0} / {1} / Action: {2} / {3}", mapping.CmdKeyChar, mapping.CmdKeyCode,
                mapping.CmdProperty,
                ((Action.ActionType) Convert.ToInt32(mapping.CmdProperty)).ToString());
              result = new Action(key, (Action.ActionType) Convert.ToInt32(mapping.CmdProperty), 0, 0);
              break;
            case "KEY": // Try and map the key to the Keys enum and process that way
              var tmpKey = Keys.A;
              if (Enum.TryParse<Keys>(mapping.CmdProperty, out tmpKey))
                result = MapToAction((int) tmpKey);
              break;
          }
          if (result != null) break;
        }
      }

      if (result == null) Log.Info("No mapping found");

      return result;
    }
Пример #14
0
 /// <summary>
 /// Creates an action.
 /// </summary>
 /// <param name="key">The key that caused the action. (E.g., a key press)</param>
 /// <param name="id">The action type</param>
 /// <param name="f1">First parameter.</param>
 /// <param name="f2">Second parameter.</param>
 public Action(Key key, ActionType id, float f1, float f2)
 {
   // TODO: No key action requires the additional parameters. Are they still needed?
   m_key = key;
   wID = id;
   fAmount1 = f1;
   fAmount2 = f2;
 }
Пример #15
0
    private void LoadMapping(string xmlFile, bool defaults)
    {
      string pathDefault = Path.Combine(MPUtils.MPCommon.CustomInputDefault, xmlFile);
      string pathCustom = Path.Combine(MPUtils.MPCommon.CustomInputDevice, xmlFile);

      try
      {
        groupBoxLayer.Enabled = false;
        groupBoxCondition.Enabled = false;
        groupBoxAction.Enabled = false;
        treeMapping.Nodes.Clear();
        XmlDocument doc = new XmlDocument();
        string path = pathDefault;
        if (!defaults && File.Exists(pathCustom))
          path = pathCustom;
        if (!File.Exists(path))
        {
          MessageBox.Show(
            "Can't locate mapping file " + xmlFile + "\n\nMake sure it exists in /InputDeviceMappings/defaults",
            "Mapping file missing", MessageBoxButtons.OK, MessageBoxIcon.Error);
          buttonUp.Enabled =
            buttonDown.Enabled =
            buttonNew.Enabled = buttonRemove.Enabled = buttonDefault.Enabled = buttonApply.Enabled = false;
          ShowInTaskbar = true;
          WindowState = FormWindowState.Minimized;
          Thread closeThread = new Thread(CloseThread);
          closeThread.Start();
          return;
        }
        doc.Load(path);
        XmlNodeList listRemotes = doc.DocumentElement.SelectNodes("/mappings/remote");

        foreach (XmlNode nodeRemote in listRemotes)
        {
          TreeNode remoteNode = new TreeNode(nodeRemote.Attributes["family"].Value);
          remoteNode.Tag = new Data("REMOTE", null, nodeRemote.Attributes["family"].Value);
          XmlNodeList listButtons = nodeRemote.SelectNodes("button");
          foreach (XmlNode nodeButton in listButtons)
          {
            TreeNode buttonNode = new TreeNode(nodeButton.Attributes["name"].Value);
            buttonNode.Tag = new Data("BUTTON", nodeButton.Attributes["name"].Value, nodeButton.Attributes["code"].Value);
            remoteNode.Nodes.Add(buttonNode);

            TreeNode layer1Node = new TreeNode("Layer 1");
            TreeNode layer2Node = new TreeNode("Layer 2");
            TreeNode layerAllNode = new TreeNode("All Layers");
            layer1Node.Tag = new Data("LAYER", null, "1");
            layer2Node.Tag = new Data("LAYER", null, "2");
            layerAllNode.Tag = new Data("LAYER", null, "0");
            layer1Node.ForeColor = Color.DimGray;
            layer2Node.ForeColor = Color.DimGray;
            layerAllNode.ForeColor = Color.DimGray;

            XmlNodeList listActions = nodeButton.SelectNodes("action");

            foreach (XmlNode nodeAction in listActions)
            {
              string conditionString = String.Empty;
              string commandString = String.Empty;

              string condition = nodeAction.Attributes["condition"].Value.ToUpper();
              string conProperty = nodeAction.Attributes["conproperty"].Value; // .ToUpper()
              string command = nodeAction.Attributes["command"].Value.ToUpper();
              string cmdProperty = nodeAction.Attributes["cmdproperty"].Value; // .ToUpper()
              string sound = String.Empty;
              XmlAttribute soundAttribute = nodeAction.Attributes["sound"];
              if (soundAttribute != null)
                sound = soundAttribute.Value;
              bool gainFocus = false;
              XmlAttribute focusAttribute = nodeAction.Attributes["focus"];
              if (focusAttribute != null)
                gainFocus = Convert.ToBoolean(focusAttribute.Value);
              int layer = Convert.ToInt32(nodeAction.Attributes["layer"].Value);

              #region Conditions

              switch (condition)
              {
                case "WINDOW":
                  {
                    conProperty = conProperty.ToUpper();
                    try
                    {
                      conditionString =
                        GetFriendlyName(Enum.GetName(typeof (GUIWindow.Window), Convert.ToInt32(conProperty)));
                    }
                    catch
                    {
                      conditionString = conProperty;
                    }
                    break;
                  }
                case "FULLSCREEN":
                  conProperty = conProperty.ToUpper();
                  if (conProperty == "TRUE")
                    conditionString = "Fullscreen";
                  else
                    conditionString = "No Fullscreen";
                  break;
                case "PLAYER":
                  conProperty = conProperty.ToUpper();
                  conditionString = _playerList[Array.IndexOf(_nativePlayerList, conProperty)];
                  break;
                case "PLUGIN":
                  conditionString = conProperty;
                  break;
                case "*":
                  conditionString = "No Condition";
                  break;
              }

              #endregion

              #region Commands

              switch (command)
              {
                case "ACTION":
                  commandString = "Action \"" +
                                  GetFriendlyName(Enum.GetName(typeof (Action.ActionType), Convert.ToInt32(cmdProperty))) +
                                  "\"";
                  break;
                case "KEY":
                  commandString = "Key \"" + cmdProperty + "\"";
                  break;
                case "WINDOW":
                  {
                    try
                    {
                      commandString = "Window \"" +
                                      GetFriendlyName(Enum.GetName(typeof (GUIWindow.Window),
                                                                   Convert.ToInt32(cmdProperty))) + "\"";
                    }
                    catch
                    {
                      commandString = "Window \"" + cmdProperty + "\"";
                    }
                    break;
                  }
                case "TOGGLE":
                  commandString = "Toggle Layer";
                  break;
                case "POWER":
                  commandString = _powerList[Array.IndexOf(_nativePowerList, cmdProperty)];
                  break;
                case "PROCESS":
                  commandString = _processList[Array.IndexOf(_nativeProcessList, cmdProperty)];
                  break;
                case "BLAST":
                  commandString = cmdProperty;
                  break;
              }

              #endregion

              TreeNode conditionNode = new TreeNode(conditionString);
              conditionNode.Tag = new Data("CONDITION", condition, conProperty);
              if (commandString == "Action \"Key Pressed\"")
              {
                string cmdKeyChar = nodeAction.Attributes["cmdkeychar"].Value;
                string cmdKeyCode = nodeAction.Attributes["cmdkeycode"].Value;
                TreeNode commandNode = new TreeNode(String.Format("Key Pressed: {0} [{1}]", cmdKeyChar, cmdKeyCode));

                Key key = new Key(Convert.ToInt32(cmdKeyChar), Convert.ToInt32(cmdKeyCode));

                commandNode.Tag = new Data("COMMAND", "KEY", key, gainFocus);
                commandNode.ForeColor = Color.DarkGreen;
                conditionNode.ForeColor = Color.Blue;
                conditionNode.Nodes.Add(commandNode);
              }
              else
              {
                TreeNode commandNode = new TreeNode(commandString);
                commandNode.Tag = new Data("COMMAND", command, cmdProperty, gainFocus);
                commandNode.ForeColor = Color.DarkGreen;
                conditionNode.ForeColor = Color.Blue;
                conditionNode.Nodes.Add(commandNode);
              }

              TreeNode soundNode = new TreeNode(sound);
              soundNode.Tag = new Data("SOUND", null, sound);
              if (String.IsNullOrEmpty(sound))
                soundNode.Text = "No Sound";
              soundNode.ForeColor = Color.DarkRed;
              conditionNode.Nodes.Add(soundNode);

              if (layer == 1) layer1Node.Nodes.Add(conditionNode);
              if (layer == 2) layer2Node.Nodes.Add(conditionNode);
              if (layer == 0) layerAllNode.Nodes.Add(conditionNode);
            }
            if (layer1Node.Nodes.Count > 0) buttonNode.Nodes.Add(layer1Node);
            if (layer2Node.Nodes.Count > 0) buttonNode.Nodes.Add(layer2Node);
            if (layerAllNode.Nodes.Count > 0) buttonNode.Nodes.Add(layerAllNode);
          }
          treeMapping.Nodes.Add(remoteNode);
          if (listRemotes.Count == 1)
            remoteNode.Expand();
        }
        _changedSettings = false;
      }
      catch (Exception ex)
      {
        Log.Error(ex);
        File.Delete(pathCustom);
        LoadMapping(xmlFile, true);
      }
    }
    private void comboBoxCmdProperty_SelectionChangeCommitted(object sender, EventArgs e)
    {
      if ((string) comboBoxCmdProperty.SelectedItem == "Key Pressed")
      {
        textBoxKeyChar.Enabled = textBoxKeyCode.Enabled = true;
      }
      else
      {
        textBoxKeyChar.Enabled = textBoxKeyCode.Enabled = false;
        textBoxKeyChar.Text = textBoxKeyCode.Text = string.Empty;
      }

      var node = getNode("COMMAND");
      var data = (NodeData) node.Tag;
      switch ((string) data.Parameter)
      {
        case "ACTION":
          if ((string) comboBoxCmdProperty.SelectedItem != "Key Pressed")
          {
            node.Tag = new NodeData("COMMAND", "ACTION",
              (int)
                Enum.Parse(typeof (Action.ActionType),
                  GetActionName((string) comboBoxCmdProperty.SelectedItem)));
            node.Text = "Action \"" + (string) comboBoxCmdProperty.SelectedItem + "\"";
          }
          else
          {
            textBoxKeyChar.Text = "0";
            textBoxKeyCode.Text = "0";
            var key = new Key(Convert.ToInt32(textBoxKeyChar.Text), Convert.ToInt32(textBoxKeyCode.Text));
            node.Tag = new NodeData("COMMAND", "KEY", key);
            node.Text = string.Format("Key Pressed: {0} [{1}]", textBoxKeyChar.Text, textBoxKeyCode.Text);
          }
          break;

        case "WINDOW":
          node.Tag = new NodeData("COMMAND", "WINDOW",
            (int)
              Enum.Parse(typeof (GUIWindow.Window),
                GetWindowName((string) comboBoxCmdProperty.SelectedItem)));
          node.Text = "Window \"" + (string) comboBoxCmdProperty.SelectedItem + "\"";
          break;

        case "POWER":
          node.Tag = new NodeData("COMMAND", "POWER",
            nativePowerList[Array.IndexOf(powerList, (string) comboBoxCmdProperty.SelectedItem)]);
          node.Text = (string) comboBoxCmdProperty.SelectedItem;
          break;

        case "PROCESS":
          node.Tag = new NodeData("COMMAND", "PROCESS",
            nativeProcessList[Array.IndexOf(processList, (string) comboBoxCmdProperty.SelectedItem)]);
          node.Text = (string) comboBoxCmdProperty.SelectedItem;
          break;
      }
      ((NodeData) node.Tag).Focus = checkBoxGainFocus.Checked;
      changedSettings = true;
    }
Пример #17
0
    private void Listener_XplMessageReceived(object sender, XplListener.XplEventArgs e)
    {
      if (e.XplMsg.Schema.msgClass.ToLowerInvariant().Equals("hbeat") && e.XplMsg.Schema.msgType.ToLowerInvariant().Equals("app"))
      {
        if (this.DoDebug)
        {
          Log.Info("xPLConnector_Listener_XplMessageReceived: Received HEARTBEAT");
        }
        this._IsConnected = true;
      }
      else if (e.XplMsg.Schema.msgClass.ToLowerInvariant().Equals("config"))
      {
        if (this.DoDebug)
        {
          Log.Info("xPLConnector_Listener_XplMessageReceived: Received CONFIG message");
        }
      }
      else if ((e.XplMsg.Source.Vendor.ToLowerInvariant().Equals(this.mVendorID.ToLowerInvariant()) &&
                e.XplMsg.Source.Device.ToLowerInvariant().Equals(this.mDeviceID.ToLowerInvariant())) &&
               e.XplMsg.Source.Instance.ToLowerInvariant().Equals(this.mInstanceID.ToLowerInvariant()))
      {
        if (this.DoDebug)
        {
          Log.Info("xPLConnector_Listener_XplMessageReceived: Received ECHO");
        }
      }
      else
      {
        if (this.DoDebug)
        {
          Log.Info("xPLConnector_Listener_XplMessageReceived: {0} - {1} - {2}",
                   new object[] {e.XplMsg.Source.Vendor, e.XplMsg.Source.Device, e.XplMsg.Content});
        }
        string str = e.XplMsg.Schema.msgClass.ToLowerInvariant() + "." + e.XplMsg.Schema.msgType.ToLowerInvariant();
        string str11 = str;
        if (str11 != null)
        {
          if (!(str11 == "media.basic"))
          {
            if (!(str11 == "media.request"))
            {
              if (str11 == "remote.basic")
              {
                foreach (string str9 in e.XplMsg.GetParam(1, "keys").Split(new char[] {','}))
                {
                  if (this.DoDebug)
                  {
                    Log.Info("xPL_Connector.Listener_XplMessageReceived(): Received remote.basic \"{0}\"",
                             new object[] {str9});
                  }
                  if (Enum.IsDefined(typeof (GUIWindow.Window), str9.ToUpperInvariant()))
                  {
                    if (this.DoDebug)
                    {
                      Log.Info("xPL_Connector.Listener_XplMessageReceived(): Received remote.basic window name",
                               new object[0]);
                    }
                    this.XPL_Send_Remote_Confirm_Message(e);
                    int num8 = (int)Enum.Parse(typeof (GUIWindow.Window), str9.ToUpperInvariant());
                    if (!GUIWindowManager.ActiveWindow.Equals(num8))
                    {
                      GUIWindowManager.SendThreadCallbackAndWait(
                        new GUIWindowManager.Callback(this.ThreadMessageCallback), 1, num8, null);
                      return;
                    }
                    break;
                  }
                  if (Enum.IsDefined(typeof (Keys), str9))
                  {
                    if (this.DoDebug)
                    {
                      Log.Info("xPL_Connector.Listener_XplMessageReceived(): Received remote.basic key name",
                               new object[0]);
                    }
                    this.XPL_Send_Remote_Confirm_Message(e);
                    Key key = new Key(0, (int)Enum.Parse(typeof (Keys), str9));
                    Action action3 = new Action();
                    if (ActionTranslator.GetAction(GUIWindowManager.ActiveWindow, key, ref action3))
                    {
                      GUIWindowManager.OnAction(action3);
                      return;
                    }
                  }

                  int result = 0;
                  int.TryParse(str9, out result);
                  if (result != 0)
                  {
                    if (this.DoDebug)
                    {
                      Log.Info("xPL_Connector.Listener_XplMessageReceived(): Received remote.basic raw keycode",
                               new object[0]);
                    }
                    this.XPL_Send_Remote_Confirm_Message(e);
                    Key key2 = new Key(0, result);
                    Action action4 = new Action();
                    if (ActionTranslator.GetAction(GUIWindowManager.ActiveWindow, key2, ref action4))
                    {
                      GUIWindowManager.OnAction(action4);
                      return;
                    }
                    break;
                  }
                }
              }
            }
            else
            {
              switch (e.XplMsg.GetParam(1, "request"))
              {
                case "devinfo":
                  this.XPL_SendDevInfo("xpl-stat");
                  return;

                case "devstate":
                  if (e.XplMsg.GetParam(1, "mp").ToLowerInvariant().Equals("player"))
                  {
                    this.XPL_SendPlayerDevstate("xpl-stat");
                  }
                  return;

                case "mpinfo":
                  if (e.XplMsg.GetParam(1, "mp").ToLowerInvariant().Equals("player"))
                  {
                    this.XPL_SendPlayerMediaPlayerInfo("xpl-stat");
                    this.XPL_SendPlayerMediaPlayerInputInfo("xpl-stat");
                  }
                  return;

                case "mptrnspt":
                  if (e.XplMsg.GetParam(1, "mp").ToLowerInvariant().Equals("player"))
                  {
                    this.XPL_SendPlayerTransportState("xpl-stat");
                  }
                  return;

                case "mpmedia":
                  if (e.XplMsg.GetParam(1, "mp").ToLowerInvariant().Equals("player"))
                  {
                    this.XPL_SendMediaInfo("xpl-stat");
                  }
                  return;

                case "mpconfig":
                  if (e.XplMsg.GetParam(1, "mp").ToLowerInvariant().Equals("player"))
                  {
                    this.XPL_SendPlayerMediaPlayerConfig("xpl-stat");
                  }
                  return;

                case "mpqueue":
                  return;
              }
            }
          }
          else
          {
            int num;
            switch (e.XplMsg.GetParam(1, "command").ToLowerInvariant())
            {
              case "record":
              case "position":
              case "chapter":
              case "power":
              case "reboot":
              case "input":
              case "options":
                return;

              case "play":
                {
                  string path = e.XplMsg.GetParam(1, "url").ToLowerInvariant();
                  if (!(path.Equals(string.Empty) & g_Player.Paused))
                  {
                    if (path.Equals(g_Player.currentFileName) & g_Player.Paused)
                    {
                      g_Player.Pause();
                      if (this.DoDebug)
                      {
                        Log.Info(
                          "xPLConnector_Listener_XplMessageReceived: Received media.basic play file command (unpause)",
                          new object[0]);
                        return;
                      }
                      return;
                    }
                    if (File.Exists(path) && !g_Player.currentFileName.Equals(path))
                    {
                      GUIMessage message = new GUIMessage();
                      message.Message = GUIMessage.MessageType.GUI_MSG_PLAY_FILE;
                      message.Label = path;
                      GUIWindowManager.SendThreadMessage(message);
                      if (!this.DoDebug)
                      {
                        return;
                      }
                      Log.Info("xPLConnector_Listener_XplMessageReceived: Received media.basic play file command",
                               new object[0]);
                    }
                    return;
                  }
                  g_Player.Pause();
                  if (this.DoDebug)
                  {
                    Log.Info(
                      "xPLConnector_Listener_XplMessageReceived: Received media.basic play file command (unpause)",
                      new object[0]);
                  }
                  return;
                }
              case "stop":
                {
                  GUIMessage message2 = new GUIMessage();
                  message2.Message = GUIMessage.MessageType.GUI_MSG_STOP_FILE;
                  GUIWindowManager.SendThreadMessage(message2);
                  if (this.DoDebug)
                  {
                    Log.Info("xPLConnector_Listener_XplMessageReceived: Received media.basic stop command",
                             new object[0]);
                  }
                  return;
                }
              case "pause":
                if (this.DoDebug)
                {
                  Log.Info("xPLConnector_Listener_XplMessageReceived: Received media.basic pause command",
                           new object[0]);
                }
                if (!g_Player.Paused)
                {
                  g_Player.Pause();
                }
                return;

              case "forward":
                {
                  string str4 = e.XplMsg.GetParam(1, "speed").ToLowerInvariant();
                  num = 0;
                  if (!str4.Equals(string.Empty))
                  {
                    num = int.Parse(str4.Replace("x", ""));
                    break;
                  }
                  num = g_Player.Speed * 2;
                  break;
                }
              case "rewind":
                {
                  string str5 = e.XplMsg.GetParam(1, "speed").ToLowerInvariant();
                  int num2 = 0;
                  if (!str5.Equals(string.Empty))
                  {
                    num2 = int.Parse(str5.Replace("x", ""));
                  }
                  else
                  {
                    num2 = Math.Abs(g_Player.Speed) * 2;
                  }
                  if (num2 > 0x20)
                  {
                    num2 = 0x20;
                  }
                  if (this.DoDebug)
                  {
                    Log.Info("xPLConnector_Listener_XplMessageReceived: Received media.basic rewind ({0}x) command",
                             new object[] {num2});
                  }
                  g_Player.Speed = -num2;
                  return;
                }
              case "next":
                Action action;
                if (!g_Player.IsDVD)
                {
                  action = new Action(Action.ActionType.ACTION_NEXT_ITEM, 0f, 0f);
                }
                else
                {
                  action = new Action(Action.ActionType.ACTION_NEXT_CHAPTER, 0f, 0f);
                }
                GUIGraphicsContext.OnAction(action);
                if (this.DoDebug)
                {
                  Log.Info("xPLConnector_Listener_XplMessageReceived: Received media.basic next command",
                           new object[0]);
                }
                return;

              case "back":
                Action action2;
                if (!g_Player.IsDVD)
                {
                  action2 = new Action(Action.ActionType.ACTION_PREV_ITEM, 0f, 0f);
                }
                else
                {
                  action2 = new Action(Action.ActionType.ACTION_PREV_CHAPTER, 0f, 0f);
                }
                GUIGraphicsContext.OnAction(action2);
                if (this.DoDebug)
                {
                  Log.Info("xPLConnector_Listener_XplMessageReceived: Received media.basic back command",
                           new object[0]);
                }
                return;

              case "mute":
                if (!(e.XplMsg.GetParam(1, "state").ToLowerInvariant() == "on"))
                {
                  if (this.DoDebug)
                  {
                    Log.Info("xPLConnector_Listener_XplMessageReceived: Received media.basic mute off command",
                             new object[0]);
                  }
                  VolumeHandler.Instance.IsMuted = false;
                  return;
                }
                if (this.DoDebug)
                {
                  Log.Info("xPLConnector_Listener_XplMessageReceived: Received media.basic mute on command",
                           new object[0]);
                }
                VolumeHandler.Instance.IsMuted = true;
                return;

              case "volume":
                {
                  string str13;
                  string s = e.XplMsg.GetParam(1, "level").ToLowerInvariant();
                  if (((str13 = s.Substring(0, 1)) == null) || (!(str13 == "+") && !(str13 == "-")))
                  {
                    int num7 = int.Parse(s);
                    VolumeHandler.Instance.Volume = (VolumeHandler.Instance.Maximum / 100) * num7;
                    if (this.DoDebug)
                    {
                      Log.Info("xPLConnector_Listener_XplMessageReceived: Received media.basic volume command",
                               new object[0]);
                    }
                    return;
                  }
                  int volume = VolumeHandler.Instance.Volume;
                  int num5 = int.Parse(s) * 0x28f;
                  int num6 = volume + num5;
                  if (num6 < 0)
                  {
                    num6 = 0;
                  }
                  if (num6 > 0xffdc)
                  {
                    num6 = 0xffdc;
                  }
                  VolumeHandler.Instance.Volume = num6;
                  if (this.DoDebug)
                  {
                    Log.Info(
                      "xPLConnector_Listener_XplMessageReceived: Received media.basic volume {0} command = orig = {1}, new = {2}, delta = {3}",
                      new object[] {s, volume, num6, num5});
                  }
                  return;
                }
              default:
                return;
            }
            if (num > 0x20)
            {
              num = 0x20;
            }
            if (this.DoDebug)
            {
              Log.Info("xPLConnector_Listener_XplMessageReceived: Received media.basic play forward ({0}x) command",
                       new object[] {num});
            }
            g_Player.Speed = num;
          }
        }
      }
    }
    /// <summary>
    /// 
    /// </summary>
    /// <param name="aProfileName"></param>
    /// <param name="defaults"></param>
    private void LoadMapping(string aProfileName, bool defaults)
    {
      var pathDefault = HidProfiles.GetDefaultProfilePath(aProfileName);
      var pathCustom = HidProfiles.GetCustomProfilePath(aProfileName);

      try
      {
        groupBoxLayer.Enabled = false;
        groupBoxCondition.Enabled = false;
        groupBoxAction.Enabled = false;
        treeMapping.Nodes.Clear();
        var doc = new XmlDocument();
        var path = pathDefault;
        if (!defaults && File.Exists(pathCustom))
        {
          path = pathCustom;
        }
        if (!File.Exists(path))
        {
          MessageBox.Show(
            "Can't locate mapping file " + aProfileName + "\n\nMake sure it exists in /InputDeviceMappings/defaults",
            "Mapping file missing", MessageBoxButtons.OK, MessageBoxIcon.Error);
          buttonUp.Enabled =
            buttonDown.Enabled =
              buttonNew.Enabled = buttonRemove.Enabled = buttonDefault.Enabled = buttonApply.Enabled = false;
          ShowInTaskbar = true;
          WindowState = FormWindowState.Minimized;
          var closeThread = new Thread(CloseThread);
          closeThread.Name = "InputMapperClose";
          closeThread.Start();
          return;
        }
        doc.Load(path);
        var listRemotes = doc.DocumentElement.SelectNodes("/HidHandler/HidUsageAction");

        foreach (XmlNode nodeRemote in listRemotes)
        {
          var usagePageAndCollection = nodeRemote.Attributes["UsagePage"].Value + "/" +
                                       nodeRemote.Attributes["UsageCollection"].Value;
          var remoteNode = new TreeNode(usagePageAndCollection);
          var huaAttributes = new HidUsageActionAttributes(nodeRemote.Attributes["UsagePage"].Value,
            nodeRemote.Attributes["UsageCollection"].Value,
            nodeRemote.Attributes["HandleHidEventsWhileInBackground"].Value);
          remoteNode.Tag = new NodeData("REMOTE", huaAttributes, null);
          var listButtons = nodeRemote.SelectNodes("button");
          foreach (XmlNode nodeButton in listButtons)
          {
            //Use code as name if no name attribute
            var buttonName = GetAttributeValue(nodeButton.Attributes["name"], nodeButton.Attributes["code"].Value);
            
            //Get background attribute and default to false
            var background = GetAttributeValue(nodeButton.Attributes["background"], "false");

            //Get repeat attribute and default to false
            var repeat = GetAttributeValue(nodeButton.Attributes["repeat"], "false");

            var shift = GetAttributeValue(nodeButton.Attributes["shift"], "false");
            var ctrl = GetAttributeValue(nodeButton.Attributes["ctrl"], "false");
            var alt = GetAttributeValue(nodeButton.Attributes["alt"], "false");
            var win = GetAttributeValue(nodeButton.Attributes["win"], "false");

            HidButtonAttributes hbAttributes = new HidButtonAttributes(buttonName, nodeButton.Attributes["code"].Value, background, repeat, shift, ctrl, alt, win);
            var buttonNode = new TreeNode(hbAttributes.GetText());            
            buttonNode.Tag = new NodeData("BUTTON", hbAttributes, null);
            remoteNode.Nodes.Add(buttonNode);

            var layer1Node = new TreeNode("Layer 1");
            var layer2Node = new TreeNode("Layer 2");
            var layerAllNode = new TreeNode("All Layers");
            layer1Node.Tag = new NodeData("LAYER", null, "1");
            layer2Node.Tag = new NodeData("LAYER", null, "2");
            layerAllNode.Tag = new NodeData("LAYER", null, "0");
            layer1Node.ForeColor = Color.DimGray;
            layer2Node.ForeColor = Color.DimGray;
            layerAllNode.ForeColor = Color.DimGray;

            var listActions = nodeButton.SelectNodes("action");

            foreach (XmlNode nodeAction in listActions)
            {
              var conditionString = string.Empty;
              var commandString = string.Empty;

              var condition = nodeAction.Attributes["condition"].Value.ToUpperInvariant();
              var conProperty = nodeAction.Attributes["conproperty"].Value.ToUpperInvariant();
              var command = nodeAction.Attributes["command"].Value.ToUpperInvariant();
              var cmdProperty = nodeAction.Attributes["cmdproperty"].Value.ToUpperInvariant();
              var sound = string.Empty;
              var soundAttribute = nodeAction.Attributes["sound"];
              if (soundAttribute != null)
              {
                sound = soundAttribute.Value;
              }
              var gainFocus = false;
              var focusAttribute = nodeAction.Attributes["focus"];
              if (focusAttribute != null)
              {
                gainFocus = Convert.ToBoolean(focusAttribute.Value);
              }
              var layer = Convert.ToInt32(nodeAction.Attributes["layer"].Value);

              #region Conditions

              switch (condition)
              {
                case "WINDOW":
                  conditionString =
                    GetFriendlyName(Enum.GetName(typeof (GUIWindow.Window), Convert.ToInt32(conProperty)));
                  if (string.IsNullOrEmpty(conditionString))
                  {
                    continue;
                  }
                  break;

                case "FULLSCREEN":
                  if (conProperty == "TRUE")
                  {
                    conditionString = "Fullscreen";
                  }
                  else
                  {
                    conditionString = "No Fullscreen";
                  }
                  break;

                case "PLAYER":
                  conditionString = playerList[Array.IndexOf(nativePlayerList, conProperty)];
                  break;

                case "*":
                  conditionString = "No Condition";
                  break;
              }

              #endregion Conditions

              #region Commands

              switch (command)
              {
                case "ACTION":
                  commandString = "Action \"" +
                                  GetFriendlyName(Enum.GetName(typeof (Action.ActionType), Convert.ToInt32(cmdProperty))) +
                                  "\"";
                  break;

                case "KEY":
                  commandString = "Key \"" + cmdProperty + "\"";
                  break;

                case "WINDOW":
                  commandString = "Window \"" +
                                  GetFriendlyName(Enum.GetName(typeof (GUIWindow.Window), Convert.ToInt32(cmdProperty))) +
                                  "\"";
                  break;

                case "TOGGLE":
                  commandString = "Toggle Layer";
                  break;

                case "POWER":
                  commandString = powerList[Array.IndexOf(nativePowerList, cmdProperty)];
                  break;

                case "PROCESS":
                  commandString = processList[Array.IndexOf(nativeProcessList, cmdProperty)];
                  break;
              }

              #endregion Commands

              var conditionNode = new TreeNode(conditionString);
              conditionNode.Tag = new NodeData("CONDITION", condition, conProperty);
              if (commandString == "Action \"Key Pressed\"")
              {
                var cmdKeyChar = nodeAction.Attributes["cmdkeychar"].Value;
                var cmdKeyCode = nodeAction.Attributes["cmdkeycode"].Value;
                var commandNode = new TreeNode(string.Format("Key Pressed: {0} [{1}]", cmdKeyChar, cmdKeyCode));

                var key = new Key(Convert.ToInt32(cmdKeyChar), Convert.ToInt32(cmdKeyCode));

                commandNode.Tag = new NodeData("COMMAND", "KEY", key, gainFocus);
                commandNode.ForeColor = Color.DarkGreen;
                conditionNode.ForeColor = Color.Blue;
                conditionNode.Nodes.Add(commandNode);
              }
              else
              {
                var commandNode = new TreeNode(commandString);
                commandNode.Tag = new NodeData("COMMAND", command, cmdProperty, gainFocus);
                commandNode.ForeColor = Color.DarkGreen;
                conditionNode.ForeColor = Color.Blue;
                conditionNode.Nodes.Add(commandNode);
              }

              var soundNode = new TreeNode(sound);
              soundNode.Tag = new NodeData("SOUND", null, sound);
              if (sound == string.Empty)
              {
                soundNode.Text = "No Sound";
              }
              soundNode.ForeColor = Color.DarkRed;
              conditionNode.Nodes.Add(soundNode);

              if (layer == 1)
              {
                layer1Node.Nodes.Add(conditionNode);
              }
              if (layer == 2)
              {
                layer2Node.Nodes.Add(conditionNode);
              }
              if (layer == 0)
              {
                layerAllNode.Nodes.Add(conditionNode);
              }
            }
            if (layer1Node.Nodes.Count > 0)
            {
              buttonNode.Nodes.Add(layer1Node);
            }
            if (layer2Node.Nodes.Count > 0)
            {
              buttonNode.Nodes.Add(layer2Node);
            }
            if (layerAllNode.Nodes.Count > 0)
            {
              buttonNode.Nodes.Add(layerAllNode);
            }
          }
          treeMapping.Nodes.Add(remoteNode);
          if (listRemotes.Count == 1)
          {
            remoteNode.Expand();
          }
        }
        changedSettings = false;
      }
      catch (Exception ex)
      {
        Log.Error(ex);
        //Force loading defaults if we were not already doing it
        if (!defaults)
        {
          //Possibly corrupted custom configuration
          //Try loading the defaults then
          LoadMapping("classic", true);
        }
        else
        {
          //Loading the default configuration failed
          //Just propagate our exception then
          throw ex;
        }        
      }
    }
Пример #19
0
    /// <summary>
    /// Execute the given conditional action if needed.
    /// </summary>
    /// <param name="aAction">The action we want to conditionally execute.</param>
    /// <param name="aProcessId">Process-ID for close/kill commands.</param>
    /// <returns></returns>
    public bool ExecuteActionIfNeeded(ConditionalAction aAction, int aProcessId = -1)
    {
      if (aAction == null)
      {
        return false;
      }

      HidListener.LogInfo("Action: {0} / {1} / {2} / {3}", aAction.Condition, aAction.ConProperty, aAction.Command, aAction.CmdProperty);

      Action action;
      if (aAction.Sound != string.Empty)
      {
        Util.Utils.PlaySound(aAction.Sound, false, true);
      }
      if (aAction.Focus && !GUIGraphicsContext.HasFocus)
      {
        GUIGraphicsContext.ResetLastActivity();
        var msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_GETFOCUS, 0, 0, 0, 0, 0, null);
        //GUIWindowManager.SendThreadMessage(msg);
        GUIGraphicsContext.SendMessage(msg);
        return true;
      }
      switch (aAction.Command)
      {
        case "ACTION": // execute Action x
          var key = new Key(aAction.CmdKeyChar, aAction.CmdKeyCode);

          HidListener.LogInfo("Executing: key {0} / {1} / Action: {2} / {3}", aAction.CmdKeyChar, aAction.CmdKeyCode,
            aAction.CmdProperty,
            ((Action.ActionType)Convert.ToInt32(aAction.CmdProperty)).ToString());

          action = new Action(key, (Action.ActionType)Convert.ToInt32(aAction.CmdProperty), 0, 0);
          GUIGraphicsContext.OnAction(action);
          break;

        case "KEY": // send Key x
          SendKeys.SendWait(aAction.CmdProperty);
          break;

        case "WINDOW": // activate Window x
          GUIGraphicsContext.ResetLastActivity();
          GUIMessage msg;
          if ((Convert.ToInt32(aAction.CmdProperty) == (int)GUIWindow.Window.WINDOW_HOME) ||
              (Convert.ToInt32(aAction.CmdProperty) == (int)GUIWindow.Window.WINDOW_SECOND_HOME))
          {
            if (_basicHome)
            {
              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);
            }
          }
          else
          {
            msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_GOTO_WINDOW, 0, 0, 0,
              Convert.ToInt32(aAction.CmdProperty),
              0, null);
          }

          GUIWindowManager.SendThreadMessage(msg);
          break;

        case "TOGGLE": // toggle Layer 1/2
          if (_currentLayer == 1)
          {
            _currentLayer = 2;
          }
          else
          {
            _currentLayer = 1;
          }
          break;

        case "POWER": // power down commands

          if ((aAction.CmdProperty == "STANDBY") || (aAction.CmdProperty == "HIBERNATE"))
          {
            GUIGraphicsContext.ResetLastActivity();
          }

          switch (aAction.CmdProperty)
          {
            case "EXIT":
              action = new Action(Action.ActionType.ACTION_EXIT, 0, 0);
              GUIGraphicsContext.OnAction(action);
              break;

            case "REBOOT":
              action = new Action(Action.ActionType.ACTION_REBOOT, 0, 0);
              GUIGraphicsContext.OnAction(action);
              break;

            case "SHUTDOWN":
              action = new Action(Action.ActionType.ACTION_SHUTDOWN, 0, 0);
              GUIGraphicsContext.OnAction(action);
              break;

            case "STANDBY":
              action = new Action(Action.ActionType.ACTION_SUSPEND, 1, 0); //1 = ignore prompt
              GUIGraphicsContext.OnAction(action);
              break;

            case "HIBERNATE":
              action = new Action(Action.ActionType.ACTION_HIBERNATE, 1, 0); //1 = ignore prompt
              GUIGraphicsContext.OnAction(action);
              break;
          }
          break;

        case "PROCESS":
          {
            GUIGraphicsContext.ResetLastActivity();
            if (aProcessId > 0)
            {
              var proc = Process.GetProcessById(aProcessId);
              if (null != proc)
              {
                switch (aAction.CmdProperty)
                {
                  case "CLOSE":
                    proc.CloseMainWindow();
                    break;

                  case "KILL":
                    proc.Kill();
                    break;
                }
              }
            }
          }
          break;

        default:
          return false;
      }
      return true;
    }