Пример #1
0
        private void SelectedDataEventHandler(object sender, HookParam hp)
        {
            DispatcherHelper.CheckBeginInvokeOnUI(() =>
            {
                if (!Properties.Settings.Default.OnlyMachineTranslation)
                {
                    DisplayTextCollection.Clear();

                    var pattern = SimpleIoc.Default.GetInstance <GameInfo>().Regexp;
                    if (!string.IsNullOrEmpty(pattern))
                    {
                        var list = Regex.Split(hp.Text, pattern);
                        hp.Text  = string.Join("", list);
                    }

                    if (hp.Text.Length > 80)
                    {
                        hp.Text = "长度大于80的文本自动跳过";
                    }

                    var mecabWordList = _mecabHelper.SentenceHandle(hp.Text);
                    foreach (MecabWordInfo mecabWord in mecabWordList)
                    {
                        DisplayTextCollection.Add(new SingleTextItem
                        {
                            Text             = mecabWord.Word,
                            RubyText         = mecabWord.Kana,
                            PartOfSpeed      = mecabWord.PartOfSpeech,
                            TextTemplateType = TextTemplateConfig
                        });
                    }

                    if (lastSentence == "")
                    {
                        currentSentence = hp.Text;
                    }
                    else
                    {
                        lastSentence    = currentSentence;
                        currentSentence = hp.Text;
                    }

                    TransText        = "";
                    TransTextVisible = Visibility.Collapsed;
                    // XXX: learn Task first
                    Task.Run(async() => await DoPreTranslateAsync());
                }
                else
                {
                    TranslateTextList.Clear();
                    if (hp.Text.Length > 80)
                    {
                        TranslateTextList.Add("长度大于80的文本自动跳过");
                        return;
                    }

                    TrasnlateAllAsync(hp.Text, Utils.GetTranslatorList());
                }
            });
        }
        public HookBindingList <long, HookParam> GetHookMapData()
        {
            HookBindingList <long, HookParam> ret = new HookBindingList <long, HookParam>(p => p.Handle);

            HookParam hp = new HookParam()
            {
                Addr      = 0,
                Ctx       = 0,
                Ctx2      = 0,
                Handle    = 0,
                Hookcode  = "*****@*****.**",
                Name      = "engine",
                Pid       = 10000,
                Text      = "Text is me",
                TotalText = "1first text\n" +
                            "2\n" +
                            "3\n" +
                            "4\n" +
                            "5\n" +
                            "6\n" +
                            "7\n" +
                            "8\n" +
                            "9\n" +
                            "10\n"
            };

            ret.Add(hp);
            hp = new HookParam()
            {
                Addr      = 1,
                Ctx       = 1,
                Ctx2      = 1,
                Handle    = 1,
                Hookcode  = "*****@*****.**",
                Name      = "engine",
                Pid       = 10000,
                Text      = "second text",
                TotalText = "second text"
            };
            ret.Add(hp);

            return(ret);
        }
Пример #3
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");
            //}
        }
Пример #4
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);
                }
            }
        }