Skip to content

Commit

Permalink
Refactor Big Time
Browse files Browse the repository at this point in the history
  • Loading branch information
jorisdeguet committed Oct 17, 2024
1 parent af9ee1a commit 04f47ff
Show file tree
Hide file tree
Showing 12 changed files with 231 additions and 182 deletions.
93 changes: 1 addition & 92 deletions scriptsharp/ScriptSharp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand All @@ -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");
}
}
12 changes: 6 additions & 6 deletions scriptsharp/ScriptSharp/Script3N5.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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") )
Expand All @@ -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();
Expand All @@ -35,7 +35,7 @@ await Task.WhenAll(

private static async Task DownloadRepo3N5()
{
await Program.DownloadRepo(Config.Url3N5, "3N5");
await Utils.DownloadRepo(Config.Url3N5, "3N5");
}

/**
Expand Down Expand Up @@ -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");
}
Expand Down
18 changes: 9 additions & 9 deletions scriptsharp/ScriptSharp/Script4N6.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")),
Expand All @@ -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();
Expand All @@ -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()
Expand All @@ -56,19 +56,19 @@ 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")));
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
Expand Down
61 changes: 19 additions & 42 deletions scriptsharp/ScriptSharp/Script5N6.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")),
Expand All @@ -32,55 +32,32 @@ 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 ...");
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")),
Expand All @@ -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"));
Expand All @@ -114,6 +91,6 @@ await Task.WhenAll(

public static async Task DownloadRepo5N6()
{
await Program.DownloadRepo(Config.Url5N6, "5N6");
await Utils.DownloadRepo(Config.Url5N6, "5N6");
}
}
Loading

0 comments on commit 04f47ff

Please sign in to comment.