CsvToLua.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using System.IO;
  5. using UnityEditor;
  6. using System.Text;
  7. using System;
  8. using Game.Config;
  9. using RO.Editor;
  10. using LuaInterface;
  11. using System.Linq;
  12. using System.Text.RegularExpressions;
  13. public class CfgLanguageCfg : GameData<CfgLanguageCfg>
  14. {
  15. public string CfgName;
  16. public string Field;
  17. public string CfgID;
  18. public int CfgType;
  19. public int Enable;
  20. public CfgLanguageCfg()
  21. {
  22. CfgName = "";
  23. Field = "";
  24. CfgID = "";
  25. CfgType = 0;
  26. Enable = 0;
  27. }
  28. public static void OnCsvLoad(CsvReader csvReader)
  29. {
  30. CfgLanguageCfg.Onload(csvReader);
  31. }
  32. public static string FileName_S()
  33. {
  34. return "";
  35. }
  36. }
  37. public class LanguageCfg : GameData<LanguageCfg>
  38. {
  39. public string key;
  40. public string Language;
  41. public LanguageCfg()
  42. {
  43. key = "";
  44. Language = "";
  45. }
  46. public static void OnCsvLoad(CsvReader csvReader)
  47. {
  48. LanguageCfg.Onload(csvReader);
  49. }
  50. public static string FileName_S()
  51. {
  52. return "";
  53. }
  54. }
  55. public class CsvToLua : EditorWindow
  56. {
  57. public static string CSV_PATH = "csv path";
  58. public static string LUA_PATH = "lua path";
  59. public static string START_LINE = "start line";
  60. public string tableDirectoryName;
  61. public string luaDirectoryName;
  62. public int startDataLine = 1;
  63. public static bool IsObj;
  64. [MenuItem("Tools/CsvToLua")]
  65. static void Init()
  66. {
  67. CsvToLua window = (CsvToLua)GetWindow(typeof(CsvToLua));
  68. window.Show();
  69. }
  70. void OnEnable()
  71. {
  72. tableDirectoryName = EditorPrefs.GetString(CSV_PATH);
  73. luaDirectoryName = EditorPrefs.GetString(LUA_PATH);
  74. startDataLine = EditorPrefs.GetInt(START_LINE);
  75. }
  76. void OnDisable()
  77. {
  78. EditorPrefs.SetString(CSV_PATH, tableDirectoryName);
  79. EditorPrefs.SetString(LUA_PATH, luaDirectoryName);
  80. EditorPrefs.SetInt(START_LINE, startDataLine);
  81. }
  82. private void OnGUI()
  83. {
  84. GUILayout.Label("Base Settings", EditorStyles.boldLabel);
  85. EditorGUILayout.BeginHorizontal();
  86. tableDirectoryName = EditorGUILayout.TextField("TableDirectory Name", tableDirectoryName);
  87. if (GUILayout.Button("选择csv路径", GUILayout.Width(200)))
  88. {
  89. tableDirectoryName = GetFilePath();
  90. }
  91. EditorGUILayout.EndHorizontal();
  92. EditorGUILayout.BeginHorizontal();
  93. luaDirectoryName = EditorGUILayout.TextField("LuaDirectory Name", luaDirectoryName);
  94. if (GUILayout.Button("选择到处table路径", GUILayout.Width(200)))
  95. {
  96. luaDirectoryName = GetFilePath();
  97. }
  98. EditorGUILayout.EndHorizontal();
  99. startDataLine = EditorGUILayout.IntField("StartDataLine", startDataLine);
  100. if (GUILayout.Button("CsvToLua"))
  101. Change();
  102. if (GUILayout.Button("测试"))
  103. {
  104. string lua = @"local aaa =
  105. {
  106. [1] =
  107. {
  108. ['a'] = 1,
  109. ['b'] = '2',
  110. ['c'] = 'asd' ,
  111. ['d'] = {1,2,3,{{1,2},{3,4},{1.2,0},{0}}},
  112. ['aId'] = 1,
  113. } ,
  114. }
  115. return aaa";
  116. using (LuaState runTime = new LuaState())
  117. {
  118. runTime.Start();
  119. //LuaState runTime = LuaClient.Instance.luaState;
  120. runTime.DoFile("Assets\\Editor\\CsvToLua\\table-save.lua");
  121. LuaTable luaTable = runTime.DoString<LuaTable>(lua);
  122. RolePreviewWindow.SaveToLua(runTime, "aaa.lua", luaTable, "AAA","");
  123. }
  124. }
  125. if (GUILayout.Button("检查"))
  126. {
  127. CheckCgf();
  128. }
  129. IsObj = GUILayout.Toggle(IsObj,"运行时启动");
  130. if (GUILayout.Button("更改CardCfg"))
  131. {
  132. ChangeLuaCfg("Assets/Lua/Config/CardCfg.lua", "Assets\\Editor\\CsvToLua\\LuaCfg.lua", "Build/NewCfg/CardCfg.lua");
  133. }
  134. if (GUILayout.Button("合并Language"))
  135. {
  136. MergeLanauage("Assets/Content/Config/LanguagePackage_cn.csv", "Build/NewCfg/ROLanguagePackage_cn.csv", "Build/NewCfg/Language_merge.csv");
  137. }
  138. if (GUILayout.Button("二进制转换"))
  139. {
  140. B2T("D:/项目/其他/Language15000-19000.csv", "D:/项目/其他/111.csv",Encoding.UTF8);
  141. }
  142. }
  143. public static string GetFilePath()
  144. {
  145. OpenDialogDir ofn2 = new OpenDialogDir();
  146. ofn2.pszDisplayName = new string(new char[2000]); ; // 存放目录路径缓冲区
  147. ofn2.lpszTitle = "Open Project";// 标题
  148. //ofn2.ulFlags = BIF_NEWDIALOGSTYLE | BIF_EDITBOX; // 新的样式,带编辑框
  149. IntPtr pidlPtr = DllOpenFileDialog.SHBrowseForFolder(ofn2);
  150. char[] charArray = new char[2000];
  151. for (int i = 0; i < 2000; i++)
  152. charArray[i] = '\0';
  153. DllOpenFileDialog.SHGetPathFromIDList(pidlPtr, charArray);
  154. string fullDirPath = new String(charArray);
  155. fullDirPath = fullDirPath.Substring(0, fullDirPath.IndexOf('\0'));
  156. return fullDirPath;
  157. }
  158. public void Change()
  159. {
  160. Debug.Log(tableDirectoryName);
  161. foreach (var item in Directory.GetFiles(tableDirectoryName))
  162. {
  163. if (item.Contains(".meta"))
  164. continue;
  165. CreatLuaTable(item);
  166. }
  167. }
  168. void CreatLuaTable(string filePath)
  169. {
  170. CreatDirectory();
  171. Save(GetSavePath(filePath), GetSaveContext(filePath));
  172. }
  173. void CreatDirectory()
  174. {
  175. string path = luaDirectoryName;
  176. if (!Directory.Exists(path))
  177. {
  178. Directory.CreateDirectory(path);
  179. AssetDatabase.Refresh();
  180. }
  181. }
  182. string GetSavePath(string filePath)
  183. {
  184. string fileName = GetFileName(filePath);
  185. return luaDirectoryName + "/" + fileName + ".lua";
  186. }
  187. string GetFileName(string filePath)
  188. {
  189. string targetPath = filePath.Replace(@"\", "/");
  190. string[] strs = targetPath.Split('/');
  191. targetPath = strs[strs.Length - 1];
  192. strs = targetPath.Split('.');
  193. string fileName = strs[0];
  194. return fileName;
  195. }
  196. string GetSaveContext(string filePath)
  197. {
  198. string fileName = GetFileName(filePath);
  199. List<string> context = GetContext(filePath);
  200. string[] propertyName = GetPropertyName(context[1]);
  201. string[] typeName = GetPropertyName(context[2]);
  202. StringBuilder sb = new StringBuilder();
  203. sb.Append("local " + fileName + " = {" + "\n");
  204. for (int i = startDataLine; i < context.Count; i++)
  205. {
  206. context[i] = context[i].Replace(" ", "");
  207. string[] details = context[i].Split(',');
  208. sb.Append("[" + details[0] + "]={" + "\n");
  209. for (int j = 0; j < propertyName.Length; j++)
  210. {
  211. sb.Append("['" + propertyName[j] + "']=");
  212. if (typeName[j].Equals("string"))
  213. sb.Append("'" + details[j] + "'," + "\n");
  214. else if (typeName[j].Equals("bool"))
  215. {
  216. sb.Append(details[j].ToLower() + "," + "\n");
  217. }
  218. else if (typeName[j].Equals("list"))
  219. {
  220. if (details[j].IndexOf(';') > 0)
  221. {
  222. ParseTable(sb, details[j], ';');
  223. }
  224. else if (details[j].IndexOf(':') > 0 && details[j].IndexOf(';') < 0)
  225. {
  226. sb.Append("{");
  227. ParseTable(sb, details[j], ':');
  228. sb.Append("}");
  229. }
  230. else
  231. {
  232. sb.Append("{");
  233. try
  234. {
  235. if (details[j].IndexOf('.') > 0)
  236. {
  237. Convert.ToDouble(details[j]);
  238. }
  239. else
  240. {
  241. Convert.ToInt32(details[j]);
  242. }
  243. sb.Append(details[j]);
  244. }
  245. catch
  246. {
  247. if (!string.IsNullOrEmpty(details[j]))
  248. sb.Append("'" + details[j] + "'");
  249. }
  250. sb.Append("}");
  251. }
  252. sb.Append(",\n");
  253. }
  254. else if (typeName[j].Equals("enum"))
  255. {
  256. sb.Append("Enum." + propertyName[j] + "." + details[j] + "," + "\n");
  257. }
  258. else
  259. {
  260. string num = "0";
  261. if (details[j] != "")
  262. {
  263. num = details[j];
  264. }
  265. sb.Append(num + "," + "\n");
  266. }
  267. }
  268. sb.Append("}," + "\n");
  269. }
  270. sb.Append("}" + "\n");
  271. sb.Append("return " + fileName);
  272. return sb.ToString();
  273. }
  274. void ParseTable(StringBuilder sb, string content, char split)
  275. {
  276. string[] strs = content.Split(split);
  277. sb.Append("{");
  278. for (int m = 0; m < strs.Length; ++m)
  279. {
  280. try
  281. {
  282. if (strs[m].IndexOf(':') > 0)
  283. {
  284. ParseTable(sb, strs[m], ':');
  285. }
  286. else
  287. {
  288. if (strs[m].IndexOf('.') > 0)
  289. {
  290. Convert.ToDouble(strs[m]);
  291. }
  292. else
  293. {
  294. Convert.ToInt32(strs[m]);
  295. }
  296. sb.Append(strs[m]);
  297. }
  298. }
  299. catch
  300. {
  301. if (!string.IsNullOrEmpty(strs[m]))
  302. sb.Append("'" + strs[m] + "'");
  303. }
  304. if (m < strs.Length - 1)
  305. {
  306. sb.Append(",");
  307. }
  308. }
  309. sb.Append("}");
  310. }
  311. List<string> GetContext(string filePath)
  312. {
  313. StreamReader sr = new StreamReader(filePath);
  314. List<string> contexts = new List<string>();
  315. string line;
  316. while ((line = sr.ReadLine()) != null)
  317. contexts.Add(line);
  318. return contexts;
  319. }
  320. string[] GetPropertyName(string line)
  321. {
  322. string[] names = line.Split(',');
  323. return names;
  324. }
  325. void Save(string path, string information)
  326. {
  327. if (File.Exists(path))
  328. File.Delete(path);
  329. FileStream aFile = new FileStream(@"" + path, FileMode.OpenOrCreate, FileAccess.ReadWrite);
  330. StreamWriter sw = new StreamWriter(aFile);
  331. sw.Write(information);
  332. sw.Close();
  333. sw.Dispose();
  334. aFile.Close();
  335. aFile.Dispose();
  336. sw = null;
  337. aFile = null;
  338. AssetDatabase.Refresh();
  339. }
  340. public static Dictionary<string, List<CfgLanguageCfg>> GetCfgLanguageCfg(string path)
  341. {
  342. Dictionary<string, List<CfgLanguageCfg>> ret = new Dictionary<string, List<CfgLanguageCfg>>();
  343. TextAsset ta = AssetDatabase.LoadAssetAtPath<TextAsset>(path);
  344. CsvReader csvReader = new CsvReader(CfgLanguageCfg.FileName_S(), ta.bytes);
  345. CfgLanguageCfg.OnCsvLoad(csvReader);
  346. CfgLanguageCfg.Foreach(it =>
  347. {
  348. if (ret.ContainsKey(it.CfgName))
  349. {
  350. ret[it.CfgName].Add(it);
  351. }
  352. else
  353. {
  354. List<CfgLanguageCfg> cfgs = new List<CfgLanguageCfg>();
  355. cfgs.Add(it);
  356. ret.Add(it.CfgName,cfgs);
  357. }
  358. //Debug.Log(it.BaseName);
  359. });
  360. CfgLanguageCfg.Clear();
  361. return ret;
  362. }
  363. public static Dictionary<string, LanguageCfg> GetLanguageCfg(string path)
  364. {
  365. Dictionary<string, LanguageCfg> ret = new Dictionary<string, LanguageCfg>();
  366. TextAsset ta = AssetDatabase.LoadAssetAtPath<TextAsset>(path);
  367. CsvReader csvReader = new CsvReader(LanguageCfg.FileName_S(), ta.bytes,1,2,3);
  368. LanguageCfg.OnCsvLoad(csvReader);
  369. LanguageCfg.Foreach(it =>
  370. {
  371. if (!ret.ContainsKey(it.key))
  372. {
  373. ret.Add(it.key, it);
  374. }
  375. else
  376. {
  377. ret.Add(it.key+ret.Count,it);
  378. Debug.Log("重复项:" + it.key);
  379. }
  380. //Debug.Log(it.BaseName);
  381. });
  382. LanguageCfg.Clear(false);
  383. return ret;
  384. }
  385. public static void CheckCgf()
  386. {
  387. string luaPath = "Assets/Lua/Config/";
  388. string csvPath = "Assets/Content/Config/";
  389. string OutPutPath = "Build/NewCfg/";
  390. Dictionary<string, List<CfgLanguageCfg>> cfgs = GetCfgLanguageCfg("Assets/Editor/CsvToLua/CfgLanguageCfg.csv");
  391. Dictionary<string, LanguageCfg> language = GetLanguageCfg("Assets/Content/Config/LanguagePackage_cn.csv");
  392. float ckcount = 0;
  393. foreach (var item in cfgs)
  394. {
  395. ckcount+=1;
  396. List<CfgLanguageCfg> value = item.Value;
  397. EditorUtility.DisplayProgressBar("检测配置中", $"检测:{item.Key}...", ckcount/cfgs.Count);
  398. string cfgPath = "";
  399. if (value[0].CfgType == 1)
  400. {
  401. cfgPath = luaPath + item.Key + ".lua";
  402. CheckLauCfg_CS(value,cfgPath,language, $"{OutPutPath}lua/{value[0].CfgName}.lua");
  403. }
  404. else
  405. {
  406. cfgPath = csvPath + item.Key + ".csv";
  407. CheckCsvCfg(value, cfgPath, language, $"{OutPutPath}csv/{value[0].CfgName}.csv");
  408. }
  409. }
  410. EditorUtility.ClearProgressBar();
  411. CsvWriter<LanguageCfg> csvWriter = new CsvWriter<LanguageCfg>(OutPutPath+ "Language.csv", "Language.csv",language.Values.ToList(), LanguageCfg.GetFormatInfo());
  412. csvWriter.Write();
  413. }
  414. private static void CheckLauCfg(List<CfgLanguageCfg> cfg,string path, Dictionary<string, LanguageCfg> language,string outputPath)
  415. {
  416. using (LuaState runTime = new LuaState())
  417. {
  418. runTime.Start();
  419. RolePreviewWindow.LuaForEach<int, LuaTable>(runTime, path, (id,luatable) =>
  420. {
  421. for (int i = 0; i < cfg.Count; i++)
  422. {
  423. if (cfg[i].Enable == 0)
  424. continue;
  425. string value = luatable.RawGet<string, string>(cfg[i].Field);
  426. if (string.IsNullOrEmpty(value))
  427. {
  428. continue;
  429. }
  430. KeyValuePair<string,LanguageCfg> valuePair = language.FirstOrDefault(it =>
  431. {
  432. return string.Equals(it.Value.Language, value);
  433. });
  434. if (!string.IsNullOrEmpty(valuePair.Key))
  435. {
  436. luatable.RawSet<string, string>(cfg[i].Field, valuePair.Key);
  437. }
  438. else
  439. {
  440. string key = cfg[i].CfgID + id;
  441. luatable.RawSet<string, string>(cfg[i].Field, key);
  442. if (value.Contains("\n"))
  443. {
  444. Debug.Log(value);
  445. value = value.Replace("\n","\\n");
  446. Debug.Log(value);
  447. }
  448. language.Add(key,new LanguageCfg() { key = key,Language = value});
  449. }
  450. }
  451. },(ltab)=>
  452. {
  453. bool useObj = IsObj;
  454. if (useObj)
  455. {
  456. LuaState luaState = LuaClient.Instance.luaState;
  457. luaState.DoFile("Assets\\Editor\\CsvToLua\\table-save.lua");
  458. RolePreviewWindow.SaveToLua(luaState, outputPath, ltab, cfg[0].CfgName, "1");
  459. }
  460. else
  461. {
  462. LuaState luaState = runTime;
  463. luaState.DoFile("Assets\\Editor\\CsvToLua\\table-save.lua");
  464. RolePreviewWindow.SaveToLua(luaState, outputPath, ltab, cfg[0].CfgName, "");
  465. }
  466. });
  467. }
  468. }
  469. private static void SetLuaLine(string[] rowDatas,int id,string key,string data,string dataF = "'{0}',")
  470. {
  471. string idkey = $"[{id}]";
  472. string keykey = $"'{key}'";
  473. string wdata = string.Format(dataF,data);//$"'{data}',";
  474. bool isFind = false;
  475. for (int line = 0; line < rowDatas.Length; line++)
  476. {
  477. if (rowDatas[line].Trim().IndexOf("--") == 0)
  478. {
  479. Debug.Log("注释跳过");
  480. }
  481. if (rowDatas[line].Contains(idkey))
  482. {
  483. isFind = true;
  484. }
  485. if (isFind && rowDatas[line].Contains(keykey))
  486. {
  487. int s = rowDatas[line].IndexOf('[');
  488. string p = "";
  489. if (s > 0)
  490. {
  491. for (int i = 0; i < s; i++)
  492. {
  493. p += " ";
  494. }
  495. }
  496. string newstr = $"{p}[{keykey}]={wdata}" ;
  497. rowDatas[line] = newstr;
  498. break;
  499. }
  500. }
  501. }
  502. private static void CheckLauCfg_CS(List<CfgLanguageCfg> cfg, string path, Dictionary<string, LanguageCfg> language, string outputPath)
  503. {
  504. string[] rowDatas = File.ReadAllLines(path);
  505. bool iswrite = true;
  506. using (LuaState runTime = new LuaState())
  507. {
  508. runTime.Start();
  509. RolePreviewWindow.LuaForEach<int, LuaTable>(runTime, path, (id, luatable) =>
  510. {
  511. for (int i = 0; i < cfg.Count; i++)
  512. {
  513. if (cfg[i].Enable == 0)
  514. {
  515. iswrite = false;
  516. continue;
  517. }
  518. string value = luatable.RawGet<string, string>(cfg[i].Field);
  519. if (string.IsNullOrEmpty(value))
  520. {
  521. continue;
  522. }
  523. KeyValuePair<string, LanguageCfg> valuePair = language.FirstOrDefault(it =>
  524. {
  525. return string.Equals(it.Value.Language, value);
  526. });
  527. if (!string.IsNullOrEmpty(valuePair.Key))
  528. {
  529. luatable.RawSet<string, string>(cfg[i].Field, valuePair.Key);
  530. SetLuaLine(rowDatas,id, cfg[i].Field, valuePair.Key);
  531. }
  532. else
  533. {
  534. string key = cfg[i].CfgID + id;
  535. luatable.RawSet<string, string>(cfg[i].Field, key);
  536. SetLuaLine(rowDatas, id, cfg[i].Field, key);
  537. if (value.Contains("\n"))
  538. {
  539. //Debug.Log(value);
  540. value = value.Replace("\n", "\\n");
  541. //Debug.Log(value);
  542. }
  543. if(!language.ContainsKey(key))
  544. language.Add(key, new LanguageCfg() { key = key, Language = value });
  545. }
  546. }
  547. });
  548. }
  549. if (iswrite)
  550. File.WriteAllLines(outputPath,rowDatas);
  551. }
  552. private static void CheckCsvCfg(List<CfgLanguageCfg> cfg, string path, Dictionary<string, LanguageCfg> language, string outputPath)
  553. {
  554. CsvReader csvReader = new CsvReader(path,1,2,3);
  555. string[][] datas = csvReader.RowDatas;
  556. for (int i = csvReader.StartLine; i < datas.Length; i++)
  557. {
  558. string[] curLine = datas[i];
  559. for (int j = 0; j < cfg.Count; j++)
  560. {
  561. if (cfg[j].Enable == 0)
  562. continue;
  563. string value = csvReader.GetDataByFieldName(cfg[j].Field,i);
  564. if (string.IsNullOrEmpty(value))
  565. {
  566. continue;
  567. }
  568. KeyValuePair<string, LanguageCfg> valuePair = language.FirstOrDefault(it =>
  569. {
  570. return string.Equals(it.Value.Language, value);
  571. });
  572. if (!string.IsNullOrEmpty(valuePair.Key))
  573. {
  574. csvReader.SetDataByFieldName(cfg[j].Field, valuePair.Key, i);
  575. }
  576. else
  577. {
  578. string key = cfg[j].CfgID + i;
  579. csvReader.SetDataByFieldName(cfg[j].Field, key,i);
  580. language.Add(key, new LanguageCfg() { key = key, Language = value });
  581. }
  582. }
  583. }
  584. FileHelper.WirteStringToFile(outputPath,csvReader.GetString());
  585. }
  586. private static void ChangeLuaCfg(string luacfgpath,string luachagepath,string outputPath)
  587. {
  588. string[] rowDatas = File.ReadAllLines(luacfgpath);
  589. using (LuaState runTime = new LuaState())
  590. {
  591. runTime.Start();
  592. LuaTable luaTable = runTime.DoFile<LuaTable>(luachagepath);
  593. RolePreviewWindow.LuaForEach<int, LuaTable>(runTime, luacfgpath, (id, luatable) =>
  594. {
  595. LuaFunction luaFunction = luaTable.GetLuaFunction("IsChangefg");
  596. bool ischange = luaFunction.Invoke<LuaTable,LuaTable, bool>(luaTable,luatable);
  597. if (ischange)
  598. {
  599. LuaTable fieldValue = luaTable.Invoke<LuaTable,LuaTable>("GetFieldAddValue", luaTable);
  600. string field = fieldValue.RawGet<string, string>("field");
  601. string value = fieldValue.RawGet<string, string>("value");
  602. SetLuaLine(rowDatas,id,field,value.ToString(),"{0},");
  603. }
  604. });
  605. }
  606. File.WriteAllLines(outputPath, rowDatas);
  607. }
  608. struct lgInfo
  609. {
  610. public int index;
  611. public int off;
  612. }
  613. private static void MergeLanauage(string oldPath,string newPath, string outputPath)
  614. {
  615. List<string> oldLg = File.ReadAllLines(oldPath).ToList();
  616. List<string> newLg = File.ReadAllLines(newPath).ToList();
  617. Dictionary<string, lgInfo> cfgmap = new Dictionary<string, lgInfo>();
  618. int length = oldLg.Count;
  619. int off = -1;
  620. for (int i = 0; i < length; i++)
  621. {
  622. off = oldLg[i].IndexOf(',');
  623. if (off < 0)
  624. {
  625. continue;
  626. }
  627. string key = oldLg[i].Substring(0,off);
  628. if (!cfgmap.ContainsKey(key))
  629. {
  630. lgInfo info = new lgInfo();
  631. info.index = i;
  632. info.off = off;
  633. cfgmap.Add(key, info);
  634. }
  635. }
  636. foreach (var item in newLg)
  637. {
  638. if (item == "" || item == ","||item == "key"||item == "string")
  639. continue;
  640. off = item.IndexOf(',');
  641. if (off < 0)
  642. {
  643. continue;
  644. }
  645. string key = item.Substring(0,off);
  646. if (!cfgmap.ContainsKey(key))
  647. {
  648. oldLg.Add(item);
  649. }
  650. else
  651. {
  652. lgInfo lgIf = cfgmap[key];
  653. oldLg[lgIf.index] = item;
  654. }
  655. }
  656. string data = FileHelper.CatStringArray(oldLg);
  657. FileHelper.WirteStringToFile(outputPath, data);
  658. }
  659. private void B2T(string bPath,string outPath, Encoding read)
  660. {
  661. using (FileStream binaryFileStream = new FileStream(bPath, FileMode.Open, FileAccess.Read))
  662. using (StreamReader reader = new StreamReader(binaryFileStream, read)) // 使用ASCII编码读取
  663. using (StreamWriter writer = new StreamWriter(outPath))
  664. {
  665. writer.Write(reader.ReadToEnd()); // 读取并写入文本文件
  666. }
  667. }
  668. }