@@ -83,35 +83,48 @@ public void Load()
83
83
timer . Stop ( ) ;
84
84
Console . WriteLine ( "Group index loaded in " + Math . Ceiling ( timer . Elapsed . TotalMilliseconds ) + "ms" ) ;
85
85
86
- timer . Restart ( ) ;
87
- if ( ! CDNConfig . Values . TryGetValue ( "file-index" , out var fileIndex ) )
88
- throw new Exception ( "No file index found in CDN config" ) ;
89
-
90
- if ( ! string . IsNullOrEmpty ( Settings . BaseDir ) && File . Exists ( Path . Combine ( Settings . BaseDir , "Data" , "indices" , fileIndex [ 0 ] + ".index" ) ) )
86
+ ulong decodedEncodingSize = 0 ;
87
+ ulong encodedEncodingSize = 0 ;
88
+ if ( BuildConfig . Values . TryGetValue ( "encoding-size" , out var bcEncodingSize ) )
91
89
{
92
- FileIndex = new IndexInstance ( Path . Combine ( Settings . BaseDir , "Data" , "indices" , fileIndex [ 0 ] + ".index" ) ) ;
90
+ decodedEncodingSize = ulong . Parse ( bcEncodingSize [ 0 ] ) ;
91
+ encodedEncodingSize = ulong . Parse ( bcEncodingSize [ 1 ] ) ;
93
92
}
94
- else
95
- {
96
- try
97
- {
98
- var fileIndexPath = cdn . GetFilePath ( "data" , fileIndex [ 0 ] + ".index" ) ;
99
- FileIndex = new IndexInstance ( fileIndexPath ) ;
100
93
101
- } catch ( Exception e )
94
+ timer . Restart ( ) ;
95
+ Encoding = new EncodingInstance ( cdn . GetDecodedFilePath ( "data" , BuildConfig . Values [ "encoding" ] [ 1 ] , encodedEncodingSize , decodedEncodingSize ) , ( int ) decodedEncodingSize ) ;
96
+ timer . Stop ( ) ;
97
+ Console . WriteLine ( "Encoding loaded in " + Math . Ceiling ( timer . Elapsed . TotalMilliseconds ) + "ms" ) ;
98
+
99
+ timer . Restart ( ) ;
100
+ if ( CDNConfig . Values . TryGetValue ( "file-index" , out var fileIndex ) )
101
+ {
102
+ if ( ! string . IsNullOrEmpty ( Settings . BaseDir ) && File . Exists ( Path . Combine ( Settings . BaseDir , "Data" , "indices" , fileIndex [ 0 ] + ".index" ) ) )
102
103
{
103
- Console . WriteLine ( "Failed to load file index: " + e . Message ) ;
104
+ FileIndex = new IndexInstance ( Path . Combine ( Settings . BaseDir , "Data" , "indices" , fileIndex [ 0 ] + ".index" ) ) ;
104
105
}
105
- }
106
+ else
107
+ {
108
+ try
109
+ {
110
+ var fileIndexPath = cdn . GetFilePath ( "data" , fileIndex [ 0 ] + ".index" ) ;
111
+ FileIndex = new IndexInstance ( fileIndexPath ) ;
106
112
107
- timer . Stop ( ) ;
108
- Console . WriteLine ( "File index loaded in " + Math . Ceiling ( timer . Elapsed . TotalMilliseconds ) + "ms" ) ;
113
+ }
114
+ catch ( Exception e )
115
+ {
116
+ Console . WriteLine ( "Failed to load file index: " + e . Message ) ;
117
+ }
118
+ }
109
119
110
- var encodingSize = ulong . Parse ( BuildConfig . Values [ "encoding-size" ] [ 0 ] ) ;
111
- timer . Restart ( ) ;
112
- Encoding = new EncodingInstance ( cdn . GetDecodedFilePath ( "data" , BuildConfig . Values [ "encoding" ] [ 1 ] , ulong . Parse ( BuildConfig . Values [ "encoding-size" ] [ 1 ] ) , encodingSize ) , ( int ) encodingSize ) ;
113
- timer . Stop ( ) ;
114
- Console . WriteLine ( "Encoding loaded in " + Math . Ceiling ( timer . Elapsed . TotalMilliseconds ) + "ms" ) ;
120
+ timer . Stop ( ) ;
121
+ Console . WriteLine ( "File index loaded in " + Math . Ceiling ( timer . Elapsed . TotalMilliseconds ) + "ms" ) ;
122
+ }
123
+ else
124
+ {
125
+ // TODO: We might want to manually build up file-index based on encoding entries not present in indexes.
126
+ Console . WriteLine ( "No file index found in CDN config, skipping file index loading." ) ;
127
+ }
115
128
116
129
timer . Restart ( ) ;
117
130
if ( ! BuildConfig . Values . TryGetValue ( "root" , out var rootKey ) )
@@ -144,7 +157,7 @@ public byte[] OpenFileByFDID(uint fileDataID)
144
157
throw new Exception ( "Root not loaded" ) ;
145
158
146
159
var fileData = Root . GetEntriesByFDID ( fileDataID ) ;
147
- if ( fileData . Count == 0 )
160
+ if ( fileData . Count == 0 )
148
161
throw new Exception ( "File not found in root" ) ;
149
162
150
163
return OpenFileByCKey ( fileData [ 0 ] . md5 . AsSpan ( ) ) ;
@@ -176,7 +189,7 @@ public byte[] OpenFileByEKey(ReadOnlySpan<byte> eKey, ulong decodedSize = 0)
176
189
177
190
if ( offset == - 1 )
178
191
{
179
- if ( FileIndex != null )
192
+ if ( FileIndex != null )
180
193
{
181
194
var fileIndexEntry = FileIndex . GetIndexInfo ( eKey ) ;
182
195
if ( fileIndexEntry . size != - 1 )
0 commit comments