Skip to content
This repository was archived by the owner on Feb 4, 2022. It is now read-only.

Commit 41c2c42

Browse files
committed
Synchronize with LibGGPK2
1 parent 0497c26 commit 41c2c42

File tree

8 files changed

+57
-29
lines changed

8 files changed

+57
-29
lines changed

BundleExporter/BundleExporter.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<TargetFramework>net5.0</TargetFramework>
55
<Authors>aianlinb</Authors>
6-
<Copyright>Copyright © 2020 aianlinb.</Copyright>
6+
<Copyright>Copyright © 2020-2021 aianlinb.</Copyright>
77
<AssemblyVersion>2.3.0.0</AssemblyVersion>
88
<Platforms>x64</Platforms>
99
<OutputType>Exe</OutputType>

FileListGenerator/FileListGenerator.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<TargetFramework>net5.0</TargetFramework>
55
<Authors>aianlinb</Authors>
6-
<Copyright>Copyright © 2020 aianlinb.</Copyright>
6+
<Copyright>Copyright © 2020-2021 aianlinb.</Copyright>
77
<AssemblyVersion>2.3.0.0</AssemblyVersion>
88
<Platforms>x64</Platforms>
99
<OutputType>Exe</OutputType>

LibBundle/BundleContainer.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public BundleContainer(string path) {
6767
public BundleContainer(BinaryReader br) {
6868
Initialize(br);
6969
}
70-
private void Initialize(BinaryReader br) {
70+
protected virtual void Initialize(BinaryReader br) {
7171
offset = br.BaseStream.Position;
7272
uncompressed_size = br.ReadInt32();
7373
compressed_size = br.ReadInt32();
@@ -122,9 +122,9 @@ public virtual MemoryStream Read(BinaryReader br) {
122122
return data;
123123
}
124124

125-
public virtual byte[] AppendAndSave(Stream newData, string path = null) {
125+
public virtual byte[] AppendAndSave(Stream newData, string originalPath = null) {
126126
offset = 0;
127-
return AppendAndSave(newData, File.Open(path ?? this.path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite));
127+
return AppendAndSave(newData, File.Open(originalPath ?? path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite));
128128
}
129129

130130
public virtual byte[] AppendAndSave(Stream newData, Stream originalData) {
@@ -203,8 +203,8 @@ public virtual byte[] AppendAndSave(Stream newData, Stream originalData) {
203203
}
204204

205205
// Packing
206-
public virtual void Save(Stream newData, string path) {
207-
var bw = new BinaryWriter(File.OpenWrite(path ?? this.path));
206+
public virtual void Save(Stream newData, string savePath) {
207+
var bw = new BinaryWriter(File.OpenWrite(savePath ?? path));
208208

209209
uncompressed_size = (int)(size_decompressed = newData.Length);
210210
entry_count = uncompressed_size / chunk_size;

LibBundle/IndexContainer.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class IndexContainer
1616
public readonly HashSet<string> Paths = new HashSet<string>();
1717
public readonly byte[] directoryBundleData;
1818

19-
private static BinaryReader tmp;
19+
protected static BinaryReader tmp;
2020
public IndexContainer(string path) : this(tmp = new BinaryReader(File.OpenRead(path)))
2121
{
2222
tmp.Close();
@@ -31,7 +31,7 @@ public IndexContainer(BinaryReader br)
3131

3232
var bundleCount = databr.ReadInt32();
3333
Bundles = new BundleRecord[bundleCount];
34-
for (int i = 0; i < bundleCount; i++)
34+
for (var i = 0; i < bundleCount; i++)
3535
Bundles[i] = new BundleRecord(databr) { bundleIndex = i };
3636

3737
var fileCount = databr.ReadInt32();
@@ -166,7 +166,7 @@ public virtual byte[] Save()
166166
return BundleContainer.Save(bw.BaseStream);
167167
}
168168

169-
public BundleRecord GetSmallestBundle(IList<BundleRecord> Bundles = null)
169+
public virtual BundleRecord GetSmallestBundle(IList<BundleRecord> Bundles = null)
170170
{
171171
Bundles ??= this.Bundles;
172172
var result = Bundles.ElementAt(0);

LibBundle/LibBundle.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
<PropertyGroup>
44
<TargetFramework>net5.0</TargetFramework>
55
<Authors>aianlinb</Authors>
6-
<Copyright>Copyright © 2020 aianlinb.</Copyright>
7-
<AssemblyVersion>2.4.2.0</AssemblyVersion>
6+
<Copyright>Copyright © 2020-2021 aianlinb.</Copyright>
7+
<AssemblyVersion>2.4.4.0</AssemblyVersion>
88
<Platforms>x64</Platforms>
99
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
1010
</PropertyGroup>

LibBundle/Records/BundleRecord.cs

+40-13
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class BundleRecord
1616
public int validSize;
1717
public readonly List<FileRecord> Files = new List<FileRecord>();
1818
internal readonly Dictionary<FileRecord, byte[]> FileToAdd = new Dictionary<FileRecord, byte[]>();
19-
private BundleContainer _bundle;
19+
protected BundleContainer _bundle;
2020

2121
public BundleContainer Bundle
2222
{
@@ -35,7 +35,7 @@ public BundleRecord(BinaryReader br)
3535
UncompressedSize = br.ReadInt32();
3636
}
3737

38-
public void Read(BinaryReader br = null, long? Offset = null)
38+
public virtual void Read(BinaryReader br = null, long? Offset = null)
3939
{
4040
if (_bundle != null) return;
4141
if (Offset.HasValue)
@@ -53,29 +53,28 @@ public void Read(BinaryReader br = null, long? Offset = null)
5353
}
5454
}
5555

56-
public void Save(string newPath = null, string originalPath = null)
56+
public virtual void Save(string newPath = null, string originalPath = null)
5757
{
5858
if (newPath == null && originalPath == null && Bundle.path == null)
5959
#pragma warning disable CA2208 // 正確地將引數例外狀況具現化
6060
throw new ArgumentNullException();
61-
#pragma warning restore CA2208 // 正確地將引數例外狀況具現化
62-
var data = new MemoryStream();
61+
var data = new MemoryStream();
6362
foreach (var d in FileToAdd)
6463
{
6564
d.Key.Offset = (int)data.Position + Bundle.uncompressed_size;
6665
data.Write(d.Value, 0, d.Key.Size);
6766
}
6867
UncompressedSize = (int)data.Length + Bundle.uncompressed_size;
6968
FileToAdd.Clear();
70-
if (newPath != null)
71-
File.WriteAllBytes(newPath, Bundle.AppendAndSave(data, originalPath));
72-
else if (originalPath != null)
73-
File.WriteAllBytes(originalPath, Bundle.AppendAndSave(data, originalPath));
74-
else
75-
File.WriteAllBytes(Bundle.path, Bundle.AppendAndSave(data, originalPath));
69+
if (newPath != null)
70+
File.WriteAllBytes(newPath, Bundle.AppendAndSave(data, originalPath));
71+
else if (originalPath != null)
72+
File.WriteAllBytes(originalPath, Bundle.AppendAndSave(data, originalPath));
73+
else
74+
File.WriteAllBytes(Bundle.path, Bundle.AppendAndSave(data, originalPath));
7675
}
7776

78-
public byte[] Save(BinaryReader br, long? Offset = null)
77+
public virtual byte[] Save(BinaryReader br, long? Offset = null)
7978
{
8079
Read(br, Offset);
8180
var data = new MemoryStream();
@@ -88,7 +87,7 @@ public byte[] Save(BinaryReader br, long? Offset = null)
8887
if (data.Length == 0)
8988
{
9089
if (br == null) {
91-
result = Bundle.Read().ToArray();
90+
result = File.ReadAllBytes(Bundle.path);
9291
} else {
9392
br.BaseStream.Seek(Bundle.offset, SeekOrigin.Begin);
9493
result = br.ReadBytes(Bundle.head_size + Bundle.compressed_size + 12);
@@ -103,5 +102,33 @@ public byte[] Save(BinaryReader br, long? Offset = null)
103102
data.Close();
104103
return result;
105104
}
105+
106+
public virtual void SaveWithRecompression(string newPath = null, string originalPath = null) {
107+
if (newPath == null && originalPath == null && Bundle.path == null)
108+
throw new ArgumentNullException();
109+
var data = Bundle.Read(originalPath);
110+
foreach (var d in FileToAdd) {
111+
d.Key.Offset = (int)data.Position;
112+
data.Write(d.Value, 0, d.Key.Size);
113+
}
114+
UncompressedSize = (int)data.Length;
115+
FileToAdd.Clear();
116+
Bundle.Save(data, newPath ?? originalPath);
117+
}
118+
119+
public virtual byte[] SaveWithRecompression(BinaryReader br, long? Offset = null) {
120+
Read(br, Offset);
121+
var data = Bundle.Read(br);
122+
data.SetLength(validSize);
123+
foreach (var (f, b) in FileToAdd) {
124+
f.Offset = (int)data.Position;
125+
data.Write(b, 0, f.Size);
126+
}
127+
UncompressedSize = (int)data.Length;
128+
var result = Bundle.Save(data);
129+
FileToAdd.Clear();
130+
data.Close();
131+
return result;
132+
}
106133
}
107134
}

LibBundle/Records/FileRecord.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public FileRecord(BinaryReader br)
2323
Size = br.ReadInt32();
2424
}
2525

26-
public byte[] Read(Stream stream = null)
26+
public virtual byte[] Read(Stream stream = null)
2727
{
2828
if (bundleRecord.FileToAdd.TryGetValue(this, out var b)) return b;
2929
b = new byte[Size];
@@ -33,7 +33,7 @@ public byte[] Read(Stream stream = null)
3333
return b;
3434
}
3535

36-
public void Move(BundleRecord target)
36+
public virtual void Move(BundleRecord target)
3737
{
3838
if (bundleRecord.FileToAdd.TryGetValue(this, out var data))
3939
bundleRecord.FileToAdd.Remove(this);
@@ -45,7 +45,7 @@ public void Move(BundleRecord target)
4545
BundleIndex = target.bundleIndex;
4646
}
4747

48-
public void Write(byte[] data)
48+
public virtual void Write(byte[] data)
4949
{
5050
Size = data.Length;
5151
bundleRecord.FileToAdd[this] = data;

VisualBundle/VisualBundle.csproj

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
<OutputType>WinExe</OutputType>
55
<TargetFramework>net5.0-windows</TargetFramework>
66
<UseWPF>true</UseWPF>
7-
<Copyright>Copyright © 2020 aianlinb</Copyright>
7+
<Authors>aianlinb</Authors>
8+
<Copyright>Copyright © 2020-2021 aianlinb</Copyright>
89
<AssemblyVersion>2.3.0.0</AssemblyVersion>
910
<Platforms>x64</Platforms>
1011
</PropertyGroup>

0 commit comments

Comments
 (0)