From 04f47ffb950c1fe525bb8914dd2f9c18a4d7cabd Mon Sep 17 00:00:00 2001 From: deguet Date: Thu, 17 Oct 2024 11:46:44 -0400 Subject: [PATCH] Refactor Big Time --- scriptsharp/ScriptSharp/Program.cs | 93 +------------------ scriptsharp/ScriptSharp/Script3N5.cs | 12 +-- scriptsharp/ScriptSharp/Script4N6.cs | 18 ++-- scriptsharp/ScriptSharp/Script5N6.cs | 61 ++++-------- scriptsharp/ScriptSharp/{ => Utils}/Utils.cs | 65 ++++++------- .../ScriptSharp/Utils/UtilsAndroidSdk.cs | 28 ++++++ .../ScriptSharp/Utils/UtilsAndroidStudio.cs | 25 +++++ .../UtilsCacheCreation.cs} | 2 +- .../ScriptSharp/Utils/UtilsFirebase.cs | 6 ++ scriptsharp/ScriptSharp/Utils/UtilsFlutter.cs | 38 ++++++++ .../ScriptSharp/Utils/UtilsIntellij.cs | 38 ++++++++ scriptsharp/ScriptSharp/Utils/UtilsJava.cs | 27 ++++++ 12 files changed, 231 insertions(+), 182 deletions(-) rename scriptsharp/ScriptSharp/{ => Utils}/Utils.cs (89%) create mode 100644 scriptsharp/ScriptSharp/Utils/UtilsAndroidSdk.cs create mode 100644 scriptsharp/ScriptSharp/Utils/UtilsAndroidStudio.cs rename scriptsharp/ScriptSharp/{CacheCreation.cs => Utils/UtilsCacheCreation.cs} (99%) create mode 100644 scriptsharp/ScriptSharp/Utils/UtilsFirebase.cs create mode 100644 scriptsharp/ScriptSharp/Utils/UtilsFlutter.cs create mode 100644 scriptsharp/ScriptSharp/Utils/UtilsIntellij.cs create mode 100644 scriptsharp/ScriptSharp/Utils/UtilsJava.cs diff --git a/scriptsharp/ScriptSharp/Program.cs b/scriptsharp/ScriptSharp/Program.cs index cbbfdd8..a18e061 100644 --- a/scriptsharp/ScriptSharp/Program.cs +++ b/scriptsharp/ScriptSharp/Program.cs @@ -107,7 +107,7 @@ private static async Task Main() case not null when choixChoisi.Contains("7."): return; case not null when choixChoisi.Contains("8."): - await CacheCreation.HandleCache(); + await UtilsCacheCreation.HandleCache(); break; } } @@ -119,96 +119,5 @@ private static void TestDebug() Utils.CreateDesktopShortcut("gni", "C:\\Program Files\\7-Zip\\plop.exe"); } - public static async Task InstallJava() - { - LogSingleton.Get.LogAndWriteLine("Installation de Java Dev Kit"); - await Utils.CopyFileFromNetworkShareAsync( - Path.Combine(Config.LocalCache, "jdk.7z"), - Path.Combine(Config.LocalTemp, "jdk.7z")); - string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); - string destinationFolder = Path.Combine(desktopPath, "jdk"); - await Utils.Unzip7ZFileAsync(Path.Combine(Config.LocalTemp, "jdk.7z"), destinationFolder); - string jdkPath = Path.Combine(desktopPath, "jdk"); - DirectoryInfo jdkDirectory = new DirectoryInfo(jdkPath); - string jdkVersion = jdkDirectory.GetDirectories()[0].Name; - string javaHome = Path.Combine(jdkPath, jdkVersion); - Utils.AddToPath(Path.Combine(javaHome, "bin")); - Environment.SetEnvironmentVariable("JAVA_HOME", javaHome, EnvironmentVariableTarget.User); - - LogSingleton.Get.LogAndWriteLine(" FAIT Installation Java"); - } - public static async Task DownloadRepoKmb() { await DownloadRepo(Config.UrlKmb, "KMB"); } - - public static async Task DownloadRepo(string url, string name) - { - // download URL_3N5 to the Desktop and unzip it - string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); - string zipFilePath = Path.Combine(desktopPath, name + ".zip"); - await Utils.DownloadFileAsync(url, zipFilePath); - LogSingleton.Get.LogAndWriteLine("Dézippage du repo " + zipFilePath + " vers " + desktopPath); - ZipFile.ExtractToDirectory(zipFilePath, desktopPath, true); - try { File.Delete(zipFilePath); } - catch - { - // ignored - } - } - - public static async Task InstallAndroidSdk() - { - LogSingleton.Get.LogAndWriteLine("Installation Android SDK démarré"); - string sdkPath = Utils.GetSdkPath(); - string androidSdkRoot = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Android", "Sdk"); - Utils.AddToPath(Path.Combine(androidSdkRoot, "cmdline-tools", "latest", "bin")); - Utils.AddToPath(Path.Combine(androidSdkRoot, "emulator")); - // get the parent directory of the SDK path - string sdkParentPath = Directory.GetParent(sdkPath)?.FullName; - await Utils.Unzip7ZFileAsync(Path.Combine(Config.LocalTemp, "Sdk.7z"), sdkParentPath); - // Add environment variables - SetEnvironmentVariable("ANDROID_SDK_ROOT", androidSdkRoot); - SetEnvironmentVariable("ANDROID_HOME", androidSdkRoot); - - // Append to PATH - - LogSingleton.Get.LogAndWriteLine(" FAIT Installation Android SDK complet"); - } - - public static async Task InstallAndroidStudio() - { - LogSingleton.Get.LogAndWriteLine("Installation Android Studio démarré"); - string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); - Utils.AddToPath(Path.Combine(desktopPath, "android-studio", "bin")); - string destinationFolder = Path.Combine(desktopPath); - await Utils.Unzip7ZFileAsync(Path.Combine(Config.LocalTemp, "android-studio.7z"), destinationFolder); - LogSingleton.Get.LogAndWriteLine(" FAIT Installation Android Studio fini"); - } - - private static void SetEnvironmentVariable(string variable, string value) - { - LogSingleton.Get.LogAndWriteLine("SetEnvironmentVariable démarré"); - Environment.SetEnvironmentVariable(variable, value, EnvironmentVariableTarget.User); - LogSingleton.Get.LogAndWriteLine("SetEnvironmentVariable arrêté"); - } - - - public static string PathToAndroidStudio() - { - return Path.Combine( - Environment.GetFolderPath(Environment.SpecialFolder.Desktop), - "android-studio", "bin", "studio64.exe"); - } - - public static string PathToIntellij() - { - return Path.Combine( - Environment.GetFolderPath(Environment.SpecialFolder.Desktop), - "idea", "bin", "idea64.exe"); - } - public static string PathToFlutter() - { - return Path.Combine( - Environment.GetFolderPath(Environment.SpecialFolder.Desktop), - "flutter", "bin", "flutter"); - } } \ No newline at end of file diff --git a/scriptsharp/ScriptSharp/Script3N5.cs b/scriptsharp/ScriptSharp/Script3N5.cs index b57f5c8..94d68f6 100644 --- a/scriptsharp/ScriptSharp/Script3N5.cs +++ b/scriptsharp/ScriptSharp/Script3N5.cs @@ -13,11 +13,11 @@ await Utils.CopyFileFromNetworkShareAsync( Path.Combine(Config.LocalCache, "Sdk.7z"), Path.Combine(Config.LocalTemp,"Sdk.7z")); await Task.WhenAll( - Program.InstallAndroidSdk(), + UtilsAndroidSdk.InstallAndroidSdk(), Utils.CopyFileFromNetworkShareAsync( Path.Combine(Config.LocalCache, ".gradle.7z"), Path.Combine(Config.LocalTemp,".gradle.7z")), - Program.InstallJava(), + UtilsJava.InstallJava(), Utils.CopyFileFromNetworkShareAsync( Path.Combine(Config.LocalCache, "android-studio.7z"), Path.Combine(Config.LocalTemp, "android-studio.7z") ) @@ -26,7 +26,7 @@ await Task.WhenAll( Utils.Unzip7ZFileAsync( Path.Combine(Config.LocalTemp,".gradle.7z"), Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)), - Program.InstallAndroidStudio(), + UtilsAndroidStudio.InstallAndroidStudio(), DownloadRepo3N5()); // start android studio await Utils.StartAndroidStudio(); @@ -35,7 +35,7 @@ await Task.WhenAll( private static async Task DownloadRepo3N5() { - await Program.DownloadRepo(Config.Url3N5, "3N5"); + await Utils.DownloadRepo(Config.Url3N5, "3N5"); } /** @@ -68,13 +68,13 @@ await Task.WhenAll( Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "idea") ), - Program.InstallJava() ); + UtilsJava.InstallJava() ); LogSingleton.Get.LogAndWriteLine("Premier gradle build pour constituer le .gradle"); // install plugins TODO ? one day? // Utils.RunCommand("idea64.exe installPlugins io.flutter"); // Utils.RunCommand("idea64.exe installPlugins com.github.copilot"); // Utils.RunCommand("idea64.exe installPlugins com.localizely.flutter-intl"); - await Task.WhenAll(DownloadRepo3N5(), Utils.StartIntellij()); + await Task.WhenAll(DownloadRepo3N5(), UtilsIntellij.StartIntellij()); LogSingleton.Get.LogAndWriteLine("IMPORTANT IMPORTANT, Si intellij ou Android Studio vous propose de configurer defender, faites-le et choisissez 'Automatically'"); LogSingleton.Get.LogAndWriteLine(" FAIT Installation de kotlin (console) 3N5"); } diff --git a/scriptsharp/ScriptSharp/Script4N6.cs b/scriptsharp/ScriptSharp/Script4N6.cs index 1ac814d..bb8c00b 100644 --- a/scriptsharp/ScriptSharp/Script4N6.cs +++ b/scriptsharp/ScriptSharp/Script4N6.cs @@ -14,11 +14,11 @@ await Utils.CopyFileFromNetworkShareAsync( Path.Combine(Config.LocalCache, "Sdk.7z"), Path.Combine(Config.LocalTemp,"Sdk.7z")); await Task.WhenAll( - Program.InstallAndroidSdk(), + UtilsAndroidSdk.InstallAndroidSdk(), Utils.CopyFileFromNetworkShareAsync( Path.Combine(Config.LocalCache, ".gradle.7z"), Path.Combine(Config.LocalTemp,".gradle.7z")), - Program.InstallJava(), + UtilsJava.InstallJava(), Utils.CopyFileFromNetworkShareAsync( Path.Combine(Config.LocalCache, "idea.7z"), Path.Combine(Config.LocalTemp,"idea.7z")), @@ -32,11 +32,11 @@ await Task.WhenAll( Utils.Unzip7ZFileAsync( Path.Combine(Config.LocalTemp,"idea.7z"), Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "idea")), - Program.InstallAndroidStudio(), - Program.DownloadRepoKmb(), + UtilsAndroidStudio.InstallAndroidStudio(), + Utils.DownloadRepoKmb(), DownloadRepo4N6()); // start android studio - Utils.CreateDesktopShortcut("IntelliJ", Program.PathToIntellij()); + Utils.CreateDesktopShortcut("IntelliJ", UtilsIntellij.PathToIntellij()); await Utils.StartAndroidStudio(); Utils.StartKmb(); @@ -46,7 +46,7 @@ await Task.WhenAll( private static async Task DownloadRepo4N6() { - await Program.DownloadRepo(Config.Url4N6, "4N6"); + await Utils.DownloadRepo(Config.Url4N6, "4N6"); } public static async Task Handle4N6AndroidAsync() @@ -56,11 +56,11 @@ await Utils.CopyFileFromNetworkShareAsync( Path.Combine(Config.LocalCache, "Sdk.7z"), Path.Combine(Config.LocalTemp, "Sdk.7z") ); await Task.WhenAll( - Program.InstallAndroidSdk(), + UtilsAndroidSdk.InstallAndroidSdk(), Utils.CopyFileFromNetworkShareAsync( Path.Combine(Config.LocalCache, ".gradle.7z"), Path.Combine(Config.LocalTemp, ".gradle.7z")), - Program.InstallJava(), + UtilsJava.InstallJava(), Utils.CopyFileFromNetworkShareAsync( Path.Combine(Config.LocalCache, "android-studio.7z"), Path.Combine(Config.LocalTemp, "android-studio.7z"))); @@ -68,7 +68,7 @@ await Task.WhenAll( Utils.Unzip7ZFileAsync( Path.Combine(Config.LocalTemp, ".gradle.7z"), Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)), - Program.InstallAndroidStudio(), + UtilsAndroidStudio.InstallAndroidStudio(), //Program.DownloadRepoKMB(), DownloadRepo4N6()); // start android studio diff --git a/scriptsharp/ScriptSharp/Script5N6.cs b/scriptsharp/ScriptSharp/Script5N6.cs index 6316536..74afa97 100644 --- a/scriptsharp/ScriptSharp/Script5N6.cs +++ b/scriptsharp/ScriptSharp/Script5N6.cs @@ -14,11 +14,11 @@ await Utils.CopyFileFromNetworkShareAsync( Path.Combine(Config.LocalCache, "Sdk-Android-Flutter.7z"), Path.Combine(Config.LocalTemp, "Sdk.7z") ); await Task.WhenAll( - Program.InstallAndroidSdk(), + UtilsAndroidSdk.InstallAndroidSdk(), Utils.CopyFileFromNetworkShareAsync( Path.Combine(Config.LocalCache, ".gradle-Android-Flutter.7z"), Path.Combine(Config.LocalTemp, ".gradle.7z")), - Program.InstallJava(), + UtilsJava.InstallJava(), Utils.CopyFileFromNetworkShareAsync( Path.Combine(Config.LocalCache, "idea.7z"), Path.Combine(Config.LocalTemp, "idea.7z")), @@ -32,43 +32,20 @@ await Task.WhenAll( Utils.Unzip7ZFileAsync( Path.Combine(Config.LocalTemp, "idea.7z"), Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "idea")), - Program.InstallAndroidStudio(), - Program.DownloadRepoKmb(), + UtilsAndroidStudio.InstallAndroidStudio(), + Utils.DownloadRepoKmb(), DownloadRepo5N6()); - Utils.RunCommand(Program.PathToAndroidStudio() + " installPlugins io.flutter"); - Utils.RunCommand(Program.PathToAndroidStudio() + " installPlugins com.github.copilot"); - Utils.RunCommand(Program.PathToAndroidStudio() + " installPlugins com.localizely.flutter-intl"); - await InstallFlutter(); + Utils.RunCommand(UtilsAndroidStudio.PathToAndroidStudio() + " installPlugins io.flutter"); + Utils.RunCommand(UtilsAndroidStudio.PathToAndroidStudio() + " installPlugins com.github.copilot"); + Utils.RunCommand(UtilsAndroidStudio.PathToAndroidStudio() + " installPlugins com.localizely.flutter-intl"); + await UtilsFlutter.InstallFlutter(); Utils.StartKmb(); await Utils.StartAndroidStudio(); - Utils.CreateDesktopShortcut("IntelliJ", Program.PathToIntellij()); + Utils.CreateDesktopShortcut("IntelliJ", UtilsIntellij.PathToIntellij()); LogSingleton.Get.LogAndWriteLine(" FAIT 5N6 Flutter complet"); } - private static async Task InstallFlutter() - { - LogSingleton.Get.LogAndWriteLine("Installation Flutter démarré"); - // ajouter flutter au path - Utils.AddToPath(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "flutter", "bin")); - await Utils.CopyFileFromNetworkShareAsync( - Path.Combine(Config.LocalCache, "flutter.7z"), - Path.Combine(Config.LocalTemp, "flutter.7z")); - await Utils.Unzip7ZFileAsync( - Path.Combine(Config.LocalTemp, "flutter.7z"), - Environment.GetFolderPath(Environment.SpecialFolder.Desktop)); - // execute "flutter doctor --android-licenses" - Utils.RunCommand(Program.PathToFlutter() +" config --android-sdk "+Utils.GetSdkPath()); - Utils.RunCommand(Program.PathToFlutter() +" config --android-studio-dir "+Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "android-studio")); - Utils.RunCommand(Program.PathToFlutter() +" doctor --android-licenses"); - Utils.RunCommand(Program.PathToFlutter() +" doctor --verbose"); - Utils.RunCommand(Program.PathToFlutter() +" precache"); - // Utils.RunCommand(Program.PathToFlutter() +" pub global activate devtools"); Obsolete depuis nouvelles version flutter - // create a fake project to initialize flutter - Utils.RunCommand(Program.PathToFlutter() +" create fake_start;cd fake_start;flutter run"); - LogSingleton.Get.LogAndWriteLine(" FAIT Installation Flutter complet"); - } - public static async Task Handle5N6FlutterFirebaseAsync() { LogSingleton.Get.LogAndWriteLine("Installation de 5N6 flutter + firebase ..."); @@ -76,11 +53,11 @@ await Utils.CopyFileFromNetworkShareAsync( Path.Combine(Config.LocalCache, "Sdk-Android-Flutter.7z"), Path.Combine(Config.LocalTemp, "Sdk.7z") ); await Task.WhenAll( - Program.InstallAndroidSdk(), + UtilsAndroidSdk.InstallAndroidSdk(), Utils.CopyFileFromNetworkShareAsync( Path.Combine(Config.LocalCache, ".gradle-Android-Flutter.7z"), Path.Combine(Config.LocalTemp, ".gradle.7z")), - Program.InstallJava(), + UtilsJava.InstallJava(), Utils.CopyFileFromNetworkShareAsync( Path.Combine(Config.LocalCache, "idea.7z"), Path.Combine(Config.LocalTemp, "idea.7z")), @@ -94,15 +71,15 @@ await Task.WhenAll( Utils.Unzip7ZFileAsync( Path.Combine(Config.LocalTemp, "idea.7z"), Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "idea")), - Program.InstallAndroidStudio(), - Program.DownloadRepoKmb(), + UtilsAndroidStudio.InstallAndroidStudio(), + Utils.DownloadRepoKmb(), DownloadRepo5N6()); - Utils.CreateDesktopShortcut("IntelliJ", Program.PathToIntellij()); + Utils.CreateDesktopShortcut("IntelliJ", UtilsIntellij.PathToIntellij()); Utils.AddToPath(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "idea", "bin")); - Utils.RunCommand(Program.PathToAndroidStudio() + " installPlugins io.flutter"); - Utils.RunCommand(Program.PathToAndroidStudio() + " installPlugins com.github.copilot"); - Utils.RunCommand(Program.PathToAndroidStudio() + " installPlugins com.localizely.flutter-intl"); - await InstallFlutter(); + Utils.RunCommand(UtilsAndroidStudio.PathToAndroidStudio() + " installPlugins io.flutter"); + Utils.RunCommand(UtilsAndroidStudio.PathToAndroidStudio() + " installPlugins com.github.copilot"); + Utils.RunCommand(UtilsAndroidStudio.PathToAndroidStudio() + " installPlugins com.localizely.flutter-intl"); + await UtilsFlutter.InstallFlutter(); //Utils.StartKMB(); Utils.AddToPath(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "AppData", "Local", "Pub", "Cache", "bin")); @@ -114,6 +91,6 @@ await Task.WhenAll( public static async Task DownloadRepo5N6() { - await Program.DownloadRepo(Config.Url5N6, "5N6"); + await Utils.DownloadRepo(Config.Url5N6, "5N6"); } } \ No newline at end of file diff --git a/scriptsharp/ScriptSharp/Utils.cs b/scriptsharp/ScriptSharp/Utils/Utils.cs similarity index 89% rename from scriptsharp/ScriptSharp/Utils.cs rename to scriptsharp/ScriptSharp/Utils/Utils.cs index 068329c..510e2c4 100644 --- a/scriptsharp/ScriptSharp/Utils.cs +++ b/scriptsharp/ScriptSharp/Utils/Utils.cs @@ -263,34 +263,13 @@ private static void RunPowerShellCommand(string command) } } - public static Task StartIntellij() - { - // start android studio - LogSingleton.Get.LogAndWriteLine("Démarrage d'Intellij IDEA"); - string path = Program.PathToIntellij(); - CreateDesktopShortcut("Intellij", path); - if (File.Exists(path)) - { - ProcessStartInfo processStartInfo = new ProcessStartInfo - { - FileName = path, - UseShellExecute = true - }; - Process.Start(processStartInfo); - } - else - { - LogSingleton.Get.LogAndWriteLine("Intellij n'est pas installé"); - } - return Task.CompletedTask; - } public static Task StartAndroidStudio() { LogSingleton.Get.LogAndWriteLine("Lancement d'Android Studio"); - string androidStudioPath = Program.PathToAndroidStudio(); + string androidStudioPath = UtilsAndroidStudio.PathToAndroidStudio(); if (File.Exists(androidStudioPath)) { - CreateDesktopShortcut("Android-Studio", Program.PathToAndroidStudio()); + CreateDesktopShortcut("Android-Studio", UtilsAndroidStudio.PathToAndroidStudio()); ProcessStartInfo processStartInfo = new ProcessStartInfo { FileName = androidStudioPath, @@ -337,7 +316,7 @@ private static void RemoveFromPath(string pattern) public static void StartKmb() { - RunCommand(Program.PathToIntellij() + " " + Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "KickMyB-Server-main")); + RunCommand(UtilsIntellij.PathToIntellij() + " " + Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "KickMyB-Server-main")); } public static void Reset() @@ -362,13 +341,13 @@ private static void DeleteAll() private static void RemoveAllEnv() { - SetEnvironmentVariable("ANDROID_HOME", null); - SetEnvironmentVariable("JAVA_HOME", null); - SetEnvironmentVariable("GRADLE_HOME", null); - SetEnvironmentVariable("ANDROID_SDK_ROOT", null); - SetEnvironmentVariable("ANDROID_NDK_HOME", null); - SetEnvironmentVariable("ANDROID_AVD_HOME", null); - SetEnvironmentVariable("ANDROID_SDK_HOME", null); + SetEnvVariable("ANDROID_HOME", null); + SetEnvVariable("JAVA_HOME", null); + SetEnvVariable("GRADLE_HOME", null); + SetEnvVariable("ANDROID_SDK_ROOT", null); + SetEnvVariable("ANDROID_NDK_HOME", null); + SetEnvVariable("ANDROID_AVD_HOME", null); + SetEnvVariable("ANDROID_SDK_HOME", null); RemoveFromPath(@"Desktop\flutter\bin"); RemoveFromPath(@"Desktop\android-studio\bin"); RemoveFromPath(@"AppData\Local\Android\Sdk\emulator"); @@ -377,7 +356,7 @@ private static void RemoveAllEnv() RemoveFromPath(@"Desktop\jdk"); } - private static void SetEnvironmentVariable(string name, string value) + public static void SetEnvVariable(string name, string value) { Environment.SetEnvironmentVariable(name, value, EnvironmentVariableTarget.User); Environment.SetEnvironmentVariable(name, value, EnvironmentVariableTarget.Process); @@ -424,4 +403,26 @@ private static void DeleteThis(string path) } } } + public static void SetEnvironmentVariable(string variable, string value) + { + LogSingleton.Get.LogAndWriteLine("SetEnvironmentVariable démarré"); + Environment.SetEnvironmentVariable(variable, value, EnvironmentVariableTarget.User); + LogSingleton.Get.LogAndWriteLine("SetEnvironmentVariable arrêté"); + } + public static async Task DownloadRepo(string url, string name) + { + // download URL_3N5 to the Desktop and unzip it + string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); + string zipFilePath = Path.Combine(desktopPath, name + ".zip"); + await Utils.DownloadFileAsync(url, zipFilePath); + LogSingleton.Get.LogAndWriteLine("Dézippage du repo " + zipFilePath + " vers " + desktopPath); + ZipFile.ExtractToDirectory(zipFilePath, desktopPath, true); + try { File.Delete(zipFilePath); } + catch + { + // ignored + } + } + + public static async Task DownloadRepoKmb() { await Utils.DownloadRepo(Config.UrlKmb, "KMB"); } } \ No newline at end of file diff --git a/scriptsharp/ScriptSharp/Utils/UtilsAndroidSdk.cs b/scriptsharp/ScriptSharp/Utils/UtilsAndroidSdk.cs new file mode 100644 index 0000000..ca55b85 --- /dev/null +++ b/scriptsharp/ScriptSharp/Utils/UtilsAndroidSdk.cs @@ -0,0 +1,28 @@ +using System; +using System.IO; +using System.Threading.Tasks; + +namespace ScriptSharp; + +public class UtilsAndroidSdk +{ + + public static async Task InstallAndroidSdk() + { + LogSingleton.Get.LogAndWriteLine("Installation Android SDK démarré"); + string sdkPath = Utils.GetSdkPath(); + string androidSdkRoot = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Android", "Sdk"); + Utils.AddToPath(Path.Combine(androidSdkRoot, "cmdline-tools", "latest", "bin")); + Utils.AddToPath(Path.Combine(androidSdkRoot, "emulator")); + // get the parent directory of the SDK path + string sdkParentPath = Directory.GetParent(sdkPath)?.FullName; + await Utils.Unzip7ZFileAsync(Path.Combine(Config.LocalTemp, "Sdk.7z"), sdkParentPath); + // Add environment variables + Utils.SetEnvironmentVariable("ANDROID_SDK_ROOT", androidSdkRoot); + Utils.SetEnvironmentVariable("ANDROID_HOME", androidSdkRoot); + + // Append to PATH + + LogSingleton.Get.LogAndWriteLine(" FAIT Installation Android SDK complet"); + } +} \ No newline at end of file diff --git a/scriptsharp/ScriptSharp/Utils/UtilsAndroidStudio.cs b/scriptsharp/ScriptSharp/Utils/UtilsAndroidStudio.cs new file mode 100644 index 0000000..051bd62 --- /dev/null +++ b/scriptsharp/ScriptSharp/Utils/UtilsAndroidStudio.cs @@ -0,0 +1,25 @@ +using System; +using System.IO; +using System.Threading.Tasks; + +namespace ScriptSharp; + +public class UtilsAndroidStudio +{ + + public static string PathToAndroidStudio() + { + return Path.Combine( + Environment.GetFolderPath(Environment.SpecialFolder.Desktop), + "android-studio", "bin", "studio64.exe"); + } + public static async Task InstallAndroidStudio() + { + LogSingleton.Get.LogAndWriteLine("Installation Android Studio démarré"); + string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); + Utils.AddToPath(Path.Combine(desktopPath, "android-studio", "bin")); + string destinationFolder = Path.Combine(desktopPath); + await Utils.Unzip7ZFileAsync(Path.Combine(Config.LocalTemp, "android-studio.7z"), destinationFolder); + LogSingleton.Get.LogAndWriteLine(" FAIT Installation Android Studio fini"); + } +} \ No newline at end of file diff --git a/scriptsharp/ScriptSharp/CacheCreation.cs b/scriptsharp/ScriptSharp/Utils/UtilsCacheCreation.cs similarity index 99% rename from scriptsharp/ScriptSharp/CacheCreation.cs rename to scriptsharp/ScriptSharp/Utils/UtilsCacheCreation.cs index 669576c..eceab88 100644 --- a/scriptsharp/ScriptSharp/CacheCreation.cs +++ b/scriptsharp/ScriptSharp/Utils/UtilsCacheCreation.cs @@ -6,7 +6,7 @@ namespace ScriptSharp; -public static class CacheCreation +public static class UtilsCacheCreation { /** * 2 ensembles de sdk / .gradle pour android studio kotlin ET android studio flutter diff --git a/scriptsharp/ScriptSharp/Utils/UtilsFirebase.cs b/scriptsharp/ScriptSharp/Utils/UtilsFirebase.cs new file mode 100644 index 0000000..13ff1ad --- /dev/null +++ b/scriptsharp/ScriptSharp/Utils/UtilsFirebase.cs @@ -0,0 +1,6 @@ +namespace ScriptSharp; + +public class UtilsFirebase +{ + +} \ No newline at end of file diff --git a/scriptsharp/ScriptSharp/Utils/UtilsFlutter.cs b/scriptsharp/ScriptSharp/Utils/UtilsFlutter.cs new file mode 100644 index 0000000..7e045af --- /dev/null +++ b/scriptsharp/ScriptSharp/Utils/UtilsFlutter.cs @@ -0,0 +1,38 @@ +using System; +using System.IO; +using System.Threading.Tasks; + +namespace ScriptSharp; + +public class UtilsFlutter +{ + + public static async Task InstallFlutter() + { + LogSingleton.Get.LogAndWriteLine("Installation Flutter démarré"); + // ajouter flutter au path + Utils.AddToPath(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "flutter", "bin")); + await Utils.CopyFileFromNetworkShareAsync( + Path.Combine(Config.LocalCache, "flutter.7z"), + Path.Combine(Config.LocalTemp, "flutter.7z")); + 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() + { + return Path.Combine( + Environment.GetFolderPath(Environment.SpecialFolder.Desktop), + "flutter", "bin", "flutter"); + } +} \ No newline at end of file diff --git a/scriptsharp/ScriptSharp/Utils/UtilsIntellij.cs b/scriptsharp/ScriptSharp/Utils/UtilsIntellij.cs new file mode 100644 index 0000000..7da7798 --- /dev/null +++ b/scriptsharp/ScriptSharp/Utils/UtilsIntellij.cs @@ -0,0 +1,38 @@ +using System; +using System.Diagnostics; +using System.IO; +using System.Threading.Tasks; + +namespace ScriptSharp; + +public class UtilsIntellij +{ + + public static string PathToIntellij() + { + return Path.Combine( + Environment.GetFolderPath(Environment.SpecialFolder.Desktop), + "idea", "bin", "idea64.exe"); + } + public static Task StartIntellij() + { + // start android studio + LogSingleton.Get.LogAndWriteLine("Démarrage d'Intellij IDEA"); + string path = UtilsIntellij.PathToIntellij(); + Utils.CreateDesktopShortcut("Intellij", path); + if (File.Exists(path)) + { + ProcessStartInfo processStartInfo = new ProcessStartInfo + { + FileName = path, + UseShellExecute = true + }; + Process.Start(processStartInfo); + } + else + { + LogSingleton.Get.LogAndWriteLine("Intellij n'est pas installé"); + } + return Task.CompletedTask; + } +} \ No newline at end of file diff --git a/scriptsharp/ScriptSharp/Utils/UtilsJava.cs b/scriptsharp/ScriptSharp/Utils/UtilsJava.cs new file mode 100644 index 0000000..66068ef --- /dev/null +++ b/scriptsharp/ScriptSharp/Utils/UtilsJava.cs @@ -0,0 +1,27 @@ +using System; +using System.IO; +using System.Threading.Tasks; + +namespace ScriptSharp; + +public class UtilsJava +{ + + public static async Task InstallJava() + { + LogSingleton.Get.LogAndWriteLine("Installation de Java Dev Kit"); + await Utils.CopyFileFromNetworkShareAsync( + Path.Combine(Config.LocalCache, "jdk.7z"), + Path.Combine(Config.LocalTemp, "jdk.7z")); + string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); + string destinationFolder = Path.Combine(desktopPath, "jdk"); + await Utils.Unzip7ZFileAsync(Path.Combine(Config.LocalTemp, "jdk.7z"), destinationFolder); + string jdkPath = Path.Combine(desktopPath, "jdk"); + DirectoryInfo jdkDirectory = new DirectoryInfo(jdkPath); + string jdkVersion = jdkDirectory.GetDirectories()[0].Name; + string javaHome = Path.Combine(jdkPath, jdkVersion); + Utils.AddToPath(Path.Combine(javaHome, "bin")); + Utils.SetEnvVariable("JAVA_HOME", javaHome); + LogSingleton.Get.LogAndWriteLine(" FAIT Installation Java"); + } +} \ No newline at end of file