Compare commits

...

39 Commits
master ... GDN

Author SHA1 Message Date
lilium-saber 4aba920f1d 0
1 year ago
lilium-saber 2e225854ea 11072002
1 year ago
lilium-saber 24095d15ba voice 11072001
1 year ago
lilium-saber 80799ae956 fix bug 11071900
1 year ago
lilium-saber 99f5d11070 test
1 year ago
lilium-saber 5c7f6f2c60 8
1 year ago
lilium-saber 071d725814 0
1 year ago
lilium-saber 0a338f743c ga
1 year ago
lilium-saber 4a21ac34b9 0
1 year ago
lilium-saber c78af1be36 0
1 year ago
lilium-saber 47f39ae49e 0
1 year ago
lilium-saber b00e0d0f24 0
1 year ago
lilium-saber 5f0d8ff810 1
1 year ago
lilium-saber 92907c90c4 jah
1 year ago
lilium-saber ab2e06535a 0
1 year ago
lilium-saber 20abb91db7 1
1 year ago
lilium-saber eb7517e2a7 1
1 year ago
lilium-saber 44887c1dd4 network to get json
1 year ago
lilium-saber 230a999be4 network to request json
1 year ago
lilium-saber 17eba24fc5 can to use cmd
1 year ago
lilium-saber 0ccf2337a1 Network request Json
1 year ago
lilium-saber fe5dbe1666 TranslationResource Fix File
1 year ago
lilium-saber 317e385d06 using cmd file by c#
1 year ago
lilium-saber 9d00379e3a key
1 year ago
lilium-saber 39dc0745a6 Merge branch 'master' of https://bdgit.educoder.net/pokyijf9p/software636 into GDN
1 year ago
pokyijf9p 21421fe357 2
1 year ago
高源 b18ccdce9c 11
1 year ago
pokyijf9p 3110398e58 1
1 year ago
高源 3165c386e8 11
1 year ago
lilium-saber 361b5ca223 Merge branch 'master' of https://bdgit.educoder.net/pokyijf9p/software636 into GDN
1 year ago
pokyijf9p 03ac7af060 1
1 year ago
高源 7f0d924021 1
1 year ago
高源 92c5c527c7 1
1 year ago
高源 17c3ef48b2 0
1 year ago
高源 d6cd6bede2 Revert "需求文档"
1 year ago
高源 6b7df8f197 需求文档
1 year ago
lilium-saber 19cc7e5bd0 test
1 year ago
pokyijf9p ce4c2d1d25 test
1 year ago
高源 d27bb9069c 1
1 year ago

@ -0,0 +1,170 @@
using System.Collections.Generic;
using WpfApp2.ScnToJson;
using WpfApp2.translationKey;
using WpfApp2.transToNet;
using WpfApp2.tools;
using WpfApp2.tools.translationKey;
namespace WpfApp2.tools
{
internal class AllClassAndInterfaceWellBeManipulatedInThisFileAndCallThroughFunction
{
public AllClassAndInterfaceWellBeManipulatedInThisFileAndCallThroughFunction() { }
TranslationPrivateIn trin = new TranslationPrivateIn();
TranslationApiStr trstr = new translationPrivateOut();
TranslationApiInt trint = new translationPublic();
TranslationScnToJson scnjson = new TranslationScnToJson();
Messiah jsonnet = new jsonNet();
TempResource temp = new TempResource();
yieldVoice voice = new yieldVoice();
public void InputPrivateBaidu(string name, string id, string key)
{
trin.InputBaiduPrivate(name, id, key);
}
public void InPutPrivateA(string name, List<string> list)
{
trin.InPutPrivate(name, list);
}
public List<string> OutputNameList()
{
List<string> list = trstr.OutputTranslationNameList();
return list;
}
public List<string> OutputStr(string id)
{
List<string> li = trstr.OutputTranslationS(id);
return li;
}
public List<string> OutputChoicPublic(int id)
{
List<string> li = trint.OutputTranslationI(id);
return li;
}
public void StartSCNTransJSON()
{
scnjson.StartTrans();
}
public void StartTransOneself(string spa, string dps)
{
scnjson.StopTrans(spa, dps);
}
public void StartTranslateJsonToScn(string spaJson,string spaGame, string dpsScn)//写文件夹路径
{
scnjson.JsonToScn(spaJson, spaGame, dpsScn);
}
public string NetBaiDu(string input)
{
return jsonnet.RequestJsonBaiDu(input);
}
public string NetBaiDu(string input, List<Charactor> list)
{
return jsonnet.RequestJsonBaiDu(input, list);
}
public string NetAllBaiDu(string input, string srcl, string dstl, string aid, string kkey)
{
return jsonnet.RequestJsonPrivateBaiDu(input, srcl, dstl, aid, kkey);
}
public string NetLanBaiDu(string input, string srcl, string dstl)
{
return jsonnet.RequestJsonLanguageChangeBaiDu(input, srcl, dstl);
}
public string NetXunFei(string input)
{
return jsonnet.RequestJsonXunFei(input);
}
public string NetXunFei(string input, List<Charactor> list)
{
return jsonnet.RequestJsonXunFei(input, list);
}
public string NetLanXunFei(string input, string srcl, string dstl)
{
return jsonnet.RequestJsonLanguageChangeXunFei(input, srcl, dstl);
}
public string NetAllXunFei(string input, string srcl, string dstl, string xid, string xsecret, string xkey)
{
return jsonnet.RequestJsonPrivateXunFei(input, srcl, dstl, xid, xsecret, xkey);
}
public void SetId(string id)
{
temp.TempIdSet(id);
}
public void SetKey(string key)
{
temp.TempKeySet(key);
}
public void SetSecret(string secret)
{
temp.TempSecretSet(secret);
}
public void SetSrc(string src)
{
temp.TempSrcSet(src);
}
public void SetDst(string dst)
{
temp.TempDstSet(dst);
}
public void SetChoic(string choic)
{
temp.TempChoicSet(choic);
}
public string GetId()
{
return temp.TempIdGet();
}
public string GetKey()
{
return temp.TempKeyGet();
}
public string GetSecret()
{
return temp.TempSecretGet();
}
public string GetSrc()
{
return temp.TempSrcGet();
}
public string GetDst()
{
return temp.TempDstGet();
}
public string GetChoic()
{
return temp.TempChoicGet();
}
public void OutPutVoice(string text, string lan)
{
voice.CreateVoice(text, lan);
}
}
}

