mirror of
https://github.com/Thealexbarney/LibHac.git
synced 2024-11-14 10:49:41 +01:00
Remove old Pfs0Builder
This commit is contained in:
parent
1bcbe9f94a
commit
468c78aadd
5 changed files with 12 additions and 85 deletions
|
@ -14,6 +14,8 @@ namespace LibHac.IO
|
|||
private List<Entry> Entries { get; } = new List<Entry>();
|
||||
private long CurrentOffset { get; set; }
|
||||
|
||||
public PartitionFileSystemBuilder() { }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="PartitionFileSystemBuilder"/> and populates it with all
|
||||
/// the files in the root directory.
|
||||
|
|
|
@ -1,75 +0,0 @@
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace LibHac
|
||||
{
|
||||
public class Pfs0Builder
|
||||
{
|
||||
private List<Entry> Entries { get; } = new List<Entry>();
|
||||
private long DataLength { get; set; }
|
||||
|
||||
public void AddFile(string filename, Stream stream)
|
||||
{
|
||||
var entry = new Entry
|
||||
{
|
||||
Name = filename,
|
||||
Stream = stream,
|
||||
Length = stream.Length,
|
||||
Offset = DataLength
|
||||
};
|
||||
|
||||
DataLength += entry.Length;
|
||||
|
||||
Entries.Add(entry);
|
||||
}
|
||||
|
||||
public void Build(Stream output, IProgressReport logger = null)
|
||||
{
|
||||
var strings = new MemoryStream();
|
||||
var stringWriter = new BinaryWriter(strings);
|
||||
var writer = new BinaryWriter(output);
|
||||
|
||||
foreach (Entry entry in Entries)
|
||||
{
|
||||
entry.StringOffset = (int)strings.Length;
|
||||
stringWriter.WriteUTF8Z(entry.Name);
|
||||
}
|
||||
|
||||
strings.Position = Util.GetNextMultiple(strings.Length, 0x10);
|
||||
byte[] stringTable = strings.ToArray();
|
||||
|
||||
output.Position = 0;
|
||||
writer.WriteUTF8("PFS0");
|
||||
writer.Write(Entries.Count);
|
||||
writer.Write(stringTable.Length);
|
||||
writer.Write(0);
|
||||
|
||||
foreach (Entry entry in Entries)
|
||||
{
|
||||
writer.Write(entry.Offset);
|
||||
writer.Write(entry.Length);
|
||||
writer.Write(entry.StringOffset);
|
||||
writer.Write(0);
|
||||
}
|
||||
|
||||
writer.Write(stringTable);
|
||||
|
||||
foreach (Entry entry in Entries)
|
||||
{
|
||||
logger?.LogMessage(entry.Name);
|
||||
entry.Stream.Position = 0;
|
||||
entry.Stream.CopyStream(output, entry.Length, logger);
|
||||
}
|
||||
logger?.SetTotal(0);
|
||||
}
|
||||
|
||||
private class Entry
|
||||
{
|
||||
public string Name;
|
||||
public Stream Stream;
|
||||
public long Length;
|
||||
public long Offset;
|
||||
public int StringOffset;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -7,7 +7,7 @@ using static hactoolnet.Print;
|
|||
|
||||
namespace hactoolnet
|
||||
{
|
||||
internal static class ProcessNsp
|
||||
internal static class ProcessPfs
|
||||
{
|
||||
public static void Process(Context ctx)
|
||||
{
|
||||
|
@ -65,11 +65,11 @@ namespace hactoolnet
|
|||
return;
|
||||
}
|
||||
|
||||
var builder = new Pfs0Builder();
|
||||
var builder = new PartitionFileSystemBuilder();
|
||||
|
||||
foreach (Nca nca in title.Ncas)
|
||||
{
|
||||
builder.AddFile(nca.Filename, nca.GetStorage().AsStream());
|
||||
builder.AddFile(nca.Filename, nca.GetStorage().AsFile(OpenMode.Read));
|
||||
}
|
||||
|
||||
var ticket = new Ticket
|
||||
|
@ -84,16 +84,16 @@ namespace hactoolnet
|
|||
SectHeaderOffset = 0x2C0
|
||||
};
|
||||
byte[] ticketBytes = ticket.GetBytes();
|
||||
builder.AddFile($"{ticket.RightsId.ToHexString()}.tik", new MemoryStream(ticketBytes));
|
||||
builder.AddFile($"{ticket.RightsId.ToHexString()}.tik", new MemoryStream(ticketBytes).AsIFile(OpenMode.ReadWrite));
|
||||
|
||||
Assembly thisAssembly = Assembly.GetExecutingAssembly();
|
||||
Stream cert = thisAssembly.GetManifestResourceStream("hactoolnet.CA00000003_XS00000020");
|
||||
builder.AddFile($"{ticket.RightsId.ToHexString()}.cert", cert);
|
||||
|
||||
builder.AddFile($"{ticket.RightsId.ToHexString()}.cert", cert.AsIFile(OpenMode.Read));
|
||||
|
||||
using (var outStream = new FileStream(ctx.Options.NspOut, FileMode.Create, FileAccess.ReadWrite))
|
||||
{
|
||||
builder.Build(outStream, ctx.Logger);
|
||||
IStorage builtPfs = builder.Build(PartitionFileSystemType.Standard);
|
||||
builtPfs.CopyToStream(outStream, builtPfs.Length, ctx.Logger);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -136,7 +136,7 @@ namespace hactoolnet
|
|||
|
||||
if (ctx.Options.NspOut != null)
|
||||
{
|
||||
ProcessNsp.CreateNsp(ctx, switchFs);
|
||||
ProcessPfs.CreateNsp(ctx, switchFs);
|
||||
}
|
||||
|
||||
if (ctx.Options.SaveOutDir != null)
|
||||
|
|
|
@ -59,7 +59,7 @@ namespace hactoolnet
|
|||
break;
|
||||
case FileType.Pfs0:
|
||||
case FileType.Nsp:
|
||||
ProcessNsp.Process(ctx);
|
||||
ProcessPfs.Process(ctx);
|
||||
break;
|
||||
case FileType.PfsBuild:
|
||||
ProcessFsBuild.ProcessPartitionFs(ctx);
|
||||
|
|
Loading…
Reference in a new issue