diff --git a/Wabbajack.BuildServer/Controllers/Heartbeat.cs b/Wabbajack.BuildServer/Controllers/Heartbeat.cs index 27661568..16680d1e 100644 --- a/Wabbajack.BuildServer/Controllers/Heartbeat.cs +++ b/Wabbajack.BuildServer/Controllers/Heartbeat.cs @@ -67,23 +67,5 @@ namespace Wabbajack.BuildServer.Controllers } return Ok(string.Join("\n", lst)); } - - [HttpPost("export_inis")] - [Authorize] - public async Task ExportInis() - { - if (!Directory.Exists("exported_inis")) - Directory.CreateDirectory("exported_inis"); - - var loaded = 0; - foreach (var ini in await Db.DownloadStates.AsQueryable().ToListAsync()) - { - var file = Path.Combine("exported_inis", ini.Hash.FromBase64().ToHex() + "_" + ini.Key.StringSHA256Hex() + ".ini"); - Alphaleonis.Win32.Filesystem.File.WriteAllLines(file, ini.State.GetMetaIni()); - loaded += 1; - } - - return Ok(loaded); - } } } diff --git a/Wabbajack.Common/AsyncBlockingConnection.cs b/Wabbajack.Common/AsyncBlockingConnection.cs deleted file mode 100644 index 3d7dd04a..00000000 --- a/Wabbajack.Common/AsyncBlockingConnection.cs +++ /dev/null @@ -1,46 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Concurrent; -using System.Collections.Generic; -using System.Threading; -using System.Threading.Tasks; - -namespace Wabbajack.Common -{ - public class AsyncBlockingCollection : IDisposable - { - private readonly ConcurrentQueue _collection; - private bool isDisposed = false; - - public AsyncBlockingCollection() - { - _collection = new ConcurrentQueue(); - } - - public void Add(T val) - { - _collection.Enqueue(val); - } - - public async ValueTask<(bool found, T val)> TryTake(TimeSpan timeout, CancellationToken token) - { - var startTime = DateTime.Now; - while (true) - { - if (_collection.TryDequeue(out T result)) - { - return (true, result); - } - - if (DateTime.Now - startTime > timeout || token.IsCancellationRequested || isDisposed) - return (false, default); - await Task.Delay(100); - } - } - - public void Dispose() - { - isDisposed = true; - } - } -} diff --git a/Wabbajack.Lib/MO2Compiler.cs b/Wabbajack.Lib/MO2Compiler.cs index 2963eeb0..6f0d222e 100644 --- a/Wabbajack.Lib/MO2Compiler.cs +++ b/Wabbajack.Lib/MO2Compiler.cs @@ -132,16 +132,17 @@ namespace Wabbajack.Lib CompilingGame.MO2Name.Replace(" ", "") //eg: Fallout 4 -> Fallout4 }; - var lootGameDir = lootGameDirs.Select(x => Path.Combine(lootPath, x)) - .FirstOrDefault(Directory.Exists); + var lootGameDir = lootGameDirs.Select(x => lootPath.Combine(x)) + .FirstOrDefault(p => p.IsDirectory); - if (lootGameDir != null) + if (lootGameDir != default) { Utils.Log($"Found LOOT game folder at {lootGameDir}"); - lootFiles = Directory.EnumerateFiles(lootGameDir, "userlist.yaml", SearchOption.TopDirectoryOnly) - .Where(p => p.FileExists()) + lootFiles = lootGameDir.EnumerateFiles(false) + .Where(p => p.FileName == (RelativePath)"userlist.yaml") + .Where(p => p.IsFile) .Select(p => new RawSourceFile(VFS.Index.ByRootPath[p], - Path.Combine(Consts.LOOTFolderFilesDir, p.RelativeTo(lootPath)))); + Consts.LOOTFolderFilesDir.Combine(p.RelativeTo(lootPath)))); if (!lootFiles.Any()) Utils.Log( diff --git a/Wabbajack.Lib/zEditIntegration.cs b/Wabbajack.Lib/zEditIntegration.cs index d3146278..98b97498 100644 --- a/Wabbajack.Lib/zEditIntegration.cs +++ b/Wabbajack.Lib/zEditIntegration.cs @@ -37,7 +37,7 @@ namespace Wabbajack.Lib public class IncludeZEditPatches : ACompilationStep { - private Dictionary _mergesIndexed; + private Dictionary _mergesIndexed; public IncludeZEditPatches(ACompiler compiler) : base(compiler) { @@ -48,7 +48,7 @@ namespace Wabbajack.Lib if (!havezEdit) { - _mergesIndexed = new Dictionary(); + _mergesIndexed = new Dictionary(); return; } @@ -66,7 +66,7 @@ namespace Wabbajack.Lib _mergesIndexed = merges.ToDictionary( - m => Path.Combine(_mo2Compiler.MO2Folder, Consts.MO2ModFolderName, m.Key.name, m.Key.filename), + m => _mo2Compiler.MO2Folder.Combine((string)Consts.MO2ModFolderName, m.Key.name, m.Key.filename), m => m.First()); } @@ -76,28 +76,29 @@ namespace Wabbajack.Lib var result = source.EvolveTo(); result.Sources = merge.plugins.Select(f => { - var origPath = Path.Combine(f.dataFolder, f.filename); + var origPath = (AbsolutePath)Path.Combine(f.dataFolder, f.filename); var paths = new[] { origPath, - origPath + ".mohidden", - Path.Combine(Path.GetDirectoryName(origPath), "optional", Path.GetFileName(origPath)) + origPath.WithExtension(new Extension(".mohidden")), + origPath.Parent.Combine((RelativePath)"optional", origPath.FileName) }; - var absPath = paths.FirstOrDefault(File.Exists); + var absPath = paths.FirstOrDefault(file => file.IsFile); - if (absPath == null) + if (absPath == default) throw new InvalidDataException( $"File {origPath} is required to build {merge.filename} but it doesn't exist searched in: \n" + string.Join("\n", paths)); - string hash = ""; + Hash hash; try { - hash = _compiler.VFS.Index.ByFullPath[absPath].Hash; + hash = _compiler.VFS.Index.ByRootPath[absPath].Hash; } catch (KeyNotFoundException e) { Utils.ErrorThrow(e, $"Could not find the key {absPath} in the VFS Index dictionary!"); + return null; } return new SourcePatch @@ -107,15 +108,15 @@ namespace Wabbajack.Lib }; }).ToList(); - var src_data = result.Sources.Select(f => _mo2Compiler.MO2Folder.Combine(f.RelativePath).ReadAllBytes()) + var srcData = result.Sources.Select(f => _mo2Compiler.MO2Folder.Combine(f.RelativePath).ReadAllBytes()) .ConcatArrays(); - var dst_data = File.ReadAllBytes(source.AbsolutePath); + var dstData = await source.AbsolutePath.ReadAllBytesAsync(); await using (var ms = new MemoryStream()) { - await Utils.CreatePatch(src_data, dst_data, ms); - result.PatchID = _compiler.IncludeFile(ms.ToArray()); + await Utils.CreatePatch(srcData, dstData, ms); + result.PatchID = await _compiler.IncludeFile(ms.ToArray()); } return result; @@ -175,17 +176,17 @@ namespace Wabbajack.Lib await installer.ModList .Directives .OfType() - .PMap(installer.Queue, m => + .PMap(installer.Queue, async m => { Utils.LogStatus($"Generating zEdit merge: {m.To}"); - var src_data = m.Sources.Select(s => File.ReadAllBytes(Path.Combine(installer.OutputFolder, s.RelativePath))) + var srcData = m.Sources.Select(s => installer.OutputFolder.Combine(s.RelativePath).ReadAllBytes()) .ConcatArrays(); - var patch_data = installer.LoadBytesFromPath(m.PatchID); + var patchData = await installer.LoadBytesFromPath(m.PatchID); - using (var fs = File.Open(Path.Combine(installer.OutputFolder, m.To), FileMode.Create)) - Utils.ApplyPatch(new MemoryStream(src_data), () => new MemoryStream(patch_data), fs); + await using var fs = installer.OutputFolder.Combine(m.To).Create(); + Utils.ApplyPatch(new MemoryStream(srcData), () => new MemoryStream(patchData), fs); }); } }