@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WpfApp2.transToNet
{
/*
internal class GrapeToJsonTrans : GrapeToJson
{
public List<string> GrapeRequestJson()
{
List<string> re = new List<string>();
return re;
}
public List<string> GrapeRequestJsonBaiDu()
{
List<string> re = new List<string>();
return re;
}
public List<string> GrapeRequestJsonLanguageChange()
{
List<string> re = new List<string>();
return re;
}
}
*/
}

@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WpfApp2.transToNet
{
interface Messiah
{
public abstract string RequestJsonPrivateBaiDu(string input, string srcl, string dstl, string aid, string kkey);
public abstract string RequestJsonLanguageChangeBaiDu(string input, string srcl, string dstl);
public abstract string RequestJsonBaiDu(string input);
public abstract string RequestJsonXunFei(string input);
public abstract string RequestJsonPrivateXunFei(string input, string srcl, string dstl, string xid, string xsecret, string xkey);
public abstract string RequestJsonLanguageChangeXunFei(string input, string srcl, string dstl);
}
/*
interface GrapeToJson
{
public abstract List<string> GrapeRequestJson();
public abstract List<string> GrapeRequestJsonLanguageChange();
public abstract List<string> GrapeRequestJsonBaiDu();
}
*/
}

@ -0,0 +1,336 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Json;
using System.Reflection.Metadata;
using System.Security.Cryptography;
using System.Security.Policy;
using System.Text;
using System.Threading.Tasks;
using System.Web;
namespace WpfApp2.transToNet
{
internal class jsonNet : Messiah
{
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
//baidu
static string xunweb = "https://itrans.xf-yun.com/v1/its";
static string xunid = "1299c840";
static string xunsec = "M2Q4YzkzZTIwZjNkMGE2ZjkwZWMxNzZk";
static string xunkey = "828cb2dc915d28464a904bda5d7b01b3";
static string xunfl = "en";//ja
static string xundl = "cn";
static string xuntxt = "Sakura miko";
//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()
{
BaseAddress = new Uri("http://api.fanyi.baidu.com/api/trans/vip/translate?"),
};
static async Task GetAsync(HttpClient httpc)
{
using HttpResponseMessage response = await httpc.GetAsync(temp);
//var value = response.EnsureSuccessStatusCode().WriteRequestToConsole();
var jsonResponse = await response.Content.ReadAsStringAsync();//收到json
Console.WriteLine($"{jsonResponse}\n");
}
*/
private HttpClient HttpRequestC(string url)//创建HTTP
{
HttpClient httpClient = new HttpClient()
{
BaseAddress = new Uri(url)
};
return httpClient;
}
private static string EncryptString(string str)//百度MD5加密计算方式
{
MD5 md5 = MD5.Create();
// 将字符串转换成字节数组
byte[] byteOld = Encoding.UTF8.GetBytes(str);
// 调用加密方法
byte[] byteNew = md5.ComputeHash(byteOld);
// 将加密结果转换为字符串
StringBuilder sb = new StringBuilder();
foreach (byte b in byteNew)
{
// 将字节转换成16进制表示的字符串
sb.Append(b.ToString("x2"));
}
// 返回加密的字符串
return sb.ToString();
}
private static string HmacSha256(string message, string secret)//hmachas256加密
{
byte[] keyBytes = Encoding.UTF8.GetBytes(secret);
byte[] messageBytes = Encoding.UTF8.GetBytes(message);
using (HMACSHA256 hmac = new HMACSHA256(keyBytes))
{
byte[] signatureBytes = hmac.ComputeHash(messageBytes);
return Convert.ToBase64String(signatureBytes);
}
}
private static string Sha256(string message)//SHA-256加密
{
byte[] messageBytes = Encoding.UTF8.GetBytes(message);
using (SHA256 sha256 = SHA256.Create())
{
byte[] signatureBytes = sha256.ComputeHash(messageBytes);
return Convert.ToBase64String(signatureBytes);
}
}
private static string signBody(string body)
{
byte[] messageBytes = Encoding.UTF8.GetBytes(body);
using (SHA256 sha256 = SHA256.Create())
{
byte[] signatureBytes = sha256.ComputeHash(messageBytes);
string signature = Convert.ToBase64String(signatureBytes);
return hmacsign(signature, xunsec);
}
}
private static string hmacsign(string signature, string apiSecret)
{
byte[] keyBytes = Encoding.UTF8.GetBytes(apiSecret);
byte[] messageBytes = Encoding.UTF8.GetBytes(signature);
using (HMACSHA256 hmac = new HMACSHA256(keyBytes))
{
byte[] signatureBytes = hmac.ComputeHash(messageBytes);
return Convert.ToBase64String(signatureBytes);
}
}
private static string ComputeSha256(string message)
{
byte[] messageBytes = Encoding.UTF8.GetBytes(message);
using (SHA256 sha256 = SHA256.Create())
{
byte[] signatureBytes = sha256.ComputeHash(messageBytes);
return Convert.ToBase64String(signatureBytes);
}
}
private static string BuildHttpBody()
{
Dictionary<string, object> paramMap = new()
{
{ "from", "cn" },
{ "to", "en" },
{ "appid", xunid },
{ "salt", DateTime.Now.Millisecond.ToString() },
{ "signType", "v3" },
{ "signature", "" },
{ "voice", "0" },
{ "text", "你好,世界!" }
};
string body = JsonConvert.SerializeObject(paramMap);
string signature = signBody(body);
paramMap["signature"] = signature;
return JsonConvert.SerializeObject(paramMap);
}
private static Dictionary<string, string> BuildHttpHeader(string body)
{
string curTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
string param = xunkey + curTime + body;
string checkSum = ComputeSha256(param);
Dictionary<string, string> header = new()
{
{ "Content-Type", "application/json" },
{ "X-Appid", xunid },
{ "X-CurTime", curTime },
{ "X-Param", body },
{ "X-CheckSum", checkSum }
};
return header;
}
public string RequestJsonPrivateBaiDu(string input, string srcl, string dstl, string aid, string kkey)//自定义idkey以及源语言和目标语言
{
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<tempC2>(retString);
Trans_result result = temp1.trans_result[0];
string s = result.dst;
return s;
}
public string RequestJsonLanguageChangeBaiDu(string input, string srcl, string dstl)//可以自定义源语言与目标语言
{
string sign = EncryptString(appid + input + salt + key);
string temp = "q=" + HttpUtility.UrlEncode(input) + "&from=" + srcl + "&to=" + dstl + "&appid=" + appid + "&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<tempC2>(retString);
Trans_result result = temp1.trans_result[0];
string s = result.dst;
return s;
}
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();
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<tempC2>(retString);
Trans_result result = temp1.trans_result[0];
string s = result.dst;
return s;
}
public string RequestJsonXunFei(string input)
{
string body = BuildHttpBody();
Console.WriteLine("【ITSWebAPI body】\n" + body);
Dictionary<string, string> header = BuildHttpHeader(body);
Dictionary<string, object> resultMap = HttpUtil.DoPost(xunweb, header, body);
string re = "error";
if (resultMap != null)
{
string resultStr = resultMap["body"].ToString();
re = resultStr;
Console.WriteLine("【ITS WebAPI 接口调用结果】\n" + resultStr);
//以下仅用于调试
ResponseData resultData = JsonConvert.DeserializeObject<ResponseData>(resultStr);
int code = resultData.code;
if (resultData.code != 0)
{
Console.WriteLine("请前往https://www.xfyun.cn/document/error-code?code=" + code + "查询解决办法");
}
}
else
{
Console.WriteLine("调用失败请根据错误信息检查代码接口文档https://www.xfyun.cn/doc/nlp/xftrans/API.html");
}
return re;
}
public string RequestJsonPrivateXunFei(string input, string srcl, string dstl, string xid, string xse , string xkey)
{
return "error";
}
public string RequestJsonLanguageChangeXunFei(string input, string srcl, string dstl)
{
return "error";
}
}
class Trans_result
{
public string src { get; set; }
public string dst { get; set; }
}
class tempC2
{
public List<Trans_result> trans_result { get; set; }
}
class ResponseData
{
public int code { get; set; }
public string message { get; set; }
public string sid { get; set; }
public List<Result> data { get; set; }
}
class Result
{
public string src { get; set; }
public string tgt { get; set; }
}
class HttpUtil//讯飞用
{
public static Dictionary<string, object> DoPost(string url, Dictionary<string, string> header, string body)
{
using (HttpClient client = new HttpClient())
{
foreach (KeyValuePair<string, string> entry in header)
{
client.DefaultRequestHeaders.Add(entry.Key, entry.Value);
}
HttpContent content = new StringContent(body, Encoding.UTF8, "application/json");
HttpResponseMessage response = client.PostAsync(url, content).Result;
if (response.IsSuccessStatusCode)
{
string resultStr = response.Content.ReadAsStringAsync().Result;
Dictionary<string, object> resultMap = JsonConvert.DeserializeObject<Dictionary<string, object>>(resultStr);
resultMap.Add("body", resultStr);
return resultMap;
}
else
{
Console.WriteLine("请求失败,错误码:" + response.StatusCode);
return null;
}
}
}
}
}

