2020-01-09 22:56:29 +00:00
|
|
|
|
using System.Collections.Generic;
|
2020-07-10 22:59:39 +00:00
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
2020-03-22 15:50:53 +00:00
|
|
|
|
using Wabbajack.Common;
|
2020-05-12 21:28:09 +00:00
|
|
|
|
using Wabbajack.Common.Serialization.Json;
|
2020-01-09 22:56:29 +00:00
|
|
|
|
|
2020-01-10 04:47:06 +00:00
|
|
|
|
namespace Wabbajack.VirtualFileSystem
|
2020-01-09 22:56:29 +00:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Response from the Build server for a indexed file
|
|
|
|
|
/// </summary>
|
2020-05-12 21:28:09 +00:00
|
|
|
|
[JsonName("IndexedVirtualFile")]
|
2020-01-09 22:56:29 +00:00
|
|
|
|
public class IndexedVirtualFile
|
|
|
|
|
{
|
2020-03-24 12:21:19 +00:00
|
|
|
|
public IPath Name { get; set; }
|
2020-03-22 15:50:53 +00:00
|
|
|
|
public Hash Hash { get; set; }
|
2020-01-09 22:56:29 +00:00
|
|
|
|
public long Size { get; set; }
|
|
|
|
|
public List<IndexedVirtualFile> Children { get; set; } = new List<IndexedVirtualFile>();
|
2020-07-10 22:59:39 +00:00
|
|
|
|
|
|
|
|
|
private void Write(BinaryWriter bw)
|
|
|
|
|
{
|
|
|
|
|
bw.Write(Name.ToString());
|
|
|
|
|
bw.Write((ulong)Hash);
|
|
|
|
|
bw.Write(Size);
|
|
|
|
|
bw.Write(Children.Count);
|
|
|
|
|
foreach (var file in Children)
|
|
|
|
|
file.Write(bw);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Write(Stream s)
|
|
|
|
|
{
|
|
|
|
|
using var bw = new BinaryWriter(s);
|
|
|
|
|
bw.Write(Size);
|
|
|
|
|
bw.Write(Children.Count);
|
|
|
|
|
foreach (var file in Children)
|
|
|
|
|
file.Write(bw);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static IndexedVirtualFile Read(BinaryReader br)
|
|
|
|
|
{
|
|
|
|
|
var ivf = new IndexedVirtualFile
|
|
|
|
|
{
|
|
|
|
|
Name = (RelativePath)br.ReadString(),
|
|
|
|
|
Hash = Hash.FromULong(br.ReadUInt64()),
|
|
|
|
|
Size = br.ReadInt64(),
|
|
|
|
|
};
|
|
|
|
|
var lst = new List<IndexedVirtualFile>();
|
2020-07-15 03:04:31 +00:00
|
|
|
|
ivf.Children = lst;
|
2020-07-10 22:59:39 +00:00
|
|
|
|
var count = br.ReadInt32();
|
|
|
|
|
for (int x = 0; x < count; x++)
|
|
|
|
|
{
|
|
|
|
|
lst.Add(Read(br));
|
|
|
|
|
}
|
2020-07-15 03:04:31 +00:00
|
|
|
|
|
2020-07-10 22:59:39 +00:00
|
|
|
|
return ivf;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static IndexedVirtualFile Read(Stream s)
|
|
|
|
|
{
|
|
|
|
|
using var br = new BinaryReader(s);
|
|
|
|
|
var ivf = new IndexedVirtualFile
|
|
|
|
|
{
|
|
|
|
|
Size = br.ReadInt64(),
|
|
|
|
|
};
|
|
|
|
|
var lst = new List<IndexedVirtualFile>();
|
|
|
|
|
ivf.Children = lst;
|
|
|
|
|
var count = br.ReadInt32();
|
|
|
|
|
for (int x = 0; x < count; x++)
|
|
|
|
|
{
|
|
|
|
|
lst.Add(Read(br));
|
|
|
|
|
}
|
|
|
|
|
return ivf;
|
|
|
|
|
}
|
2020-01-09 22:56:29 +00:00
|
|
|
|
}
|
|
|
|
|
}
|