mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
rework tests and log handling
This commit is contained in:
parent
4ee08d8290
commit
ccb10d6b44
@ -13,40 +13,63 @@ namespace Wabbajack.Test
|
||||
{
|
||||
public TestContext TestContext { get; set; }
|
||||
|
||||
[TestMethod]
|
||||
public void TestDirectMatch()
|
||||
private TestUtils utils { get; set; }
|
||||
|
||||
[TestInitialize]
|
||||
public void TestInitialize()
|
||||
{
|
||||
var utils = new TestUtils();
|
||||
|
||||
utils = new TestUtils();
|
||||
utils.GameName = "Skyrim Special Edition";
|
||||
var profile = utils.AddProfile();
|
||||
var mod = utils.AddMod();
|
||||
var test_pex = utils.AddModFile(mod, @"Data\scripts\test.pex", 10);
|
||||
utils.Configure();
|
||||
|
||||
utils.AddManualDownload(
|
||||
new Dictionary<string, byte[]>() {{"/baz/biz.pex", File.ReadAllBytes(test_pex)}});
|
||||
|
||||
Utils.SetStatusFn((f, idx) => { });
|
||||
Utils.SetLoggerFn(f => TestContext.WriteLine(f));
|
||||
WorkQueue.Init((x, y, z) => { }, (min, max) => { });
|
||||
|
||||
VirtualFileSystem.Reconfigure(utils.TestFolder);
|
||||
var compiler = new Compiler(utils.MO2Folder, msg => TestContext.WriteLine(msg));
|
||||
compiler.ShowReportWhenFinished = false;
|
||||
compiler.MO2Profile = profile;
|
||||
}
|
||||
|
||||
[TestCleanup]
|
||||
public void TestCleanup()
|
||||
{
|
||||
utils.Dispose();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestDirectMatch()
|
||||
{
|
||||
|
||||
var profile = utils.AddProfile();
|
||||
var mod = utils.AddMod();
|
||||
var test_pex = utils.AddModFile(mod, @"Data\scripts\test.pex", 10);
|
||||
|
||||
utils.Configure();
|
||||
|
||||
utils.AddManualDownload(
|
||||
new Dictionary<string, byte[]> {{"/baz/biz.pex", File.ReadAllBytes(test_pex)}});
|
||||
|
||||
|
||||
var compiler = ConfigureCompiler(profile);
|
||||
Assert.IsTrue(compiler.Compile());
|
||||
|
||||
Install(compiler);
|
||||
utils.VerifyInstalledFile(mod, @"Data\scripts\test.pex");
|
||||
}
|
||||
|
||||
var installer = new Installer(compiler.ModList, utils.InstallFolder, TestContext.WriteLine);
|
||||
|
||||
private void Install(Compiler compiler)
|
||||
{
|
||||
var installer = new Installer(compiler.ModList, utils.InstallFolder);
|
||||
installer.DownloadFolder = utils.DownloadsFolder;
|
||||
installer.GameFolder = utils.GameFolder;
|
||||
installer.Install();
|
||||
}
|
||||
|
||||
utils.VerifyInstalledFile(mod, @"Data\scripts\test.pex");
|
||||
|
||||
utils.Dispose();
|
||||
|
||||
private Compiler ConfigureCompiler(string profile)
|
||||
{
|
||||
VirtualFileSystem.Reconfigure(utils.TestFolder);
|
||||
var compiler = new Compiler(utils.MO2Folder);
|
||||
compiler.MO2Profile = profile;
|
||||
compiler.ShowReportWhenFinished = false;
|
||||
return compiler;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -453,7 +453,7 @@ namespace Wabbajack
|
||||
ModListName = profile_name;
|
||||
Mode = "Building";
|
||||
|
||||
var tmp_compiler = new Compiler(mo2folder, Utils.Log);
|
||||
var tmp_compiler = new Compiler(mo2folder);
|
||||
DownloadLocation = tmp_compiler.MO2DownloadsFolder;
|
||||
|
||||
_mo2Folder = mo2folder;
|
||||
@ -472,7 +472,7 @@ namespace Wabbajack
|
||||
UIReady = false;
|
||||
if (Mode == "Installing")
|
||||
{
|
||||
var installer = new Installer(_modList, Location, msg => LogMsg(msg));
|
||||
var installer = new Installer(_modList, Location);
|
||||
|
||||
installer.IgnoreMissingFiles = IgnoreMissingFiles;
|
||||
installer.DownloadFolder = DownloadLocation;
|
||||
@ -500,7 +500,7 @@ namespace Wabbajack
|
||||
}
|
||||
else
|
||||
{
|
||||
var compiler = new Compiler(_mo2Folder, msg => LogMsg(msg));
|
||||
var compiler = new Compiler(_mo2Folder);
|
||||
compiler.IgnoreMissingFiles = IgnoreMissingFiles;
|
||||
compiler.MO2Profile = ModListName;
|
||||
var th = new Thread(() =>
|
||||
|
@ -36,10 +36,9 @@ namespace Wabbajack
|
||||
|
||||
public string MO2Profile;
|
||||
|
||||
public Compiler(string mo2_folder, Action<string> log_fn)
|
||||
public Compiler(string mo2_folder)
|
||||
{
|
||||
MO2Folder = mo2_folder;
|
||||
Log_Fn = log_fn;
|
||||
MO2Ini = Path.Combine(MO2Folder, "ModOrganizer.ini").LoadIniFile();
|
||||
GamePath = ((string) MO2Ini.General.gamePath).Replace("\\\\", "\\");
|
||||
}
|
||||
@ -67,7 +66,6 @@ namespace Wabbajack
|
||||
|
||||
public string MO2ProfileDir => Path.Combine(MO2Folder, "profiles", MO2Profile);
|
||||
|
||||
public Action<string> Log_Fn { get; }
|
||||
public List<Directive> InstallDirectives { get; private set; }
|
||||
public string NexusKey { get; private set; }
|
||||
internal UserStatus User { get; private set; }
|
||||
@ -84,26 +82,19 @@ namespace Wabbajack
|
||||
|
||||
public HashSet<string> SelectedProfiles { get; set; } = new HashSet<string>();
|
||||
|
||||
public void Info(string msg, params object[] args)
|
||||
public void Info(string msg)
|
||||
{
|
||||
if (args.Length > 0)
|
||||
msg = string.Format(msg, args);
|
||||
Log_Fn(msg);
|
||||
Utils.Log(msg);
|
||||
}
|
||||
|
||||
public void Status(string msg, params object[] args)
|
||||
public void Status(string msg)
|
||||
{
|
||||
if (args.Length > 0)
|
||||
msg = string.Format(msg, args);
|
||||
WorkQueue.Report(msg, 0);
|
||||
}
|
||||
|
||||
|
||||
private void Error(string msg, params object[] args)
|
||||
private void Error(string msg)
|
||||
{
|
||||
if (args.Length > 0)
|
||||
msg = string.Format(msg, args);
|
||||
Log_Fn(msg);
|
||||
Utils.Log(msg);
|
||||
throw new Exception(msg);
|
||||
}
|
||||
|
||||
@ -187,7 +178,7 @@ namespace Wabbajack
|
||||
.DistinctBy(f => f.Path)
|
||||
.ToList();
|
||||
|
||||
Info("Found {0} files to build into mod list", AllFiles.Count);
|
||||
Info($"Found {AllFiles.Count} files to build into mod list");
|
||||
|
||||
ExtraFiles = new ConcurrentBag<Directive>();
|
||||
|
||||
@ -214,9 +205,9 @@ namespace Wabbajack
|
||||
results = results.Concat(ExtraFiles).ToList();
|
||||
|
||||
var nomatch = results.OfType<NoMatch>();
|
||||
Info("No match for {0} files", nomatch.Count());
|
||||
Info($"No match for {nomatch.Count()} files");
|
||||
foreach (var file in nomatch)
|
||||
Info(" {0}", file.To);
|
||||
Info($" {file.To}");
|
||||
if (nomatch.Count() > 0)
|
||||
{
|
||||
if (IgnoreMissingFiles)
|
||||
@ -311,7 +302,7 @@ namespace Wabbajack
|
||||
.GroupBy(p => p.ArchiveHashPath[0])
|
||||
.ToList();
|
||||
|
||||
Info("Patching building patches from {0} archives", groups.Count);
|
||||
Info($"Patching building patches from {groups.Count} archives");
|
||||
var absolute_paths = AllFiles.ToDictionary(e => e.Path, e => e.AbsolutePath);
|
||||
groups.PMap(group => BuildArchivePatches(group.Key, group, absolute_paths));
|
||||
|
||||
@ -330,7 +321,7 @@ namespace Wabbajack
|
||||
// Now Create the patches
|
||||
group.PMap(entry =>
|
||||
{
|
||||
Info("Patching {0}", entry.To);
|
||||
Info($"Patching {entry.To}");
|
||||
using (var origin = by_path[string.Join("|", entry.ArchiveHashPath.Skip(1))].OpenRead())
|
||||
using (var output = new MemoryStream())
|
||||
{
|
||||
@ -385,14 +376,10 @@ namespace Wabbajack
|
||||
if (archives.TryGetValue(sha, out var found))
|
||||
{
|
||||
if (found.IniData == null)
|
||||
Error(
|
||||
"No download metadata found for {0}, please use MO2 to query info or add a .meta file and try again.",
|
||||
found.Name);
|
||||
Error($"No download metadata found for {found.Name}, please use MO2 to query info or add a .meta file and try again.");
|
||||
var general = found.IniData.General;
|
||||
if (general == null)
|
||||
Error(
|
||||
"No General section in mod metadata found for {0}, please use MO2 to query info or add the info and try again.",
|
||||
found.Name);
|
||||
Error($"No General section in mod metadata found for {found.Name}, please use MO2 to query info or add the info and try again.");
|
||||
|
||||
Archive result;
|
||||
|
||||
@ -490,7 +477,7 @@ namespace Wabbajack
|
||||
}
|
||||
else
|
||||
{
|
||||
Error("No way to handle archive {0} but it's required by the modlist", found.Name);
|
||||
Error($"No way to handle archive {found.Name} but it's required by the modlist");
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -503,7 +490,7 @@ namespace Wabbajack
|
||||
|
||||
Info($"Checking link for {found.Name}");
|
||||
|
||||
var installer = new Installer(null, "", Utils.Log);
|
||||
var installer = new Installer(null, "");
|
||||
installer.NexusAPIKey = NexusKey;
|
||||
if (!installer.DownloadArchive(result, false))
|
||||
Error(
|
||||
@ -512,14 +499,14 @@ namespace Wabbajack
|
||||
return result;
|
||||
}
|
||||
|
||||
Error("No match found for Archive sha: {0} this shouldn't happen", sha);
|
||||
Error($"No match found for Archive sha: {sha} this shouldn't happen");
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
private Directive RunStack(IEnumerable<Func<RawSourceFile, Directive>> stack, RawSourceFile source)
|
||||
{
|
||||
Status("Compiling {0}", source.Path);
|
||||
Status($"Compiling {source.Path}");
|
||||
foreach (var f in stack)
|
||||
{
|
||||
var result = f(source);
|
||||
@ -1137,7 +1124,7 @@ namespace Wabbajack
|
||||
var settings = new JsonSerializerSettings {TypeNameHandling = TypeNameHandling.Auto};
|
||||
var executable = Assembly.GetExecutingAssembly().Location;
|
||||
var out_path = Path.Combine(Path.GetDirectoryName(executable), MO2Profile + ".exe");
|
||||
Info("Patching Executable {0}", Path.GetFileName(out_path));
|
||||
Info($"Patching Executable {Path.GetFileName(out_path)}");
|
||||
File.Copy(executable, out_path, true);
|
||||
using (var os = File.OpenWrite(out_path))
|
||||
using (var bw = new BinaryWriter(os))
|
||||
|
@ -25,11 +25,10 @@ namespace Wabbajack
|
||||
{
|
||||
private string _downloadsFolder;
|
||||
|
||||
public Installer(ModList mod_list, string output_folder, Action<string> log_fn)
|
||||
public Installer(ModList mod_list, string output_folder)
|
||||
{
|
||||
Outputfolder = output_folder;
|
||||
ModList = mod_list;
|
||||
Log_Fn = log_fn;
|
||||
}
|
||||
|
||||
public VirtualFileSystem VFS => VirtualFileSystem.VFS;
|
||||
@ -43,39 +42,30 @@ namespace Wabbajack
|
||||
}
|
||||
|
||||
public ModList ModList { get; }
|
||||
public Action<string> Log_Fn { get; }
|
||||
public Dictionary<string, string> HashedArchives { get; private set; }
|
||||
|
||||
public string NexusAPIKey { get; set; }
|
||||
public bool IgnoreMissingFiles { get; internal set; }
|
||||
public string GameFolder { get; set; }
|
||||
|
||||
public void Info(string msg, params object[] args)
|
||||
public void Info(string msg)
|
||||
{
|
||||
if (args.Length > 0)
|
||||
msg = string.Format(msg, args);
|
||||
Log_Fn(msg);
|
||||
Utils.Log(msg);
|
||||
}
|
||||
|
||||
public void Status(string msg, params object[] args)
|
||||
public void Status(string msg)
|
||||
{
|
||||
if (args.Length > 0)
|
||||
msg = string.Format(msg, args);
|
||||
WorkQueue.Report(msg, 0);
|
||||
}
|
||||
|
||||
public void Status(int progress, string msg, params object[] args)
|
||||
public void Status(string msg, int progress)
|
||||
{
|
||||
if (args.Length > 0)
|
||||
msg = string.Format(msg, args);
|
||||
WorkQueue.Report(msg, progress);
|
||||
}
|
||||
|
||||
private void Error(string msg, params object[] args)
|
||||
private void Error(string msg)
|
||||
{
|
||||
if (args.Length > 0)
|
||||
msg = string.Format(msg, args);
|
||||
Log_Fn(msg);
|
||||
Utils.Log(msg);
|
||||
throw new Exception(msg);
|
||||
}
|
||||
|
||||
@ -121,7 +111,7 @@ namespace Wabbajack
|
||||
if (missing.Count > 0)
|
||||
{
|
||||
foreach (var a in missing)
|
||||
Info("Unable to download {0}", a.Name);
|
||||
Info($"Unable to download {a.Name}");
|
||||
if (IgnoreMissingFiles)
|
||||
Info("Missing some archives, but continuing anyways at the request of the user");
|
||||
else
|
||||
@ -266,7 +256,7 @@ namespace Wabbajack
|
||||
.OfType<InlineFile>()
|
||||
.PMap(directive =>
|
||||
{
|
||||
Status("Writing included file {0}", directive.To);
|
||||
Status($"Writing included file {directive.To}");
|
||||
var out_path = Path.Combine(Outputfolder, directive.To);
|
||||
if (File.Exists(out_path)) File.Delete(out_path);
|
||||
if (directive is RemappedInlineFile)
|
||||
@ -362,7 +352,7 @@ namespace Wabbajack
|
||||
var on_finish = VFS.Stage(vfiles.Select(f => f.FromFile).Distinct());
|
||||
|
||||
|
||||
Status("Copying files for {0}", archive.Name);
|
||||
Status($"Copying files for {archive.Name}");
|
||||
|
||||
vfiles.DoIndexed((idx, file) =>
|
||||
{
|
||||
@ -377,7 +367,7 @@ namespace Wabbajack
|
||||
foreach (var to_patch in grouping.OfType<PatchedFromArchive>())
|
||||
using (var patch_stream = new MemoryStream())
|
||||
{
|
||||
Status("Patching {0}", Path.GetFileName(to_patch.To));
|
||||
Status($"Patching {Path.GetFileName(to_patch.To)}");
|
||||
// Read in the patch data
|
||||
|
||||
var patch_data = to_patch.Patch;
|
||||
@ -404,7 +394,7 @@ namespace Wabbajack
|
||||
private void DownloadArchives()
|
||||
{
|
||||
var missing = ModList.Archives.Where(a => !HashedArchives.ContainsKey(a.Hash)).ToList();
|
||||
Info("Missing {0} archives", missing.Count);
|
||||
Info($"Missing {missing.Count} archives");
|
||||
|
||||
Info("Getting Nexus API Key, if a browser appears, please accept");
|
||||
if (ModList.Archives.OfType<NexusMod>().Any())
|
||||
@ -501,7 +491,7 @@ namespace Wabbajack
|
||||
var file_link = new Uri(m.URL);
|
||||
var node = client.GetNodeFromLink(file_link);
|
||||
if (!download) return true;
|
||||
Status("Downloading MEGA file: {0}", m.Name);
|
||||
Status($"Downloading MEGA file: {m.Name}");
|
||||
|
||||
var output_path = Path.Combine(DownloadFolder, m.Name);
|
||||
client.DownloadFile(file_link, output_path);
|
||||
@ -588,14 +578,14 @@ namespace Wabbajack
|
||||
{
|
||||
var read = webs.Read(buffer, 0, buffer_size);
|
||||
if (read == 0) break;
|
||||
Status((int) (total_read * 100 / content_size), "Downloading {0}", archive.Name);
|
||||
Status("Downloading {archive.Name}", (int)(total_read * 100 / content_size));
|
||||
|
||||
fs.Write(buffer, 0, read);
|
||||
total_read += read;
|
||||
}
|
||||
}
|
||||
|
||||
Status("Hashing {0}", archive.Name);
|
||||
Status($"Hashing {archive.Name}");
|
||||
HashArchive(output_path);
|
||||
return true;
|
||||
}
|
||||
@ -623,7 +613,7 @@ namespace Wabbajack
|
||||
if (cache.FileExists() && new FileInfo(cache).LastWriteTime >= new FileInfo(e).LastWriteTime)
|
||||
return File.ReadAllText(cache);
|
||||
|
||||
Status("Hashing {0}", Path.GetFileName(e));
|
||||
Status($"Hashing {Path.GetFileName(e)}");
|
||||
File.WriteAllText(cache, e.FileSHA256());
|
||||
return HashArchive(e);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user