diff --git a/src/translationKey/TempResource.cs b/src/translationKey/TempResource.cs index 5b15a31..43a89db 100644 --- a/src/translationKey/TempResource.cs +++ b/src/translationKey/TempResource.cs @@ -25,18 +25,23 @@ namespace WpfApp2 public TempResource() //用于创建 { - if(Directory.Exists(jsonpath)) + if(!Directory.Exists(jsonpath)) { - List js = JsonConvert.DeserializeObject>(jsonpath); - js.Add(new MyData() { ID = "20230923001827495", KEY = "yjvMNY33Qc1TYSBjTQYQ", SECRET = "M2Q4YzkzZTIwZjNkMGE2ZjkwZWMxNzZk", SRCLAN = "jp", DSTLAN = "zh", NOW = "baidu", } ); - string jjson = JsonConvert.SerializeObject(js); - File.WriteAllText(jsonpath, jjson); + 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() { - string jsonF = File.ReadAllText(jsonpath); + var jsonF = File.ReadAllText(jsonpath); MyData da = JsonConvert.DeserializeObject(jsonF); return da; } diff --git a/src/translationKey/translationPrivateIn.cs b/src/translationKey/translationPrivateIn.cs index 1bb4a6d..06898d4 100644 --- a/src/translationKey/translationPrivateIn.cs +++ b/src/translationKey/translationPrivateIn.cs @@ -1,10 +1,5 @@ - -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace WpfApp2.translationKey { @@ -24,19 +19,21 @@ namespace WpfApp2.translationKey string temppathTemp = pathTemp + "\\" + name + ".txt"; StreamWriter sw = new StreamWriter(temppathTemp); + StreamWriter sw2 = new StreamWriter(txtPath,true); + foreach (string s in list) { sw.WriteLine(s); } - name = "\n" + name; - System.IO.File.AppendAllText(txtPath, name); + sw2.WriteLine(name); sw.Close(); + sw2.Close(); } public void InputBaiduPrivate(string name, string id, string key)//该函数仅百度支持 { - if(!Directory.Exists(pathTemp)) + if (!Directory.Exists(pathTemp)) { Directory.CreateDirectory(pathTemp); } @@ -44,10 +41,10 @@ namespace WpfApp2.translationKey string temppathTemp = pathTemp + "\\" + name + ".txt"; StreamWriter sw = new StreamWriter(temppathTemp); StreamWriter sw2 = new StreamWriter(txtPath); - - InputTranslationId(id,sw); - InputTranslationKey(key,sw); - + + InputTranslationId(id, sw); + InputTranslationKey(key, sw); + sw2.WriteLine(name); sw.Close(); sw2.Close();