瀏覽代碼

优化一下依赖包下载

tanghai 1 年之前
父節點
當前提交
fe2dd9996a

+ 11 - 26
Packages/cn.etetet.init/Editor/GitDependencyResolver/DependencyResolver.cs

@@ -27,9 +27,9 @@ namespace Hibzz.DependencyResolver
         static void MoveToPackage()
         {
 #if UNITY_EDITOR_WIN
-            ProcessHelper.Run("powershell.exe", $"-NoExit -ExecutionPolicy Bypass -File \"Scripts/MoveToPackages.ps1\"");
+            ProcessHelper.Run("powershell.exe", $"-NoExit -ExecutionPolicy Bypass -File \"Scripts/MoveToPackages.ps1\"", waitExit: true);
 #else
-            ProcessHelper.Run("pwsh", $"-NoExit -ExecutionPolicy Bypass -File \"Scripts/MoveToPackages.ps1\"");
+            ProcessHelper.Run("pwsh", $"-NoExit -ExecutionPolicy Bypass -File \"Scripts/MoveToPackages.ps1\"", waitExit: true);
 #endif
         }
         
@@ -72,9 +72,10 @@ namespace Hibzz.DependencyResolver
                     dependencies[gitDependency.Key] = gitDependency.Value;
                 }
             }
-            
-            Debug.Log($"Packages Dependency: {string.Join(" ", dependencies.Keys)}");
-            
+
+            MoveToPackage();
+            AssetDatabase.Refresh();
+
             // Install the dependencies
             InstallDependencies(dependencies);
         }
@@ -153,16 +154,7 @@ namespace Hibzz.DependencyResolver
             // the dependencies to install are... additionally, check if the
             // application is being run on batch mode so that we can skip the
             // installation dialog
-            if (!Application.isBatchMode &&
-                !EditorUtility.DisplayDialog(
-                    $"Dependency Resolver",
-                    $"The following dependencies are required:\n{string.Join("\n", dependencies.Keys)}",
-                    "Install Dependencies",
-                    "Cancel"))
-            {
-                // user decided to cancel the installation of the dependencies...
-                return;
-            }
+            Debug.Log($"The following dependencies are required:\n{string.Join("\n", dependencies.Keys)}");
 
             // the user pressed install, perform the actual installation
             // (or the application was in batch mode)
@@ -191,6 +183,10 @@ namespace Hibzz.DependencyResolver
         [MenuItem("ET/RepairDependencies")]
         static void RepairDependencies()
         {
+            AssetDatabase.Refresh();
+            MoveToPackage();
+            AssetDatabase.Refresh();
+            
             Dictionary<string, string> dependencies = new();
             List<PackageInfo> installedPackages = PackageInfo.GetAllRegisteredPackages().ToList();
             
@@ -218,17 +214,6 @@ namespace Hibzz.DependencyResolver
                 return;
             }
             
-            if (!Application.isBatchMode &&
-                !EditorUtility.DisplayDialog(
-                    $"Dependency Resolver",
-                    $"The following dependencies are required:\n{string.Join("\n", dependencies.Keys)}",
-                    "Install Dependencies",
-                    "Cancel"))
-            {
-                // user decided to cancel the installation of the dependencies...
-                return;
-            }
-            
             InstallDependencies(dependencies);
         }
     }

+ 1 - 51
Packages/cn.etetet.init/Editor/GitDependencyResolver/ProcessHelper.cs

@@ -40,7 +40,7 @@ namespace ET
 
                 if (waitExit)
                 {
-                    WaitExitAsync(process);
+                    process.WaitForExit();
                 }
 
                 return process;
@@ -50,55 +50,5 @@ namespace ET
                 throw new Exception($"dir: {Path.GetFullPath(workingDirectory)}, command: {exe} {arguments}", e);
             }
         }
-        
-        private static async Task WaitExitAsync(System.Diagnostics.Process process)
-        {
-            await process.WaitForExitAsync();
-#if UNITY
-            Debug.Log($"process exit, exitcode: {process.ExitCode} {process.StandardOutput.ReadToEnd()} {process.StandardError.ReadToEnd()}");
-#endif
-        }
-        
-#if UNITY
-        private static async Task WaitForExitAsync(this System.Diagnostics.Process self)
-        {
-            if (!self.HasExited)
-            {
-                return;
-            }
-
-            try
-            {
-                self.EnableRaisingEvents = true;
-            }
-            catch (InvalidOperationException)
-            {
-                if (self.HasExited)
-                {
-                    return;
-                }
-                throw;
-            }
-
-            var tcs = new TaskCompletionSource<bool>();
-
-            void Handler(object s, EventArgs e) => tcs.TrySetResult(true);
-            
-            self.Exited += Handler;
-
-            try
-            {
-                if (self.HasExited)
-                {
-                    return;
-                }
-                await tcs.Task;
-            }
-            finally
-            {
-                self.Exited -= Handler;
-            }
-        }
-#endif
     }
 }