From 5ada28cec3634b67b83e7b7bae29f34609a65a0e Mon Sep 17 00:00:00 2001 From: rounk-ctrl <70931017+rounk-ctrl@users.noreply.github.com> Date: Sat, 23 Sep 2023 10:16:15 +0400 Subject: [PATCH] mmchelper.cs --- Rectify11Installer/Core/Backend/MMCHelper.cs | 37 +++++++++----------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/Rectify11Installer/Core/Backend/MMCHelper.cs b/Rectify11Installer/Core/Backend/MMCHelper.cs index 0d010ef45..c9e9f56ae 100644 --- a/Rectify11Installer/Core/Backend/MMCHelper.cs +++ b/Rectify11Installer/Core/Backend/MMCHelper.cs @@ -24,7 +24,9 @@ public static bool PatchAll() List r11Msc = new(Directory.GetFiles(Path.Combine(Variables.r11Files, "mmc"), "*.msc", SearchOption.TopDirectoryOnly)); CopyFiles(langMsc, usaMsc, r11Msc); + // exit if current language is en-us if (CultureInfo.CurrentUICulture.Name == "en-US") return true; + List r11LangMsc = new(Directory.GetFiles(Path.Combine(tempDir, "msc", CultureInfo.CurrentUICulture.Name), "*.msc", SearchOption.TopDirectoryOnly)); List sysMsc = new(Directory.GetFiles(Path.Combine(tempDir, "msc", CultureInfo.CurrentUICulture.Name, "temp"), "*.msc", SearchOption.TopDirectoryOnly)); for (var i = 0; i < r11LangMsc.Count; i++) @@ -37,7 +39,8 @@ public static bool PatchAll() } } } - Directory.Delete(Path.Combine(tempDir, "msc", CultureInfo.CurrentUICulture.Name, "temp"), true); + + Helper.SafeDirectoryDeletion(Path.Combine(tempDir, "msc", CultureInfo.CurrentUICulture.Name, "temp"), false); var msc = Path.Combine(tempDir, "msc"); if (CultureInfo.CurrentUICulture.Name != "en-US") { @@ -76,32 +79,25 @@ private static void ReplaceString(string file, string r11file) } private static void CopyFiles(IReadOnlyList langMsc, IList usaMsc, IReadOnlyList r11Msc) { - if (Directory.Exists(Path.Combine(tempDir, "msc"))) - { - Directory.Delete(Path.Combine(tempDir, "msc")); - } + string path = Path.Combine(tempDir, "msc"); + Helper.SafeDirectoryDeletion(path, false); + Directory.CreateDirectory(Path.Combine(tempDir, "msc")); if (CultureInfo.CurrentUICulture.Name != "en-US") { - if (Directory.Exists(Path.Combine(tempDir, "msc", CultureInfo.CurrentUICulture.Name))) - { - Directory.Delete(Path.Combine(tempDir, "msc", CultureInfo.CurrentUICulture.Name)); - } - Directory.CreateDirectory(Path.Combine(tempDir, "msc", CultureInfo.CurrentUICulture.Name)); + path = Path.Combine(tempDir, "msc", CultureInfo.CurrentUICulture.Name); + Helper.SafeDirectoryDeletion(path, false); + Directory.CreateDirectory(path); - if (Directory.Exists(Path.Combine(tempDir, "msc", CultureInfo.CurrentUICulture.Name, "temp"))) - { - Directory.Delete(Path.Combine(tempDir, "msc", CultureInfo.CurrentUICulture.Name, "temp")); - } - Directory.CreateDirectory(Path.Combine(tempDir, "msc", CultureInfo.CurrentUICulture.Name, "temp")); + path = Path.Combine(tempDir, "msc", CultureInfo.CurrentUICulture.Name, "temp"); + Helper.SafeDirectoryDeletion(path, false); + Directory.CreateDirectory(path); } else { - if (Directory.Exists(Path.Combine(tempDir, "msc", "en-US"))) - { - Directory.Delete(Path.Combine(tempDir, "msc", "en-US")); - } - Directory.CreateDirectory(Path.Combine(tempDir, "msc", "en-US")); + path = Path.Combine(tempDir, "msc", "en-US"); + Helper.SafeDirectoryDeletion(path, false); + Directory.CreateDirectory(path); } if (CultureInfo.CurrentUICulture.Name != "en-US") { @@ -122,7 +118,6 @@ private static void CopyFiles(IReadOnlyList langMsc, IList usaMs for (var i = 0; i < langMsc.Count; i++) { if (Path.GetFileName(langMsc[i]) != Path.GetFileName(r11Msc[j])) continue; - Debug.WriteLine(langMsc[i]); if (File.Exists(Path.Combine(backupDir, "msc", CultureInfo.CurrentUICulture.Name, Path.GetFileName(r11Msc[j])))) continue; if (Path.GetFileName(langMsc[i]) == "lusrmgr.msc"