wabbajack/Wabbajack.Lib/Data.cs

282 lines
7.0 KiB
C#
Raw Normal View History

using System;
2019-07-21 04:40:54 +00:00
using System.Collections.Generic;
using System.IO;
using System.Linq;
2019-10-11 23:31:36 +00:00
using Compression.BSA;
using Newtonsoft.Json;
using Wabbajack.Common;
using Wabbajack.Common.Serialization.Json;
using Wabbajack.Lib.Downloaders;
2019-11-15 13:06:34 +00:00
using Wabbajack.VirtualFileSystem;
2019-07-21 04:40:54 +00:00
namespace Wabbajack.Lib
2019-07-21 04:40:54 +00:00
{
2019-09-14 04:35:42 +00:00
public class RawSourceFile
2019-07-21 04:40:54 +00:00
{
2020-03-25 12:47:25 +00:00
public readonly RelativePath Path;
2019-09-14 04:35:42 +00:00
2020-03-25 12:47:25 +00:00
public RawSourceFile(VirtualFile file, RelativePath path)
{
File = file;
Path = path;
}
2019-07-21 04:40:54 +00:00
public AbsolutePath AbsolutePath => File.StagedPath;
2019-09-14 04:35:42 +00:00
public VirtualFile File { get; }
2020-03-22 15:50:53 +00:00
public Hash Hash => File.Hash;
2019-07-21 04:40:54 +00:00
public T EvolveTo<T>() where T : Directive, new()
{
var v = new T();
v.To = Path;
v.Hash = Hash;
v.Size = File.Size;
2019-07-21 04:40:54 +00:00
return v;
}
}
[JsonName("ModList")]
2019-07-21 04:40:54 +00:00
public class ModList
{
/// <summary>
2019-09-14 04:35:42 +00:00
/// Archives required by this modlist
2019-07-21 04:40:54 +00:00
/// </summary>
2020-04-10 01:29:53 +00:00
public List<Archive> Archives = new List<Archive>();
2019-07-21 04:40:54 +00:00
/// <summary>
/// Author of the ModList
/// </summary>
2020-04-10 01:29:53 +00:00
public string Author = string.Empty;
/// <summary>
/// Description of the ModList
/// </summary>
2020-04-10 01:29:53 +00:00
public string Description = string.Empty;
2019-07-21 04:40:54 +00:00
/// <summary>
2019-09-14 04:35:42 +00:00
/// Install directives
2019-07-21 04:40:54 +00:00
/// </summary>
2020-04-10 01:29:53 +00:00
public List<Directive> Directives = new List<Directive>();
2019-07-21 04:40:54 +00:00
/// <summary>
/// The game variant to which this game applies
2019-07-21 04:40:54 +00:00
/// </summary>
public Game GameType;
2019-08-30 23:57:56 +00:00
2019-10-07 14:43:46 +00:00
/// <summary>
/// Hash of the banner-image
2019-10-07 14:43:46 +00:00
/// </summary>
2020-03-25 22:30:43 +00:00
public RelativePath Image;
2019-10-07 14:43:46 +00:00
/// <summary>
/// The Mod Manager used to create the modlist
2019-10-07 14:43:46 +00:00
/// </summary>
public ModManager ModManager;
2019-10-07 14:43:46 +00:00
/// <summary>
/// Name of the ModList
2019-10-07 14:43:46 +00:00
/// </summary>
2020-04-10 01:29:53 +00:00
public string Name = string.Empty;
2019-10-07 14:43:46 +00:00
/// <summary>
2020-04-15 17:40:41 +00:00
/// URL to the readme
2019-10-07 14:43:46 +00:00
/// </summary>
2020-04-10 01:29:53 +00:00
public string Readme = string.Empty;
2019-10-07 14:43:46 +00:00
/// <summary>
/// The build version of Wabbajack used when compiling the Modlist
/// </summary>
2020-04-10 01:29:53 +00:00
public Version? WabbajackVersion;
/// <summary>
/// Website of the ModList
/// </summary>
2020-04-10 01:29:53 +00:00
public Uri? Website;
/// <summary>
/// The size of all the archives once they're downloaded
/// </summary>
[JsonIgnore]
public long DownloadSize => Archives.Sum(a => a.Size);
2019-12-20 20:01:01 +00:00
/// <summary>
/// The size of all the files once they are installed (excluding downloaded archives)
2019-12-20 20:01:01 +00:00
/// </summary>
[JsonIgnore]
public long InstallSize => Directives.Sum(s => s.Size);
public ModList Clone()
{
using var ms = new MemoryStream();
this.ToJson(ms);
ms.Position = 0;
return ms.FromJson<ModList>();
}
2019-07-21 04:40:54 +00:00
}
public abstract class Directive
2019-07-21 04:40:54 +00:00
{
public Hash Hash { get; set; }
public long Size { get; set; }
2019-07-21 04:40:54 +00:00
/// <summary>
2019-09-14 04:35:42 +00:00
/// location the file will be copied to, relative to the install path.
2019-07-21 04:40:54 +00:00
/// </summary>
2020-03-25 12:47:25 +00:00
public RelativePath To { get; set; }
2019-07-21 04:40:54 +00:00
}
public class IgnoredDirectly : Directive
{
2020-04-10 01:29:53 +00:00
public string Reason = string.Empty;
2019-07-21 04:40:54 +00:00
}
public class NoMatch : IgnoredDirectly
{
}
[JsonName("InlineFile")]
2019-07-21 04:40:54 +00:00
public class InlineFile : Directive
{
/// <summary>
2019-09-14 04:35:42 +00:00
/// Data that will be written as-is to the destination location;
2019-07-21 04:40:54 +00:00
/// </summary>
2020-03-25 12:47:25 +00:00
public RelativePath SourceDataID { get; set; }
2019-07-21 04:40:54 +00:00
}
[JsonName("ArchiveMeta")]
public class ArchiveMeta : Directive
{
2020-03-25 12:47:25 +00:00
public RelativePath SourceDataID { get; set; }
}
2019-10-11 12:56:55 +00:00
public enum PropertyType { Banner, Readme }
2019-10-11 11:09:34 +00:00
/// <summary>
/// File meant to be extracted before the installation
/// </summary>
[JsonName("PropertyFile")]
2019-10-11 11:09:34 +00:00
public class PropertyFile : InlineFile
{
public PropertyType Type;
}
[JsonName("CleanedESM")]
2019-08-25 03:46:32 +00:00
public class CleanedESM : InlineFile
{
2020-03-22 15:50:53 +00:00
public Hash SourceESMHash;
2019-08-25 03:46:32 +00:00
}
2019-08-24 23:20:54 +00:00
/// <summary>
2019-09-14 04:35:42 +00:00
/// A file that has the game and MO2 folders remapped on installation
2019-08-24 23:20:54 +00:00
/// </summary>
[JsonName("RemappedInlineFile")]
2019-08-24 23:20:54 +00:00
public class RemappedInlineFile : InlineFile
{
}
[JsonName("SteamMeta")]
2019-12-02 16:43:43 +00:00
public class SteamMeta : ArchiveMeta
{
public int ItemID { get; set; }
2019-12-02 16:43:43 +00:00
}
[JsonName("FromArchive")]
2019-07-21 04:40:54 +00:00
public class FromArchive : Directive
{
2020-04-10 01:29:53 +00:00
private string? _fullPath;
2019-09-14 04:35:42 +00:00
2020-03-25 12:47:25 +00:00
public HashRelativePath ArchiveHashPath { get; set; }
[JsonIgnore]
2020-04-10 01:29:53 +00:00
public VirtualFile? FromFile { get; set; }
[JsonIgnore]
2020-03-22 15:50:53 +00:00
public string FullPath => _fullPath ??= string.Join("|", ArchiveHashPath);
2019-07-21 04:40:54 +00:00
}
[JsonName("CreateBSA")]
2019-07-26 20:59:14 +00:00
public class CreateBSA : Directive
{
2020-03-25 22:30:43 +00:00
public RelativePath TempID { get; set; }
2020-04-10 01:29:53 +00:00
public ArchiveStateObject State { get; }
public List<FileStateObject> FileStates { get; set; } = new List<FileStateObject>();
public CreateBSA(ArchiveStateObject state, IEnumerable<FileStateObject>? items = null)
{
State = state;
if (items != null)
{
FileStates.AddRange(items);
}
}
2019-07-26 20:59:14 +00:00
}
[JsonName("PatchedFromArchive")]
2019-07-21 22:47:17 +00:00
public class PatchedFromArchive : FromArchive
2019-07-21 04:40:54 +00:00
{
public Hash FromHash { get; set; }
2019-07-21 04:40:54 +00:00
/// <summary>
2019-09-14 04:35:42 +00:00
/// The file to apply to the source file to patch it
2019-07-21 04:40:54 +00:00
/// </summary>
2020-03-25 22:30:43 +00:00
public RelativePath PatchID { get; set; }
2019-07-21 04:40:54 +00:00
}
[JsonName("SourcePatch")]
2019-09-23 21:37:10 +00:00
public class SourcePatch
{
public Hash Hash { get; set; }
2020-03-25 12:47:25 +00:00
public RelativePath RelativePath { get; set; }
2019-09-23 21:37:10 +00:00
}
[JsonName("MergedPatch")]
2019-09-23 21:37:10 +00:00
public class MergedPatch : Directive
{
2020-03-25 22:30:43 +00:00
public RelativePath PatchID { get; set; }
2020-04-10 01:29:53 +00:00
public List<SourcePatch> Sources { get; set; } = new List<SourcePatch>();
2019-09-23 21:37:10 +00:00
}
[JsonName("Archive")]
2019-07-21 04:40:54 +00:00
public class Archive
{
/// <summary>
2020-03-27 03:10:23 +00:00
/// xxHash64 of the archive
2019-07-21 04:40:54 +00:00
/// </summary>
2020-03-22 15:50:53 +00:00
public Hash Hash { get; set; }
2019-07-21 22:47:17 +00:00
2019-11-04 12:53:02 +00:00
/// <summary>
/// Meta INI for the downloaded archive
2019-07-21 22:47:17 +00:00
/// </summary>
2020-04-10 01:29:53 +00:00
public string? Meta { get; set; }
2019-09-14 04:35:42 +00:00
/// <summary>
/// Human friendly name of this archive
/// </summary>
2020-04-10 01:29:53 +00:00
public string Name { get; set; } = string.Empty;
2019-09-14 04:35:42 +00:00
public long Size { get; set; }
2020-04-10 01:29:53 +00:00
public AbstractDownloadState State { get; }
2020-04-10 01:29:53 +00:00
public Archive(AbstractDownloadState state)
{
State = state;
}
2019-07-21 04:40:54 +00:00
}
2020-04-10 01:29:53 +00:00
public class IndexedArchive
2019-07-21 04:40:54 +00:00
{
2020-04-10 01:29:53 +00:00
public dynamic? IniData;
public string Meta = string.Empty;
public string Name = string.Empty;
public VirtualFile File { get; }
2019-07-21 04:40:54 +00:00
2020-04-10 01:29:53 +00:00
public IndexedArchive(VirtualFile file)
{
File = file;
}
}
}