Kaynağa Gözat

修复windows下 Tools菜单 导Excel跟导proto的错误

tanghai 4 yıl önce
ebeveyn
işleme
a142ad6740

+ 2 - 2
Tools/App/Apps/ExcelExporter/ExcelExporter.cs

@@ -103,11 +103,11 @@ namespace ET
                 ExportExcelProtobuf(ConfigType.c);
                 ExportExcelProtobuf(ConfigType.s);
                 
-                Console.WriteLine("导表成功!");
+                Log.Console("Export Excel Sucess!");
             }
             catch (Exception e)
             {
-                Console.WriteLine(e);
+                Log.Console(e.ToString());
             }
         }
 

+ 21 - 8
Unity/Assets/Editor/Helper/ShellHelper.cs

@@ -1,6 +1,8 @@
 using System;
 using System.Diagnostics;
 using System.Collections.Generic;
+using System.Threading;
+using System.Threading.Tasks;
 
 namespace ET
 {
@@ -42,7 +44,7 @@ namespace ET
                     }
                 }
 
-                start.Arguments += (" \"" + cmd + " \"");
+                start.Arguments += (" \"" + cmd + "\"");
                 start.CreateNoWindow = true;
                 start.ErrorDialog = true;
                 start.UseShellExecute = false;
@@ -63,16 +65,25 @@ namespace ET
                     start.StandardErrorEncoding = System.Text.Encoding.UTF8;
                 }
 
-                p = Process.Start(start);
-                p.ErrorDataReceived += delegate(object sender, DataReceivedEventArgs e) { UnityEngine.Debug.LogError(e.Data); };
-                p.OutputDataReceived += delegate(object sender, DataReceivedEventArgs e) { UnityEngine.Debug.LogError(e.Data); };
-                p.Exited += delegate(object sender, System.EventArgs e) { UnityEngine.Debug.LogError(e.ToString()); };
+                bool isFinish = false;
 
-                bool hasError = false;
+                Barrier barrier = new Barrier(2);
+                
+                // 放到新线程启动进程,主线程循环读标准输出,直到进程结束
+                Task.Run(() =>
+                {
+                    p = Process.Start(start);
+                    barrier.RemoveParticipant();
+                    p.WaitForExit();
+                    isFinish = true;
+                });
+                
+                // 这里要等待进程启动才能往下走,否则p将为null
+                barrier.SignalAndWait();
                 do
                 {
                     string line = p.StandardOutput.ReadLine();
-                    if (line == null)
+                    if (string.IsNullOrEmpty(line))
                     {
                         break;
                     }
@@ -81,8 +92,9 @@ namespace ET
 
                     UnityEngine.Debug.Log(line);
                 }
-                while (true);
+                while (!isFinish);
 
+                bool hasError = false;
                 while (true)
                 {
                     string error = p.StandardError.ReadLine();
@@ -95,6 +107,7 @@ namespace ET
                     UnityEngine.Debug.LogError(error);
                 }
 
+                
                 p.Close();
                 if (hasError)
                 {

+ 4 - 4
Unity/Assets/Editor/ToolEditor/ToolsEditor.cs

@@ -10,9 +10,9 @@ namespace ET
 #if UNITY_EDITOR_OSX
             const string tools = "./Tools";
 #else
-            const string tools = "./Tools.exe";
+            const string tools = ".\\Tools.exe";
 #endif
-            ShellHelper.Run($"{tools} --AppType=ExcelExporter", "../Bin/");
+            ShellHelper.Run($"{tools} --AppType=ExcelExporter --Console=1", "../Bin/");
         }
         
         [MenuItem("Tools/Proto2CS")]
@@ -21,9 +21,9 @@ namespace ET
 #if UNITY_EDITOR_OSX
             const string tools = "./Tools";
 #else
-            const string tools = "./Tools.exe";
+            const string tools = ".\\Tools.exe";
 #endif
-            ShellHelper.Run($"{tools} --AppType=Proto2CS", "../Bin/");
+            ShellHelper.Run($"{tools} --AppType=Proto2CS --Console=1", "../Bin/");
         }
     }
 }