Skip to content

Commit

Permalink
Update log, fix folder delete
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreOlivierBrillant committed Oct 16, 2024
1 parent 953e14f commit a367d54
Show file tree
Hide file tree
Showing 8 changed files with 161 additions and 102 deletions.
10 changes: 5 additions & 5 deletions scriptsharp/ScriptSharp/CacheCreation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class CacheCreation
*/
public static async Task HandleCache()
{
Utils.LogAndWriteLine("Creation de la cache ...");
LogSingleton.Get.LogAndWriteLine("Creation de la cache ...");
var downloadTasks = new[]
{
Utils.DownloadFileAsync(Config.IDEA_URL, "idea.zip"),
Expand All @@ -55,7 +55,7 @@ public static async Task HandleCache()
{
Directory.Delete(Path.Combine(tempcache, "android-studio"), true);
}
Utils.LogAndWriteLine("Creation du Android Studio avec plugins");
LogSingleton.Get.LogAndWriteLine("Creation du Android Studio avec plugins");
string localTempPath = Path.Combine(tempcache, "studio.zip");
ZipFile.ExtractToDirectory(localTempPath, Path.Combine(tempcache));

Expand All @@ -70,15 +70,15 @@ public static async Task HandleCache()
Path.Combine(tempcache,"android-studio", "plugins"));
// create android-studio.7z from the folder with plugins
await Utils.CompressFolderTo7zAsync("android-studio", "android-studio.7z");
Utils.LogAndWriteLine("Conversions des zip en 7z");
LogSingleton.Get.LogAndWriteLine("Conversions des zip en 7z");
var convertTasks = new[]
{
Utils.ConvertZipTo7zAsync("idea.zip", "idea.7z"),
Utils.ConvertZipTo7zAsync("corretto.zip", "jdk.7z"),
Utils.ConvertZipTo7zAsync("flutter.zip", "flutter.7z")
};
await Task.WhenAll(convertTasks);
Utils.LogAndWriteLine("Copie des 7z dans le cache " + Config.cachePath);
LogSingleton.Get.LogAndWriteLine("Copie des 7z dans le cache " + Config.cachePath);
// copy the 7z files to the cache folder
File.Copy("idea.7z", Path.Combine(Config.cachePath, "idea.7z"), true);
File.Copy("idea.zip", Path.Combine(Config.cachePath, "idea.zip"), true);
Expand All @@ -98,6 +98,6 @@ public static async Task HandleCache()
Console.WriteLine(
"Merci de partir Android Studio creer un projet et le partir sur un emulateur pour constituer le SDK et le .gradle");
var s = Console.ReadLine();
Utils.LogAndWriteLine("Creation de la cache finie");
LogSingleton.Get.LogAndWriteLine("Creation de la cache finie");
}
}
3 changes: 0 additions & 3 deletions scriptsharp/ScriptSharp/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ public class Config
public static string URL_4N6 = "https://github.com/departement-info-cem/4N6-Mobile/archive/refs/heads/master.zip";
public static string URL_5N6 = "https://github.com/departement-info-cem/5N6-mobile-2/archive/refs/heads/main.zip";
public static string URL_KMB = "https://github.com/departement-info-cem/KickMyB-Server/archive/refs/heads/main.zip";




public static string cachePath = "\\\\ed5depinfo\\Logiciels\\Android\\scripts\\cachecache\\";
public static string localCache = "\\\\ed5depinfo\\Logiciels\\Android\\scripts\\cachecache\\";
Expand Down
36 changes: 36 additions & 0 deletions scriptsharp/ScriptSharp/LogSingleton.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using System.IO;

namespace ScriptSharp;

