コード例 #1
0
ファイル: MainForm.cs プロジェクト: lxzh/lxzhASS
        /// <summary>
        /// 保存设置项
        /// </summary>
        /// <returns></returns>
        private bool SaveSetting()
        {
            string path   = txtSavePath.Text;
            bool   result = true;

            try {
                DirectoryInfo di = new DirectoryInfo(path);
            } catch (Exception e) {
                result = false;
                Console.WriteLine(e.ToString());
            }
            if (!checkPathChar(path))
            {
                result = false;
            }
            if (!result)
            {
                new Toast(1, "截图文件保存路径不是有效的文件路径,请重新输入!").Show();
                return(false);
            }
            else
            {
                if (!Directory.Exists(path))
                {
                    new Toast(1, "截图文件保存路径不存在,请重新输入!").Show();
                    ScanFolder();
                }
                #region 保存配置
                IniFile.WriteIniData(Util.CONFIG_SECTION, Util.START_ON_POWER_ON, chkSPO.Checked.ToString());
                RegistryUtil.setStart(chkSPO.Checked);

                IniFile.WriteIniData(Util.CONFIG_SECTION, Util.SAVE_FILE_EXTENSION, cbbExtension.SelectedItem.ToString());

                IniFile.WriteIniData(Util.CONFIG_SECTION, Util.SAVE_PIC_PATH, txtSavePath.Text);

                for (int i = 0; i < hotKeyCount; i++)
                {
                    if (!hotKeys[i].setHotkey(new bool[] { chkHotkeys[i][2].Checked, chkHotkeys[i][0].Checked, chkHotkeys[i][1].Checked, chkHotkeys[i][3].Checked }, cbbHotkeys[i].SelectedIndex))
                    {
                        cbbHotkeys[i].Select();
                        new Toast(1, "请至少选择一个辅助键(Ctrl/Alt/Shift/Win)!").Show();
                        return(false);
                    }
                }

                #endregion
                if (!checkHotkeyConflit())
                {
                    return(false);
                }
                #region 注册新设置的快捷键
                for (int i = 0; i < hotKeyCount; i++)
                {
                    if (hotKeys[i].RegistedHotkey != hotKeys[i].Hotkey)
                    {
                        bool rst = HotKey.RegisteSetHotkey(Program.mainForm.Handle, hotKeys[i]);
                        if (rst)
                        {
                            IniFile.WriteIniData(Util.CONFIG_SECTION, hotKeys[i].KeyName, hotKeys[i].Hotkey);
                        }
                        result &= rst;
                    }
                }

                if (!result)
                {
                    new Toast(2, "保存失败,请检查是否有快捷键和其他应用程序存在冲突").Show();
                }
                #endregion
                isSaved = result;
                return(isSaved);
            }
        }
