diff --git a/MisakaTranslator-WPF/GuidePages/Hook/ChooseGamePage.xaml.cs b/MisakaTranslator-WPF/GuidePages/Hook/ChooseGamePage.xaml.cs index 226bd6e1..74fefd6b 100644 --- a/MisakaTranslator-WPF/GuidePages/Hook/ChooseGamePage.xaml.cs +++ b/MisakaTranslator-WPF/GuidePages/Hook/ChooseGamePage.xaml.cs @@ -54,8 +54,11 @@ private void ConfirmButton_Click(object sender, RoutedEventArgs e) Common.textHooker = new TextHookHandle(SameNameGameProcessList); } - Common.textHooker.Init(!(bool)x64GameCheckBox.IsChecked); - + if(!Common.textHooker.Init(!(bool)x64GameCheckBox.IsChecked)) + { + HandyControl.Controls.MessageBox.Show(Application.Current.Resources["MainWindow_TextractorError_Hint"].ToString()); + return; + } Common.GameID = -1; string filepath = ProcessHelper.FindProcessPath(GamePid); diff --git a/MisakaTranslator-WPF/MainWindow.xaml.cs b/MisakaTranslator-WPF/MainWindow.xaml.cs index 1ef8008a..3637a70f 100644 --- a/MisakaTranslator-WPF/MainWindow.xaml.cs +++ b/MisakaTranslator-WPF/MainWindow.xaml.cs @@ -202,7 +202,7 @@ private void Back_MouseLeftButtonDown(object sender, System.Windows.Input.MouseB GameInfoDrawer.IsOpen = true; } - private void StartTranslateByGid(int gid) { + private async Task StartTranslateByGid(int gid) { var pidList = new List(); foreach (var p in Process.GetProcesses()) @@ -256,7 +256,11 @@ private void StartTranslateByGid(int gid) { Common.textHooker = pidList.Count == 1 ? new TextHookHandle(pidList[0].Id) : new TextHookHandle(pidList); - Common.textHooker.Init(!gameInfoList[gid].Isx64); + if(!Common.textHooker.Init(!gameInfoList[gid].Isx64)) + { + HandyControl.Controls.MessageBox.Show(Application.Current.Resources["MainWindow_TextractorError_Hint"].ToString()); + return; + } Common.textHooker.HookCodeList.Add(gameInfoList[gid].Hookcode); Common.textHooker.HookCode_Custom = gameInfoList[gid].HookCodeCustom; @@ -269,12 +273,10 @@ private void StartTranslateByGid(int gid) { Common.textHooker.MisakaCodeList = null; //2020-06-08 大部分情况无重复码的游戏不会hook到很多,不进行去多余hook //Common.textHooker.DetachUnrelatedHookWhenDataRecv = Convert.ToBoolean(Common.appSettings.AutoDetach); - Common.textHooker.StartHook(Convert.ToBoolean(Common.appSettings.AutoHook)); - var task1 = Task.Run(async delegate - { - await Task.Delay(3000); - Common.textHooker.Auto_AddHookToGame(); - }); + await Common.textHooker.StartHook(Convert.ToBoolean(Common.appSettings.AutoHook)); + + await Task.Delay(3000); + Common.textHooker.Auto_AddHookToGame(); var tw = new TranslateWindow(); tw.Show(); @@ -290,7 +292,7 @@ private async void StartBtn_Click(object sender, RoutedEventArgs e) { res?.WaitForInputIdle(5000); GameInfoDrawer.IsOpen = false; await Task.Delay(2000); - StartTranslateByGid(gid); + await StartTranslateByGid(gid); } /// @@ -326,7 +328,7 @@ private async void LEStartBtn_Click(object sender, RoutedEventArgs e) { res?.WaitForInputIdle(5000); GameInfoDrawer.IsOpen = false; await Task.Delay(2000); - StartTranslateByGid(gid); + await StartTranslateByGid(gid); } private void BlurWindow_Closing(object sender, CancelEventArgs e) { @@ -369,13 +371,13 @@ private void Language_MenuItem_Click(object sender, RoutedEventArgs e) { } } - private void AutoStart_BtnClick(object sender, RoutedEventArgs e) { + private async void AutoStart_BtnClick(object sender, RoutedEventArgs e) { var res = GetGameListHasProcessGame_PID_ID(); if (res == -1) { Growl.ErrorGlobal(Application.Current.Resources["MainWindow_AutoStartError_Hint"].ToString()); } else { - StartTranslateByGid(res); + await StartTranslateByGid(res); } } diff --git a/MisakaTranslator-WPF/TranslateWindow.xaml.cs b/MisakaTranslator-WPF/TranslateWindow.xaml.cs index 4ef03943..cf75a997 100644 --- a/MisakaTranslator-WPF/TranslateWindow.xaml.cs +++ b/MisakaTranslator-WPF/TranslateWindow.xaml.cs @@ -390,8 +390,8 @@ private void TranslateText(string repairedText, bool isRenew = false) UpdateSource(repairedText); // 分别获取两个翻译结果 - TranslateApiSubmitSync(repairedText, 1, isRenew); - TranslateApiSubmitSync(repairedText, 2, isRenew); + TranslateApiSubmitASync(repairedText, 1, isRenew); + TranslateApiSubmitASync(repairedText, 2, isRenew); } } @@ -494,7 +494,7 @@ private void UpdateSource(string repairedText) /// 原文 /// 翻译框序号 /// 是否是重新获取翻译 - private async void TranslateApiSubmitSync(string repairedText, int tranResultIndex, bool isRenew = false) + private async Task TranslateApiSubmitASync(string repairedText, int tranResultIndex, bool isRenew = false) { //4.翻译前预处理 string beforeString = _beforeTransHandle.AutoHandle(repairedText); @@ -730,8 +730,8 @@ private void RenewOCR_Item_Click(object sender, RoutedEventArgs e) } else { - TranslateApiSubmitSync(_currentsrcText, 1, true); - TranslateApiSubmitSync(_currentsrcText, 2, true); + TranslateApiSubmitASync(_currentsrcText, 1, true); + TranslateApiSubmitASync(_currentsrcText, 2, true); } } diff --git a/MisakaTranslator-WPF/lang/en-US.xaml b/MisakaTranslator-WPF/lang/en-US.xaml index 692aa39a..a8ee318e 100644 --- a/MisakaTranslator-WPF/lang/en-US.xaml +++ b/MisakaTranslator-WPF/lang/en-US.xaml @@ -34,6 +34,7 @@ Game process with saved settings is not found! Global OCR shortcut registration failed! Game process not found! + Textractor doesn't exist or failed to start. Preferences MisakaTranslator diff --git a/MisakaTranslator-WPF/lang/zh-CN.xaml b/MisakaTranslator-WPF/lang/zh-CN.xaml index a0701f68..711cbd0f 100644 --- a/MisakaTranslator-WPF/lang/zh-CN.xaml +++ b/MisakaTranslator-WPF/lang/zh-CN.xaml @@ -36,6 +36,7 @@ 未在当前进程列表中找到可以自动开始翻译的游戏! 全局OCR热键注册失败! 未找到游戏进程! + Textractor不存在或启动失败 MisakaTranslator本体设置 diff --git a/TextHookLibrary/TextHookHandle.cs b/TextHookLibrary/TextHookHandle.cs index 95435f9b..fab37044 100644 --- a/TextHookLibrary/TextHookHandle.cs +++ b/TextHookLibrary/TextHookHandle.cs @@ -236,7 +236,7 @@ public async void CloseTextractor() { /// /// 开始注入,会判断是否智能注入 /// - public async void StartHook(bool AutoHook = false) { + public async Task StartHook(bool AutoHook = false) { if (HandleMode == 1) { await AttachProcess(GamePID); }