Beispiel #1
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (!Setting())
            {
                Application.Current.Shutdown(0xD); //ERROR_INVALID_DATA
                return;
            }

            string outString   = "";
            int    update_type = mConfigData.Options.CheckUpdates ? CheckUpdates(mParserData == null ? "0.0.0.0" : mParserData.Version[1]) : 0;

            string start_msg = "프로그램 버전 " + GetFileVersion() + " 을(를) 시작합니다." + '\n' + '\n'
                               + "* 사용법: 인게임 아이템 위에서 Ctrl + C 하면 창이 뜹니다." + '\n'
                               + "* 종료는: 트레이 아이콘을 우클릭 하시면 됩니다." + '\n' + '\n'
                               + (mAdministrator ? "관리자로 실행했기에 추가 단축키 기능이" : "추가 단축키 기능은 관리자 권한으로 실행해야")
                               + " 작동합니다.";

            if (update_type == 1)
            {
                MessageBoxResult result = MessageBox.Show(
                    Application.Current.MainWindow,
                    start_msg + '\n' + '\n' + "이 프로그램의 최신 버전이 발견 되었습니다."
                    + '\n' + "자동으로 업데이트를 하시겠습니까?",
                    "POE 거래소 검색",
                    MessageBoxButton.YesNo, MessageBoxImage.Question
                    );

                if (result == MessageBoxResult.Yes)
                {
                    // Process.Start("https://github.com/phiDelPark/PoeTradeSearch/releases");
                    PoeExeUpdates();
                    Application.Current.Shutdown();
                    return;
                }
            }
            else
            {
                if (update_type == 2)
                {
                    WinPopup winPopup = new WinPopup(null);
                    Task.Factory.StartNew(() =>
                    {
                        if (PoeDataUpdates())
                        {
                            if (!Setting())
                            {
                                Application.Current.Shutdown(0xD); //ERROR_INVALID_DATA
                                return;
                            }
                        }
                        else
                        {
                            start_msg = start_msg + '\n' + '\n' + "최신 POE 데이터 업데이트를 실패하였습니다."
                                        + '\n' + "접속이 원할하지 않을 수 있으므로 다음 실행시 다시 시도합니다." + '\n';
                        }

                        this.Dispatcher.Invoke(() => { winPopup.Close(); });
                    });
                    winPopup.ShowDialog();
                }

                MessageBox.Show(
                    Application.Current.MainWindow,
                    start_msg + '\n' + "더 자세한 정보를 보시려면 프로그램 상단 (?) 를 눌러 확인하세요.",
                    "POE 거래소 검색"
                    );
            }

            if (!LoadData(out outString))
            {
                this.Visibility = Visibility.Hidden;
                Application.Current.Shutdown(0xD); //ERROR_INVALID_DATA
                return;
            }

            /////////////
            RS.ServerType = RS.ServerType == "" ? mConfigData.Options.League : RS.ServerType;
            RS.ServerType = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(RS.ServerType.ToLower()).Replace(" ", "%20");
            RS.ServerLang = (byte)(mConfigData.Options.Server == "en" ? 1 : 0);

            ComboBox[] cbs = { cbOrbs, cbSplinters, cbCorrupt, cbInfluence1, cbInfluence2 };
            foreach (ComboBox cb in cbs)
            {
                ControlTemplate ct    = cb.Template;
                Popup           popup = ct.FindName("PART_Popup", cb) as Popup;
                if (popup != null)
                {
                    popup.Placement = PlacementMode.Top;
                }
            }

            Grid input = cbName.Template.FindName("templateRoot", cbName) as Grid;

            if (input != null)
            {
                ToggleButton toggleButton = input.FindName("toggleButton") as ToggleButton;
                if (toggleButton != null)
                {
                    Border border = toggleButton.Template.FindName("templateRoot", toggleButton) as Border;
                    if (border != null)
                    {
                        border.BorderThickness = new Thickness(0, 0, 0, 1);
                        border.Background      = System.Windows.Media.Brushes.Transparent;
                    }
                }
            }

            cbName.FontSize = cbOrbs.FontSize + 2;

            cbOrbs.Items.Add("교환을 원하는 오브 선택");
            foreach (ParserDictionary item in mParserData.Currency)
            {
                if (item.Hidden == false)
                {
                    cbOrbs.Items.Add(item.Text[0]);
                }
            }

            cbSplinters.Items.Add("기폭제, 화석, 조각등등");
            foreach (ParserDictionary item in mParserData.Exchange)
            {
                if (item.Hidden == false)
                {
                    cbSplinters.Items.Add(item.Text[0]);
                }
            }

            this.Title     += " - " + RS.ServerType;
            this.Visibility = Visibility.Hidden;

            /////////////////
            mMainHwnd = new WindowInteropHelper(this).Handle;
            HwndSource source = HwndSource.FromHwnd(mMainHwnd);

            source.AddHook(new HwndSourceHook(WndProc));

            if (mAdministrator)
            {
                foreach (var item in mConfigData.Shortcuts)
                {
                    if (item.Keycode > 0 && (item.Value ?? "") != "")
                    {
                        if (!mDisableClip && item.Value.ToLower() == "{run}")
                        {
                            mDisableClip = true;
                        }
                        else if (item.Value.ToLower() == "{close}")
                        {
                            closeKeyCode = item.Keycode;
                        }
                    }
                }

                // 창 활성화 후킹 사용시 가끔 꼬여서 타이머로 교체
                //InstallRegisterHotKey();
                //EventHook.EventAction += new EventHandler(WinEvent);
                //EventHook.Start();

                if (mConfigData.Options.CtrlWheel)
                {
                    mMouseHookCallbackTime = Convert.ToDateTime(DateTime.Now);
                    MouseHook.MouseAction += new EventHandler(MouseEvent);
                    MouseHook.Start();
                }

                DispatcherTimer timer = new DispatcherTimer();
                timer.Interval = TimeSpan.FromMilliseconds(1000);
                timer.Tick    += new EventHandler(Timer_Tick);
                timer.Start();
            }

            if (!mDisableClip)
            {
                IntPtr mNextClipBoardViewerHWnd = Native.SetClipboardViewer(mMainHwnd);
            }
        }
