Merge pull request #154 from wabbajack-tools/move-dont-copy

Move files into the install folder
This commit is contained in:
Timothy Baldridge 2019-11-06 21:56:16 -07:00 committed by GitHub
commit fdfe9d36f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 5 deletions

View File

@ -397,13 +397,29 @@ namespace Wabbajack.Lib
Status($"Copying files for {archive.Name}");
vfiles.DoIndexed((idx, file) =>
void CopyFile(string from, string to, bool use_move)
{
if (File.Exists(to))
File.Delete(to);
if (use_move)
File.Move(from, to);
else
File.Copy(from, to);
}
vfiles.GroupBy(f => f.FromFile)
.DoIndexed((idx, group) =>
{
Utils.Status("Installing files", idx * 100 / vfiles.Count);
var dest = Path.Combine(Outputfolder, file.To);
if (File.Exists(dest))
File.Delete(dest);
File.Copy(file.FromFile.StagedPath, dest);
var first_dest = Path.Combine(Outputfolder, group.First().To);
CopyFile(group.Key.StagedPath, first_dest, true);
foreach (var copy in group.Skip(1))
{
var next_dest = Path.Combine(Outputfolder, copy.To);
CopyFile(first_dest, next_dest, false);
}
});
Status("Unstaging files");

View File

@ -34,6 +34,29 @@ namespace Wabbajack.Test
utils.VerifyInstalledFile(mod, @"Data\scripts\test.pex");
}
[TestMethod]
public void TestDuplicateFilesAreCopied()
{
var profile = utils.AddProfile();
var mod = utils.AddMod();
var test_pex = utils.AddModFile(mod, @"Data\scripts\test.pex", 10);
// Make a copy to make sure it gets picked up and moved around.
File.Copy(test_pex, test_pex + ".copy");
utils.Configure();
utils.AddManualDownload(
new Dictionary<string, byte[]> { { "/baz/biz.pex", File.ReadAllBytes(test_pex) } });
CompileAndInstall(profile);
utils.VerifyInstalledFile(mod, @"Data\scripts\test.pex");
utils.VerifyInstalledFile(mod, @"Data\scripts\test.pex.copy");
}
[TestMethod]
public void CleanedESMTest()
{