@ -0,0 +1,85 @@
using System.Diagnostics;
using System.IO;
namespace WpfApp2.ScnToJson
{
internal class TranslationScnToJson
{
//private string spath;//scn路径
//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()
{
this.DirExsis("VNT\\p1");
this.DirExsis("VNT\\p2");
var p = new Process
{
StartInfo =
{
FileName = "PowerShell.exe",
Arguments = "/c " + cmdHandle + "\n" + voice,
UseShellExecute = false,
CreateNoWindow = false,
}
};
p.Start();
p.WaitForExit();
p.Close();
}
public void DirExsis(string id)
{
if (Directory.Exists(Directory.GetCurrentDirectory() + "\\" + id))
{
Directory.CreateDirectory(Directory.GetCurrentDirectory() + "\\" + id);
}
}
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();
}
public void JsonToScn(string srcgame, string srcjson, string dstgame)
{
string temp = ".\\VNTextPatch insertlocal " + srcgame + " " + srcjson + " " + dstgame;
var p = new Process
{
StartInfo =
{
FileName = "PowerShell.exe",
Arguments = "/c " + cmdHandle + "\n" + temp,
UseShellExecute = false,
CreateNoWindow = false,
}
};
p.Start();
p.WaitForExit();
p.Close();
}
}
}

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
</startup>
<appSettings>
<!-- When using an API key to access Google spreadsheets -->
<add key="GoogleApiKey" value="" />
<!-- Instead of using an API key, you can also use a service account. This way, you don't have to make your spreadsheet public. -->
<!-- To use a service account, download its private key and store it in a file called "google-service-account.json" -->
<add key="MonospaceCharactersPerLine" value="50" />
<add key="ProportionalFontName" value="Franklin Gothic Book" />
<add key="ProportionalFontSize" value="40" />
<add key="ProportionalFontBold" value="false" />
<add key="ProportionalLineWidth" value="1000" />
<add key="SecondaryProportionalLineWidth" value="670" />
</appSettings>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" />
</dependentAssembly>
</assemblyBinding>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

