Example #1
0
 private void MetroWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
 {
     if (DataUtil.Config.sysConfig.exitConfirm && MessageBox.Show("是否确定要退出团长助理?", "退出确认", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No)
     {
         e.Cancel = true;
         return;
     }
     timerCheck.Dispose();
     timerClock.Dispose();
     timerAuto.Dispose();
     if (DataUtil.Config.sysConfig.enableHotKey)
     {
         IntPtr handle = new WindowInteropHelper(this).Handle;
         HotKeyHelper.UnregisterHotKey(handle, HotKeyHelper.hotKeyId);
     }
     if (SoundHelper.isMute)
     {
         SoundHelper.Mute();
     }
     if (notifyIcon != null)
     {
         notifyIcon.Dispose();
         notifyIcon = null;
     }
 }
Example #2
0
        private void InitializeNotifyIcon()
        {
            var notifyIcon = new NotifyIcon {
                Icon = this.Icon, Visible = true
            };

            this.Closing += delegate
            {
                HotKeyHelper.UnregisterHotKey(this.Handle, 100);
                HotKeyHelper.UnregisterHotKey(this.Handle, 101);
            };

            notifyIcon.MouseDown += (sender, e) =>
            {
                if (e.Button == MouseButtons.Left)
                {
                    this.Activate();
                    this.Visible = true;
                }
                if (e.Button == MouseButtons.Right)
                {
                    if (MessageBox.Show("Are your sure to exit the PassBerry?", "Exit", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        this.Close();
                    }
                }
            };
        }
Example #3
0
        void MainWindow_Closing(object sender, CancelEventArgs e)
        {
            Storage.Save(m_rootViewModel.TaskData);
            HotKeyHelper.UnregisterHotKey(this, c_hotKeyId);

            UnregisterApplicationRecoveryAndRestart();
        }
Example #4
0
        private void RegiseterHotKey(int hotKeyId, string hotkey)
        {
            string[] keys = hotkey.Split('+');
            List <HotKeyHelper.KeyModifiers> keyModifiers = new List <HotKeyHelper.KeyModifiers>();
            List <string> normalKey = new List <string>();

            for (int i = 0; i < keys.Length; i++)
            {
                if (keys[i].ToLower() == "ctrl")
                {
                    keyModifiers.Add(HotKeyHelper.KeyModifiers.Ctrl);
                }
                else if (keys[i].ToLower() == "alt")
                {
                    keyModifiers.Add(HotKeyHelper.KeyModifiers.Alt);
                }
                else if (keys[i].ToLower() == "shift")
                {
                    keyModifiers.Add(HotKeyHelper.KeyModifiers.Shift);
                }
                else
                {
                    normalKey.Add(keys[i]);
                }
            }
            if (normalKey.Count == 1) //
            {
                Keys norKey = Keys.D1;
                int  key    = 0;
                try
                {
                    if (int.TryParse(normalKey[0], out key))
                    {
                        norKey = (Keys)System.Enum.Parse(typeof(Keys), "D" + normalKey[0]);
                    }
                    else
                    {
                        norKey = (Keys)System.Enum.Parse(typeof(Keys), normalKey[0]);
                    }
                }
                catch (Exception)
                {
                    return;
                }

                HotKeyHelper.KeyModifiers sysKeyModifiers = HotKeyHelper.KeyModifiers.None;
                for (int i = 0; i < keyModifiers.Count; i++)
                {
                    sysKeyModifiers |= keyModifiers[i];
                }
                HotKeyHelper.UnregisterHotKey(handle, hotKeyId);
                HotKeyHelper.RegisterHotKey(handle, hotKeyId, sysKeyModifiers, norKey);
            }
        }
Example #5
0
        private void ActivateContent()
        {
            HotKeyHelper.UnregisterHotKey();
            this.viewModel.ShowAllCommands();
            if (this.viewModel.FilteredCommandList.Count > 0)
            {
                this.SuggestionList.ScrollIntoView(this.viewModel.FilteredCommandList[0]);
            }

            this.Top           = ScreenHelper.GetPrimaryScreen().Bounds.Height * 0.20;
            this.Left          = ScreenHelper.GetAppCenterScreenWidth(this.Width);
            this.Visibility    = Visibility.Visible;
            this.SizeToContent = SizeToContent.Height;

            HotKeyHelper.SetForegroundWindow(HotKeyHelper.applicationHandle);
        }
        public OptionsView(Config config)
        {
            this.config = config ??
                          throw new ArgumentNullException(nameof(config));

            this.viewModel = new OptionsViewModel(this.config);

            this.InitializeComponent();
            this.SourceInitialized += this.OptionsView_SourceInitialized;
            this.DataContext        = this.viewModel;

            this.btnSave.Click   += this.BtnSave_Click;
            this.btnCancel.Click += this.BtnCancel_Click;
            this.Closing         += this.OptionsView_Closing;
            this.Closed          += this.OptionsView_Closed;
            HotKeyHelper.UnregisterHotKey();
        }
Example #7
0
        public AboutView(Config config)
        {
            this.config = config ??
                          throw new ArgumentNullException(nameof(config));

            this.viewModel = new AboutViewModel(this.config);

            this.InitializeComponent();
            this.DataContext = this.viewModel;
            HotKeyHelper.UnregisterHotKey();

            this.Closing            += this.AboutView_Closing;
            this.topPanel.MouseDown += this.TopPanel_MouseDown;
            this.btnClose.Click     += this.BtnClose_Click;

            this.mMaier.MouseUp  += this.MMaier_MouseUp;
            this.gCookie.MouseUp += this.GCookie_MouseUp;

            this.gitHubLogo.MouseUp += this.GitHubLogo_MouseUp;
            this.ipLogo.MouseUp     += this.IpLogo_MouseUp;
        }
Example #8
0
        /// <summary>
        /// 启用老板键
        /// </summary>
        private void EnableHotKey()
        {
            System.Windows.Forms.Keys k = (System.Windows.Forms.Keys)Enum.Parse(typeof(System.Windows.Forms.Keys), DataUtil.Config.sysConfig.hotKey.ToString().ToUpper());
            HotKeyHelper.KeyModifiers m = HotKeyHelper.KeyModifiers.None;
            if (DataUtil.Config.sysConfig.hotKeyCtrl)
            {
                m = HotKeyHelper.KeyModifiers.Ctrl;
            }
            if (DataUtil.Config.sysConfig.hotKeyAlt)
            {
                if (m == HotKeyHelper.KeyModifiers.None)
                {
                    m = HotKeyHelper.KeyModifiers.Alt;
                }
                else
                {
                    m = m | HotKeyHelper.KeyModifiers.Alt;
                }
            }
            if (DataUtil.Config.sysConfig.hotKeyShift)
            {
                if (m == HotKeyHelper.KeyModifiers.None)
                {
                    m = HotKeyHelper.KeyModifiers.Shift;
                }
                else
                {
                    m = m | HotKeyHelper.KeyModifiers.Shift;
                }
            }
            IntPtr handle = new WindowInteropHelper(this).Handle;

            if (HotKeyHelper.isRegistered)
            {
                HotKeyHelper.UnregisterHotKey(handle, HotKeyHelper.hotKeyId);
            }
            HotKeyHelper.isRegistered = HotKeyHelper.RegisterHotKey(handle, HotKeyHelper.hotKeyId, m, k);
            HotKeyHelper.InstallHotKeyHook(this);
        }
Example #9
0
        /// <summary>
        /// 将图形界面设置保存到设置模块
        /// </summary>
        private async Task <bool> SaveSettingsToConfig()
        {
            tbHotKey.Text = tbHotKey.Text.ToUpper();

            int tryInt;

            if (!int.TryParse(tbProxyPort.Text, out tryInt))
            {
                await this.ShowMessageAsync("错误 - 保存失败", "代理服务器端口号必须是整数!");

                return(false);
            }
            if (!int.TryParse(tbAPTarget.Text, out tryInt))
            {
                await this.ShowMessageAsync("错误 - 保存失败", "指定体力必须是整数!");

                return(false);
            }
            if (!int.TryParse(tbBPTarget.Text, out tryInt))
            {
                await this.ShowMessageAsync("错误 - 保存失败", "指定战点必须是整数!");

                return(false);
            }
            if (!int.TryParse(tbPushTimes.Text, out tryInt))
            {
                await this.ShowMessageAsync("错误 - 保存失败", "代理服务器端口号必须是整数!");

                return(false);
            }
            if (!int.TryParse(tbDelayTime.Text, out tryInt))
            {
                await this.ShowMessageAsync("错误 - 保存失败", "代理服务器端口号必须是整数!");

                return(false);
            }
            if (chkEnableHotKey.IsChecked.HasValue && (bool)chkEnableHotKey.IsChecked)
            {
                if (!(bool)chkHotKeyAlt.IsChecked && !(bool)chkHotKeyCtrl.IsChecked && !(bool)chkHotKeyShift.IsChecked)
                {
                    await this.ShowMessageAsync("错误 - 保存失败", "老板键必须要选择Ctrl、Alt、Shift中的一个或者多个!");

                    return(false);
                }
            }

            DataUtil.Config.sysConfig.showLoginDialog = chkShowLogin.IsChecked.HasValue ? (bool)chkShowLogin.IsChecked : false;
            DataUtil.Config.sysConfig.showLoginNews   = chkShowNews.IsChecked.HasValue ? (bool)chkShowNews.IsChecked : false;
            DataUtil.Config.sysConfig.gameServer      = cbGameServer.SelectedIndex;
            DataUtil.Config.sysConfig.gameHomePage    = cbLoginPage.SelectedIndex;

            if (rbNotUseProxy.IsChecked.HasValue && (bool)rbNotUseProxy.IsChecked)
            {
                DataUtil.Config.sysConfig.proxyType = SysConfig.ProxySettingsType.DirectAccess;
            }
            else if (rbUseIEProxy.IsChecked.HasValue && (bool)rbUseIEProxy.IsChecked)
            {
                DataUtil.Config.sysConfig.proxyType = SysConfig.ProxySettingsType.UseSystemProxy;
            }
            else if (rbUseCusProxy.IsChecked.HasValue && (bool)rbUseCusProxy.IsChecked)
            {
                DataUtil.Config.sysConfig.proxyType = SysConfig.ProxySettingsType.UseUserProxy;
            }
            DataUtil.Config.sysConfig.proxyServer = tbProxyServer.Text;
            DataUtil.Config.sysConfig.proxyPort   = int.Parse(tbProxyPort.Text);

            DataUtil.Config.sysConfig.apTargetNotify   = chkAPTarget.IsChecked.HasValue ? (bool)chkAPTarget.IsChecked ? short.Parse(tbAPTarget.Text) : (short)0 : (short)0;
            DataUtil.Config.sysConfig.apFullNotify     = chkAPFull.IsChecked.HasValue ? (bool)chkAPFull.IsChecked : false;
            DataUtil.Config.sysConfig.bpTargetNotify   = chkBPTarget.IsChecked.HasValue ? (bool)chkBPTarget.IsChecked ? short.Parse(tbBPTarget.Text) : (short)0 : (short)0;
            DataUtil.Config.sysConfig.bpFullNotify     = chkBPFull.IsChecked.HasValue ? (bool)chkBPFull.IsChecked : false;
            DataUtil.Config.sysConfig.spEveryNotify    = chkSPEvery.IsChecked.HasValue ? (bool)chkSPEvery.IsChecked : false;
            DataUtil.Config.sysConfig.spFullNotify     = chkSPFull.IsChecked.HasValue ? (bool)chkSPFull.IsChecked : false;
            DataUtil.Config.sysConfig.foundStageNotify = chkFoundStage.IsChecked.HasValue ? (bool)chkFoundStage.IsChecked : false;
            DataUtil.Config.sysConfig.foundBossNotify  = chkFoundBoss.IsChecked.HasValue ? (bool)chkFoundBoss.IsChecked : false;

            DataUtil.Config.sysConfig.logGame  = chkGameLog.IsChecked.HasValue ? (bool)chkGameLog.IsChecked : false;
            DataUtil.Config.sysConfig.logGacha = chkGachaLog.IsChecked.HasValue ? (bool)chkGachaLog.IsChecked : false;

            DataUtil.Config.sysConfig.autoGoInMaps  = chkAutoGo.IsChecked.HasValue ? (bool)chkAutoGo.IsChecked : false;
            DataUtil.Config.sysConfig.autoGoTimeout = (int)slAutoRate.Value;

            DataUtil.Config.sysConfig.changeTitle    = chkTitleChange.IsChecked.HasValue ? (bool)chkTitleChange.IsChecked : false;
            DataUtil.Config.sysConfig.alwaysShowTray = chkAlwaysTray.IsChecked.HasValue ? (bool)chkAlwaysTray.IsChecked : false;
            DataUtil.Config.sysConfig.miniToTray     = chkMiniToTray.IsChecked.HasValue ? (bool)chkMiniToTray.IsChecked : false;
            DataUtil.Config.sysConfig.miniToMute     = chkAutoMute.IsChecked.HasValue ? (bool)chkAutoMute.IsChecked : false;
            DataUtil.Config.sysConfig.exitConfirm    = chkExitConfrim.IsChecked.HasValue ? (bool)chkExitConfrim.IsChecked : false;

            DataUtil.Config.sysConfig.enableHotKey = chkEnableHotKey.IsChecked.HasValue ? (bool)chkEnableHotKey.IsChecked : false;
            DataUtil.Config.sysConfig.hotKeyCtrl   = chkHotKeyCtrl.IsChecked.HasValue ? (bool)chkHotKeyCtrl.IsChecked : false;
            DataUtil.Config.sysConfig.hotKeyAlt    = chkHotKeyAlt.IsChecked.HasValue ? (bool)chkHotKeyAlt.IsChecked : false;
            DataUtil.Config.sysConfig.hotKeyShift  = chkHotKeyShift.IsChecked.HasValue ? (bool)chkHotKeyShift.IsChecked : false;
            DataUtil.Config.sysConfig.hotKey       = tbHotKey.Text[0];

            //自动推兔设置
            DataUtil.Config.sysConfig.autoType  = cbAutoType.SelectedIndex;
            DataUtil.Config.sysConfig.pushType  = cbPushType.SelectedIndex;
            DataUtil.Config.sysConfig.pushTimes = int.Parse(tbPushTimes.Text);

            DataUtil.Config.sysConfig.potionTrue = chkPotionTrue.IsChecked.HasValue ? (bool)chkPotionTrue.IsChecked : false;
            DataUtil.Config.sysConfig.stoneTrue  = chkStoneTrue.IsChecked.HasValue ? (bool)chkStoneTrue.IsChecked : false;

            DataUtil.Config.sysConfig.raidOther   = chkRaidOther.IsChecked.HasValue ? (bool)chkRaidOther.IsChecked : false;
            DataUtil.Config.sysConfig.raidSelf    = chkRaidSelf.IsChecked.HasValue ? (bool)chkRaidSelf.IsChecked : false;
            DataUtil.Config.sysConfig.specialTrue = chkSpecialTrue.IsChecked.HasValue ? (bool)chkSpecialTrue.IsChecked : false;

            DataUtil.Config.sysConfig.delayTime = int.Parse(tbDelayTime.Text);

            DataUtil.Config.sysConfig.sellTrue    = chkSellTrue.IsChecked.HasValue ? (bool)chkSellTrue.IsChecked : false;
            DataUtil.Config.sysConfig.exploreTrue = chkExploreTrue.IsChecked.HasValue ? (bool)chkExploreTrue.IsChecked : false;
            DataUtil.Config.sysConfig.gardenTrue  = chkGardenTrue.IsChecked.HasValue ? (bool)chkGardenTrue.IsChecked : false;
            DataUtil.Config.sysConfig.actionPrep  = chkActionPrep.IsChecked.HasValue ? (bool)chkActionPrep.IsChecked : false;

            DataUtil.Config.sysConfig.gameRestart = chkGameRestart.IsChecked.HasValue ? (bool)chkGameRestart.IsChecked : false;

            DataUtil.Config.sysConfig.specialBlock = chkSpecialBlock.IsChecked.HasValue ? (bool)chkSpecialBlock.IsChecked : false;


            DataUtil.Config.sysConfig.capFormat = (SysConfig.ScreenShotFormat)cbCapFormat.SelectedIndex;

            if (cbGameServer.SelectedIndex == (int)GameInfo.ServersList.American || cbGameServer.SelectedIndex == (int)GameInfo.ServersList.AmericanR18)
            {
                DataUtil.Config.sysConfig.userCSSAmerican = tbCssStyle.Text;
            }
            else
            {
                DataUtil.Config.sysConfig.userCSS = tbCssStyle.Text;
            }

            if (DataUtil.Config.sysConfig.alwaysShowTray)
            {
                notifyIcon.Visible = true;
            }
            else
            {
                notifyIcon.Visible = false;
            }

            if (DataUtil.Config.sysConfig.enableHotKey)
            {
                EnableHotKey();
            }
            else if (HotKeyHelper.isRegistered)
            {
                IntPtr handle = new WindowInteropHelper(this).Handle;
                HotKeyHelper.UnregisterHotKey(handle, HotKeyHelper.hotKeyId);
            }

            ApplyProxySettings();

            return(true);
        }
Example #10
0
 private void StopWorking()
 {
     this.config.Save(this.configFilePath);
     HotKeyHelper.UnregisterHotKey();
 }
Example #11
0
 private void UnregisterHotKey()
 {
     HotKeyHelper.UnregisterHotKey(this.Handle, HotKeyHelper.HOTKEY_ID_START_MACRO);
     HotKeyHelper.UnregisterHotKey(this.Handle, HotKeyHelper.HOTKEY_ID_END_MACRO);
 }
Example #12
0
        /// <summary>
        /// 取消热键,程序退出时调用,窗体句柄,热键ID
        /// </summary>
        private void UnRegisterHotKey()
        {
            var success = HotKeyHelper.UnregisterHotKey(this.Handle, 0);

            Console.WriteLine("--反注册热键:" + success);
        }