@@ -32,156 +32,4 @@ public void Serialize(ref DataBuffer db) {
3232 public long SerializeSize => UncompressedDataHash . Length + 8 +
3333 BlocksInfo . Sum ( item => item . SerializeSize ) +
3434 DirectoryInfo . Sum ( item => item . SerializeSize ) ;
35-
36- /*public void uncompresseFlags()
37- {
38- foreach (var block in BlocksInfo)
39- {
40- //block.flags &= ~StorageBlockFlags.CompressionTypeMask;
41- block.Flags &= 0x0;
42- block.CompressedSize = block.UncompressedSize;
43- }
44- Update();
45- }
46-
47- public void merge()
48- {
49- List<StorageBlockInfo> newBlocksInfo = new List<StorageBlockInfo>();
50-
51- foreach (var block in BlocksInfo)
52- {
53- if (newBlocksInfo.Count > 0)
54- {
55- if (newBlocksInfo.Last().Flags != block.Flags)
56- {
57- throw new Exception("Expected all blocks to have the same flags");
58- }
59- long newSize = (long)newBlocksInfo.Last().UncompressedSize + block.UncompressedSize;
60- if (newSize <= uint.MaxValue)
61- {
62- newBlocksInfo.Last().UncompressedSize = (uint)newSize;
63- newBlocksInfo.Last().CompressedSize += block.CompressedSize;
64- }
65- else
66- {
67- newBlocksInfo.Add(block);
68- }
69- }
70- else
71- {
72- newBlocksInfo.Add(block);
73- }
74- }
75-
76- if (DirectoryInfo.Sum(x => x.Size) != newBlocksInfo.Sum(x => x.UncompressedSize))
77- {
78- throw new Exception("Expected all blocks size bigger than CAB size");
79- }
80-
81- BlocksInfo = newBlocksInfo;
82- Update();
83- }
84-
85- public void ResizeBlocksInfos()
86- {
87- List<StorageBlockInfo> newBlocksInfo = new List<StorageBlockInfo>();
88- foreach (var block in BlocksInfo)
89- {
90- if (block.UncompressedSize > 0x00020000)
91- {
92- uint num = block.UncompressedSize / 0x00020000;
93- uint num2 = block.UncompressedSize % 0x00020000;
94- for (uint i = 0; i < num; i++)
95- {
96- newBlocksInfo.Add(new StorageBlockInfo(0x00020000, 0x00020000, block.Flags));
97- }
98- if (num2 > 0)
99- {
100- newBlocksInfo.Add(new StorageBlockInfo(num2, num2, block.Flags));
101- }
102- }
103- else
104- {
105- newBlocksInfo.Add(block);
106- }
107- }
108- BlocksInfo = newBlocksInfo;
109- Update();
110- }
111-
112- public void Update(CompressionType compressionType = CompressionType.None)
113- {
114- // 写入数据到BlocksInfoBytes
115- var BlocksInfoStream = new MemoryStream();
116- using AssetWriter writer = new AssetWriter(BlocksInfoStream);
117- writer.Write(UncompressedDataHash);
118- writer.WriteInt32(BlocksInfo.Count);
119- foreach (var block in BlocksInfo)
120- {
121- //block.Write(writer);
122- }
123- writer.WriteInt32(DirectoryInfo.Count);
124- foreach (var node in DirectoryInfo)
125- {
126- //node.Write(writer);
127- }
128-
129- uncompressedSize = (uint)BlocksInfoStream.Length;
130- BlocksInfoBytes = Compression.CompressStream(BlocksInfoStream, compressionType);
131- }
132-
133- public void calculateSize(ref uint uncompressedBlocksInfoSize, ref uint compressedBlocksInfoSize)
134- {
135- uncompressedBlocksInfoSize = uncompressedSize;
136- compressedBlocksInfoSize = (uint)BlocksInfoBytes.Count;
137- }
138-
139- public void FixSize(int diff)
140- {
141-
142- if (DirectoryInfo[^1].Size + diff <= UInt32.MaxValue && DirectoryInfo[^1].Size + diff > 0)
143- {
144- if (BlocksInfo[^1].UncompressedSize + diff <= UInt32.MaxValue && BlocksInfo[^1].UncompressedSize + diff > 0)
145- {
146- if (diff > 0)
147- {
148- BlocksInfo[^1].UncompressedSize += (uint)diff;
149- BlocksInfo[^1].CompressedSize += (uint)diff;
150- DirectoryInfo[^1].Size += (uint)diff;
151- }
152- else
153- {
154- BlocksInfo[^1].UncompressedSize -= (uint)-diff;
155- BlocksInfo[^1].CompressedSize -= (uint)-diff;
156- DirectoryInfo[^1].Size -= (uint)-diff;
157- }
158- }
159- else
160- {
161- if (BlocksInfo[^1].UncompressedSize + diff <= UInt32.MaxValue)
162- {
163- BlocksInfo.Add(new StorageBlockInfo((uint)diff, (uint)diff ,BlocksInfo[^1].Flags));
164- DirectoryInfo[^1].Size += (uint)diff;
165- }
166- else
167- {
168- diff += (int)BlocksInfo[^1].UncompressedSize;
169- diff = -diff;
170- BlocksInfo.Remove(BlocksInfo[^1]);
171- BlocksInfo[^1].UncompressedSize -= (uint)diff;
172- BlocksInfo[^1].CompressedSize -= (uint)diff;
173- DirectoryInfo[^1].Size -= (uint)diff;
174- }
175- }
176- }
177- else
178- {
179- throw new Exception("DirectoryInfo size overflow");
180- }
181- }
182-
183- public void Write(AssetWriter writer)
184- {
185- writer.Write(BlocksInfoBytes.ToArray());
186- }*/
18735}
0 commit comments