Program.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. using System;
  2. using System.Diagnostics;
  3. using System.IO;
  4. namespace ResBuilder
  5. {
  6. class Program
  7. {
  8. const string luaFileRoot = @"UIEdit\res\ui_edit\lua";
  9. const string defLuaJitExePath = @"luajit\luajit.exe";
  10. const string uiConvertBinExe = @"UIEdit\2binnp.bat";
  11. const string uiRoot = @"UIEdit\res";
  12. const string uiXmlFileRootRelative = @"ui_edit\xmds_ui";
  13. const string uiResFileRootRelative = @"ui_edit\res";
  14. const string editorDataRoot = @"../data";
  15. static void Main(string[] args)
  16. {
  17. var root = "./";//Tools.FindUpDirectory("GameEditors", 10);
  18. if (string.IsNullOrEmpty(root))
  19. {
  20. Console.WriteLine("error:找不到GameEditors目录!");
  21. Console.ReadKey();
  22. return;
  23. }
  24. var outPath = Path.Combine(root, "resBuilder/out/bin");
  25. var tmpPath = Path.Combine(root, "resBuilder/tmp");
  26. if (Directory.Exists(outPath))
  27. {
  28. Directory.Delete(outPath, true);
  29. }
  30. Directory.CreateDirectory(outPath);
  31. try
  32. {
  33. foreach (var argv in args)
  34. {
  35. Program.SetConfig(argv.Trim());
  36. }
  37. // lua
  38. if (IsDoLua)
  39. {
  40. var luaSrcRoot = Path.Combine(root, luaFileRoot);
  41. var luaProcessedRoot = Path.Combine(outPath, "scr");
  42. var luaJitExePath = Path.Combine(root, defLuaJitExePath);
  43. Console.WriteLine("start -> process lua...");
  44. var luaProc = new LuaProcessor(luaSrcRoot, luaProcessedRoot, tmpPath, luaJitExePath);
  45. luaProc.Execute();
  46. Console.WriteLine(" end -> process lua...");
  47. if (IsPackLuaBin)
  48. {
  49. Console.WriteLine("start -> pack lua...");
  50. var luaBinPacker = new LuaBinPacker(luaProcessedRoot, outPath);
  51. luaBinPacker.Pack();
  52. Directory.Delete(luaProcessedRoot, true);
  53. Console.WriteLine(" end -> pack lua...");
  54. }
  55. }
  56. // gamedata
  57. if (IsDoGameData)
  58. {
  59. Console.WriteLine("start -> pack editor ...");
  60. var editPacker = new EditorBinPacker(
  61. Path.Combine(root, editorDataRoot),
  62. outPath);
  63. editPacker.Pack();
  64. Console.WriteLine(" end -> pack editor data ...");
  65. }
  66. // ui convert bin
  67. if (IsUIConvertBin)
  68. {
  69. Console.WriteLine("start -> ui convert bin ...");
  70. StartProcess(Path.Combine(root, uiConvertBinExe));
  71. Console.WriteLine(" end -> ui convert bin ...");
  72. }
  73. // ui xml
  74. if (IsPackUIXml )
  75. {
  76. Console.WriteLine("start -> pack ui xml...");
  77. var uiXmlPacker = new UIXmlPacker(
  78. Path.Combine(root, uiRoot, uiXmlFileRootRelative),
  79. outPath, true);
  80. uiXmlPacker.Pack();
  81. Console.WriteLine(" end -> pack ui xml...");
  82. }
  83. // ui res
  84. if (IsDoUIRes)
  85. {
  86. var uiResOutPath = Path.Combine(root, "resBuilder/out");
  87. Console.WriteLine("start -> process ui res...");
  88. var urProc = new UIResProcessor(Path.Combine(root , uiRoot), uiResOutPath , uiResFileRootRelative);
  89. urProc.Execute();
  90. Console.WriteLine(" end -> process ui res...");
  91. if (IsPackUiRes)
  92. {
  93. //Console.WriteLine("start -> pack ui res...");
  94. //var uiResPacker = new UIResPacker(
  95. // Path.Combine(root, uiResFileRoot),
  96. // uiResOutPath);
  97. //uiResPacker.Pack();
  98. //Console.WriteLine(" end -> pack ui res...");
  99. }
  100. }
  101. }
  102. catch (Exception e)
  103. {
  104. var color = Console.ForegroundColor;
  105. Console.ForegroundColor = ConsoleColor.Red;
  106. Console.WriteLine(e.Message);
  107. Console.WriteLine(e.StackTrace);
  108. Console.ForegroundColor = color;
  109. }
  110. if (IsPauseOnFinish)
  111. {
  112. Console.WriteLine("press any key to exit!");
  113. Console.ReadKey();
  114. }
  115. }
  116. public static bool IsPauseOnFinish = true;
  117. public static bool IsDoLua = false;
  118. public static bool IsJitLuaBytes = false;
  119. public static bool IsZipLuaBytes = false;
  120. public static bool IsPackLuaBin = false;
  121. public static bool IsDoGameData = true;
  122. public static bool IsPackUIXml = false;
  123. public static bool IsUIConvertBin = false;
  124. public static bool IsDoUIRes = false;
  125. public static bool IsPackUiRes = false;
  126. static void SetConfig(string arg)
  127. {
  128. if (arg.Equals("-!lua", StringComparison.OrdinalIgnoreCase))
  129. {
  130. IsDoLua = false;
  131. }
  132. else if (arg.Equals("-luajit", StringComparison.OrdinalIgnoreCase))
  133. {
  134. IsJitLuaBytes = true;
  135. }
  136. else if (arg.Equals("-luazip", StringComparison.OrdinalIgnoreCase))
  137. {
  138. IsZipLuaBytes = true;
  139. }
  140. else if (arg.Equals("-luapack", StringComparison.OrdinalIgnoreCase))
  141. {
  142. IsPackLuaBin = true;
  143. }
  144. else if (arg.Equals("-!gamedata", StringComparison.OrdinalIgnoreCase))
  145. {
  146. IsDoGameData = false;
  147. }
  148. else if (arg.Equals("-uixmlpack", StringComparison.OrdinalIgnoreCase))
  149. {
  150. IsPackUIXml = true;
  151. }
  152. else if (arg.Equals("-!uiconvertbin", StringComparison.OrdinalIgnoreCase))
  153. {
  154. IsUIConvertBin = false;
  155. }
  156. else if (arg.Equals("-!uires", StringComparison.OrdinalIgnoreCase))
  157. {
  158. IsDoUIRes = false;
  159. }
  160. else if (arg.Equals("-uirespack", StringComparison.OrdinalIgnoreCase))
  161. {
  162. IsPackUiRes = true;
  163. }
  164. else if (arg.Equals("-np", StringComparison.OrdinalIgnoreCase))
  165. {
  166. IsPauseOnFinish = false;
  167. }
  168. }
  169. public static void StartProcess(string luajitPath, string args = null)
  170. {
  171. var start = new ProcessStartInfo(luajitPath);
  172. start.WorkingDirectory = Path.GetDirectoryName(luajitPath);
  173. start.CreateNoWindow = false;
  174. start.UseShellExecute = false;
  175. start.RedirectStandardInput = false;
  176. start.RedirectStandardOutput = false;
  177. if (args != null)
  178. {
  179. start.Arguments = args;
  180. }
  181. var pro = Process.Start(start);
  182. pro.WaitForExit();
  183. }
  184. }
  185. }