From 9d5d74b41f09ccc248e4b53e3adf27d81af23df9 Mon Sep 17 00:00:00 2001 From: Anairkoen Schno Date: Sat, 6 Apr 2019 12:35:27 -0500 Subject: [PATCH] The pending installer now keeps copying when one file errors, allows mods to be installed more sanely --- IPA.Injector/Updates.cs | 7 ++++++- IPA.Loader/Utilities/Utils.cs | 25 ++++++++++++++++++------- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/IPA.Injector/Updates.cs b/IPA.Injector/Updates.cs index 94522478..aea8891c 100644 --- a/IPA.Injector/Updates.cs +++ b/IPA.Injector/Updates.cs @@ -97,7 +97,12 @@ namespace IPA.Injector try { - Utils.CopyAll(new DirectoryInfo(pendingDir), new DirectoryInfo(BeatSaber.InstallPath)); + Utils.CopyAll(new DirectoryInfo(pendingDir), new DirectoryInfo(BeatSaber.InstallPath), onCopyException: (e, f) => + { + updater.Error($"Error copying file {Utils.GetRelativePath(f.FullName, pendingDir)} from Pending:"); + updater.Error(e); + return true; + }); } catch (Exception e) { diff --git a/IPA.Loader/Utilities/Utils.cs b/IPA.Loader/Utilities/Utils.cs index a702f5b3..b442e65b 100644 --- a/IPA.Loader/Utilities/Utils.cs +++ b/IPA.Loader/Utilities/Utils.cs @@ -87,8 +87,10 @@ namespace IPA.Utilities /// /// the source directory /// the destination directory - /// - public static void CopyAll(DirectoryInfo source, DirectoryInfo target, string appendFileName = "") + /// the filename of the file to append together + /// a delegate called when there is an error copying. Return true to keep going. + public static void CopyAll(DirectoryInfo source, DirectoryInfo target, string appendFileName = "", + Func onCopyException = null) { if (source.FullName.ToLower() == target.FullName.ToLower()) { @@ -104,10 +106,19 @@ namespace IPA.Utilities // Copy each file into it's new directory. foreach (FileInfo fi in source.GetFiles()) { - if (fi.Name == appendFileName) - File.AppendAllLines(Path.Combine(target.ToString(), fi.Name), File.ReadAllLines(fi.FullName)); - else - fi.CopyTo(Path.Combine(target.ToString(), fi.Name), true); + try + { + if (fi.Name == appendFileName) + File.AppendAllLines(Path.Combine(target.ToString(), fi.Name), File.ReadAllLines(fi.FullName)); + else + fi.CopyTo(Path.Combine(target.ToString(), fi.Name), true); + } + catch (Exception e) + { + var keepOn = onCopyException?.Invoke(e, fi); + if (!keepOn.Unwrap()) + throw; + } } // Copy each subdirectory using recursion. @@ -115,7 +126,7 @@ namespace IPA.Utilities { DirectoryInfo nextTargetSubDir = target.CreateSubdirectory(diSourceSubDir.Name); - CopyAll(diSourceSubDir, nextTargetSubDir, appendFileName); + CopyAll(diSourceSubDir, nextTargetSubDir, appendFileName, onCopyException); } } }