@ -0,0 +1,2 @@
<?xml version="1.0"?>
<names xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />

@ -0,0 +1,7 @@
Excel:
VNTextPatch extractlocal <folder containing original game files> script.xlsx
VNTextPatch insertlocal <folder containing original game files> script.xlsx <folder to receive patched game files>
JSON:
VNTextPatch extractlocal <folder containing original game files> <folder to receive .json files>
VNTextPatch insertlocal <folder containing original game files> <folder containing .json files> <folder to receive patched game files>

@ -0,0 +1,108 @@
using System.Drawing;
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Runtime.InteropServices;
//using System.Windows.Forms;
namespace WpfApp1.WinOcr
{
internal class OcrSofia : Sofia
{
static string path = Directory.GetCurrentDirectory() + "\\TempImage";
public OcrSofia() { }
public string WindowsOcrToGetStringAndTranslate(string name)
{
string retxt = "";
/*
this.DirExists();
Image image = null;
MODI.Document modiDocument = new MODI.Document();
modiDocument.Create(path + "\\" + name + ".jpg");
modiDocument.OCR(MODI.MiLANGUAGES.miLANG_CHINESE_SIMPLIFIED, true, true);
MODI.Image modiImage = (MODI.Image)modiDocument.Images[0];
retxt = modiImage.Layout.Text;
*/
return retxt;
/*
string processName = "notepad"; // 替换为要跟踪的进程名称
Process[] processes = Process.GetProcessesByName(processName);
if (processes.Length > 0)
{
Process process = processes[0];
IntPtr hwnd = process.MainWindowHandle;
var Ocr = new IronTesseract();
OcrResult Result = null;
Ocr.TextAvailable += (s, e) =>
{
Console.WriteLine(e.Text);
Result = e.Result;
};
while (true)
{
if (hwnd != IntPtr.Zero)
{
int length = GetWindowTextLength(hwnd);
if (length > 0)
{
IntPtr buffer = Marshal.AllocHGlobal(length + 1);
GetWindowText(hwnd, buffer, length + 1);
string text = Marshal.PtrToStringAnsi(buffer);
Marshal.FreeHGlobal(buffer);
Ocr.Read(text);
}
}
}
}
else
{
Console.WriteLine("找不到进程:{0}", processName);
}
*/
}
public void DirExists()
{
if(Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
}
/*
internal class OcrSofia : Sofia
{
public OcrSofia() { }
public string WindowsOcrToGetStringAndTranslate()
{
string result = "";
// 获取剪贴板中的图像
Image image = Clipboard.GetImage();
// 将图像保存到临时文件中
string tempFile = Path.GetTempFileName();
image.Save(tempFile, ImageFormat.Tiff);
// 使用Windows OCR引擎识别图像中的文本
MODI.Document modiDocument = new MODI.Document();
modiDocument.Create(tempFile);
modiDocument.OCR(MODI.MiLANGUAGES.miLANG_CHINESE_SIMPLIFIED, true, true);
MODI.Image modiImage = (MODI.Image)modiDocument.Images[0];
result = modiImage.Layout.Text;
// 删除临时文件
File.Delete(tempFile);
return result;
}
}
*/
}
}

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WpfApp1.WinOcr
{
internal interface Sofia
{
public abstract string WindowsOcrToGetStringAndTranslate(string name);
}
}

@ -0,0 +1,14 @@
<Window x:Class="WpfApp2.WindowsSEL.ErrorIn"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp2.WindowsSEL"
mc:Ignorable="d"
Title="警告" Height="120" Width="150">
<Grid>
<Button Content="确定" HorizontalAlignment="Center" Margin="0,56,0,0" VerticalAlignment="Top" Click="Button_Click"/>
<TextBlock HorizontalAlignment="Center" Margin="0,14,0,0" TextWrapping="Wrap" Text="未输入Id" VerticalAlignment="Top" Height="28" Width="58"/>
</Grid>
</Window>

@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace WpfApp2.WindowsSEL
{
/// <summary>
/// ErrorIn.xaml 的交互逻辑
/// </summary>
public partial class ErrorIn : Window
{
public ErrorIn()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
}
}

@ -0,0 +1,14 @@
<Window x:Class="WpfApp2.WindowsSEL.SelectPriTrueWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp2.WindowsSEL"
mc:Ignorable="d"
Title="选择成功" Height="200" Width="200">
<Grid>
<Button Content="返回" HorizontalAlignment="Center" Margin="0,138,0,0" VerticalAlignment="Top" Click="Button_Click"/>
<TextBlock HorizontalAlignment="Center" Margin="0,45,0,0" TextWrapping="Wrap" Text="选择成功" VerticalAlignment="Top" Height="47" Width="88"/>
</Grid>
</Window>

@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace WpfApp2.WindowsSEL
{
/// <summary>
/// SelectPriTrueWindow.xaml 的交互逻辑
/// </summary>
public partial class SelectPriTrueWindow : Window
{
string value
{ set; get; }
public SelectPriTrueWindow(string id )
{
InitializeComponent();
value = id;
DataContext = this;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
}
}

@ -0,0 +1,21 @@
<Window x:Class="WpfApp2.view.TransSourceInWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp2.view"
mc:Ignorable="d"
Title="私有翻译接口写入" Height="300" Width="400">
<Grid>
<Button Content="取消" HorizontalAlignment="Left" Margin="301,226,0,0" VerticalAlignment="Top" Click="Button_Close"/>
<Button Content="保存" HorizontalAlignment="Left" Margin="58,226,0,0" VerticalAlignment="Top" Click="Button_Save"/>
<TextBox x:Name="InId" HorizontalAlignment="Left" Margin="115,47,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="214"/>
<TextBox x:Name="InKey" HorizontalAlignment="Left" Margin="115,86,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="214"/>
<TextBox x:Name="InSecret" HorizontalAlignment="Left" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="214" Margin="115,125,0,0"/>
<TextBlock HorizontalAlignment="Left" Margin="54,47,0,0" TextWrapping="Wrap" Text="ID" VerticalAlignment="Top"/>
<TextBlock HorizontalAlignment="Left" Margin="45,86,0,0" TextWrapping="Wrap" Text="KEY" VerticalAlignment="Top"/>
<TextBlock HorizontalAlignment="Left" Margin="31,125,0,0" TextWrapping="Wrap" Text="Sercet" VerticalAlignment="Top"/>
<TextBlock HorizontalAlignment="Left" Margin="72,178,0,0" TextWrapping="Wrap" Text="提示保存时ID不能留空Sercet可以留空" VerticalAlignment="Top" Width="243"/>
</Grid>
</Window>

@ -0,0 +1,63 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using WpfApp2.WindowsSEL;
namespace WpfApp2.view
{
/// <summary>
/// TransSourceInWindow.xaml 的交互逻辑
/// </summary>
public partial class TransSourceInWindow : Window
{
AllClassAndInterfaceWellBeManipulatedInThisFileAndCallThroughFunction a = new AllClassAndInterfaceWellBeManipulatedInThisFileAndCallThroughFunction();
public TransSourceInWindow()
{
InitializeComponent();
}
private void Button_Close(object sender, RoutedEventArgs e)
{
this.Close();
}
private void Button_Save(object sender, RoutedEventArgs e)
{
string id = InId.Text;
string key = InKey.Text;
string secret = InSecret.Text;
if (id == "")
{
var windows = new ErrorIn();
windows.ShowDialog();
}
else
{
List<string> li = new List<string> { };
li.Add(id);
li.Add(key);
if(secret != "")
{
li.Add(secret);
}
a.InPutPrivateA(id, li);
this.Close();
}
}
}
}

@ -0,0 +1,17 @@
<Window x:Class="WpfApp2.WindowsSEL.TransSourceSelectPri"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp2.WindowsSEL"
mc:Ignorable="d"
Title="私有翻译接口选择" Height="500" Width="350">
<Grid>
<ComboBox x:Name="myComBox" HorizontalAlignment="Left" Margin="131,65,0,0" VerticalAlignment="Top" Width="164" SelectionChanged="myComBox_SelectionChanged" ItemsSource="{Binding mylist}"/>
<TextBlock HorizontalAlignment="Center" Margin="0,38,0,0" TextWrapping="Wrap" Text="选择以写入的私有翻译源" VerticalAlignment="Top" Height="38" Width="150"/>
<Button Content="确定更改" HorizontalAlignment="Left" Margin="59,392,0,0" VerticalAlignment="Top" Height="30" Width="62" Click="Button_True"/>
<Button Content="取消" HorizontalAlignment="Left" Margin="213,392,0,0" VerticalAlignment="Top" Height="30" Width="53" Click="Button_Close"/>
</Grid>
</Window>

@ -0,0 +1,83 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace WpfApp2.WindowsSEL
{
/// <summary>
/// TransSourceSelectPri.xaml 的交互逻辑
/// </summary>
public partial class TransSourceSelectPri : Window
{
AllClassAndInterfaceWellBeManipulatedInThisFileAndCallThroughFunction a = new AllClassAndInterfaceWellBeManipulatedInThisFileAndCallThroughFunction();
string selectvalue = null;
public List<string> mylist { get; set; }
public TransSourceSelectPri()
{
InitializeComponent();
List<string> mylist = a.OutputNameList();
myComBox.ItemsSource = mylist;
}
private void myComBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
selectvalue = myComBox.SelectedItem.ToString();
}
private void Button_True(object sender, RoutedEventArgs e)
{
if(selectvalue == "")
{
this.Close();
}
else
{
List<string> li = a.OutputStr(selectvalue);
int i = 0;
string id = "";
foreach (string s in li)
{
if (i == 0)
{
id = s;
a.SetId(s);
a.SetChoic(s);
}
if(i == 1)
{
a.SetKey(s);
}
if (i == 2)
{
a.SetSecret(s);
}
i++;
}
var win = new SelectPriTrueWindow(id);
win.Show();
}
this.Close();
}
private void Button_Close(object sender, RoutedEventArgs e)
{
this.Close();
}
}
}

@ -0,0 +1,15 @@
<Window x:Class="WpfApp2.view.TranslationSourceSelect"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp2.view"
mc:Ignorable="d"
Title="公共翻译接口选择" Height="300" Width="200">
<Grid Margin="0,0,200,-5">
<Button Content="选择百度翻译1" Margin="53,61,-142,0" VerticalAlignment="Top" Click="Button1_Click"/>
<Button Content="选择百度翻译2" Margin="53,97,-144,0" VerticalAlignment="Top" Click="Button2_Click"/>
<Button Content="选择讯飞翻译" Margin="53,22,-142,0" VerticalAlignment="Top" Click="ButtonXunfei_Click"/>
<Button Content="取消选择" Margin="53,165,-142,0" VerticalAlignment="Top" Click="ButtonOff_Click"/>
</Grid>
</Window>

@ -0,0 +1,98 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using WpfApp2;
namespace WpfApp2.view
{
/// <summary>
/// TranslationSourceSelect.xaml 的交互逻辑
/// </summary>
public partial class TranslationSourceSelect : Window
{
AllClassAndInterfaceWellBeManipulatedInThisFileAndCallThroughFunction a = new AllClassAndInterfaceWellBeManipulatedInThisFileAndCallThroughFunction();
public TranslationSourceSelect()
{
InitializeComponent();
}
private void Button1_Click(object sender, RoutedEventArgs e)
{
a.SetChoic("baidu");
int i = 0;
List<string> list = a.OutputChoicPublic(1);
foreach(string s in list)
{
if(i == 0)
{
a.SetId(s);
}else if(i == 1)
{
a.SetKey(s);
}
i++;
}
this.Close();
}
private void Button2_Click(object sender, RoutedEventArgs e)
{
a.SetChoic("baidu");
int i = 0;
List<string> list = a.OutputChoicPublic(2);
foreach (string s in list)
{
if (i == 0)
{
a.SetId(s);
}
else if (i == 1)
{
a.SetKey(s);
}
i++;
}
this.Close();
}
private void ButtonXunfei_Click(object sender, RoutedEventArgs e)
{
a.SetChoic("xunfei");
int i = 0;
List<string> list = a.OutputChoicPublic(0);
foreach (string s in list)
{
if (i == 0)
{
a.SetId(s);
}
else if (i == 1)
{
a.SetKey(s);
}else if (i == 2)
{
a.SetSecret(s);
}
i++;
}
this.Close();
}
private void ButtonOff_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
}
}

@ -0,0 +1,133 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http.Json;
using System.Text;
using System.Threading.Tasks;
namespace WpfApp2
{
class TempResource
{
string jsonpath = Directory.GetCurrentDirectory() + "\\TempS.json";
class MyData
{
public string ID { get; set; }
public string KEY { get; set; }
public string SECRET { get; set; }
public string SRCLAN { get; set; }
public string DSTLAN { get; set; }
public string NOW { get; set; }
}
public TempResource() //用于创建
{
if(!Directory.Exists(jsonpath))
{
StreamWriter streamWriter = new StreamWriter(jsonpath);
streamWriter.WriteLine("{\n\"ID\" : \"20230923001827495\"," +
"\n\"KEY\" : \"yjvMNY33Qc1TYSBjTQYQ\"," +
"\n\"SECRET\" : \"M2Q4YzkzZTIwZjNkMGE2ZjkwZWMxNzZk\"," +
"\n\"SRCLAN\" : \"jp\"," +
"\n\"DSTLAN\" : \"zh\"," +
"\n\"NOW\":\"baidu\"\n" +
"}");
streamWriter.Close();
}
}
private MyData GetJsonStream()
{
var jsonF = File.ReadAllText(jsonpath);
MyData da = JsonConvert.DeserializeObject<MyData>(jsonF);
return da;
}
private void SetJsonStream(MyData da)
{
string js = JsonConvert.SerializeObject(da);
File.WriteAllText(jsonpath, js);
}
public void TempIdSet(string id)
{
MyData da = GetJsonStream();
da.ID = id;
SetJsonStream(da);
}
public void TempKeySet(string key)
{
MyData myData = GetJsonStream();
myData.KEY = key;
SetJsonStream(myData);
}
public void TempSecretSet(string secret)
{
MyData myData1 = GetJsonStream();
myData1.SECRET = secret;
SetJsonStream(myData1);
}
public void TempSrcSet(string src)
{
MyData myData = GetJsonStream();
myData.SRCLAN = src;
SetJsonStream(myData);
}
public void TempDstSet(string dst)
{
MyData mydata = GetJsonStream();
mydata.DSTLAN = dst;
SetJsonStream(mydata);
}
public void TempChoicSet(string choic)
{
MyData my = GetJsonStream();
my.NOW = choic;
SetJsonStream(my);
}
public string TempIdGet()
{
MyData my = GetJsonStream();
return my.ID;
}
public string TempKeyGet()
{
MyData my1 = GetJsonStream();
return my1.KEY;
}
public string TempSecretGet()
{
MyData my = GetJsonStream();
return my.SECRET;
}
public string TempSrcGet()
{
MyData my = GetJsonStream();
return my.SECRET;
}
public string TempDstGet()
{
MyData tmp = GetJsonStream();
return tmp.DSTLAN;
}
public string TempChoicGet()
{
MyData my2 = GetJsonStream();
return my2.NOW;
}
}
}

@ -0,0 +1,18 @@
using System.Collections.Generic;
namespace WpfApp2.translationKey
{
interface TranslationApiStr//Mohammed
{
public abstract List<string> OutputTranslationS(string id);
public abstract List<string> OutputTranslationNameList();
}
interface TranslationApiInt
{
public abstract List<string> OutputTranslationI(int id);
}
}

@ -0,0 +1,64 @@
using System.Collections.Generic;
using System.IO;
namespace WpfApp2.translationKey
{
class TranslationPrivateIn
{
private static string pathTemp = Directory.GetCurrentDirectory() + "\\translationResource";
private static string txtPath = Directory.GetCurrentDirectory() + "\\translationResource\\ListPrivate.txt";
public TranslationPrivateIn() { }
public void InPutPrivate(string name, List<string> list)
{
if (!Directory.Exists(pathTemp))
{
Directory.CreateDirectory(pathTemp);
}
string temppathTemp = pathTemp + "\\" + name + ".txt";
StreamWriter sw = new StreamWriter(temppathTemp);
StreamWriter sw2 = new StreamWriter(txtPath,true);
foreach (string s in list)
{
sw.WriteLine(s);
}
sw2.WriteLine(name);
sw.Close();
sw2.Close();
}
public void InputBaiduPrivate(string name, string id, string key)//该函数仅百度支持
{
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);
InputTranslationKey(key, sw);
sw2.WriteLine(name);
sw.Close();
sw2.Close();
}
public void InputTranslationId(string id, StreamWriter sw)
{
sw.WriteLine(id);
}
public void InputTranslationKey(string key, StreamWriter sw)
{
sw.WriteLine(key);
}
}
}

