예제 #1
0
        private void DataProcess(object sender, HookParam hp)
        {
            // Refresh
            gameViewModel.AppendTextList.Clear();

            // User define RegExp
            var pattern = GameConfig.RegExp;

            if (!string.IsNullOrEmpty(pattern))
            {
                var list = Regex.Split(hp.Text, pattern);
                hp.Text = string.Join("", list);
            }

            // Clear ascii control characters
            hp.Text = new string(hp.Text.Select(c => c < ' ' ? '_' : c).ToArray()).Replace("_", string.Empty);
            // Linebreak
            // Full-width space
            hp.Text = hp.Text.Replace(" ", string.Empty);
            // Ruby like <.*?>

            if (hp.Text.Length > 120)
            {
                gameViewModel.TextControl.SourceTextCollection.Clear();
                AppendDataEvent?.Invoke(typeof(GameViewDataService), Language.Strings.GameView_MaxLenthTip, string.Empty);
                return;
            }

            // DeepL Extension
            if (DataRepository.PasteToDeepL)
            {
                Process[] temp = Process.GetProcessesByName("DeepL");
                if (temp.Length != 0)
                {
                    IntPtr handle = temp[0].MainWindowHandle;
                    NativeMethods.SwitchToThisWindow(handle);

                    // Do SetText and Paste both
                    new DeepLHelper(DataFormats.Text, hp.Text).Go();

                    if (NativeMethods.GetForegroundWindow() != handle)
                    {
                        // Better use Toast in win10
                        Application.Current.Dispatcher.InvokeAsync(() => ModernWpf.MessageBox.Show(
                                                                       "Didn't find DeepL client in front, will turn off DeepL extension..", "Eroge Helper"));

                        DataRepository.PasteToDeepL = false;
                    }
                }
            }

            gameViewModel.SourceTextArchiver.Enqueue(hp.Text);
            gameViewModel.TextControl.CardControl.TotalText = hp.Text;

            // Process source japanese text
            if (mecabViewModel.MecabToggle)
            {
                var collect = Utils.BindableTextMaker(mecabHelper.IpaDicParser(hp.Text));
                SourceDataEvent?.Invoke(typeof(GameViewDataService), collect);
            }

            if (Utils.NetIsConnected)
            {
                foreach (var translator in TranslatorManager.GetEnabled())
                {
                    Task.Run(async() =>
                    {
                        Stopwatch sw = new();
                        sw.Start();
                        var result = await translator.TranslateAsync(hp.Text, DataRepository.TransSrcLanguage, DataRepository.TransTargetLanguage);
                        sw.Stop();
                        if (!result.Equals(string.Empty))
                        {
                            Log.Debug($"{translator.Name}: {result}");
                            AppendDataEvent?.Invoke(typeof(GameViewDataService), result, $"{translator.Name} {sw.ElapsedMilliseconds}ms");
                        }
                    });
                }
            }

            // hard code for sakura no uta
            //if (GameConfig.MD5.Equals("BAB61FB3BD98EF1F1538EE47A8A46A26"))
            //{
            //    string result = sakuraNoUtaHelper.QueryText(hp.Text);
            //    if (!string.IsNullOrWhiteSpace(result))
            //        AppendDataEvent?.Invoke(typeof(GameViewDataService), result, "人工字幕 by luki");
            //}
        }
예제 #2
0
        private void DataProgress(object sender, HookParam hp)
        {
            // Refresh
            IoC.Get <GameViewModel>().AppendTextList.Clear(); // Clear or give new value? is that same

            // User define regexp
            var pattern = GameConfig.Regexp;

            if (!string.IsNullOrEmpty(pattern))
            {
                var list = Regex.Split(hp.Text, pattern);
                hp.Text = string.Join("", list);
            }

            // Clear ascii control characters
            hp.Text = new string(hp.Text.Select(c => c < ' ' ? '_' : c).ToArray()).Replace("_", string.Empty);
            // Linebreak
            // Full-width space
            hp.Text = hp.Text.Replace(" ", string.Empty);
            // Ruby
            // <.*?>

            if (hp.Text.Length > 120)
            {
                IoC.Get <TextViewModel>().SourceTextCollection.Clear();
                AppendDataEvent?.Invoke(typeof(GameViewDataService), Language.Strings.GameView_MaxLenthTip);
                return;
            }

            // DeepL Extension
            if (DataRepository.PasteToDeepL)
            {
                Process[] temp = Process.GetProcessesByName("DeepL");
                if (temp.Length != 0)
                {
                    IntPtr handle = temp[0].MainWindowHandle;
                    NativeMethods.SwitchToThisWindow(handle);
                    // TODO 6: check the front window is handle, else toast user得注意这些操作时间开销
                    // Do SetText and Paste both
                    new SetClipboardHelper(DataFormats.Text, hp.Text).Go();
                }
            }

            var collect = new BindableCollection <SingleTextItem>();

            foreach (MecabWordInfo mecabWord in mecabHelper.MecabWordEnumerable(hp.Text))
            {
                collect.Add(new SingleTextItem
                {
                    Text             = mecabWord.Word,
                    RubyText         = mecabWord.Kana,
                    PartOfSpeed      = mecabWord.PartOfSpeech,
                    TextTemplateType = SourceTextTemplate,
                    SubMarkColor     = Utils.Hinshi2Color(mecabWord.PartOfSpeech)
                });
            }

            SourceDataEvent?.Invoke(typeof(GameViewDataService), collect);

            // hard code for sakura no uta
            if (GameConfig.MD5.Equals("BAB61FB3BD98EF1F1538EE47A8A46A26"))
            {
                string result = sakuraNoUtaHelper.QueryText(hp.Text);
                if (!string.IsNullOrWhiteSpace(result))
                {
                    AppendDataEvent?.Invoke(typeof(GameViewDataService), result);
                }
            }
        }