wabbajack/Wabbajack.Lib/Data.cs

337 lines
7.9 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 MessagePack;
using Wabbajack.Common;
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;
}
}
[MessagePackObject]
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>
[Key(0)]
2019-09-14 04:35:42 +00:00
public List<Archive> Archives;
2019-07-21 04:40:54 +00:00
/// <summary>
/// Author of the ModList
/// </summary>
[Key(1)]
public string Author;
/// <summary>
/// Description of the ModList
/// </summary>
[Key(2)]
public string Description;
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>
[Key(3)]
2019-07-21 04:40:54 +00:00
public List<Directive> Directives;
/// <summary>
/// The game variant to which this game applies
2019-07-21 04:40:54 +00:00
/// </summary>
[Key(4)]
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>
[Key(5)]
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>
[Key(6)]
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>
[Key(7)]
public string Name;
2019-10-07 14:43:46 +00:00
/// <summary>
/// readme path or website
2019-10-07 14:43:46 +00:00
/// </summary>
[Key(8)]
public string Readme;
2019-10-07 14:43:46 +00:00
2019-10-11 12:56:55 +00:00
/// <summary>
/// Whether readme is a website
2019-10-11 12:56:55 +00:00
/// </summary>
[Key(9)]
public bool ReadmeIsWebsite;
2019-10-11 12:56:55 +00:00
/// <summary>
/// The build version of Wabbajack used when compiling the Modlist
/// </summary>
[Key(10)]
public Version WabbajackVersion;
/// <summary>
/// Website of the ModList
/// </summary>
[Key(11)]
public Uri Website;
/// <summary>
/// The size of all the archives once they're downloaded
/// </summary>
[IgnoreMember]
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>
[IgnoreMember]
public long InstallSize => Directives.Sum(s => s.Size);
public ModList Clone()
{
using var ms = new MemoryStream();
ms.WriteAsMessagePack(this);
ms.Position = 0;
return ms.ReadAsMessagePack<ModList>();
}
2019-07-21 04:40:54 +00:00
}
[MessagePackObject]
[Union(0, typeof(ArchiveMeta))]
[Union(1, typeof(CreateBSA))]
[Union(2, typeof(FromArchive))]
[Union(3, typeof(MergedPatch))]
[Union(4, typeof(InlineFile))]
[Union(5, typeof(PatchedFromArchive))]
[Union(6, typeof(RemappedInlineFile))]
2020-03-28 02:54:14 +00:00
[Union(7, typeof(CleanedESM))]
public abstract class Directive
2019-07-21 04:40:54 +00:00
{
[Key(0)]
public Hash Hash { get; set; }
[Key(1)]
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>
[Key(2)]
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
{
public string Reason;
}
public class NoMatch : IgnoredDirectly
{
}
[MessagePackObject]
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>
[Key(3)]
2020-03-25 12:47:25 +00:00
public RelativePath SourceDataID { get; set; }
2019-07-21 04:40:54 +00:00
}
[MessagePackObject]
public class ArchiveMeta : Directive
{
[Key(3)]
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>
2020-03-28 02:54:14 +00:00
[MessagePackObject]
2019-10-11 11:09:34 +00:00
public class PropertyFile : InlineFile
{
2020-03-28 02:54:14 +00:00
[Key(4)]
2019-10-11 11:09:34 +00:00
public PropertyType Type;
}
2020-03-28 02:54:14 +00:00
[MessagePackObject]
2019-08-25 03:46:32 +00:00
public class CleanedESM : InlineFile
{
2020-03-28 02:54:14 +00:00
[Key(4)]
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>
[MessagePackObject]
2019-08-24 23:20:54 +00:00
public class RemappedInlineFile : InlineFile
{
}
[MessagePackObject]
2019-12-02 16:43:43 +00:00
public class SteamMeta : ArchiveMeta
{
[Key(4)]
public int ItemID { get; set; }
2019-12-02 16:43:43 +00:00
}
[MessagePackObject]
2019-07-21 04:40:54 +00:00
public class FromArchive : Directive
{
2019-09-14 04:35:42 +00:00
private string _fullPath;
[Key(3)]
2020-03-25 12:47:25 +00:00
public HashRelativePath ArchiveHashPath { get; set; }
[IgnoreMember]
public VirtualFile FromFile { get; set; }
[IgnoreMember]
2020-03-22 15:50:53 +00:00
public string FullPath => _fullPath ??= string.Join("|", ArchiveHashPath);
2019-07-21 04:40:54 +00:00
}
[MessagePackObject]
2019-07-26 20:59:14 +00:00
public class CreateBSA : Directive
{
[Key(3)]
2020-03-25 22:30:43 +00:00
public RelativePath TempID { get; set; }
[Key(4)]
2019-10-11 23:31:36 +00:00
public ArchiveStateObject State { get; set; }
[Key(5)]
2019-10-11 23:31:36 +00:00
public List<FileStateObject> FileStates { get; set; }
2019-07-26 20:59:14 +00:00
}
[MessagePackObject]
2019-07-21 22:47:17 +00:00
public class PatchedFromArchive : FromArchive
2019-07-21 04:40:54 +00:00
{
[Key(4)]
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>
[Key(5)]
2020-03-25 22:30:43 +00:00
public RelativePath PatchID { get; set; }
2019-07-21 04:40:54 +00:00
}
[MessagePackObject]
2019-09-23 21:37:10 +00:00
public class SourcePatch
{
[Key(0)]
public Hash Hash { get; set; }
[Key(1)]
2020-03-25 12:47:25 +00:00
public RelativePath RelativePath { get; set; }
2019-09-23 21:37:10 +00:00
}
[MessagePackObject]
2019-09-23 21:37:10 +00:00
public class MergedPatch : Directive
{
[Key(3)]
2020-03-25 22:30:43 +00:00
public RelativePath PatchID { get; set; }
[Key(4)]
public List<SourcePatch> Sources { get; set; }
2019-09-23 21:37:10 +00:00
}
[MessagePackObject]
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>
[Key(0)]
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>
[Key(1)]
public string Meta { get; set; }
2019-09-14 04:35:42 +00:00
/// <summary>
/// Human friendly name of this archive
/// </summary>
[Key(2)]
public string Name { get; set; }
2019-09-14 04:35:42 +00:00
[Key(3)]
public long Size { get; set; }
[Key(4)]
public AbstractDownloadState State { get; set; }
}
public class IndexedArchive
2019-07-21 04:40:54 +00:00
{
public dynamic IniData;
2019-07-21 22:47:17 +00:00
public string Meta;
2019-09-14 04:35:42 +00:00
public string Name;
public VirtualFile File { get; internal set; }
2019-07-21 04:40:54 +00:00
}
/// <summary>
2019-09-14 04:35:42 +00:00
/// A archive entry
2019-07-21 04:40:54 +00:00
/// </summary>
public class IndexedEntry
{
/// <summary>
2019-09-14 04:35:42 +00:00
/// MurMur3 hash of this file
2019-07-21 04:40:54 +00:00
/// </summary>
2019-09-14 04:35:42 +00:00
public string Hash;
2019-07-21 04:40:54 +00:00
/// <summary>
2019-09-14 04:35:42 +00:00
/// Path in the archive to this file
2019-07-21 04:40:54 +00:00
/// </summary>
2019-09-14 04:35:42 +00:00
public string Path;
2019-07-21 04:40:54 +00:00
/// <summary>
2019-09-14 04:35:42 +00:00
/// Size of the file (uncompressed)
2019-07-21 04:40:54 +00:00
/// </summary>
public long Size;
}
public class IndexedArchiveEntry : IndexedEntry
{
public string[] HashPath;
}
}