/// <summary> /// 触发进入下一步的事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Next_Click(object sender, RoutedEventArgs e) { GuidePages.PageChangeRoutedEventArgs args = e as GuidePages.PageChangeRoutedEventArgs; if (args.XamlPath == "1") { if (GuideMode == 1) { //Hook方式设置 完成 Common.transMode = 1; TranslateWindow translateWindow = new TranslateWindow(); translateWindow.Show(); this.Close(); } else if (GuideMode == 2) { //OCR方式设置 完成 Common.transMode = 2; TranslateWindow translateWindow = new TranslateWindow(); translateWindow.Show(); this.Close(); } else { } } else { //其他情况就跳转指定页面 GuidePageFrame.Navigate(new Uri(args.XamlPath, UriKind.Relative)); GuideStepBar.Next(); } }
public TransWinSettingsWindow(TranslateWindow Win) { translateWin = Win; InitializeComponent(); FontList = new List <string>(); System.Drawing.Text.InstalledFontCollection fonts = new System.Drawing.Text.InstalledFontCollection(); foreach (System.Drawing.FontFamily family in fonts.Families) { FontList.Add(family.Name); } sourceFont.ItemsSource = FontList; firstFont.ItemsSource = FontList; EventInit(); UI_Init(); }
private void dataInit() { OCREngine ocr; string res = null; if (Common.appSettings.OCRsource == "TesseractOCR") { ocr = new TesseractOCR(); if (ocr.OCR_Init("", "") != false) { ocr.SetOCRSourceLang(Common.appSettings.GlobalOCRLang); res = ocr.OCRProcess(new System.Drawing.Bitmap(img)); if (res != null) { sourceText.Text = res; } else { HandyControl.Controls.Growl.ErrorGlobal($"TesseractOCR {Application.Current.Resources["APITest_Error_Hint"]}\n{ocr.GetLastError()}"); } } else { HandyControl.Controls.Growl.ErrorGlobal($"TesseractOCR {Application.Current.Resources["APITest_Error_Hint"]}\n{ocr.GetLastError()}"); } } else if (Common.appSettings.OCRsource == "TesseractOCR5") { ocr = new Tesseract5OCR(); if (ocr.OCR_Init(Common.appSettings.Tesseract5OCR_Path, Common.appSettings.Tesseract5OCR_Args)) { ocr.SetOCRSourceLang(Common.appSettings.GlobalOCRLang); res = ocr.OCRProcess(new System.Drawing.Bitmap(img)); if (res != null) { sourceText.Text = res; } else { HandyControl.Controls.Growl.ErrorGlobal($"TesseractOCR5 {Application.Current.Resources["APITest_Error_Hint"]}\n{ocr.GetLastError()}"); } } else { HandyControl.Controls.Growl.ErrorGlobal($"TesseractOCR5 {Application.Current.Resources["APITest_Error_Hint"]}\n{ocr.GetLastError()}"); } } else if (Common.appSettings.OCRsource == "BaiduOCR") { ocr = new BaiduGeneralOCR(); if (ocr.OCR_Init(Common.appSettings.BDOCR_APIKEY, Common.appSettings.BDOCR_SecretKey)) { ocr.SetOCRSourceLang(Common.appSettings.GlobalOCRLang); res = ocr.OCRProcess(new System.Drawing.Bitmap(img)); if (res != null) { sourceText.Text = res; } else { HandyControl.Controls.Growl.ErrorGlobal($"百度OCR {Application.Current.Resources["APITest_Error_Hint"]}\n{ocr.GetLastError()}"); } } else { HandyControl.Controls.Growl.ErrorGlobal($"百度OCR {Application.Current.Resources["APITest_Error_Hint"]}\n{ocr.GetLastError()}"); } } if (res == null) { FirstTransText.Text = "OCR ERROR"; } else { ITranslator translator1 = TranslateWindow.TranslatorAuto(Common.appSettings.FirstTranslator); ITranslator translator2 = TranslateWindow.TranslatorAuto(Common.appSettings.SecondTranslator); //5.提交翻译 string transRes1 = ""; string transRes2 = ""; if (translator1 != null) { transRes1 = translator1.Translate(res, Common.UsingDstLang, Common.UsingSrcLang); } if (translator2 != null) { transRes2 = translator2.Translate(res, Common.UsingDstLang, Common.UsingSrcLang); } FirstTransText.Text = transRes1; SecondTransText.Text = transRes2; } }
private void StartTranslateByGid(int gid) { var ps = Process.GetProcesses(); var pidList = new List <Process>(); foreach (var process in ps) { string filepath; try { filepath = process.MainModule.FileName; } catch (Exception) { continue; //这个地方直接跳过,是因为32位程序确实会读到64位的系统进程,而系统进程是不能被访问的 //throw ex; } if (gameInfoList[gid].FilePath == filepath) { pidList.Add(process); } } if (pidList.Count == 0) { HandyControl.Controls.MessageBox.Show(Application.Current.Resources["MainWindow_StartError_Hint"].ToString(), Application.Current.Resources["MessageBox_Hint"].ToString()); return; } else { var pid = pidList[0].Id; pidList.Clear(); pidList = ProcessHelper.FindSameNameProcess(pid); } Common.GameID = gameInfoList[gid].GameID; Common.transMode = 1; Common.UsingDstLang = gameInfoList[gid].DstLang; Common.UsingSrcLang = gameInfoList[gid].SrcLang; Common.UsingRepairFunc = gameInfoList[gid].RepairFunc; switch (Common.UsingRepairFunc) { case "RepairFun_RemoveSingleWordRepeat": Common.repairSettings.SingleWordRepeatTimes = gameInfoList[gid].RepairParamA; break; case "RepairFun_RemoveSentenceRepeat": Common.repairSettings.SentenceRepeatFindCharNum = gameInfoList[gid].RepairParamA; break; case "RepairFun_RegexReplace": Common.repairSettings.Regex = gameInfoList[gid].RepairParamA; Common.repairSettings.Regex_Replace = gameInfoList[gid].RepairParamB; break; default: break; } Common.RepairFuncInit(); Common.textHooker = pidList.Count == 1 ? new TextHookHandle(pidList[0].Id) : new TextHookHandle(pidList); Common.textHooker.Init(!gameInfoList[gid].Isx64); Common.textHooker.HookCodeList.Add(gameInfoList[gid].Hookcode); Common.textHooker.HookCode_Custom = gameInfoList[gid].HookCodeCustom; if (gameInfoList[gid].IsMultiHook) { var ggw = new GameGuideWindow(3); ggw.Show(); } else { //无重复码。直接进游戏 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(); }); var tw = new TranslateWindow(); tw.Show(); } }
private void Button_Click_1(object sender, RoutedEventArgs e) { TranslateWindow translateWindow = new TranslateWindow(); translateWindow.Show(); }
private void dataInit() { IOptChaRec ocr; string res = null; if (Common.appSettings.OCRsource == "TesseractOCR") { ocr = new TesseractOCR(); if (ocr.OCR_Init("", "") != false) { ocr.SetOCRSourceLang(Common.appSettings.GlobalOCRLang); res = ocr.OCRProcess(new System.Drawing.Bitmap(img)); if (res != null) { sourceText.Text = res; } else { HandyControl.Controls.Growl.ErrorGlobal("TesseractOCR 工作异常\n" + ocr.GetLastError()); } } else { HandyControl.Controls.Growl.ErrorGlobal("TesseractOCR 工作异常\n" + ocr.GetLastError()); } } else if (Common.appSettings.OCRsource == "BaiduOCR") { ocr = new BaiduGeneralOCR(); if (ocr.OCR_Init(Common.appSettings.BDOCR_APIKEY, Common.appSettings.BDOCR_SecretKey) != false) { ocr.SetOCRSourceLang(Common.appSettings.GlobalOCRLang); res = ocr.OCRProcess(new System.Drawing.Bitmap(img)); if (res != null) { sourceText.Text = res; } else { HandyControl.Controls.Growl.ErrorGlobal("百度OCR API工作异常\n" + ocr.GetLastError()); } } else { HandyControl.Controls.Growl.ErrorGlobal("百度OCR API工作异常\n" + ocr.GetLastError()); } } if (res == null) { FirstTransText.Text = "OCR ERROR"; } else { ITranslator translator1 = TranslateWindow.TranslatorAuto(Common.appSettings.FirstTranslator); ITranslator translator2 = TranslateWindow.TranslatorAuto(Common.appSettings.SecondTranslator); //5.提交翻译 string transRes1 = ""; string transRes2 = ""; if (translator1 != null) { transRes1 = translator1.Translate(res, Common.UsingDstLang, Common.UsingSrcLang); } if (translator2 != null) { transRes2 = translator2.Translate(res, Common.UsingDstLang, Common.UsingSrcLang); } FirstTransText.Text = transRes1; SecondTransText.Text = transRes2; } }
private void StartTranslateBygid(int gid) { Process[] ps = Process.GetProcesses(); List <Process> pidlst = new List <Process>(); for (int i = 0; i < ps.Length; i++) { string filepath = ""; try { filepath = ps[i].MainModule.FileName; } catch (Exception) { continue; //这个地方直接跳过,是因为32位程序确实会读到64位的系统进程,而系统进程是不能被访问的 //throw ex; } if (gameInfolst[gid].FilePath == filepath) { pidlst.Add(ps[i]); } } if (pidlst.Count == 0) { HandyControl.Controls.MessageBox.Show("未找到游戏进程!", "提示"); return; } else { int pid = pidlst[0].Id; pidlst.Clear(); pidlst = ProcessHelper.FindSameNameProcess(pid); } Common.transMode = 1; Common.UsingDstLang = gameInfolst[gid].Dst_Lang; Common.UsingSrcLang = gameInfolst[gid].Src_Lang; Common.UsingRepairFunc = gameInfolst[gid].Repair_func; switch (Common.UsingRepairFunc) { case "RepairFun_RemoveSingleWordRepeat": Common.repairSettings.SingleWordRepeatTimes = gameInfolst[gid].Repair_param_a; break; case "RepairFun_RemoveSentenceRepeat": Common.repairSettings.SentenceRepeatFindCharNum = gameInfolst[gid].Repair_param_a; break; case "RepairFun_RegexReplace": Common.repairSettings.Regex = gameInfolst[gid].Repair_param_a; Common.repairSettings.Regex_Replace = gameInfolst[gid].Repair_param_b; break; default: break; } Common.RepairFuncInit(); if (pidlst.Count == 1) { Common.textHooker = new TextHookHandle(pidlst[0].Id); } else { Common.textHooker = new TextHookHandle(pidlst); } Common.textHooker.Init(!gameInfolst[gid].Isx64); Common.textHooker.HookCodeList.Add(gameInfolst[gid].Hookcode); if (gameInfolst[gid].IsMultiHook == true) { GameGuideWindow ggw = new GameGuideWindow(3); ggw.Show(); } else { //无重复码。直接进游戏 Common.textHooker.MisakaCodeList = null; Common.textHooker.DetachUnrelatedHookWhenDataRecv = Convert.ToBoolean(Common.appSettings.AutoDetach); Common.textHooker.StartHook(Convert.ToBoolean(Common.appSettings.AutoHook)); TranslateWindow tw = new TranslateWindow(); tw.Show(); } }
private async void dataInit() { OCREngine ocr; string res = null; if (Common.appSettings.OCRsource == "TesseractOCR") { ocr = new TesseractOCR(); if (ocr.OCR_Init("", "") != false) { ocr.SetOCRSourceLang(Common.appSettings.GlobalOCRLang); res = await ocr.OCRProcessAsync(img); if (res != null) { sourceText.Text = res; } else { HandyControl.Controls.Growl.WarningGlobal($"TesseractOCR {Application.Current.Resources["APITest_Error_Hint"]}\n{ocr.GetLastError()}"); } } else { HandyControl.Controls.Growl.ErrorGlobal($"TesseractOCR {Application.Current.Resources["APITest_Error_Hint"]}\n{ocr.GetLastError()}"); } } else if (Common.appSettings.OCRsource == "Tesseract5") { ocr = new Tesseract5OCR(); if (ocr.OCR_Init(Common.appSettings.Tesseract5OCR_Path, Common.appSettings.Tesseract5OCR_Args)) { ocr.SetOCRSourceLang(Common.appSettings.GlobalOCRLang); res = await ocr.OCRProcessAsync(img); if (res != null) { sourceText.Text = res; } else { HandyControl.Controls.Growl.WarningGlobal($"Tesseract5 {Application.Current.Resources["APITest_Error_Hint"]}\n{ocr.GetLastError()}"); } } else { HandyControl.Controls.Growl.ErrorGlobal($"Tesseract5 {Application.Current.Resources["APITest_Error_Hint"]}\n{ocr.GetLastError()}"); } } else if (Common.appSettings.OCRsource == "BaiduOCR") { ocr = new BaiduGeneralOCR(); if (ocr.OCR_Init(Common.appSettings.BDOCR_APIKEY, Common.appSettings.BDOCR_SecretKey)) { ocr.SetOCRSourceLang(Common.appSettings.GlobalOCRLang); res = await ocr.OCRProcessAsync(img); if (res != null) { sourceText.Text = res; } else { HandyControl.Controls.Growl.WarningGlobal($"百度智能云OCR {Application.Current.Resources["APITest_Error_Hint"]}\n{ocr.GetLastError()}"); } } else { HandyControl.Controls.Growl.ErrorGlobal($"百度智能云OCR {Application.Current.Resources["APITest_Error_Hint"]}\n{ocr.GetLastError()}"); } } else if (Common.appSettings.OCRsource == "BaiduFanyiOCR") { ocr = new BaiduFanyiOCR(); if (ocr.OCR_Init(Common.appSettings.BDappID, Common.appSettings.BDsecretKey)) { ocr.SetOCRSourceLang(Common.appSettings.GlobalOCRLang); res = await ocr.OCRProcessAsync(img); if (res != null) { FirstTransText.Text = res; } else { HandyControl.Controls.Growl.WarningGlobal($"百度翻译OCR {Application.Current.Resources["APITest_Error_Hint"]}\n{ocr.GetLastError()}"); } } else { HandyControl.Controls.Growl.ErrorGlobal($"百度翻译OCR {Application.Current.Resources["APITest_Error_Hint"]}\n{ocr.GetLastError()}"); } } if (res == null) { FirstTransText.Text = "OCR ERROR"; } else if (Common.appSettings.OCRsource != "BaiduFanyiOCR") { // 因为历史原因,OCR的源语言用的是三个字母的,如eng和jpn。而翻译的API即Common.UsingSrcLang用的两个字母,如en和jp string srclang; switch (Common.appSettings.GlobalOCRLang) { case "eng": srclang = "en"; break; case "jpn": srclang = "jp"; break; default: srclang = Common.appSettings.GlobalOCRLang; break; } if (!Common.appSettings.EachRowTrans) { if (srclang == "en") { res = res.Replace("\n", " ").Replace("\r", " "); } else { res = res.Replace("\n", "").Replace("\r", ""); } } ITranslator translator1 = TranslateWindow.TranslatorAuto(Common.appSettings.FirstTranslator); ITranslator translator2 = TranslateWindow.TranslatorAuto(Common.appSettings.SecondTranslator); //5.提交翻译 string transRes1 = ""; string transRes2 = ""; if (translator1 != null) { transRes1 = await translator1.TranslateAsync(res, Common.UsingDstLang, srclang); } if (translator2 != null) { transRes2 = await translator2.TranslateAsync(res, Common.UsingDstLang, srclang); } FirstTransText.Text = transRes1; SecondTransText.Text = transRes2; } }