public sealed class LogSingleton
{
private static LogSingleton _instance;
private static readonly object Padlock = new();


private LogSingleton()
{
}

public static LogSingleton Get
{
get
{
if (_instance != null) return _instance;
lock (Padlock)
{
_instance ??= new LogSingleton();
}

return _instance;
}
}

public void LogAndWriteLine(string message)
{
Console.WriteLine(message);
using StreamWriter writer = new(Config.logFilePath, true);
writer.WriteLine($"{DateTime.Now}: {message}");
}
}
58 changes: 29 additions & 29 deletions scriptsharp/ScriptSharp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ static async Task Main(string[] args)
//clear the log file
Directory.CreateDirectory(Config.logPath);
File.WriteAllText(Config.logFilePath, string.Empty);
Utils.LogAndWriteLine("Bienvenue dans l'installeur pour les cours de mobile");
Utils.LogAndWriteLine("ATTENTION DE BIEN ATTENDRE LA FIN DE L'INSTALLATION AVANT D'OUVRIR UN PROJET");
Utils.LogAndWriteLine("Une fois un projet ouvert, surtout choisir Automatically si on vous propose de configurer Defender");
Utils.LogAndWriteLine("Un fichier de log de l'installation est dispo sur le bureau, dossier log ");
LogSingleton.Get.LogAndWriteLine("Bienvenue dans l'installeur pour les cours de mobile");
LogSingleton.Get.LogAndWriteLine("ATTENTION DE BIEN ATTENDRE LA FIN DE L'INSTALLATION AVANT D'OUVRIR UN PROJET");
LogSingleton.Get.LogAndWriteLine("Une fois un projet ouvert, surtout choisir Automatically si on vous propose de configurer Defender");
LogSingleton.Get.LogAndWriteLine("Un fichier de log de l'installation est dispo sur le bureau, dossier log ");
if (!Directory.Exists(Config.localCache) && isWindows)
{
Utils.LogAndWriteLine(
LogSingleton.Get.LogAndWriteLine(
"Le dossier de cache local n'existe pas. Veuillez vous assurer que le partage réseau est monté et réessayez.");
Utils.LogAndWriteLine("Main arrêté car le dossier de cache local n'existe pas");
LogSingleton.Get.LogAndWriteLine("Main arrêté car le dossier de cache local n'existe pas");
return;
}
if (isWindows)
Expand All @@ -87,14 +87,14 @@ static async Task Main(string[] args)
// Console.WriteLine("Defender toujours actif, pensez a rouler ca en admin");
// }
}
Utils.LogAndWriteLine("Veuillez choisir une option:");
Utils.LogAndWriteLine("1. 3N5 console kotlin");
Utils.LogAndWriteLine("2. 3N5 Android");
Utils.LogAndWriteLine("3. 4N6 Android");
Utils.LogAndWriteLine("4. 4N6 Android + Spring");
Utils.LogAndWriteLine("5. 5N6 flutter");
Utils.LogAndWriteLine("6. 5N6 flutter + firebase");
Utils.LogAndWriteLine("7. supprimer .gradle SDK .android bureau");
LogSingleton.Get.LogAndWriteLine("Veuillez choisir une option:");
LogSingleton.Get.LogAndWriteLine("1. 3N5 console kotlin");
LogSingleton.Get.LogAndWriteLine("2. 3N5 Android");
LogSingleton.Get.LogAndWriteLine("3. 4N6 Android");
LogSingleton.Get.LogAndWriteLine("4. 4N6 Android + Spring");
LogSingleton.Get.LogAndWriteLine("5. 5N6 flutter");
LogSingleton.Get.LogAndWriteLine("6. 5N6 flutter + firebase");
LogSingleton.Get.LogAndWriteLine("7. supprimer .gradle SDK .android bureau");
string choice = Console.ReadLine();
switch (choice)
{
Expand All @@ -105,20 +105,20 @@ static async Task Main(string[] args)
case "4": await Script4N6.Handle4N6AndroidSpringAsync(); break;
case "5": await Script5N6.Handle5N6FlutterAsync(); break;
case "6": await Script5N6.Handle5N6FlutterFirebaseAsync(); break;
case "7": Utils.DeleteAll(); break;
case "7": Utils.Reset(); break;
default:
Utils.LogAndWriteLine(
LogSingleton.Get.LogAndWriteLine(
"Choix invalide. Veuillez redémarrer le programme et choisir une option valide.");
break;
}
Utils.LogAndWriteLine("Installation finie");
Utils.LogAndWriteLine("Appuyer sur la touche Entrée pour quitter, on a fini ...");
LogSingleton.Get.LogAndWriteLine("Installation finie");
LogSingleton.Get.LogAndWriteLine("Appuyer sur la touche Entrée pour quitter, on a fini ...");
Console.ReadLine();
}