@ -0,0 +1,112 @@
using System;
using System.Collections.Generic;
using System.IO;
namespace WpfApp2.translationKey;
class translationPrivateOut : TranslationApiStr
{
private static string path = Directory.GetCurrentDirectory() + "\\translationResource";
private static string txtPath = Directory.GetCurrentDirectory() + "\\translationResource\\ListPrivate.txt";
private String getTranslationPrivateApi(StreamReader sr)
{
String temp = sr.ReadLine();
if (temp != null)
{
return temp;
}
else
{
return "ERROR";
}
}
private String getTranslationPrivateKey(StreamReader sr)
{
String temp = sr.ReadLine();
if (temp != null)
{
return temp;
}
else
{
return "ERROR";
}
}
public string getpath(string id)
{
return path + "\\" + id + ".txt";
}
public string gettxt()
{
return txtPath;
}
public List<string> OutputTranslationS(string id)
{
string temppath = path + "\\" + id + ".txt";
List<string> temp = new List<string> { };
if (Directory.Exists(temppath))//若不存在
{
temp.Add("尚未输入!!!");
return temp;
}
StreamReader sr = new StreamReader(temppath);
temp.Add(this.getTranslationPrivateApi(sr));
temp.Add(this.getTranslationPrivateKey(sr));
sr.Close();
return temp;
}
public List<string> OutputTranslationNameList()
{
List<string> temp = new List<string> { };
string temptxtpath = txtPath;
if (Directory.Exists(temptxtpath))
{
temp.Add("ERROR");
return temp;
}
StreamReader sr = new StreamReader(temptxtpath);
string temp2 = sr.ReadLine();
if (temp2 == null)
{
temp.Add("ERROR");
}
else
{
while (temp2 != null)
{
temp.Add(temp2);
temp2 = sr.ReadLine();
}
}
sr.Close();
return temp;
}
}
class customTransApi
{
private string ID { get; set; }
private string KEY { get; set; }
private string SECRET { get; set; }
}

