From fbe2f05f604a76be161ca3d53364ffee713db378 Mon Sep 17 00:00:00 2001 From: erri120 Date: Sun, 5 Jul 2020 17:11:52 +0200 Subject: [PATCH] IncludeSteamWorkshopItems fixes --- .../StoreHandlers/SteamHandler.cs | 6 +-- .../IncludeSteamWorkshopItems.cs | 39 +++++++++++++++---- Wabbajack.Lib/MO2Compiler.cs | 1 + 3 files changed, 36 insertions(+), 10 deletions(-) diff --git a/Wabbajack.Common/StoreHandlers/SteamHandler.cs b/Wabbajack.Common/StoreHandlers/SteamHandler.cs index 81aa3b77..72211510 100644 --- a/Wabbajack.Common/StoreHandlers/SteamHandler.cs +++ b/Wabbajack.Common/StoreHandlers/SteamHandler.cs @@ -23,7 +23,7 @@ namespace Wabbajack.Common.StoreHandlers { public readonly SteamGame Game; public int ItemID; - public int Size; + public long Size; public SteamWorkshopItem(SteamGame game) { @@ -210,7 +210,7 @@ namespace Wabbajack.Common.StoreHandlers .Where(f => f.IsFile) .Do(f => { - if (f.FileName.ToString() != $"appworkshop{game.ID}.acf") + if (f.FileName.ToString() != $"appworkshop_{game.ID}.acf") return; Utils.Log($"Found Steam Workshop item file {f} for \"{game.Name}\""); @@ -284,7 +284,7 @@ namespace Wabbajack.Common.StoreHandlers return; if (currentLine == bracketStart + 1) - if (!int.TryParse(GetVdfValue(l), out currentItem.Size)) + if (!long.TryParse(GetVdfValue(l), out currentItem.Size)) return; if (bracketStart == 0 || bracketEnd == 0 || currentItem.ItemID == 0 || currentItem.Size == 0) diff --git a/Wabbajack.Lib/CompilationSteps/IncludeSteamWorkshopItems.cs b/Wabbajack.Lib/CompilationSteps/IncludeSteamWorkshopItems.cs index f4f5ddbe..55aafa7c 100644 --- a/Wabbajack.Lib/CompilationSteps/IncludeSteamWorkshopItems.cs +++ b/Wabbajack.Lib/CompilationSteps/IncludeSteamWorkshopItems.cs @@ -1,5 +1,6 @@ using System; using System.Linq; +using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using Alphaleonis.Win32.Filesystem; @@ -10,31 +11,55 @@ namespace Wabbajack.Lib.CompilationSteps { public class IncludeSteamWorkshopItems : ACompilationStep { - private readonly SteamGame _game; private readonly Regex _regex = new Regex("steamWorkshopItem_\\d*\\.meta$"); + private readonly bool _isGenericGame; + private readonly SteamGame? _game; - public IncludeSteamWorkshopItems(ACompiler compiler, SteamGame steamGame) : base(compiler) + public IncludeSteamWorkshopItems(ACompiler compiler) : base(compiler) { - _game = steamGame; + var mo2Compiler = (MO2Compiler)compiler; + _isGenericGame = mo2Compiler.CompilingGame.IsGenericMO2Plugin; + _game = (SteamGame)StoreHandler.Instance.SteamHandler.Games.FirstOrDefault(x => + mo2Compiler.CompilingGame.SteamIDs!.Contains(x.ID)); } public override async ValueTask Run(RawSourceFile source) { + if (!_isGenericGame) + return null; + + if (_game == null) + return null; + if (!_regex.IsMatch((string)source.Path)) return null; try { var lines = await source.AbsolutePath.ReadAllLinesAsync(); - var id = 0; - lines.Where(l => l.StartsWith("itemID=")).Do(l => int.TryParse(l.Replace("itemID=", ""), out id)); + var sID = lines.FirstOrDefault(l => l.StartsWith("itemID="))?.Replace("itemID=", ""); + if (string.IsNullOrEmpty(sID)) + { + Utils.Error($"Found no itemID= in file {source.AbsolutePath}!"); + return null; + } + + if(!int.TryParse(sID, out var id)) + { + Utils.Error($"Unable to parse int {sID} in {source.AbsolutePath}"); + return null; + } + + //Get-ChildItem -Name -Directory | ForEach-Object -Process {Out-File -FilePath .\steamWorkshopItem_$_.meta -InputObject "itemID=$($_)" -Encoding utf8} if (id == 0) return null; - SteamWorkshopItem? item = null; - _game.WorkshopItems.Where(i => i.ItemID == id).Do(i => item = i); + SteamWorkshopItem? item = _game.WorkshopItems.FirstOrDefault(x => x.ItemID == id); if (item == null) + { + Utils.Error($"Unable to find workshop item with ID {id} in loaded workshop item list!"); return null; + } var fromSteam = source.EvolveTo(); fromSteam.SourceDataID = await _compiler.IncludeFile(source.AbsolutePath); diff --git a/Wabbajack.Lib/MO2Compiler.cs b/Wabbajack.Lib/MO2Compiler.cs index f769c2c2..b18f16ba 100644 --- a/Wabbajack.Lib/MO2Compiler.cs +++ b/Wabbajack.Lib/MO2Compiler.cs @@ -591,6 +591,7 @@ namespace Wabbajack.Lib { new IgnoreGameFilesIfGameFolderFilesExist(this), new IncludePropertyFiles(this), + //new IncludeSteamWorkshopItems(this), new IgnoreSaveFiles(this), new IgnoreStartsWith(this,"logs\\"), new IgnoreStartsWith(this, "downloads\\"),