From 5ba16ec04585829b8be380169fd04491b0b95493 Mon Sep 17 00:00:00 2001 From: PierreOlivierBrillant Date: Wed, 16 Oct 2024 15:06:15 -0400 Subject: [PATCH] =?UTF-8?q?Fonction=20supprimer=20g=C3=A9n=C3=A9rique?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scriptsharp/ScriptSharp/Utils.cs | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/scriptsharp/ScriptSharp/Utils.cs b/scriptsharp/ScriptSharp/Utils.cs index 70f8b41..6d42ad7 100644 --- a/scriptsharp/ScriptSharp/Utils.cs +++ b/scriptsharp/ScriptSharp/Utils.cs @@ -2,6 +2,7 @@ using System.Diagnostics; using System.IO; using System.IO.Compression; +using System.Linq; using System.Net.Http; using System.Threading.Tasks; @@ -373,13 +374,9 @@ public static void DeleteAll() DeleteThis( Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "AppData", "Local", "Android")); DeleteThis( Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), - "AppData", "Local", "Google", "AndroidStudio2024.2")); + "AppData", "Local", "Google", "AndroidStudio*")); DeleteThis( Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), - "AppData", "Roaming", "Google", "AndroidStudio2024.2")); - DeleteThis( Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), - "AppData", "Local", "Google", "AndroidStudio2024.1")); - DeleteThis( Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), - "AppData", "Roaming", "Google", "AndroidStudio2024.1")); + "AppData", "Roaming", "Google", "AndroidStudio*")); DeleteThis(Environment.GetFolderPath(Environment.SpecialFolder.Desktop)); DeleteThis(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".android")); DeleteThis(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".gradle")); @@ -389,12 +386,24 @@ public static void DeleteAll() private static void DeleteThis(string path) { - try { - if (Directory.Exists(path)) - { Directory.Delete(path, true); } + try + { + DirectoryInfo parent = Directory.GetParent(path)!; + string pattern = new DirectoryInfo(path).Name; + foreach (string dir in Directory.GetDirectories(parent.FullName, pattern)) + { + Directory.Delete(dir); + } + + foreach (string file in Directory.GetFiles(parent.FullName, pattern)) + { + File.Delete(file); + } } catch (Exception ex) - { Console.WriteLine($"An error occurred while deleting the directory {path}: {ex.Message} {ex.Data}"); } + { + Console.WriteLine($"An error occurred while deleting the directory {path}: {ex.Message} {ex.Data}"); + } } }