@@ -7,50 +7,51 @@ namespace LibBundle.Records
7
7
{
8
8
public class BundleRecord
9
9
{
10
- public long IndexOffset ;
11
10
public int NameLength ;
12
11
public string Name ;
13
12
public int UncompressedSize ;
14
13
15
14
public int bundleIndex ;
16
15
public int validSize ;
17
- public readonly List < FileRecord > Files = new List < FileRecord > ( ) ;
18
- internal readonly Dictionary < FileRecord , byte [ ] > FileToAdd = new Dictionary < FileRecord , byte [ ] > ( ) ;
16
+ public readonly List < FileRecord > Files = new ( ) ;
17
+ internal readonly Dictionary < FileRecord , byte [ ] > FileToAdd = new ( ) ;
19
18
protected BundleContainer _bundle ;
19
+ private bool bundleNull ;
20
20
21
21
public BundleContainer Bundle
22
22
{
23
23
get
24
24
{
25
+ if ( bundleNull )
26
+ return null ;
25
27
Read ( ) ;
26
28
return _bundle ;
27
29
}
28
30
}
29
31
30
32
public BundleRecord ( BinaryReader br )
31
33
{
32
- IndexOffset = br . BaseStream . Position ;
33
34
NameLength = br . ReadInt32 ( ) ;
34
35
Name = Encoding . UTF8 . GetString ( br . ReadBytes ( NameLength ) ) + ".bundle.bin" ;
35
36
UncompressedSize = br . ReadInt32 ( ) ;
36
37
}
37
38
38
- public virtual void Read ( BinaryReader br = null , long ? Offset = null )
39
- {
39
+ public virtual void Read ( BinaryReader br = null , long ? Offset = null ) {
40
40
if ( _bundle != null ) return ;
41
- if ( Offset . HasValue )
42
- {
41
+ if ( Offset . HasValue ) {
43
42
br . BaseStream . Seek ( Offset . Value , SeekOrigin . Begin ) ;
44
43
_bundle = new BundleContainer ( br ) ;
45
- }
46
- else if ( br == null )
47
- {
44
+ } else if ( br == null )
48
45
_bundle = new BundleContainer ( Name ) ;
49
- }
46
+
47
+ // This will result in reading from the wrong place when bundle.bin is not found
48
+ /*
50
49
else
51
- {
52
50
_bundle = new BundleContainer(br);
53
- }
51
+ */
52
+
53
+ else
54
+ bundleNull = true ;
54
55
}
55
56
56
57
public virtual void Save ( string newPath = null , string originalPath = null )
@@ -64,7 +65,7 @@ public virtual void Save(string newPath = null, string originalPath = null)
64
65
d . Key . Offset = ( int ) data . Position + Bundle . uncompressed_size ;
65
66
data . Write ( d . Value , 0 , d . Key . Size ) ;
66
67
}
67
- UncompressedSize = ( int ) data . Length + Bundle . uncompressed_size ;
68
+ UncompressedSize = validSize = ( int ) data . Length + Bundle . uncompressed_size ;
68
69
FileToAdd . Clear ( ) ;
69
70
if ( newPath != null )
70
71
File . WriteAllBytes ( newPath , Bundle . AppendAndSave ( data , originalPath ) ) ;
@@ -95,7 +96,7 @@ public virtual byte[] Save(BinaryReader br, long? Offset = null)
95
96
}
96
97
else
97
98
{
98
- UncompressedSize = ( int ) data . Length + Bundle . uncompressed_size ;
99
+ UncompressedSize = validSize = ( int ) data . Length + Bundle . uncompressed_size ;
99
100
result = Bundle . AppendAndSave ( data , br ? . BaseStream ?? Bundle . Read ( ) ) ;
100
101
}
101
102
FileToAdd . Clear ( ) ;
@@ -113,7 +114,7 @@ public virtual void SaveWithRecompression(string newPath = null, string original
113
114
d . Key . Offset = ( int ) data . Position ;
114
115
data . Write ( d . Value , 0 , d . Key . Size ) ;
115
116
}
116
- UncompressedSize = ( int ) data . Length ;
117
+ UncompressedSize = validSize = ( int ) data . Length ;
117
118
FileToAdd . Clear ( ) ;
118
119
Bundle . Save ( data , newPath ?? originalPath ) ;
119
120
}
0 commit comments