Exemplo n.º 1
0
        /// <summary>
        /// Saves settings from <see cref="Settings"/> class to XML-file.
        /// </summary>
        public static void SaveSettings()
        {
            IrssLog.Info("Saving settings ...");

            try
            {
                using (XmlTextWriter writer = new XmlTextWriter(ConfigurationFile, Encoding.UTF8))
                {
                    writer.Formatting  = Formatting.Indented;
                    writer.Indentation = 1;
                    writer.IndentChar  = (char)9;
                    writer.WriteStartDocument(true);
                    writer.WriteStartElement("settings"); // <settings>

                    writer.WriteAttributeString("AbstractRemoteMode", AbstractRemoteMode.ToString());
                    writer.WriteAttributeString("Mode", Enum.GetName(typeof(IRServerMode), Mode));
                    writer.WriteAttributeString("HostComputer", HostComputer);
                    writer.WriteAttributeString("ProcessPriority", ProcessPriority);
                    writer.WriteAttributeString("LogVerbosity", LogVerbosity);
                    writer.WriteAttributeString("PluginTransmit", PluginNameTransmit);

                    if (PluginNameReceive != null)
                    {
                        StringBuilder receivers = new StringBuilder();
                        for (int index = 0; index < PluginNameReceive.Length; index++)
                        {
                            receivers.Append(PluginNameReceive[index]);

                            if (index < PluginNameReceive.Length - 1)
                            {
                                receivers.Append(',');
                            }
                        }
                        writer.WriteAttributeString("PluginReceive", receivers.ToString());
                    }
                    else
                    {
                        writer.WriteAttributeString("PluginReceive", String.Empty);
                    }

                    writer.WriteEndElement(); // </settings>
                    writer.WriteEndDocument();
                }
            }
            catch (Exception ex)
            {
                IrssLog.Error(ex);
            }
        }
Exemplo n.º 2
0
        private static void CommsFailure(object obj)
        {
            Exception ex = obj as Exception;

            if (ex != null)
            {
                IrssLog.Error("Communications failure: {0}", ex.Message);
            }
            else
            {
                IrssLog.Error("Communications failure");
            }

            StopClient();
        }
Exemplo n.º 3
0
        private void ClickSetup(object sender, EventArgs e)
        {
            IrssLog.Info("Setup");

            _inConfiguration = true;

            if (Configure())
            {
                Stop();
                Thread.Sleep(500);
                Start();
            }

            _inConfiguration = false;
        }
Exemplo n.º 4
0
        private void StopListener()
        {
            IrssLog.Debug("DirectInput: Stop listening...");

            if (_diListener != null)
            {
                _diListener.DeInitDevice();
                _diListener.StopListener();

                _diListener.OnStateChange -= diListener_OnStateChange;
                _diListener = null;
            }

            _deviceList = null;
        }
Exemplo n.º 5
0
 public static void ServiceInstall()
 {
     try
     {
         IrssLog.Info("Installing IR Server service");
         Process IRServer = Process.Start(Shared.IRServerFile, "/INSTALL");
         IRServer.WaitForExit((int)defaultServiceTime.TotalMilliseconds);
         IrssLog.Info("Installing IR Server service - done");
     }
     catch (Exception ex)
     {
         IrssLog.Error("Installing IR Server service - failed (see following...)");
         IrssLog.Error(ex);
     }
 }
Exemplo n.º 6
0
        /// <summary>
        /// Load a configuration file.
        /// </summary>
        /// <param name="fileName">File to load from.</param>
        /// <returns>Loaded Configuration.</returns>
        internal static AppProfile Load(string fileName)
        {
            try
            {
                XmlSerializer reader = new XmlSerializer(typeof(AppProfile));
                using (StreamReader file = new StreamReader(fileName))
                    return((AppProfile)reader.Deserialize(file));
            }
            catch (Exception ex)
            {
                IrssLog.Error(ex);
            }

            return(null);
        }
