@@ -16,7 +16,7 @@ public class BundleRecord
16
16
public int validSize ;
17
17
public readonly List < FileRecord > Files = new List < FileRecord > ( ) ;
18
18
internal readonly Dictionary < FileRecord , byte [ ] > FileToAdd = new Dictionary < FileRecord , byte [ ] > ( ) ;
19
- private BundleContainer _bundle ;
19
+ protected BundleContainer _bundle ;
20
20
21
21
public BundleContainer Bundle
22
22
{
@@ -35,7 +35,7 @@ public BundleRecord(BinaryReader br)
35
35
UncompressedSize = br . ReadInt32 ( ) ;
36
36
}
37
37
38
- public void Read ( BinaryReader br = null , long ? Offset = null )
38
+ public virtual void Read ( BinaryReader br = null , long ? Offset = null )
39
39
{
40
40
if ( _bundle != null ) return ;
41
41
if ( Offset . HasValue )
@@ -53,29 +53,28 @@ public void Read(BinaryReader br = null, long? Offset = null)
53
53
}
54
54
}
55
55
56
- public void Save ( string newPath = null , string originalPath = null )
56
+ public virtual void Save ( string newPath = null , string originalPath = null )
57
57
{
58
58
if ( newPath == null && originalPath == null && Bundle . path == null )
59
59
#pragma warning disable CA2208 // 正確地將引數例外狀況具現化
60
60
throw new ArgumentNullException ( ) ;
61
- #pragma warning restore CA2208 // 正確地將引數例外狀況具現化
62
- var data = new MemoryStream ( ) ;
61
+ var data = new MemoryStream ( ) ;
63
62
foreach ( var d in FileToAdd )
64
63
{
65
64
d . Key . Offset = ( int ) data . Position + Bundle . uncompressed_size ;
66
65
data . Write ( d . Value , 0 , d . Key . Size ) ;
67
66
}
68
67
UncompressedSize = ( int ) data . Length + Bundle . uncompressed_size ;
69
68
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 ) ) ;
76
75
}
77
76
78
- public byte [ ] Save ( BinaryReader br , long ? Offset = null )
77
+ public virtual byte [ ] Save ( BinaryReader br , long ? Offset = null )
79
78
{
80
79
Read ( br , Offset ) ;
81
80
var data = new MemoryStream ( ) ;
@@ -88,7 +87,7 @@ public byte[] Save(BinaryReader br, long? Offset = null)
88
87
if ( data . Length == 0 )
89
88
{
90
89
if ( br == null ) {
91
- result = Bundle . Read ( ) . ToArray ( ) ;
90
+ result = File . ReadAllBytes ( Bundle . path ) ;
92
91
} else {
93
92
br . BaseStream . Seek ( Bundle . offset , SeekOrigin . Begin ) ;
94
93
result = br . ReadBytes ( Bundle . head_size + Bundle . compressed_size + 12 ) ;
@@ -103,5 +102,33 @@ public byte[] Save(BinaryReader br, long? Offset = null)
103
102
data . Close ( ) ;
104
103
return result ;
105
104
}
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
+ }
106
133
}
107
134
}
0 commit comments