Skip to content

Commit

Permalink
The pending installer now keeps copying when one file errors, allows …
Browse files Browse the repository at this point in the history
…mods to be installed more sanely
  • Loading branch information
nike4613 committed Apr 6, 2019
1 parent 527be5a commit 6147cbc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
7 changes: 6 additions & 1 deletion IPA.Injector/Updates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,12 @@ public static void InstallPendingUpdates()

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)
{
Expand Down
25 changes: 18 additions & 7 deletions IPA.Loader/Utilities/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,10 @@ public static string GetRelativePath(string file, string folder)
/// </summary>
/// <param name="source">the source directory</param>
/// <param name="target">the destination directory</param>
/// <param name="appendFileName"></param>
public static void CopyAll(DirectoryInfo source, DirectoryInfo target, string appendFileName = "")
/// <param name="appendFileName">the filename of the file to append together</param>
/// <param name="onCopyException">a delegate called when there is an error copying. Return true to keep going.</param>
public static void CopyAll(DirectoryInfo source, DirectoryInfo target, string appendFileName = "",
Func<Exception, FileInfo, bool> onCopyException = null)
{
if (source.FullName.ToLower() == target.FullName.ToLower())
{
Expand All @@ -104,18 +106,27 @@ public static void CopyAll(DirectoryInfo source, DirectoryInfo target, string ap
// 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.
foreach (DirectoryInfo diSourceSubDir in source.GetDirectories())
{
DirectoryInfo nextTargetSubDir =
target.CreateSubdirectory(diSourceSubDir.Name);
CopyAll(diSourceSubDir, nextTargetSubDir, appendFileName);
CopyAll(diSourceSubDir, nextTargetSubDir, appendFileName, onCopyException);
}
}
}
Expand Down

0 comments on commit 6147cbc

Please sign in to comment.