mirror of
https://github.com/Thealexbarney/LibHac.git
synced 2024-11-14 10:49:41 +01:00
Compress result name data
This commit is contained in:
parent
2c7291b9ae
commit
6b8b1515c2
3 changed files with 28 additions and 2 deletions
|
@ -7,6 +7,7 @@ using System.Security.Cryptography;
|
|||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using ICSharpCode.SharpZipLib.Zip;
|
||||
using ICSharpCode.SharpZipLib.Zip.Compression;
|
||||
using LibHacBuild.CodeGen.Stage1;
|
||||
using Nuke.Common;
|
||||
using Nuke.Common.CI.AppVeyor;
|
||||
|
@ -514,6 +515,21 @@ namespace LibHacBuild
|
|||
}
|
||||
}
|
||||
|
||||
public static byte[] DeflateBytes(byte[] data)
|
||||
{
|
||||
var s = new Deflater(9, true);
|
||||
s.SetInput(data);
|
||||
s.Finish();
|
||||
byte[] buffer = new byte[data.Length];
|
||||
s.Deflate(buffer);
|
||||
|
||||
Debug.Assert(s.IsFinished);
|
||||
|
||||
byte[] compressed = new byte[s.TotalOut];
|
||||
Array.Copy(buffer, compressed, compressed.Length);
|
||||
return compressed;
|
||||
}
|
||||
|
||||
public static void PushArtifact(string path)
|
||||
{
|
||||
if (!File.Exists(path))
|
||||
|
|
|
@ -36,7 +36,8 @@ namespace LibHacBuild.CodeGen.Stage1
|
|||
}
|
||||
|
||||
byte[] archive = BuildArchive(modules);
|
||||
string archiveStr = PrintArchive(archive);
|
||||
byte[] compressedArchive = Build.DeflateBytes(archive);
|
||||
string archiveStr = PrintArchive(compressedArchive);
|
||||
WriteOutput("LibHac/ResultNameResolver.Generated.cs", archiveStr);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using LibHac.Common;
|
||||
|
@ -19,10 +20,18 @@ namespace LibHac
|
|||
|
||||
private static Dictionary<Result, string> GetResultNames()
|
||||
{
|
||||
var archiveReader = new ResultArchiveReader(ArchiveData);
|
||||
var archiveReader = new ResultArchiveReader(DecompressArchive());
|
||||
return archiveReader.GetDictionary();
|
||||
}
|
||||
|
||||
private static byte[] DecompressArchive()
|
||||
{
|
||||
var deflateStream = new DeflateStream(new MemoryStream(ArchiveData.ToArray()), CompressionMode.Decompress);
|
||||
var archiveDataStream = new MemoryStream();
|
||||
deflateStream.CopyTo(archiveDataStream);
|
||||
return archiveDataStream.ToArray();
|
||||
}
|
||||
|
||||
// To save a bunch of space in the assembly, Results with their names are packed into
|
||||
// an archive and unpacked at runtime.
|
||||
private readonly ref struct ResultArchiveReader
|
||||
|
|
Loading…
Reference in a new issue