Example #1
0
 private void SaveHotKeyItems(KeyGo data)
 {
     try
     {
         data.SaveXml(_DataFilePath);
     }
     catch (Exception ex)
     {
         MessageBox.Show("保存数据文件异常:" + ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Example #2
0
        private KeyGo LoadHotKeyItems(string xmlFilePath)
        {
            KeyGo instance = null;

            try
            {
                instance = KeyGo.LoadXml(xmlFilePath);
            }
            catch (Exception ex)
            {
                MessageBox.Show("载入数据文件异常:" + ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            return(instance ?? new KeyGo());
        }
Example #3
0
        /// <summary>
        /// Loads the XML.
        /// </summary>
        /// <param name="filePath">The file path.</param>
        /// <returns></returns>
        public static KeyGo LoadXml(string filePath)
        {
            KeyGo data = null;

            if (File.Exists(filePath))
            {
                XmlSerializer formatter = new XmlSerializer(typeof(KeyGo));
                using (var stream = File.OpenRead(filePath))
                {
                    if (stream.Length > 0)
                    {
                        data = formatter.Deserialize(stream) as KeyGo;
                    }
                }
            }
            return(data);
        }
Example #4
0
        public FormMain()
        {
            InitializeComponent();
            _Initializing = true;

            // 读取程序集版本,显示到标题栏
            Assembly     assembly      = Assembly.GetExecutingAssembly();
            AssemblyName thisAssemName = assembly.GetName();

            Text += $" - {thisAssemName.Version} - github.com/jie65535/KeyGo";

            // 载入并初始化配置
            _AppConfig = LoadAppConfig(_AppConfigFilePath);
            TSMICloseToHide.Checked = _AppConfig.CloseToHide;
            TSMIPowerBoot.Checked   = _AppConfig.PowerBoot;
            SetPowerBoot(_AppConfig.PowerBoot);

            // 载入热键数据
            _KeyGo = LoadHotKeyItems(_DataFilePath);
            _KeyGo.HotKeyTriggerEvent += KeyGo_HotKeyTriggerEvent;
            _KeyGo.FormHandle          = Handle;
            var p = Process.GetCurrentProcess();

            _CurrentProcessName = p.ProcessName;
            if (_KeyGo.Items.Count == 0)
            {
                _KeyGo.Items.Add(new HotKeyItem
                {
                    ProcessName = _CurrentProcessName,
                    StartupPath = p.MainModule.FileName,
                    HotKey      = "Ctrl+G",
                });
            }
            _KeyGo.RegAllKey();

            // 初始化UI
            FLPHotKeys.SuspendLayout();
            foreach (var item in _KeyGo.Items)
            {
                FLP_AddItem(item);
            }
            FLPHotKeys.ResumeLayout();

            _Initializing = false;
        }