Beispiel #2
0
        private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            if (msg == Native.WM_DRAWCLIPBOARD)
            {
                if (!mPausedHotKey)
                {
#if DEBUG
                    if (true)
#else
                    if (Native.GetForegroundWindow().Equals(Native.FindWindow(RS.PoeClass, RS.PoeCaption)))
#endif
                    {
                        try
                        {
                            if (Clipboard.ContainsText(TextDataFormat.UnicodeText) || Clipboard.ContainsText(TextDataFormat.Text))
                            {
                                ItemTextParser(GetClipText(Clipboard.ContainsText(TextDataFormat.UnicodeText)), !mShowWiki);
                                if (mShowWiki)
                                {
                                    Button_Click_4(null, new RoutedEventArgs());
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                        finally
                        {
                            mShowWiki = false;
                        }
                    }
                }
            }
            else if (msg == (int)0x0112 /*WM_SYSCOMMAND*/ && ((int)wParam & 0xFFF0) == (int)0xf180 /*SC_CONTEXTHELP*/)
            {
                WinSetting winSetting = new WinSetting();
                winSetting.Show();
                handled = true;
            }
            else if (!mHotkeyProcBlock && msg == (int)0x312) //WM_HOTKEY
            {
                mHotkeyProcBlock = true;

                IntPtr findHwnd = Native.FindWindow(RS.PoeClass, RS.PoeCaption);

                if (Native.GetForegroundWindow().Equals(findHwnd))
                {
                    int          key_idx            = wParam.ToInt32() - 10001;
                    const string POPUP_WINDOW_TITLE = "이곳을 잡고 이동, 닫기는 클릭 또는 ESC";

                    try
                    {
                        if (key_idx == -1)
                        {
                            IntPtr pHwnd  = Native.FindWindow(null, POPUP_WINDOW_TITLE);
                            IntPtr pHwnd2 = Native.FindWindow(null, Title + " - " + "{grid:stash}");
                            if (pHwnd.ToInt32() != 0 || pHwnd2.ToInt32() != 0)
                            {
                                if (pHwnd.ToInt32() != 0)
                                {
                                    Native.SendMessage(pHwnd, /* WM_CLOSE = */ 0x10, IntPtr.Zero, IntPtr.Zero);
                                }
                                if (pHwnd2.ToInt32() != 0)
                                {
                                    Native.SendMessage(pHwnd2, /* WM_CLOSE = */ 0x10, IntPtr.Zero, IntPtr.Zero);
                                }
                            }
                            else if (this.Visibility == Visibility.Hidden)
                            {
                                Native.SendMessage(findHwnd, 0x0101, new IntPtr(/* ESC = */ 27), IntPtr.Zero);
                            }
                            else if (this.Visibility == Visibility.Visible)
                            {
                                Close();
                            }
                        }
                        else
                        {
                            ConfigShortcut shortcut = mConfig.Shortcuts[key_idx];

                            if (shortcut != null && shortcut.Value != null)
                            {
                                string valueLower = shortcut.Value.ToLower();

                                if (valueLower.IndexOf("{pause}") == 0)
                                {
                                    mPausedHotKey = !mPausedHotKey;

                                    if (mPausedHotKey)
                                    {
                                        if (mConfig.Options.UseCtrlWheel)
                                        {
                                            MouseHook.Stop();
                                        }

                                        MessageBox.Show(Application.Current.MainWindow, "프로그램 동작을 일시 중지합니다." + '\n'
                                                        + "다시 시작하려면 일시 중지 단축키를 한번더 누르세요.", "POE 거래소 검색");
                                    }
                                    else
                                    {
                                        if (mConfig.Options.UseCtrlWheel)
                                        {
                                            MouseHook.Start();
                                        }

                                        MessageBox.Show(Application.Current.MainWindow, "프로그램 동작을 다시 시작합니다.", "POE 거래소 검색");
                                    }

                                    Native.SetForegroundWindow(findHwnd);
                                }
                                else if (valueLower.IndexOf("{restart}") == 0)
                                {
                                    Process.Start(new ProcessStartInfo(Assembly.GetExecutingAssembly().Location)
                                    {
                                        Arguments = "/wait_shutdown"
                                    });
                                    Application.Current.Shutdown();
                                }
                                else if (!mPausedHotKey)
                                {
                                    if (valueLower.IndexOf("{run}") == 0 || valueLower.IndexOf("{wiki}") == 0)
                                    {
                                        mShowWiki = valueLower.IndexOf("{wiki}") == 0;
                                        System.Windows.Forms.SendKeys.SendWait("^{c}");
                                    }
                                    else if (valueLower.IndexOf("{enter}") == 0)
                                    {
                                        Regex    regex = new Regex(@"{enter}", RegexOptions.IgnoreCase);
                                        string   tmp   = regex.Replace(shortcut.Value, "" + '\n');
                                        string[] strs  = tmp.Trim().Split('\n');

                                        for (int i = 0; i < strs.Length; i++)
                                        {
                                            SetClipText(strs[i], TextDataFormat.UnicodeText);
                                            Thread.Sleep(300);
                                            System.Windows.Forms.SendKeys.SendWait("{enter}");
                                            System.Windows.Forms.SendKeys.SendWait("^{a}");
                                            System.Windows.Forms.SendKeys.SendWait("^{v}");
                                            System.Windows.Forms.SendKeys.SendWait("{enter}");
                                        }
                                    }
                                    else if (valueLower.IndexOf("{link}") == 0)
                                    {
                                        Regex    regex = new Regex(@"{link}", RegexOptions.IgnoreCase);
                                        string   tmp   = regex.Replace(shortcut.Value, "" + '\n');
                                        string[] strs  = tmp.Trim().Split('\n');
                                        if (strs.Length > 0)
                                        {
                                            Process.Start(strs[0]);
                                        }
                                    }
                                    else if (valueLower.IndexOf("{grid:stash}") == 0)
                                    {
                                        IntPtr pHwnd = Native.FindWindow(null, Title + " - " + "{grid:stash}");
                                        if (pHwnd.ToInt32() != 0)
                                        {
                                            Native.SendMessage(pHwnd, /* WM_CLOSE = */ 0x10, IntPtr.Zero, IntPtr.Zero);
                                        }
                                        else
                                        {
                                            WinGrid winGrid = new WinGrid(findHwnd);
                                            winGrid.Title = Title + " - " + "{grid:stash}";
                                            winGrid.Show();
                                        }
                                    }
                                    else if (valueLower.IndexOf(".jpg") > 0)
                                    {
                                        IntPtr pHwnd = Native.FindWindow(null, POPUP_WINDOW_TITLE);
                                        if (pHwnd.ToInt32() != 0)
                                        {
                                            Native.SendMessage(pHwnd, /* WM_CLOSE = */ 0x10, IntPtr.Zero, IntPtr.Zero);
                                        }

                                        WinPopup winPopup = new WinPopup(shortcut.Value);
                                        winPopup.WindowStartupLocation = WindowStartupLocation.Manual;
                                        winPopup.Title = POPUP_WINDOW_TITLE;
                                        winPopup.Left  = 10;
                                        winPopup.Top   = 10;
                                        winPopup.Show();
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception)
                    {
                        ForegroundMessage("잘못된 단축키 명령입니다.", "단축키 에러", MessageBoxButton.OK, MessageBoxImage.Error);
                    }

                    handled = true;
                }

                mHotkeyProcBlock = false;
            }

            return(IntPtr.Zero);
        }