@@ -11,20 +11,32 @@ public class BuildInstance
1111 public IndexInstance ? GroupIndex { get ; private set ; }
1212 public IndexInstance ? FileIndex { get ; private set ; }
1313
14- public BuildInstance ( string buildConfig , string cdnConfig )
14+ public CDN cdn { get ; private set ; }
15+
16+ public Settings Settings { get ; private set ; } = new Settings ( ) ;
17+
18+ public BuildInstance ( )
19+ {
20+ cdn = new ( Settings ) ;
21+ }
22+
23+ public void LoadConfigs ( string buildConfig , string cdnConfig )
1524 {
16- // Always load configs so we have basic information available, loading the full build is optional.
25+ Settings . BuildConfig = buildConfig ;
26+ Settings . CDNConfig = cdnConfig ;
27+
1728 var timer = new System . Diagnostics . Stopwatch ( ) ;
1829 timer . Start ( ) ;
30+
1931 if ( File . Exists ( buildConfig ) )
20- BuildConfig = new Config ( buildConfig , true ) ;
32+ BuildConfig = new Config ( cdn , buildConfig , true ) ;
2133 else if ( buildConfig . Length == 32 && buildConfig . All ( c => "0123456789abcdef" . Contains ( c ) ) )
22- BuildConfig = new Config ( buildConfig , false ) ;
34+ BuildConfig = new Config ( cdn , buildConfig , false ) ;
2335
2436 if ( File . Exists ( cdnConfig ) )
25- CDNConfig = new Config ( cdnConfig , true ) ;
37+ CDNConfig = new Config ( cdn , cdnConfig , true ) ;
2638 else if ( cdnConfig . Length == 32 && cdnConfig . All ( c => "0123456789abcdef" . Contains ( c ) ) )
27- CDNConfig = new Config ( cdnConfig , false ) ;
39+ CDNConfig = new Config ( cdn , cdnConfig , false ) ;
2840
2941 if ( BuildConfig == null || CDNConfig == null )
3042 throw new Exception ( "Failed to load configs" ) ;
@@ -34,13 +46,17 @@ public BuildInstance(string buildConfig, string cdnConfig)
3446
3547 public void Load ( )
3648 {
49+ if ( BuildConfig == null || CDNConfig == null )
50+ throw new Exception ( "Configs not loaded" ) ;
51+
3752 var timer = new System . Diagnostics . Stopwatch ( ) ;
3853
3954 timer . Start ( ) ;
4055 if ( ! CDNConfig . Values . TryGetValue ( "archive-group" , out var groupArchiveIndex ) )
4156 {
4257 Console . WriteLine ( "No group index found in CDN config, generating fresh group index..." ) ;
43- var groupIndexHash = TACTSharp . GroupIndex . Generate ( "" , CDNConfig . Values [ "archives" ] ) ;
58+ var groupIndex = new GroupIndex ( ) ;
59+ var groupIndexHash = groupIndex . Generate ( cdn , Settings , "" , CDNConfig . Values [ "archives" ] ) ;
4460 var groupIndexPath = Path . Combine ( Settings . CacheDir , "wow" , "data" , groupIndexHash + ".index" ) ;
4561 GroupIndex = new IndexInstance ( groupIndexPath ) ;
4662 }
@@ -54,7 +70,10 @@ public void Load()
5470 {
5571 var groupIndexPath = Path . Combine ( Settings . CacheDir , "wow" , "data" , groupArchiveIndex [ 0 ] + ".index" ) ;
5672 if ( ! File . Exists ( groupIndexPath ) )
57- TACTSharp . GroupIndex . Generate ( groupArchiveIndex [ 0 ] , CDNConfig . Values [ "archives" ] ) ;
73+ {
74+ var groupIndex = new GroupIndex ( ) ;
75+ groupIndex . Generate ( cdn , Settings , groupArchiveIndex [ 0 ] , CDNConfig . Values [ "archives" ] ) ;
76+ }
5877 GroupIndex = new IndexInstance ( groupIndexPath ) ;
5978 }
6079 }
@@ -71,7 +90,7 @@ public void Load()
7190 }
7291 else
7392 {
74- var fileIndexPath = CDN . GetFilePath ( "wow" , "data" , fileIndex [ 0 ] + ".index" ) ;
93+ var fileIndexPath = cdn . GetFilePath ( "wow" , "data" , fileIndex [ 0 ] + ".index" ) ;
7594 FileIndex = new IndexInstance ( fileIndexPath ) ;
7695 }
7796
@@ -80,7 +99,7 @@ public void Load()
8099
81100 var encodingSize = ulong . Parse ( BuildConfig . Values [ "encoding-size" ] [ 0 ] ) ;
82101 timer . Restart ( ) ;
83- Encoding = new EncodingInstance ( CDN . GetDecodedFilePath ( "wow" , "data" , BuildConfig . Values [ "encoding" ] [ 1 ] , ulong . Parse ( BuildConfig . Values [ "encoding-size" ] [ 1 ] ) , encodingSize ) , ( int ) encodingSize ) ;
102+ Encoding = new EncodingInstance ( cdn . GetDecodedFilePath ( "wow" , "data" , BuildConfig . Values [ "encoding" ] [ 1 ] , ulong . Parse ( BuildConfig . Values [ "encoding-size" ] [ 1 ] ) , encodingSize ) , ( int ) encodingSize ) ;
84103 timer . Stop ( ) ;
85104 Console . WriteLine ( "Encoding loaded in " + Math . Ceiling ( timer . Elapsed . TotalMilliseconds ) + "ms" ) ;
86105
@@ -92,7 +111,7 @@ public void Load()
92111 if ( ! rootEncodingKeys )
93112 throw new Exception ( "Root key not found in encoding" ) ;
94113
95- Root = new RootInstance ( CDN . GetDecodedFilePath ( "wow" , "data" , Convert . ToHexStringLower ( rootEncodingKeys [ 0 ] ) , 0 , rootEncodingKeys . DecodedFileSize ) ) ;
114+ Root = new RootInstance ( cdn . GetDecodedFilePath ( "wow" , "data" , Convert . ToHexStringLower ( rootEncodingKeys [ 0 ] ) , 0 , rootEncodingKeys . DecodedFileSize ) , Settings ) ;
96115 timer . Stop ( ) ;
97116 Console . WriteLine ( "Root loaded in " + Math . Ceiling ( timer . Elapsed . TotalMilliseconds ) + "ms" ) ;
98117
@@ -104,7 +123,7 @@ public void Load()
104123 if ( ! installEncodingKeys )
105124 throw new Exception ( "Install key not found in encoding" ) ;
106125
107- Install = new InstallInstance ( CDN . GetDecodedFilePath ( "wow" , "data" , Convert . ToHexStringLower ( installEncodingKeys [ 0 ] ) , 0 , installEncodingKeys . DecodedFileSize ) ) ;
126+ Install = new InstallInstance ( cdn . GetDecodedFilePath ( "wow" , "data" , Convert . ToHexStringLower ( installEncodingKeys [ 0 ] ) , 0 , installEncodingKeys . DecodedFileSize ) ) ;
108127 timer . Stop ( ) ;
109128 Console . WriteLine ( "Install loaded in " + Math . Ceiling ( timer . Elapsed . TotalMilliseconds ) + "ms" ) ;
110129 }
@@ -149,16 +168,16 @@ public byte[] OpenFileByEKey(ReadOnlySpan<byte> eKey, ulong decodedSize = 0)
149168 if ( fileIndexEntry . size == - 1 )
150169 {
151170 Console . WriteLine ( "Warning: EKey " + Convert . ToHexStringLower ( eKey ) + " not found in group or file index and might not be available on CDN." ) ;
152- fileBytes = CDN . GetFile ( "wow" , "data" , Convert . ToHexStringLower ( eKey ) , 0 , decodedSize , true ) ;
171+ fileBytes = cdn . GetFile ( "wow" , "data" , Convert . ToHexStringLower ( eKey ) , 0 , decodedSize , true ) ;
153172 }
154173 else
155174 {
156- fileBytes = CDN . GetFile ( "wow" , "data" , Convert . ToHexStringLower ( eKey ) , ( ulong ) fileIndexEntry . size , decodedSize , true ) ;
175+ fileBytes = cdn . GetFile ( "wow" , "data" , Convert . ToHexStringLower ( eKey ) , ( ulong ) fileIndexEntry . size , decodedSize , true ) ;
157176 }
158177 }
159178 else
160179 {
161- fileBytes = CDN . GetFileFromArchive ( Convert . ToHexStringLower ( eKey ) , "wow" , CDNConfig . Values [ "archives" ] [ archiveIndex ] , offset , size , decodedSize , true ) ;
180+ fileBytes = cdn . GetFileFromArchive ( Convert . ToHexStringLower ( eKey ) , "wow" , CDNConfig . Values [ "archives" ] [ archiveIndex ] , offset , size , decodedSize , true ) ;
162181 }
163182
164183 return fileBytes ;
0 commit comments