@ -0,0 +1,42 @@
using System.Collections.Generic;
namespace WpfApp2.translationKey
{
class translationPublic : TranslationApiInt
{
public List<string> OutputTranslationI(int id)
{
var temp = new List<string> { };
switch (id)
{
case 0://讯飞
{
temp.Add("1299c840");//id
temp.Add("M2Q4YzkzZTIwZjNkMGE2ZjkwZWMxNzZk");//APISecret
temp.Add("828cb2dc915d28464a904bda5d7b01b3");//APIKey
break;
}
case 1://百度
{
temp.Add("20230923001827495");//APIAppid
temp.Add("yjvMNY33Qc1TYSBjTQYQ");//APIKey
break;
}
case 2://百度2
{
temp.Add("20230925001829663");
temp.Add("f7ZHpw28izQ1VU_ixoY5");
break;
}
case 3://google
{
temp.Add("UNSET!");//NULL,空
temp.Add("UNSET!");//APIKey
break;
}
}
return temp;
}
}
}

@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using System.Windows;
using Windows.Media.SpeechSynthesis;
using System.Speech.Synthesis;
namespace WpfApp2.tools.translationKey
{
internal class yieldVoice//
{
private string language = "zh-CN";
public async void CreateVoice(string temp, string lan)
{
await Task.Delay(TimeSpan.FromSeconds(1));//延迟1s
var syn = new System.Speech.Synthesis.SpeechSynthesizer();
var bui = new PromptBuilder();
syn.SetOutputToDefaultAudioDevice();
lan ??= language;
bui.StartVoice(new System.Globalization.CultureInfo(lan));
bui.AppendText(temp);
bui.EndVoice();
syn.Speak(bui);
}
}
}

Binary file not shown.
Loading…
Cancel
Save