2019-12-02 16:44:24 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text.RegularExpressions;
|
2019-12-04 01:26:26 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2019-12-02 16:44:24 +00:00
|
|
|
|
using Alphaleonis.Win32.Filesystem;
|
|
|
|
|
using Wabbajack.Common;
|
2020-01-03 17:22:50 +00:00
|
|
|
|
using Wabbajack.Common.StoreHandlers;
|
2019-12-02 16:44:24 +00:00
|
|
|
|
|
|
|
|
|
namespace Wabbajack.Lib.CompilationSteps
|
|
|
|
|
{
|
|
|
|
|
public class IncludeSteamWorkshopItems : ACompilationStep
|
|
|
|
|
{
|
|
|
|
|
private readonly SteamGame _game;
|
|
|
|
|
private readonly Regex _regex = new Regex("steamWorkshopItem_\\d*\\.meta$");
|
|
|
|
|
|
|
|
|
|
public IncludeSteamWorkshopItems(ACompiler compiler, SteamGame steamGame) : base(compiler)
|
|
|
|
|
{
|
|
|
|
|
_game = steamGame;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-09 18:14:05 +00:00
|
|
|
|
public override async ValueTask<Directive?> Run(RawSourceFile source)
|
2019-12-02 16:44:24 +00:00
|
|
|
|
{
|
2020-03-25 22:30:43 +00:00
|
|
|
|
if (!_regex.IsMatch((string)source.Path))
|
2019-12-02 16:44:24 +00:00
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2020-03-25 22:30:43 +00:00
|
|
|
|
var lines = await source.AbsolutePath.ReadAllLinesAsync();
|
2019-12-02 16:44:24 +00:00
|
|
|
|
var id = 0;
|
|
|
|
|
lines.Where(l => l.StartsWith("itemID=")).Do(l => int.TryParse(l.Replace("itemID=", ""), out id));
|
|
|
|
|
if (id == 0)
|
|
|
|
|
return null;
|
|
|
|
|
|
2020-04-09 18:14:05 +00:00
|
|
|
|
SteamWorkshopItem? item = null;
|
2019-12-02 16:44:24 +00:00
|
|
|
|
_game.WorkshopItems.Where(i => i.ItemID == id).Do(i => item = i);
|
|
|
|
|
if (item == null)
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
var fromSteam = source.EvolveTo<SteamMeta>();
|
2020-03-25 22:30:43 +00:00
|
|
|
|
fromSteam.SourceDataID = await _compiler.IncludeFile(source.AbsolutePath);
|
2019-12-02 16:44:24 +00:00
|
|
|
|
fromSteam.ItemID = item.ItemID;
|
|
|
|
|
fromSteam.Size = item.Size;
|
|
|
|
|
return fromSteam;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
2019-12-05 05:07:44 +00:00
|
|
|
|
Utils.Error(e, $"Exception while trying to evolve source to FromSteam");
|
2019-12-02 16:44:24 +00:00
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override IState GetState()
|
|
|
|
|
{
|
|
|
|
|
return new State(_game);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class State : IState
|
|
|
|
|
{
|
|
|
|
|
private readonly SteamGame _game;
|
|
|
|
|
|
|
|
|
|
public State(SteamGame game)
|
|
|
|
|
{
|
|
|
|
|
_game = game;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ICompilationStep CreateStep(ACompiler compiler)
|
|
|
|
|
{
|
|
|
|
|
return new IncludeSteamWorkshopItems(compiler, _game);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|