From 20abb91db7706c1d20e0e63b13de55cc9e4cb704 Mon Sep 17 00:00:00 2001 From: lilium-saber Date: Thu, 12 Oct 2023 17:45:05 +0800 Subject: [PATCH] 1 Signed-off-by: lilium-saber --- src/Network/GrapeToJsonTrans.cs | 38 ++++++++++++++++ src/Network/TransNetworkApi.cs | 30 +++++++++++++ src/Network/jsonNet.cs | 49 ++++++++++++++++----- src/ScnToJson/TranslationScnToJson.cs | 25 +++++++++-- src/translationKey/translationPrivateIn.cs | 18 +++++--- src/translationKey/translationPrivateOut.cs | 28 ++++++++---- 6 files changed, 160 insertions(+), 28 deletions(-) create mode 100644 src/Network/GrapeToJsonTrans.cs create mode 100644 src/Network/TransNetworkApi.cs diff --git a/src/Network/GrapeToJsonTrans.cs b/src/Network/GrapeToJsonTrans.cs new file mode 100644 index 0000000..b81a1bd --- /dev/null +++ b/src/Network/GrapeToJsonTrans.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace testRjgc.transToNet +{ + /* + internal class GrapeToJsonTrans : GrapeToJson + { + + + + + public List GrapeRequestJson() + { + List re = new List(); + + return re; + } + + public List GrapeRequestJsonBaiDu() + { + List re = new List(); + + return re; + } + + public List GrapeRequestJsonLanguageChange() + { + List re = new List(); + + return re; + } + } + */ +} diff --git a/src/Network/TransNetworkApi.cs b/src/Network/TransNetworkApi.cs new file mode 100644 index 0000000..3b826eb --- /dev/null +++ b/src/Network/TransNetworkApi.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace testRjgc.transToNet +{ + interface StrToJson + { + public abstract string RequestJsonPrivate(string input, string srcl, string dstl, string aid, string kkey); + + public abstract string RequestJsonLanguageChange(string input, string srcl, string dstl); + + public abstract string RequestJsonBaiDu(string input); + + } + + /* + interface GrapeToJson + { + public abstract List GrapeRequestJson(); + + public abstract List GrapeRequestJsonLanguageChange(); + + public abstract List GrapeRequestJsonBaiDu(); + + } + */ +} diff --git a/src/Network/jsonNet.cs b/src/Network/jsonNet.cs index 035642b..efa384e 100644 --- a/src/Network/jsonNet.cs +++ b/src/Network/jsonNet.cs @@ -14,20 +14,20 @@ using System.Text; using System.Threading.Tasks; using System.Web; -namespace WpfApp1.translationKey +namespace testRjgc.transToNet { - internal class jsonNet + internal class jsonNet : StrToJson { static string https = "http://api.fanyi.baidu.com/api/trans/vip/translate?"; - + static string appid = "20230925001829663";//20230925001829663,20230923001827495 static Random rd = new Random(); static string salt = rd.Next(100000).ToString(); static string key = "f7ZHpw28izQ1VU_ixoY5";//f7ZHpw28izQ1VU_ixoY5,yjvMNY33Qc1TYSBjTQYQ - + //static HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("http://api.fanyi.baidu.com/api/trans/vip/translate?q=apple&from=en&to=zh&appid=20230925001829663&salt=1435660288&sign=c963bc2275c0fd1ed30da014c1ef1933"); - + /* private static HttpClient HttpRe = new HttpClient() { @@ -45,7 +45,7 @@ namespace WpfApp1.translationKey Console.WriteLine($"{jsonResponse}\n"); } */ - + public static string EncryptString(string str)//百度MD5加密计算方式 { MD5 md5 = MD5.Create(); @@ -63,8 +63,33 @@ namespace WpfApp1.translationKey // 返回加密的字符串 return sb.ToString(); } - - public string RequestJsonLanguageChange(string input, string srcl, string dstl) + + public string RequestJsonPrivate(string input, string srcl, string dstl, string aid, string kkey)//自定义id,key以及源语言和目标语言 + { + string sign = EncryptString(aid + input + salt + kkey); + + string temp = "q=" + HttpUtility.UrlEncode(input) + "&from=" + srcl + "&to=" + dstl + "&appid=" + aid + "&salt=" + salt + "&sign=" + sign; + Console.WriteLine(https + temp); + //Task t = GetAsync(HttpRe); t.Wait(); + HttpWebRequest request = (HttpWebRequest)WebRequest.Create(https + temp); + request.Method = "GET"; + request.ContentType = "text/html;charset=UTF-8"; + request.UserAgent = null; + request.Timeout = 6000; + + + var response = request.GetResponse(); + var myResponseStream = response.GetResponseStream(); + var myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8")); + string retString = myStreamReader.ReadToEnd(); + tempC2 temp1 = JsonConvert.DeserializeObject(retString); + + Trans_result result = temp1.trans_result[0]; + string s = result.dst; + return s; + } + + public string RequestJsonLanguageChange(string input, string srcl, string dstl)//可以自定义源语言与目标语言 { string sign = EncryptString(appid + input + salt + key); @@ -89,10 +114,10 @@ namespace WpfApp1.translationKey return s; } - public string RequestJsonBaiDu(string input) + public string RequestJsonBaiDu(string input)//默认 { string sign = EncryptString(appid + input + salt + key); - + string temp = "q=" + HttpUtility.UrlEncode(input) + "&from=jp&to=zh&appid=" + appid + "&salt=" + salt + "&sign=" + sign; Console.WriteLine(https + temp); //Task t = GetAsync(HttpRe); t.Wait(); @@ -112,8 +137,8 @@ namespace WpfApp1.translationKey Trans_result result = temp1.trans_result[0]; string s = result.dst; return s; - - } + + } } public class Trans_result diff --git a/src/ScnToJson/TranslationScnToJson.cs b/src/ScnToJson/TranslationScnToJson.cs index c5f91a7..6cf2cfe 100644 --- a/src/ScnToJson/TranslationScnToJson.cs +++ b/src/ScnToJson/TranslationScnToJson.cs @@ -5,9 +5,9 @@ namespace WpfApp1.ScnToJson internal class TranslationScnToJson { private string spath;//scn路径 - private string dpath;//json路径 - private string cmdHandle = "cd E:\\programingg\\vsprogam\\testRjgc\\VNT\\VNTextPatch";//cmd命令字符串 - private string voice = ".\\VNTextPatch extractlocal E:\\programingg\\vsprogam\\testRjgc\\VNT\\p1 E:\\programingg\\vsprogam\\testRjgc\\VNT\\p2";//VNTextPatch extractlocal + private string dpath;//json + private string cmdHandle = "cd " + Directory.GetCurrentDirectory() + "\\VNT\\VNTextPatch"; + private string voice = ".\\VNTextPatch extractlocal " + Directory.GetCurrentDirectory() + "\\VNT\\p1 " + Directory.GetCurrentDirectory() + "\\VNT\\p2"; public void StartTrans() { @@ -27,6 +27,25 @@ namespace WpfApp1.ScnToJson } + public void StopTrans(string spa, string dps) + { + string tempVoice = ".\\VNTextPatch extractlocal " + spa + dps; + + var p = new Process + { + StartInfo = + { + FileName = "PowerShell.exe", + Arguments = "/c " + cmdHandle + "\n" + tempVoice, + UseShellExecute = false, + CreateNoWindow = false, + } + }; + p.Start(); + p.WaitForExit(); + p.Close(); + } + diff --git a/src/translationKey/translationPrivateIn.cs b/src/translationKey/translationPrivateIn.cs index dea2343..a2f8adb 100644 --- a/src/translationKey/translationPrivateIn.cs +++ b/src/translationKey/translationPrivateIn.cs @@ -1,4 +1,5 @@ -using System; +using Stripe; +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -9,13 +10,20 @@ namespace WpfApp1.translationKey { class TranslationPrivateIn { - private string pathTemp = "E:\\programingg\\vsprogam\\testRjgc\\translationResource"; - private string txtPath = "E:\\programingg\\vsprogam\\testRjgc\\translationResource\\ListPrivate.txt"; + private static string pathTemp = Directory.GetCurrentDirectory() + "\\translationResource"; + private static string txtPath = Directory.GetCurrentDirectory() + "\\translationResource\\ListPrivate.txt"; + + public TranslationPrivateIn() { } public void InputTranslationPrivate(string name, string id, string key) { - pathTemp = pathTemp + "\\" + name + ".txt"; - StreamWriter sw = new StreamWriter(pathTemp); + if(!Directory.Exists(pathTemp)) + { + Directory.CreateDirectory(pathTemp); + } + + string temppathTemp = pathTemp + "\\" + name + ".txt"; + StreamWriter sw = new StreamWriter(temppathTemp); StreamWriter sw2 = new StreamWriter(txtPath); InputTranslationId(id,sw); diff --git a/src/translationKey/translationPrivateOut.cs b/src/translationKey/translationPrivateOut.cs index 752c59e..b27ff60 100644 --- a/src/translationKey/translationPrivateOut.cs +++ b/src/translationKey/translationPrivateOut.cs @@ -9,9 +9,8 @@ namespace WpfApp1.translationKey { class translationPrivateOut : TranslationApiStr { - private string name; - private string path = "E:\\programingg\\vsprogam\\testRjgc\\translationResource\\"; - private string txtPath = "E:\\programingg\\vsprogam\\testRjgc\\translationResource\\ListPrivate.txt"; + private static string path = Directory.GetCurrentDirectory() + "\\translationResource"; + private static string txtPath = Directory.GetCurrentDirectory() + "\\translationResource\\ListPrivate.txt"; private String getTranslationPrivateApi(StreamReader sr) { @@ -45,12 +44,18 @@ namespace WpfApp1.translationKey public List OutputTranslationS(string id) { - this.name = id; - this.path = this.path + this.name + ".txt"; - - StreamReader sr = new StreamReader(this.path); + string temppath = path + "\\" + id + ".txt"; var temp = new List { }; + if (!Directory.Exists(temppath)) + { + temp.Add("ERROR"); + return temp; + } + + StreamReader sr = new StreamReader(temppath); + + temp.Add(this.getTranslationPrivateApi(sr)); temp.Add(this.getTranslationPrivateKey(sr)); @@ -61,8 +66,15 @@ namespace WpfApp1.translationKey public List OutputTranslationNameList() { List temp = new List { }; + string temptxtpath = txtPath; + + if(!Directory.Exists(temptxtpath)) + { + temp.Add("ERROR"); + return temp; + } - StreamReader sr = new StreamReader(this.txtPath); + StreamReader sr = new StreamReader(temptxtpath); string temp2 = sr.ReadLine(); if (temp2 == null) {