Exemplo n.º 1
0
 static void Main(string[] args)
 {
     logger     = LogManager.GetLogger(typeof(Program));
     keysSounds = new KeysSoundEffects(logger, Resources.key1, Resources.key2, Resources.ctrl,
                                       Resources.shift, Resources.win, Resources.alt);
     try
     {
         configFilePath = "config.txt";
         config         = new JsonConfigSource(logger, configFilePath);
         hookService    = new GlobalHookService(logger, config, keysSounds, true);
         hookService.StartHookService();
         Application.Run();
         while (true)
         {
             if (System.Console.Read() == (int)Keys.Enter)
             {
                 hookService.StopHookService();
             }
         }
     }
     catch (Exception e)
     {
         logger.Error(e.StackTrace);
         System.Console.ReadKey();
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Reloads the configuration.
        /// </summary>
        /// <param name="newConfig">New configuration</param>
        public void ReloadConfig(IConfigSource newConfig)
        {
            try
            {
                logger.Info("START CONFIG RELOAD");
                config         = newConfig;
                configFileName = config.ConfigFilePath;
                if (hookService != null)
                {
                    hookService.StopHookService();
                    hookService.LoadCombinationsConfiguration(config);
                }
                else
                {
                    hookService = new GlobalHookService(logger, config, keysSounds, true);
                    hookService.LoadCombinationsConfiguration();
                }
                if (hookService.combinationsConfig != null && hookService.combinationsConfig.Combinations.Any())
                {
                    hookService.StartHookService(config, helperWindow);
                    Helper.FillCombinationsTable(logger, this.combinationsTable, hookService.combinationsConfig);
                    AddUpdateAppSettings("DefaultConfigFileName", config.ConfigFilePath);
                    if (existingConfigs.All(x => x != configFileName))
                    {
                        CollectExistingConfigs();
                        if (!existingConfigs.Any())
                        {
                            this.EditConfigBtn.Enabled = false;
                        }
                        else
                        {
                            this.EditConfigBtn.Enabled = true;
                        }
                    }

                    existingConfigs = existingConfigs.Distinct().ToList();
                    ExistingConfigsComboBox.DataSource = existingConfigs
                                                         .ToArray();
                    ExistingConfigsComboBox.SelectedIndex = existingConfigs.FindIndex(x => x == configFileName
                                                                                      .Split('.')[0]);
                    this.startAppBtn.Enabled = false;
                    this.stopAppBtn.Enabled  = true;
                }
                else
                {
                    this.startAppBtn.Enabled = false;
                    this.stopAppBtn.Enabled  = false;
                }
                logger.Info("CONFIG RELOAD SUCCESSFULLY ENDS");
            }
            catch (Exception e)
            {
                logger.Error("CONFIG RELOAD ERROR");
                logger.Error(e.StackTrace);
                this.Close();
            }
        }
Exemplo n.º 3
0
        public MainWindow(ILog log)
        {
            InitializeComponent();
            logger                  = log;
            helperWindow            = new HelpWindow(logger);
            configFileName          = ConfigurationManager.AppSettings["DefaultConfigFileName"];
            Globals.AliasResources  = new ResXResourceSet(ConfigurationManager.AppSettings["KeyAliasesResxFileName"]);
            Globals.GlobalResources = new ResXResourceSet(ConfigurationManager.AppSettings["GlobalResxFileName"]);
            keysSounds              = new KeysSoundEffects(logger, Resources.Resources.key1, Resources.Resources.key2,
                                                           Resources.Resources.ctrl, Resources.Resources.shift, Resources.Resources.win,
                                                           Resources.Resources.alt);
            Globals.IsSoundOn = true;
            existingConfigs   = new List <string>();
            try
            {
                CollectExistingConfigs();
                if (!File.Exists(configFileName))
                {
                    configFileName = existingConfigs[0] ?? "";
                }

                if (existingConfigs.Any())
                {
                    config      = new JsonConfigSource(logger, configFileName);
                    hookService = new GlobalHookService(logger, config, keysSounds, true);
                }
                Helper.AddNumericRowsToGrid(combinationsTable);
            }
            catch (ArgumentOutOfRangeException outRangeException)
            {
                Helper.AddNumericRowsToGrid(combinationsTable);
                this.startAppBtn.Enabled   = false;
                this.stopAppBtn.Enabled    = false;
                this.EditConfigBtn.Enabled = false;
            }
            catch (Exception e)
            {
                logger.Error(e.StackTrace);
            }
        }