From 9429055a12fb941cb68c49d811e0ee9c9ac59ff9 Mon Sep 17 00:00:00 2001 From: deguet Date: Thu, 17 Oct 2024 12:33:17 -0400 Subject: [PATCH] Fix pour npm --- scriptsharp/ScriptSharp/Program.cs | 5 +- scriptsharp/ScriptSharp/Utils/Utils.cs | 48 +++++++++++-------- scriptsharp/ScriptSharp/Utils/UtilsFlutter.cs | 6 --- 3 files changed, 30 insertions(+), 29 deletions(-) diff --git a/scriptsharp/ScriptSharp/Program.cs b/scriptsharp/ScriptSharp/Program.cs index a18e061..8849b15 100644 --- a/scriptsharp/ScriptSharp/Program.cs +++ b/scriptsharp/ScriptSharp/Program.cs @@ -49,6 +49,8 @@ static class Program private static async Task Main() { + //LogSingleton.Get.LogAndWriteLine("yo"); + //TestDebug(); Directory.SetCurrentDirectory(Environment.GetFolderPath(Environment.SpecialFolder.Desktop)); //clear the log file LogSingleton.Get.LogAndWriteLine("Bienvenue dans l'installeur pour les cours de mobile"); @@ -115,8 +117,7 @@ private static async Task Main() private static void TestDebug() { - Utils.CreateDesktopShortcut("gna", "C:\\Program Files\\7-Zip\\7z.exe"); - Utils.CreateDesktopShortcut("gni", "C:\\Program Files\\7-Zip\\plop.exe"); + UtilsFirebase.InstallFirebase(); } diff --git a/scriptsharp/ScriptSharp/Utils/Utils.cs b/scriptsharp/ScriptSharp/Utils/Utils.cs index 510e2c4..ffd498f 100644 --- a/scriptsharp/ScriptSharp/Utils/Utils.cs +++ b/scriptsharp/ScriptSharp/Utils/Utils.cs @@ -93,35 +93,41 @@ public static void RunCommand(string command) LogSingleton.Get.LogAndWriteLine("Execution de la commande: " + command); try { + // Récupérer la variable d'environnement PATH + //string pathVariable = Environment.GetEnvironmentVariable("PATH"); + //Console.WriteLine("La variable d'environnement PATH est:"); + //Console.WriteLine(pathVariable); + + // Configuration de ProcessStartInfo ProcessStartInfo processStartInfo = new ProcessStartInfo { - FileName = "C:\\Windows\\System32\\cmd.exe", + FileName = "C:\\Windows\\system32\\cmd.exe", Arguments = $"/c {command}", RedirectStandardOutput = true, RedirectStandardError = true, UseShellExecute = false, - CreateNoWindow = true, - WorkingDirectory = Environment.CurrentDirectory + CreateNoWindow = true }; - processStartInfo.EnvironmentVariables["PATH"] = Environment.GetEnvironmentVariable("PATH", EnvironmentVariableTarget.User); - - using Process process = Process.Start(processStartInfo); - - string currentTime = DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss"); - string outputFilePath = Path.Combine(Config.LogPath, $"Commande-{currentTime}.txt"); - using (StreamWriter writer = new StreamWriter(outputFilePath)) - { - writer.WriteLine("Trace de l'exeuction de la commande:"); - writer.WriteLine(command); - writer.WriteLine(process.StandardOutput.ReadToEnd()); - writer.WriteLine(process.StandardError.ReadToEnd()); - writer.Close(); - } - process.WaitForExit(); - if (process.ExitCode != 0) + // Exécution du processus + using (Process process = new Process { StartInfo = processStartInfo }) { - throw new Exception($"Command exited with code {process.ExitCode}"); + process.Start(); + string output = process.StandardOutput.ReadToEnd(); + string error = process.StandardError.ReadToEnd(); + process.WaitForExit(); + + // Afficher les résultats de la commande exécutée + if (string.IsNullOrEmpty(error)) + { + LogSingleton.Get.LogAndWriteLine(" FAIT Sortie pour : " + command); + LogSingleton.Get.LogAndWriteLine(output); + } + else + { + LogSingleton.Get.LogAndWriteLine(" ERREUR Sortie pour : " + command); + LogSingleton.Get.LogAndWriteLine(error); + } } } catch (Exception ex) @@ -187,7 +193,7 @@ public static async Task Unzip7ZFileAsync(string sourceFile, string destinationF LogSingleton.Get.LogAndWriteLine($"Une erreur est survenue: {ex.Message}"); } - LogSingleton.Get.LogAndWriteLine("Dézippage avec 7z fini pour " + sourceFile); + LogSingleton.Get.LogAndWriteLine(" FAIT Dézippage 7z fini pour " + sourceFile); } public static async Task CopyFileFromNetworkShareAsync(string networkFilePath, string localFilePath) diff --git a/scriptsharp/ScriptSharp/Utils/UtilsFlutter.cs b/scriptsharp/ScriptSharp/Utils/UtilsFlutter.cs index 7e045af..96260da 100644 --- a/scriptsharp/ScriptSharp/Utils/UtilsFlutter.cs +++ b/scriptsharp/ScriptSharp/Utils/UtilsFlutter.cs @@ -18,15 +18,9 @@ await Utils.CopyFileFromNetworkShareAsync( await Utils.Unzip7ZFileAsync( Path.Combine(Config.LocalTemp, "flutter.7z"), Environment.GetFolderPath(Environment.SpecialFolder.Desktop)); - // execute "flutter doctor --android-licenses" Utils.RunCommand(PathToFlutter() +" config --android-sdk "+Utils.GetSdkPath()); Utils.RunCommand(PathToFlutter() +" config --android-studio-dir "+Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "android-studio")); - Utils.RunCommand(PathToFlutter() +" doctor --android-licenses"); Utils.RunCommand(PathToFlutter() +" doctor --verbose"); - Utils.RunCommand(PathToFlutter() +" precache"); - // Utils.RunCommand(Program.PathToFlutter() +" pub global activate devtools"); Obsolete depuis nouvelles version flutter - // create a fake project to initialize flutter - Utils.RunCommand(PathToFlutter() +" create fake_start;cd fake_start;flutter run"); LogSingleton.Get.LogAndWriteLine(" FAIT Installation Flutter complet"); } public static string PathToFlutter()