コード例 #2
0
        /// <summary>
        /// 保存设置项
        /// </summary>
        /// <returns></returns>
        private bool SaveSetting()
        {
            string path   = txtSavePath.Text;
            bool   result = true;

            try {
                DirectoryInfo di = new DirectoryInfo(path);
            } catch (Exception e) {
                result = false;
                Console.WriteLine(e.ToString());
            }
            if (!checkPathChar(path))
            {
                result = false;
            }
            if (!result)
            {
                new Toast(1, "截图文件保存路径不是有效的文件路径,请重新输入!").Show();
                return(false);
            }
            else
            {
                if (!Directory.Exists(path))
                {
                    new Toast(1, "截图文件保存路径不存在,请重新输入!").Show();
                    ScanFolder();
                }
                #region 保存配置
                IniFile.WriteIniData(Util.CONFIG_SECTION, Util.START_ON_POWER_ON, chkSPO.Checked.ToString());
                RegistryUtil.setStart(chkSPO.Checked);

                IniFile.WriteIniData(Util.CONFIG_SECTION, Util.SAVE_FILE_EXTENSION, cbbExtension.SelectedItem.ToString());

                IniFile.WriteIniData(Util.CONFIG_SECTION, Util.SAVE_PIC_PATH, txtSavePath.Text);

                if (!Util.HOTKEY_WHOLE.setHotkey(new bool[] { chkAlt1.Checked, chkCtrl1.Checked, chkShift1.Checked, chkWin1.Checked }, cbbKeys1.SelectedIndex))
                {
                    cbbKeys1.Select();
                    new Toast(1, "请至少选择一个辅助键(Ctrl/Alt/Shift/Win)!").Show();
                    return(false);
                }
                if (!Util.HOTKEY_ACTIVE.setHotkey(new bool[] { chkAlt2.Checked, chkCtrl2.Checked, chkShift2.Checked, chkWin2.Checked }, cbbKeys2.SelectedIndex))
                {
                    cbbKeys2.Select();
                    new Toast(1, "请至少选择一个辅助键(Ctrl/Alt/Shift/Win)!").Show();
                    return(false);
                }
                if (!Util.HOTKEY_FREE.setHotkey(new bool[] { chkAlt3.Checked, chkCtrl3.Checked, chkShift3.Checked, chkWin3.Checked }, cbbKeys3.SelectedIndex))
                {
                    cbbKeys3.Select();
                    new Toast(1, "请至少选择一个辅助键(Ctrl/Alt/Shift/Win)!").Show();
                    return(false);
                }
                if (!Util.HOTKEY_LAST.setHotkey(new bool[] { chkAlt4.Checked, chkCtrl4.Checked, chkShift4.Checked, chkWin4.Checked }, cbbKeys4.SelectedIndex))
                {
                    cbbKeys4.Select();
                    new Toast(1, "请至少选择一个辅助键(Ctrl/Alt/Shift/Win)!").Show();
                    return(false);
                }
                if (!Util.HOTKEY_CLIP.setHotkey(new bool[] { chkAlt5.Checked, chkCtrl5.Checked, chkShift5.Checked, chkWin5.Checked }, cbbKeys5.SelectedIndex))
                {
                    cbbKeys5.Select();
                    new Toast(1, "请至少选择一个辅助键(Ctrl/Alt/Shift/Win)!").Show();
                    return(false);
                }
                if (!Util.HOTKEY_EXIT.setHotkey(new bool[] { chkAlt6.Checked, chkCtrl6.Checked, chkShift6.Checked, chkWin6.Checked }, cbbKeys6.SelectedIndex))
                {
                    cbbKeys6.Select();
                    new Toast(1, "请至少选择一个辅助键(Ctrl/Alt/Shift/Win)!").Show();
                    return(false);
                }
                #endregion
                if (!checkHotkeyConflit())
                {
                    return(false);
                }
                #region 注册新设置的快捷键
                if (Util.HOTKEY_WHOLE.RegistedHotkey != Util.HOTKEY_WHOLE.Hotkey)
                {
                    IniFile.WriteIniData(Util.CONFIG_SECTION, Util.HOTKEY_WHOLE.KeyName, Util.HOTKEY_WHOLE.Hotkey);
                    result &= HotKey.RegisteSetHotkey(Program.mainForm.Handle, Util.HOTKEY_WHOLE);
                }
                if (Util.HOTKEY_ACTIVE.RegistedHotkey != Util.HOTKEY_ACTIVE.Hotkey)
                {
                    IniFile.WriteIniData(Util.CONFIG_SECTION, Util.HOTKEY_ACTIVE.KeyName, Util.HOTKEY_ACTIVE.Hotkey);
                    result &= HotKey.RegisteSetHotkey(Program.mainForm.Handle, Util.HOTKEY_ACTIVE);
                }
                if (Util.HOTKEY_FREE.RegistedHotkey != Util.HOTKEY_FREE.Hotkey)
                {
                    IniFile.WriteIniData(Util.CONFIG_SECTION, Util.HOTKEY_FREE.KeyName, Util.HOTKEY_FREE.Hotkey);
                    result &= HotKey.RegisteSetHotkey(Program.mainForm.Handle, Util.HOTKEY_FREE);
                }
                if (Util.HOTKEY_LAST.RegistedHotkey != Util.HOTKEY_LAST.Hotkey)
                {
                    IniFile.WriteIniData(Util.CONFIG_SECTION, Util.HOTKEY_LAST.KeyName, Util.HOTKEY_LAST.Hotkey);
                    result &= HotKey.RegisteSetHotkey(Program.mainForm.Handle, Util.HOTKEY_LAST);
                }
                if (Util.HOTKEY_CLIP.RegistedHotkey != Util.HOTKEY_CLIP.Hotkey)
                {
                    IniFile.WriteIniData(Util.CONFIG_SECTION, Util.HOTKEY_CLIP.KeyName, Util.HOTKEY_CLIP.Hotkey);
                    result &= HotKey.RegisteSetHotkey(Program.mainForm.Handle, Util.HOTKEY_CLIP);
                }
                if (Util.HOTKEY_EXIT.RegistedHotkey != Util.HOTKEY_EXIT.Hotkey)
                {
                    IniFile.WriteIniData(Util.CONFIG_SECTION, Util.HOTKEY_EXIT.KeyName, Util.HOTKEY_EXIT.Hotkey);
                    result &= HotKey.RegisteSetHotkey(Program.mainForm.Handle, Util.HOTKEY_EXIT);
                }
                if (!result)
                {
                    new Toast(2, "保存失败,请检查是否有快捷键和其他应用程序存在冲突").Show();
                }
                #endregion
                isSaved = result;
                return(isSaved);
            }
        }