public static async Task InstallJava()
{
Utils.LogAndWriteLine("Installation de Java Dev Kit");
LogSingleton.Get.LogAndWriteLine("Installation de Java Dev Kit");
await Utils.CopyFileFromNetworkShareAsync(
Path.Combine(Config.localCache, "jdk.7z"),
Path.Combine(Config.localTemp, "jdk.7z"));
Expand All @@ -132,7 +132,7 @@ await Utils.CopyFileFromNetworkShareAsync(
Utils.AddToPath(Path.Combine(javaHome, "bin"));
Environment.SetEnvironmentVariable("JAVA_HOME", javaHome, EnvironmentVariableTarget.User);

Utils.LogAndWriteLine(" FAIT Installation Java");
LogSingleton.Get.LogAndWriteLine(" FAIT Installation Java");
}

public static async Task DownloadRepoKMB() { await DownloadRepo(Config.URL_KMB, "KMB"); }
Expand All @@ -143,7 +143,7 @@ public static async Task DownloadRepo(string url, string name)
string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
string zipFilePath = Path.Combine(desktopPath, name + ".zip");
await Utils.DownloadFileAsync(url, zipFilePath);
Utils.LogAndWriteLine("Dézippage du repo " + zipFilePath + " vers " + desktopPath);
LogSingleton.Get.LogAndWriteLine("Dézippage du repo " + zipFilePath + " vers " + desktopPath);
ZipFile.ExtractToDirectory(zipFilePath, desktopPath, true);
try { File.Delete(zipFilePath); }catch { }
}
Expand All @@ -152,7 +152,7 @@ public static async Task DownloadRepo(string url, string name)
public static async Task InstallAndroidSDK()
{
// fix ANDROID_SDK_ROOT and ANDROID_HOME with GetSDKPath
Utils.LogAndWriteLine("Installation Android SDK démarré");
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"));
Expand All @@ -166,19 +166,19 @@ public static async Task InstallAndroidSDK()

// Append to PATH

Utils.LogAndWriteLine(" FAIT Installation Android SDK complet");
LogSingleton.Get.LogAndWriteLine(" FAIT Installation Android SDK complet");
}

public static async Task InstallAndroidStudio()
{
Utils.LogAndWriteLine("Installation Android Studio démarré");
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);
// TODO add shortcut

Utils.LogAndWriteLine(" FAIT Installation Android Studio fini");
LogSingleton.Get.LogAndWriteLine(" FAIT Installation Android Studio fini");
}

public static void AddDesktopToDefenderExclusion()
Expand Down Expand Up @@ -211,7 +211,7 @@ public static void AddDesktopToDefenderExclusion()

static void DisableWindowsDefender()
{
Utils.LogAndWriteLine("Desactivation du Defender en cours");
LogSingleton.Get.LogAndWriteLine("Desactivation du Defender en cours");
string command = "powershell -Command \"Set-MpPreference -DisableRealtimeMonitoring $true\"";
ProcessStartInfo processStartInfo = new ProcessStartInfo
{
Expand All @@ -229,14 +229,14 @@ static void DisableWindowsDefender()
throw new Exception($"La commande s'est terminée avec le code {process.ExitCode}");
}
}
Utils.LogAndWriteLine(" FAIT Defender inactif");
LogSingleton.Get.LogAndWriteLine(" FAIT Defender inactif");
}

static void SetEnvironmentVariable(string variable, string value)
{
Utils.LogAndWriteLine("SetEnvironmentVariable démarré");
LogSingleton.Get.LogAndWriteLine("SetEnvironmentVariable démarré");
Environment.SetEnvironmentVariable(variable, value, EnvironmentVariableTarget.User);
Utils.LogAndWriteLine("SetEnvironmentVariable arrêté");
LogSingleton.Get.LogAndWriteLine("SetEnvironmentVariable arrêté");
}