Exemplo n.º 7
0
        private static void ReceivedMessage(IrssMessage received)
        {
            IrssLog.Debug("Received Message \"{0}\"", received.Type);

            try
            {
                switch (received.Type)
                {
                case MessageType.BlastIR:
                    if ((received.Flags & MessageFlags.Success) == MessageFlags.Success)
                    {
                        Info("Blast Success");
                    }
                    else if ((received.Flags & MessageFlags.Failure) == MessageFlags.Failure)
                    {
                        Warn("Blast Failed!");
                    }
                    break;

                case MessageType.RegisterClient:
                    if ((received.Flags & MessageFlags.Success) == MessageFlags.Success)
                    {
                        Info("Registered to IR Server");
                        _registered = true;
                        //_irServerInfo = TransceiverInfo.FromString(received.Data);
                    }
                    else if ((received.Flags & MessageFlags.Failure) == MessageFlags.Failure)
                    {
                        _registered = false;
                        Warn("IR Server refused to register");
                    }
                    break;

                case MessageType.ServerShutdown:
                    _registered = false;
                    Warn("IR Server Shutdown - Blasting disabled until IR Server returns");
                    break;

                case MessageType.Error:
                    Warn(received.GetDataAsString());
                    break;
                }
            }
            catch (Exception ex)
            {
                Error(ex);
            }
        }
Exemplo n.º 8
0
        private static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            IrssLog.LogLevel = IrssLog.Level.Debug;
            IrssLog.Open("Keyboard Input Relay.log");

            Application.ThreadException += Application_ThreadException;

            SetupNotify();

            LoadSettings();

            bool clientStarted = false;

            IPAddress  serverIP = Network.GetIPFromName(_serverHost);
            IPEndPoint endPoint = new IPEndPoint(serverIP, Server.DefaultPort);

            try
            {
                clientStarted = StartClient(endPoint);
            }
            catch (Exception ex)
            {
                IrssLog.Error(ex);
                clientStarted = false;
            }

            if (clientStarted)
            {
                StartHook();

                _notifyIcon.Visible = true;

                Application.Run();

                _notifyIcon.Visible = false;

                StopHook();

                StopClient();
            }

            Application.ThreadException -= Application_ThreadException;

            IrssLog.Close();
        }
Exemplo n.º 9
0
        /// <summary>
        /// Save the supplied AppProfile to file.
        /// </summary>
        /// <param name="profile">AppProfile to save.</param>
        /// <param name="fileName">File to save to.</param>
        /// <returns><c>true</c> if successful, otherwise <c>false</c>.</returns>
        internal static bool Save(AppProfile profile, string fileName)
        {
            try
            {
                XmlSerializer writer = new XmlSerializer(typeof(AppProfile));
                using (StreamWriter file = new StreamWriter(fileName))
                    writer.Serialize(file, profile);

                return(true);
            }
            catch (Exception ex)
            {
                IrssLog.Error(ex);
                return(false);
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Save the supplied configuration to file.
        /// </summary>
        /// <param name="config">Configuration to save.</param>
        /// <param name="fileName">File to save to.</param>
        /// <returns><c>true</c> if successful, otherwise <c>false</c>.</returns>
        public static bool Save(Configuration config, string fileName)
        {
            try
            {
                XmlSerializer writer = new XmlSerializer(typeof(Configuration));
                using (StreamWriter file = new StreamWriter(fileName))
                    writer.Serialize(file, config);

                return(true);
            }
            catch (Exception ex)
            {
                IrssLog.Error(ex);
                return(false);
            }
        }
Exemplo n.º 11
0
        private static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            IrssLog.LogLevel = IrssLog.Level.Debug;
            IrssLog.Open(Common.FolderIrssLogs + "MacroScope.log");

            Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);

            Application.Run(new MainForm());

            Application.ThreadException -= new ThreadExceptionEventHandler(Application_ThreadException);

            IrssLog.Close();
        }
