commit 50800699de9179f3f177909fff8d809df8f4767f
Author: sin365 <353374337@qq.com>
Date: Mon Oct 16 14:35:56 2023 +0800
归档
diff --git a/AutoRranslateTextToCsv.csproj b/AutoRranslateTextToCsv.csproj
new file mode 100644
index 0000000..1121dbe
--- /dev/null
+++ b/AutoRranslateTextToCsv.csproj
@@ -0,0 +1,24 @@
+
+
+
+ Exe
+ net7.0
+ enable
+ enable
+
+
+
+
+
+
+
+
+
+
+
+
+ Always
+
+
+
+
diff --git a/AutoRranslateTextToCsv.csproj.user b/AutoRranslateTextToCsv.csproj.user
new file mode 100644
index 0000000..2be4cd8
--- /dev/null
+++ b/AutoRranslateTextToCsv.csproj.user
@@ -0,0 +1,6 @@
+
+
+
+ <_LastSelectedProfileId>F:\Sin365\AutoRranslateTextToCsv\Properties\PublishProfiles\FolderProfile.pubxml
+
+
\ No newline at end of file
diff --git a/AutoRranslateTextToCsv.sln b/AutoRranslateTextToCsv.sln
new file mode 100644
index 0000000..16fe576
--- /dev/null
+++ b/AutoRranslateTextToCsv.sln
@@ -0,0 +1,25 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 17
+VisualStudioVersion = 17.7.34031.279
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoRranslateTextToCsv", "AutoRranslateTextToCsv.csproj", "{6F081B40-B803-4741-8A05-CB49F9095495}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {6F081B40-B803-4741-8A05-CB49F9095495}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {6F081B40-B803-4741-8A05-CB49F9095495}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {6F081B40-B803-4741-8A05-CB49F9095495}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {6F081B40-B803-4741-8A05-CB49F9095495}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {E41C24E3-4BE7-4C4F-934E-6DE391955CF7}
+ EndGlobalSection
+EndGlobal
diff --git a/FileHelper.cs b/FileHelper.cs
new file mode 100644
index 0000000..74f4f61
--- /dev/null
+++ b/FileHelper.cs
@@ -0,0 +1,61 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Text.RegularExpressions;
+using System.Threading.Tasks;
+
+namespace AutoRranslateTextToCsv
+{
+ public class FileHelper
+ {
+ public static bool LoadFile(string FilePath, out byte[] data)
+ {
+ using (FileStream fs = new FileStream(FilePath, FileMode.Open, FileAccess.Read))
+ {
+ try
+ {
+ byte[] buffur = new byte[fs.Length];
+ fs.Read(buffur, 0, (int)fs.Length);
+ fs.Close();
+ data = buffur;
+ return true;
+ }
+ catch (Exception ex)
+ {
+ data = null;
+ return false;
+ }
+ }
+ }
+
+ public static string[] GetDirFile(string Path)
+ {
+ return Directory.GetFiles(Path);
+ }
+
+ public static byte[] String2Byte(string value)
+ {
+ return Encoding.Default.GetBytes(value);
+ }
+ public static bool SaveFile(string FilePath, byte[] buffer)
+ {
+ try
+ {
+ //创建一个文件流
+ using (FileStream wfs = new FileStream(FilePath, FileMode.Create))
+ {
+ //将byte数组写入文件中
+ wfs.Write(buffer, 0, buffer.Length);
+ //所有流类型都要关闭流,否则会出现内存泄露问题
+ wfs.Close();
+ return true;
+ }
+ }
+ catch
+ {
+ return false;
+ }
+ }
+ }
+}
diff --git a/Program.cs b/Program.cs
new file mode 100644
index 0000000..5e7ceff
--- /dev/null
+++ b/Program.cs
@@ -0,0 +1,183 @@
+using System.Text;
+
+namespace AutoRranslateTextToCsv
+{
+ internal class Program
+ {
+ static string loc = Path.GetDirectoryName(AppContext.BaseDirectory) + "\\";
+
+ const string InDir = "Input";
+ const string OutDir = "Out";
+ const string SrcDataFile = "_TextDictionary.csv";
+ const string Ver = "0.1";
+ static Dictionary mDictSrcData;
+ static void Main(string[] args)
+ {
+ string title = $"AutoRranslateTextToCsv Ver.{Ver} By axibug.com";
+ Console.Title = title;
+ Console.WriteLine(title);
+
+
+ if (!Directory.Exists(loc + InDir))
+ {
+ Console.WriteLine("Input文件不存在");
+ Console.ReadLine();
+ return;
+ }
+
+ if (!Directory.Exists(loc + OutDir))
+ {
+ Console.WriteLine("Out文件不存在");
+ Console.ReadLine();
+ return;
+ }
+
+ if (!File.Exists(loc + SrcDataFile))
+ {
+ Console.WriteLine($"{SrcDataFile}文件不存在");
+ Console.ReadLine();
+ return;
+ }
+
+ Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
+
+ Console.WriteLine($"开始加载译文数据源……");
+ if (!LoadCsv(loc + SrcDataFile, out Dictionary _dictSrcData))
+ {
+ Console.WriteLine($"译文数据源加载失败");
+ Console.ReadLine();
+ return;
+ }
+
+ mDictSrcData = _dictSrcData;
+ Console.WriteLine($"译文数据源加载成功,共{_dictSrcData.Count}条数据");
+
+ string[] files = FileHelper.GetDirFile(loc + InDir);
+ Console.WriteLine($"Input中共{files.Length}个文件,是否处理? (y/n)");
+ string yn = Console.ReadLine();
+ if (yn.ToLower() != "y")
+ return;
+
+ int index = 0;
+ int errcount = 0;
+ for (int i = 0; i < files.Length; i++)
+ {
+ string FileName = files[i].Substring(files[i].LastIndexOf("\\"));
+
+ if (!FileName.ToLower().Contains(".csv"))
+ {
+ continue;
+ }
+ index++;
+ Console.WriteLine($">>>>>>>>>>>>>>开始处理 第{index}个文件 {FileName}<<<<<<<<<<<<<<<<<<<");
+
+ if (DoReplaceRranslateFile(files[i], out string[] TempArr,out int DoneIndex))
+ {
+ string newfileName = FileName;
+ string outstring = loc + OutDir + "\\" + newfileName;
+ File.WriteAllLines(outstring, TempArr);
+ Console.WriteLine($">>>>>>>>>>>>>>成功处理 第{index}个:{outstring} | 其中成功处理文本{DoneIndex}个");
+ }
+ else
+ {
+ errcount++;
+ Console.WriteLine($">>>>>>>>>>>>>>处理失败 第{index}个");
+ }
+ }
+
+ Console.WriteLine($"已处理{files.Length}个文件,其中{errcount}个失败");
+ Console.ReadLine();
+ }
+
+
+ public static bool LoadCsv(string path, out Dictionary _dictSrcData)
+ {
+ _dictSrcData = new Dictionary();
+ using (StreamReader sr = new StreamReader(path, Encoding.GetEncoding("gb2312")))
+ {
+ while (!sr.EndOfStream)
+ {
+ string line = sr.ReadLine();
+ string[] values = line.Split(',');
+ if (values.Length >= 2)
+ {
+ string k = null;
+ string v = null;
+ k = values[0];
+ v = values[1];
+ if (string.IsNullOrEmpty(k) || string.IsNullOrEmpty(v))
+ continue;
+ if (string.Equals(k,v))
+ continue;
+ _dictSrcData[k] = v;
+ }
+ }
+ }
+ return true;
+ }
+
+ public static bool DoReplaceRranslateFile(string path,out string[] TempArr,out int DoneNum)
+ {
+ DoneNum = 0;
+ try
+ {
+ string[] StrArr = File.ReadAllLines(path, Encoding.GetEncoding("shift-jis"));
+ TempArr = new string[StrArr.Length];
+ for (int i = 0; i < StrArr.Length; i++)
+ {
+
+ string line = StrArr[i];
+ if (i == 0)
+ {
+ TempArr[i] = line;
+ continue;
+ }
+ string[] valueArr = StrArr[i].Split("\t");
+ if (valueArr.Length >= 2 && GetRranslateText(valueArr[2], out string Resultline))
+ {
+ string newline = "";
+ for (int j = 0; j < valueArr.Length; j++)
+ {
+ if (j == 2)
+ newline += EncodingConvert(Encoding.GetEncoding("gb2312"), Encoding.GetEncoding("shift-jis"), Resultline);
+ else
+ newline += valueArr[j];
+
+ if(j < valueArr.Length -1)
+ newline += "\t";
+
+ DoneNum++;
+ }
+ line = newline;
+ }
+ TempArr[i] = line;
+ }
+
+ return true;
+ }
+ catch(Exception ex)
+ {
+ TempArr = null;
+ return false;
+ }
+ }
+ public static string EncodingConvert(Encoding src, Encoding dst, string text)
+ {
+ var bytes = src.GetBytes(text);
+ bytes = Encoding.Convert(src, dst, bytes);
+ return dst.GetString(bytes);
+ }
+
+ public static bool GetRranslateText(string line, out string Resultline)
+ {
+ if (mDictSrcData.ContainsKey(line))
+ {
+ Resultline = mDictSrcData[line];
+ return true;
+ }
+ Resultline = null;
+ return false;
+ }
+
+ }
+}
\ No newline at end of file
diff --git a/Properties/PublishProfiles/FolderProfile.pubxml b/Properties/PublishProfiles/FolderProfile.pubxml
new file mode 100644
index 0000000..e128b59
--- /dev/null
+++ b/Properties/PublishProfiles/FolderProfile.pubxml
@@ -0,0 +1,18 @@
+
+
+
+
+ Release
+ Any CPU
+ bin\Release\net7.0\publish\win-x64\
+ FileSystem
+ <_TargetId>Folder
+ net7.0
+ win-x64
+ false
+ true
+ true
+
+
\ No newline at end of file
diff --git a/Properties/PublishProfiles/FolderProfile.pubxml.user b/Properties/PublishProfiles/FolderProfile.pubxml.user
new file mode 100644
index 0000000..8f3a47d
--- /dev/null
+++ b/Properties/PublishProfiles/FolderProfile.pubxml.user
@@ -0,0 +1,10 @@
+
+
+
+
+ True|2023-10-16T06:28:28.4099321Z;True|2023-10-16T14:28:04.3437847+08:00;True|2023-10-16T14:26:50.3929900+08:00;False|2023-10-16T14:26:22.6712614+08:00;
+
+
+
\ No newline at end of file
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..de63fbf
--- /dev/null
+++ b/README.md
@@ -0,0 +1,31 @@
+译文批量填CSV表转换工具 by 皓月云 axibug.com
+
+服务于:ReFrontier魔改版本,下 FrontierTextTool 导出工具的译文批量处理
+
+使用方法:
+
+1._TextDictionary.csv
+
+该文件为,原文和译文。在本CSV中填入文本。
+
+程序将读取作为字典之用。
+
+*本表固定文字编码为GB2312
+
+2.Input文件夹中放入 需要处理的文件
+
+如指针|日文 的csv文件
+
+例:mhfdat_01.csv
+
+*使用中不要破坏表列结构,默认即可
+
+*读取本表文字编码固定为shift-jis
+
+3.运行 AutoRranslateTextToCsv.exe
+
+即可输入处理文件到Out文件夹
+
+按照_TextDictionary.csv 替换文本列字段
+
+*输出表文字编码固定为shift-jis
\ No newline at end of file