Expand Down
12 changes: 6 additions & 6 deletions scriptsharp/ScriptSharp/Script3N5.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class Script3N5
{
public static async Task Handle3N5AndroidAsync()
{
Utils.LogAndWriteLine("Installation pour 3N5 Android...");
LogSingleton.Get.LogAndWriteLine("Installation pour 3N5 Android...");
await Utils.CopyFileFromNetworkShareAsync(
Path.Combine(Config.localCache, "Sdk.7z"),
Path.Combine(Config.localTemp,"Sdk.7z"));
Expand All @@ -30,7 +30,7 @@ await Task.WhenAll(
DownloadRepo3N5());
// start android studio
await Utils.StartAndroidStudio();
Utils.LogAndWriteLine(" FAIT Installation pour 3N5 Android complet");
LogSingleton.Get.LogAndWriteLine(" FAIT Installation pour 3N5 Android complet");
}

public static async Task DownloadRepo3N5()
Expand All @@ -56,7 +56,7 @@ public static async Task DownloadRepo3N5()
*/
public static async Task Handle3N5KotlinConsoleAsync()
{
Utils.LogAndWriteLine("Installation de kotlin (console) 3N5...");
LogSingleton.Get.LogAndWriteLine("Installation de kotlin (console) 3N5...");
Utils.AddToPath(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "idea", "bin"));
await Task.WhenAll(
Utils.CopyFileFromNetworkShareAsync(
Expand All @@ -71,13 +71,13 @@ await Task.WhenAll(
"idea")
),
Program.InstallJava() );
Utils.LogAndWriteLine("Premier gradle build pour constituer le .gradle");
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());
Utils.LogAndWriteLine("IMPORTANT IMPORTANT, Si intellij ou Android Studio vous propose de configurer defender, faites-le et choisissez 'Automatically'");
Utils.LogAndWriteLine(" FAIT Installation de kotlin (console) 3N5");
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");
}
}
8 changes: 4 additions & 4 deletions scriptsharp/ScriptSharp/Script4N6.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class Script4N6
{
public static async Task Handle4N6AndroidSpringAsync()
{
Utils.LogAndWriteLine("Installation pour 4N6 Android + serveur Spring ...");
LogSingleton.Get.LogAndWriteLine("Installation pour 4N6 Android + serveur Spring ...");
Utils.AddToPath(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "idea", "bin"));
await Utils.CopyFileFromNetworkShareAsync(
Path.Combine(Config.localCache, "Sdk.7z"),
Expand Down Expand Up @@ -40,7 +40,7 @@ await Task.WhenAll(

await Utils.StartAndroidStudio();
Utils.StartKMB();
Utils.LogAndWriteLine(" FAIT Installation 4N6 Android + serveur Spring ");
LogSingleton.Get.LogAndWriteLine(" FAIT Installation 4N6 Android + serveur Spring ");
}


Expand All @@ -51,7 +51,7 @@ public static async Task DownloadRepo4N6()

public static async Task Handle4N6AndroidAsync()
{
Utils.LogAndWriteLine("Installation pour 4N6 Android...");
LogSingleton.Get.LogAndWriteLine("Installation pour 4N6 Android...");
await Utils.CopyFileFromNetworkShareAsync(
Path.Combine(Config.localCache, "Sdk.7z"),
Path.Combine(Config.localTemp, "Sdk.7z") );
Expand All @@ -73,6 +73,6 @@ await Task.WhenAll(
DownloadRepo4N6());
// start android studio
await Utils.StartAndroidStudio();
Utils.LogAndWriteLine(" FAIT Installation 4N6 Android fini");
LogSingleton.Get.LogAndWriteLine(" FAIT Installation 4N6 Android fini");
}
}
12 changes: 6 additions & 6 deletions scriptsharp/ScriptSharp/Script5N6.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class Script5N6
{
public static async Task Handle5N6FlutterAsync()
{
Utils.LogAndWriteLine("Installation de 5N6 flutter (et Android Studio plus Intellij)...");
LogSingleton.Get.LogAndWriteLine("Installation de 5N6 flutter (et Android Studio plus Intellij)...");
Utils.AddToPath(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "idea", "bin"));
await Utils.CopyFileFromNetworkShareAsync(
Path.Combine(Config.localCache, "Sdk-Android-Flutter.7z"),
Expand Down Expand Up @@ -43,12 +43,12 @@ await Task.WhenAll(
Utils.StartKMB();
await Utils.StartAndroidStudio();
Utils.CreateDesktopShortcut("IntelliJ", Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "idea", "bin", "idea64.exe"));
Utils.LogAndWriteLine(" FAIT 5N6 Flutter complet");
LogSingleton.Get.LogAndWriteLine(" FAIT 5N6 Flutter complet");
}

private static async Task InstallFlutter()
{
Utils.LogAndWriteLine("Installation Flutter démarré");
LogSingleton.Get.LogAndWriteLine("Installation Flutter démarré");
// ajouter flutter au path
Utils.AddToPath(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "flutter", "bin"));
// TODO remove this in favor of cache flutter
Expand All @@ -67,12 +67,12 @@ await Utils.Unzip7zFileAsync(
Utils.RunCommand(Program.PathToFlutter() +" pub global activate devtools");
// create a fake project to initialize flutter
Utils.RunCommand(Program.PathToFlutter() +" create fake_start;cd fake_start;flutter run");
Utils.LogAndWriteLine(" FAIT Installation Flutter complet");
LogSingleton.Get.LogAndWriteLine(" FAIT Installation Flutter complet");
}

public static async Task Handle5N6FlutterFirebaseAsync()
{
Utils.LogAndWriteLine("Installation de 5N6 flutter + firebase ...");
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") );
Expand Down Expand Up @@ -110,7 +110,7 @@ await Task.WhenAll(
Utils.RunCommand("npm install -g firebase-tools");
Utils.RunCommand("dart pub global activate flutterfire_cli");
await Utils.StartAndroidStudio();
Utils.LogAndWriteLine(" FAIT 5N6 Flutter + firebase complet");
LogSingleton.Get.LogAndWriteLine(" FAIT 5N6 Flutter + firebase complet");
}

public static async Task DownloadRepo5N6()
Expand Down
Loading

0 comments on commit a367d54

Please sign in to comment.