Exemplo n.º 12
0
        private void StatusMessage(string format, params object[] args)
        {
            string message = String.Format(format, args);

            toolStripStatusLabel.Text = message;
            statusStrip.Update();

            if (message.StartsWith("ERROR", StringComparison.OrdinalIgnoreCase))
            {
                IrssLog.Error(message);
            }
            else
            {
                IrssLog.Info(message);
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// Loads default values into settings class.
        /// </summary>
        private static void CreateDefaultSettings()
        {
            try
            {
                string[] blasters = Shared.DetectBlasters();
                if (blasters == null || blasters.Length == 0)
                {
                    PluginNameTransmit = String.Empty;
                }
                else
                {
                    PluginNameTransmit = blasters[0];
                }
            }
            catch (Exception ex)
            {
                IrssLog.Error(ex);
                PluginNameTransmit = String.Empty;
            }

            try
            {
                string[] receivers = Shared.DetectReceivers();
                if (receivers == null || receivers.Length == 0)
                {
                    PluginNameReceive = null;
                }
                else
                {
                    PluginNameReceive = receivers;
                }
            }
            catch (Exception ex)
            {
                IrssLog.Error(ex);
                PluginNameReceive = null;
            }

            try
            {
                SaveSettings();
            }
            catch (Exception ex)
            {
                IrssLog.Error(ex);
            }
        }
Exemplo n.º 14
0
        private void onEventArrived(object sender, EventArrivedEventArgs e)
        {
            ManagementBaseObject _o = e.NewEvent["TargetInstance"] as ManagementBaseObject;

            if (_o == null)
            {
                return;
            }

            ManagementObject mo = new ManagementObject(_o["Dependent"].ToString());

            if (mo == null)
            {
                return;
            }

            IList <DeviceInstance> newDeviceList = new DirectInput().GetDevices(DeviceClass.GameController,
                                                                                DeviceEnumerationFlags.AttachedOnly);

            if (_deviceList != null && _deviceList.Count == newDeviceList.Count)
            {
                return;
            }

            try
            {
                if (mo.GetPropertyValue("DeviceID").ToString() != string.Empty)
                {
                    //connected
                    IrssLog.Debug("DirectInput: An USB device has been connected");
                    RestartListener();
                }
            }
            catch
            {
                //disconnected
                IrssLog.Debug("DirectInput: An USB device has been disconnected");
                if (newDeviceList.Count == 0)
                {
                    StopListener();
                }
                else
                {
                    RestartListener();
                }
            }
        }
Exemplo n.º 15
0
        private void ReceivedMessage(IrssMessage received)
        {
            IrssLog.Debug("Received Message \"{0}\"", received.Type);

            try
            {
                switch (received.Type)
                {
                case MessageType.RemoteEvent:
                    if (listViewButtons.SelectedItems.Count == 1)
                    {
                        string keyCode = received.MessageData[IrssMessage.KEY_CODE] as string;

                        listViewButtons.SelectedItems[0].SubItems[1].Text = keyCode;
                    }
                    return;

                case MessageType.RegisterClient:
                    if ((received.Flags & MessageFlags.Success) == MessageFlags.Success)
                    {
                        _registered = true;
                    }
                    else if ((received.Flags & MessageFlags.Failure) == MessageFlags.Failure)
                    {
                        _registered = false;
                        MessageBox.Show(this, "Failed to register with server", "Virtual Remote Skin Editor Error",
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    return;

                case MessageType.ServerShutdown:
                    MessageBox.Show(this, "Server has been shut down", "Virtual Remote Skin Editor Error", MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                    return;

                case MessageType.Error:
                    MessageBox.Show(this, received.GetDataAsString(), "Virtual Remote Skin Editor Error from Server",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
            catch (Exception ex)
            {
                IrssLog.Error(ex);
                MessageBox.Show(this, ex.Message, "Virtual Remote Skin Editor Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 16
0
        /// <summary>
        /// Load external channel configuration.
        /// </summary>
        private static void LoadExternalConfig()
        {
            string fileName = Path.Combine(ExtCfgFolder, "ExternalChannelConfig.xml");

            try
            {
                _externalChannelConfig = ExternalChannelConfig.Load(fileName);
            }
            catch (Exception ex)
            {
                IrssLog.Error(ex);

                _externalChannelConfig = new ExternalChannelConfig(fileName);
            }

            _externalChannelConfig.CardId = 0;
        }
Exemplo n.º 17
0
 /// <summary>
 /// Detect the presence of this device.
 /// </summary>
 public override DetectionResult Detect()
 {
     try
     {
         new FireDTVControl((IntPtr)0);
         return(DetectionResult.DevicePresent);
     }
     catch (FileNotFoundException)
     {
         return(DetectionResult.DeviceNotFound);
     }
     catch (Exception ex)
     {
         IrssLog.Error("{0,15}: exception {1} type: {2}", Name, ex.Message, ex.GetType());
         return(DetectionResult.DeviceException);
     }
 }
Exemplo n.º 18
0
        private void buttonTestMacro_Click(object sender, EventArgs e)
        {
            if (listViewMacro.SelectedItems.Count != 1)
            {
                return;
            }

            try
            {
                Tray.ProcessCommand(Common.CmdPrefixMacro + listViewMacro.SelectedItems[0].Text, false);
            }
            catch (Exception ex)
            {
                IrssLog.Error(ex);
                MessageBox.Show(this, ex.Message, "Test failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 19
0
        /// <summary>
        /// Detect the presence of this device.
        /// </summary>
        public override DetectionResult Detect()
        {
            try
            {
                if (WinLircServer.IsServerRunning())
                {
                    return(DetectionResult.DevicePresent);
                }
            }
            catch (Exception ex)
            {
                IrssLog.Error("{0,15}: exception {1}", Name, ex.Message);
                return(DetectionResult.DeviceException);
            }

            return(DetectionResult.DeviceNotFound);
        }
Exemplo n.º 20
0
            /// <summary>
            /// Saves the settings.
            /// </summary>
            public static void SaveSettings(Config config)
            {
                IrssLog.Info("SaveSettings()");
                XmlSerializer ser = new XmlSerializer(typeof(Config));
                FileStream    str = new FileStream(ConfigurationFile, FileMode.Create);

                try
                {
                    ser.Serialize(str, config);
                }
                catch (Exception ex)
                {
                    IrssLog.Error(ex.ToString());
                }

                str.Close();
            }
Exemplo n.º 21
0
 /// <summary>
 /// Detect the presence of this device.
 /// </summary>
 public override DetectionResult Detect()
 {
     try
     {
         _irRemoteWrapper = new IrRemoteWrapper();
         return(DetectionResult.DevicePresent);
     }
     catch (DirectoryNotFoundException)
     {
         IrssLog.Warn("{0,15}: IrRemote.dll not found", Name);
         return(DetectionResult.DeviceNotFound);
     }
     catch (Exception ex)
     {
         IrssLog.Error("{0,15}: exception {1} type: {2}", Name, ex.Message, ex.GetType());
         return(DetectionResult.DeviceException);
     }
 }
Exemplo n.º 22
0
            /// <summary>
            /// Loads the settings.
            /// </summary>
            public static void LoadSettings(ref Config config)
            {
                IrssLog.Info("LoadSettings()");
                XmlSerializer ser = new XmlSerializer(typeof(Config));
                StreamReader  sr  = new StreamReader(ConfigurationFile);

                try
                {
                    config = (Config)ser.Deserialize(sr);
                }
                catch (Exception ex)
                {
                    IrssLog.Error(ex.ToString());
                    config = new Config();
                }

                sr.Close();
            }
Exemplo n.º 23
0
        private static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            IrssLog.LogLevel = IrssLog.Level.Debug;
            IrssLog.Open("Virtual Remote Skin Editor.log");

            Application.ThreadException += Application_ThreadException;

            MainForm mainForm = new MainForm();

            Application.Run(mainForm);

            Application.ThreadException -= Application_ThreadException;

            IrssLog.Close();
        }
Exemplo n.º 24
0
        private static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(true);

            if (ProcessHelper.IsProcessAlreadyRunning())
            {
                return;
            }

            IrssLog.LogLevel = IrssLog.Level.Debug;
            IrssLog.Open("IR Server Configuration.log");

            Settings.LoadSettings();
            Application.Run(new Config());

            IrssLog.Close();
        }
Exemplo n.º 25
0
        private static void CommsFailure(object obj)
        {
            Exception ex = obj as Exception;

            if (ex != null)
            {
                IrssLog.Error("Communications failure: {0}", ex.Message);
            }
            else
            {
                IrssLog.Error("Communications failure");
            }

            StopClient();

            MessageBox.Show("Please report this error.", "Virtual Remote - Communications failure", MessageBoxButtons.OK,
                            MessageBoxIcon.Error);
        }
Exemplo n.º 26
0
        private string GetCommand()
        {
            string buf;
            string command = String.Empty;
            bool   first   = true;

            AutoResetEvent resetEvent = new AutoResetEvent(false);

            ThreadPool.QueueUserWorkItem(new WaitCallback(e =>
            {
                try
                {
                    //in rare situations the call to ReadLine seems to cause an .NET internal dead-lock or whatever. Unfortunately I don't have a exact idea,
                    //but when I just execute this code-parts in a new thread it raises an exception, that can be handled. Without that the process just hangs
                    //forever until you kill it manually.
                    //The exception that is raised is the following:
                    //System.IO.IOException: Von der Übertragungsverbindung können keine Daten gelesen werden: Ein Blockierungsvorgang wurde durch einen Aufruf von WSACancelBlockingCall unterbrochen.

                    while ((buf = _networkReader.ReadLine()) != null && buf.Length > 0)
                    {
                        if (first)
                        {
                            command = buf;
                            first   = false;
                        }
                    }
                }
                catch (Exception ex)
                {
                    IrssLog.Error(ex);
                }
                finally
                {
                    ((AutoResetEvent)e).Set();
                }
            }), resetEvent);

            if (!resetEvent.WaitOne(5000))
            {
                IrssLog.Error("GetCommand failed. Timeout!");
            }

            return(command);
        }
Exemplo n.º 27
0
        private void Advanced()
        {
            IrssLog.Info("Entering advanced configuration ...");

            Advanced advanced = new Advanced();

            advanced.AbstractRemoteMode = _abstractRemoteMode;
            advanced.Mode            = _mode;
            advanced.HostComputer    = _hostComputer;
            advanced.ProcessPriority = _processPriority;

            if (advanced.ShowDialog(this) == DialogResult.OK)
            {
                _abstractRemoteMode = advanced.AbstractRemoteMode;
                _mode            = advanced.Mode;
                _hostComputer    = advanced.HostComputer;
                _processPriority = advanced.ProcessPriority;
            }
        }
Exemplo n.º 28
0
        private void buttonCommandRemove_Click(object sender, EventArgs e)
        {
            string cmdSelected = SelectedCommand;

            if (cmdSelected != null && _editableGroups.Contains(treeViewCommandList.SelectedNode.Parent))
            {
                bool macro = cmdSelected.IndexOf(Common.CmdPrefixMacro) >= 0;
                int  idx   = cmdSelected.IndexOf(':');
                if (idx < 1 || idx + 3 > cmdSelected.Length)
                {
                    return;
                }

                string srcname = cmdSelected.Substring(idx + 2);
                string srcfile;
                if (macro)
                {
                    srcfile = Path.Combine(FolderMacros, srcname + Common.FileExtensionMacro);
                }
                else
                {
                    srcfile = Path.Combine(FolderBlaster, srcname + Common.FileExtensionIR);
                }
                try
                {
                    File.Delete(srcfile);
                }
                catch (Exception ex)
                {
                    IrssLog.Error(ex);
                    MessageBox.Show(this, ex.Message, "Failed deleting file: " + srcfile, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                if (macro)
                {
                    RefreshMacroList();
                }
                else
                {
                    RefreshBlastList();
                }
            }
        }
Exemplo n.º 29
0
        private void ClickSetup(object sender, EventArgs e)
        {
            if (_inConfiguration)
            {
                IrssLog.Info("Setup clicked, but configuration is already open.");
                return;
            }

            _inConfiguration = true;

            if (Configure())
            {
                Stop();
                Thread.Sleep(500);
                Start();
            }

            _inConfiguration = false;
        }
Exemplo n.º 30
0
        /// <summary>
        /// Load a configuration file.
        /// </summary>
        /// <param name="fileName">File to load from.</param>
        /// <returns>Loaded Configuration.</returns>
        public static Configuration Load(string fileName)
        {
            try
            {
                XmlSerializer reader = new XmlSerializer(typeof(Configuration));
                using (StreamReader file = new StreamReader(fileName))
                    return((Configuration)reader.Deserialize(file));
            }
            catch (FileNotFoundException)
            {
                IrssLog.Warn("No configuration file found ({0}), creating new configuration", fileName);
            }
            catch (Exception ex)
            {
                IrssLog.Error(ex);
            }

            return(null);
        }