@@ -75,7 +75,7 @@ public void Load()
7575 if ( ! File . Exists ( groupIndexPath ) )
7676 {
7777 var groupIndex = new GroupIndex ( ) ;
78- groupIndex . Generate ( cdn , Settings , groupArchiveIndex [ 0 ] , CDNConfig . Values [ "archives" ] ) ;
78+ groupIndex . Generate ( cdn , Settings , groupArchiveIndex [ 0 ] , CDNConfig . Values [ "archives" ] , true ) ;
7979 }
8080 GroupIndex = new IndexInstance ( groupIndexPath ) ;
8181 }
@@ -93,8 +93,15 @@ public void Load()
9393 }
9494 else
9595 {
96- var fileIndexPath = cdn . GetFilePath ( "data" , fileIndex [ 0 ] + ".index" ) ;
97- FileIndex = new IndexInstance ( fileIndexPath ) ;
96+ try
97+ {
98+ var fileIndexPath = cdn . GetFilePath ( "data" , fileIndex [ 0 ] + ".index" ) ;
99+ FileIndex = new IndexInstance ( fileIndexPath ) ;
100+
101+ } catch ( Exception e )
102+ {
103+ Console . WriteLine ( "Failed to load file index: " + e . Message ) ;
104+ }
98105 }
99106
100107 timer . Stop ( ) ;
@@ -161,31 +168,28 @@ public byte[] OpenFileByCKey(ReadOnlySpan<byte> cKey)
161168
162169 public byte [ ] OpenFileByEKey ( ReadOnlySpan < byte > eKey , ulong decodedSize = 0 )
163170 {
164- if ( GroupIndex == null || FileIndex == null )
171+ if ( GroupIndex == null )
165172 throw new Exception ( "Indexes not loaded" ) ;
166173
167174 var ( offset , size , archiveIndex ) = GroupIndex . GetIndexInfo ( eKey ) ;
168175 byte [ ] fileBytes ;
169176
170177 if ( offset == - 1 )
171178 {
172- var fileIndexEntry = FileIndex . GetIndexInfo ( eKey ) ;
173- if ( fileIndexEntry . size == - 1 )
179+ if ( FileIndex != null )
174180 {
175- Console . WriteLine ( "Warning: EKey " + Convert . ToHexStringLower ( eKey ) + " not found in group or file index and might not be available on CDN." ) ;
176- fileBytes = cdn . GetFile ( "data" , Convert . ToHexStringLower ( eKey ) , 0 , decodedSize , true ) ;
177- }
178- else
179- {
180- fileBytes = cdn . GetFile ( "data" , Convert . ToHexStringLower ( eKey ) , ( ulong ) fileIndexEntry . size , decodedSize , true ) ;
181+ var fileIndexEntry = FileIndex . GetIndexInfo ( eKey ) ;
182+ if ( fileIndexEntry . size != - 1 )
183+ return cdn . GetFile ( "data" , Convert . ToHexStringLower ( eKey ) , ( ulong ) fileIndexEntry . size , decodedSize , true ) ;
181184 }
185+
186+ Console . WriteLine ( "Warning: EKey " + Convert . ToHexStringLower ( eKey ) + " not found in group or file index and might not be available on CDN." ) ;
187+ return cdn . GetFile ( "data" , Convert . ToHexStringLower ( eKey ) , 0 , decodedSize , true ) ;
182188 }
183189 else
184190 {
185- fileBytes = cdn . GetFileFromArchive ( Convert . ToHexStringLower ( eKey ) , CDNConfig . Values [ "archives" ] [ archiveIndex ] , offset , size , decodedSize , true ) ;
191+ return cdn . GetFileFromArchive ( Convert . ToHexStringLower ( eKey ) , CDNConfig . Values [ "archives" ] [ archiveIndex ] , offset , size , decodedSize , true ) ;
186192 }
187-
188- return fileBytes ;
189193 }
190194 }
191195}
0 commit comments