1010using static System . Runtime . InteropServices . JavaScript . JSType ;
1111using System . Xml . Linq ;
1212using Newtonsoft . Json ;
13+ using Analyzer . SQLite . Commands ;
1314
1415namespace UnityDataTools . Analyzer . SQLite ;
1516
@@ -49,8 +50,8 @@ public class SQLiteWriter : IWriter
4950 private SqliteCommand m_AddObjectCommand = new SqliteCommand ( ) ;
5051 private SqliteCommand m_AddTypeCommand = new SqliteCommand ( ) ;
5152 private SqliteCommand m_InsertDepCommand = new SqliteCommand ( ) ;
52- private SqliteCommand m_InsertBuild = new SqliteCommand ( ) ;
53- private SqliteCommand m_ExplicitAsset = new SqliteCommand ( ) ;
53+ private AddressablesBuild m_AddressablesBuild = new AddressablesBuild ( ) ;
54+ private AddressablesBuildExplicitAsset m_AddressablesExplicitAsset = new AddressablesBuildExplicitAsset ( ) ;
5455 private SqliteCommand m_LastId = new SqliteCommand ( ) ;
5556 private SqliteTransaction m_CurrentTransaction = null ;
5657 public SQLiteWriter ( string databaseName , bool skipReferences )
@@ -154,40 +155,8 @@ private void CreateSQLiteCommands()
154155 m_InsertDepCommand . Parameters . Add ( "@object" , SqliteType . Integer ) ;
155156 m_InsertDepCommand . Parameters . Add ( "@dependency" , SqliteType . Integer ) ;
156157
157- m_InsertBuild = m_Database . CreateCommand ( ) ;
158- m_InsertBuild . CommandText = "INSERT INTO build_layouts (name, build_target, start_time, duration, error, package_version, player_version, build_script, result_hash, type, unity_version) VALUES (@name, @build_target, @start_time, @duration, @error, @package_version, @player_version, @build_script, @result_hash, @type, @unity_version)" ;
159- m_InsertBuild . Parameters . Add ( "@name" , SqliteType . Text ) ;
160- m_InsertBuild . Parameters . Add ( "@build_target" , SqliteType . Integer ) ;
161- m_InsertBuild . Parameters . Add ( "@start_time" , SqliteType . Integer ) ;
162- m_InsertBuild . Parameters . Add ( "@duration" , SqliteType . Real ) ;
163- m_InsertBuild . Parameters . Add ( "@error" , SqliteType . Text ) ;
164- m_InsertBuild . Parameters . Add ( "@package_version" , SqliteType . Text ) ;
165- m_InsertBuild . Parameters . Add ( "@player_version" , SqliteType . Text ) ;
166- m_InsertBuild . Parameters . Add ( "@build_script" , SqliteType . Text ) ;
167- m_InsertBuild . Parameters . Add ( "@result_hash" , SqliteType . Text ) ;
168- m_InsertBuild . Parameters . Add ( "@type" , SqliteType . Integer ) ;
169- m_InsertBuild . Parameters . Add ( "@unity_version" , SqliteType . Text ) ;
170-
171- m_ExplicitAsset = m_Database . CreateCommand ( ) ;
172- m_ExplicitAsset . CommandText =
173- "INSERT INTO build_layout_explicit_assets (id, build_id, bundle, file, asset_hash, asset_path, addressable_name, externally_referenced_assets, group_guid, guid, internal_id, internal_referenced_explicit_assets, internal_referenced_other_assets, labels, streamed_size, serialized_size, main_asset_type) VALUES (@id, @build_id, @bundle, @file, @asset_hash, @asset_path, @addressable_name, @externally_referenced_assets, @group_guid, @guid, @internal_id, @internal_referenced_explicit_assets, @internal_referenced_other_assets, @labels, @streamed_size, @serialized_size, @main_asset_type)" ;
174- m_ExplicitAsset . Parameters . Add ( "@id" , SqliteType . Integer ) ;
175- m_ExplicitAsset . Parameters . Add ( "@build_id" , SqliteType . Integer ) ;
176- m_ExplicitAsset . Parameters . Add ( "@bundle" , SqliteType . Integer ) ;
177- m_ExplicitAsset . Parameters . Add ( "@file" , SqliteType . Integer ) ;
178- m_ExplicitAsset . Parameters . Add ( "@asset_hash" , SqliteType . Text ) ;
179- m_ExplicitAsset . Parameters . Add ( "@asset_path" , SqliteType . Text ) ;
180- m_ExplicitAsset . Parameters . Add ( "@addressable_name" , SqliteType . Text ) ;
181- m_ExplicitAsset . Parameters . Add ( "@externally_referenced_assets" , SqliteType . Text ) ; // JSONB type in SQLite uses TEXT
182- m_ExplicitAsset . Parameters . Add ( "@group_guid" , SqliteType . Text ) ;
183- m_ExplicitAsset . Parameters . Add ( "@guid" , SqliteType . Text ) ;
184- m_ExplicitAsset . Parameters . Add ( "@internal_id" , SqliteType . Text ) ;
185- m_ExplicitAsset . Parameters . Add ( "@internal_referenced_explicit_assets" , SqliteType . Text ) ; // JSONB type in SQLite uses TEXT
186- m_ExplicitAsset . Parameters . Add ( "@internal_referenced_other_assets" , SqliteType . Text ) ; // JSONB type in SQLite uses TEXT
187- m_ExplicitAsset . Parameters . Add ( "@labels" , SqliteType . Text ) ; // JSONB type in SQLite uses TEXT
188- m_ExplicitAsset . Parameters . Add ( "@streamed_size" , SqliteType . Integer ) ;
189- m_ExplicitAsset . Parameters . Add ( "@serialized_size" , SqliteType . Integer ) ;
190- m_ExplicitAsset . Parameters . Add ( "@main_asset_type" , SqliteType . Integer ) ;
158+ m_AddressablesBuild . CreateCommand ( m_Database ) ;
159+ m_AddressablesExplicitAsset . CreateCommand ( m_Database ) ;
191160
192161 m_LastId = m_Database . CreateCommand ( ) ;
193162 m_LastId . CommandText = "SELECT last_insert_rowid()" ;
@@ -216,26 +185,26 @@ public void EndAssetBundle()
216185 m_CurrentAssetBundleId = - 1 ;
217186 }
218187
219- public void WriteBuildLayout ( string filename , BuildLayout buildLayout )
188+ public void WriteAddressablesBuild ( string filename , BuildLayout buildLayout )
220189 {
221190 using var transaction = m_Database . BeginTransaction ( ) ;
222191 m_CurrentTransaction = transaction ;
223192
224193 try
225194 {
226- m_InsertBuild . Transaction = transaction ;
227- m_InsertBuild . Parameters [ "@ name"] . Value = Path . GetFileName ( filename ) ;
228- m_InsertBuild . Parameters [ "@ build_target"] . Value = buildLayout . BuildTarget ;
229- m_InsertBuild . Parameters [ "@ start_time"] . Value = buildLayout . BuildStartTime ;
230- m_InsertBuild . Parameters [ "@ duration"] . Value = buildLayout . Duration ;
231- m_InsertBuild . Parameters [ "@ error"] . Value = buildLayout . BuildError ;
232- m_InsertBuild . Parameters [ "@ package_version"] . Value = buildLayout . PackageVersion ;
233- m_InsertBuild . Parameters [ "@ player_version"] . Value = buildLayout . PlayerBuildVersion ;
234- m_InsertBuild . Parameters [ "@ build_script"] . Value = buildLayout . BuildScript ;
235- m_InsertBuild . Parameters [ "@ result_hash"] . Value = buildLayout . BuildResultHash ;
236- m_InsertBuild . Parameters [ "@ type"] . Value = buildLayout . BuildType ;
237- m_InsertBuild . Parameters [ "@ unity_version"] . Value = buildLayout . UnityVersion ;
238- m_InsertBuild . ExecuteNonQuery ( ) ;
195+ m_AddressablesBuild . SetTransaction ( transaction ) ;
196+ m_AddressablesBuild . SetValue ( " name", Path . GetFileName ( filename ) ) ;
197+ m_AddressablesBuild . SetValue ( " build_target", buildLayout . BuildTarget ) ;
198+ m_AddressablesBuild . SetValue ( " start_time", buildLayout . BuildStartTime ) ;
199+ m_AddressablesBuild . SetValue ( " duration", buildLayout . Duration ) ;
200+ m_AddressablesBuild . SetValue ( " error", buildLayout . BuildError ) ;
201+ m_AddressablesBuild . SetValue ( " package_version", buildLayout . PackageVersion ) ;
202+ m_AddressablesBuild . SetValue ( " player_version", buildLayout . PlayerBuildVersion ) ;
203+ m_AddressablesBuild . SetValue ( " build_script", buildLayout . BuildScript ) ;
204+ m_AddressablesBuild . SetValue ( " result_hash", buildLayout . BuildResultHash ) ;
205+ m_AddressablesBuild . SetValue ( " type", buildLayout . BuildType ) ;
206+ m_AddressablesBuild . SetValue ( " unity_version", buildLayout . UnityVersion ) ;
207+ m_AddressablesBuild . ExecuteNonQuery ( ) ;
239208
240209 m_LastId . Transaction = transaction ;
241210 long buildId = ( long ) m_LastId . ExecuteScalar ( ) ;
@@ -246,25 +215,27 @@ public void WriteBuildLayout(string filename, BuildLayout buildLayout)
246215 switch ( reference . type . Class )
247216 {
248217 case "BuildLayout/ExplicitAsset" :
249- m_ExplicitAsset . Transaction = transaction ;
250- m_ExplicitAsset . Parameters [ "@id" ] . Value = reference . rid ;
251- m_ExplicitAsset . Parameters [ "@build_id" ] . Value = buildId ;
252- m_ExplicitAsset . Parameters [ "@bundle" ] . Value = reference . data . Bundle . rid ;
253- m_ExplicitAsset . Parameters [ "@file" ] . Value = reference . data . File . rid ;
254- m_ExplicitAsset . Parameters [ "@asset_hash" ] . Value = reference . data . AssetHash . Hash ;
255- m_ExplicitAsset . Parameters [ "@asset_path" ] . Value = reference . data . AssetPath ;
256- m_ExplicitAsset . Parameters [ "@addressable_name" ] . Value = reference . data . AddressableName ;
257- m_ExplicitAsset . Parameters [ "@externally_referenced_assets" ] . Value = JsonConvert . SerializeObject ( reference . data . ExternallyReferencedAssets ) ?? "[]" ;
258- m_ExplicitAsset . Parameters [ "@group_guid" ] . Value = reference . data . GroupGuid ;
259- m_ExplicitAsset . Parameters [ "@guid" ] . Value = reference . data . Guid ;
260- m_ExplicitAsset . Parameters [ "@internal_id" ] . Value = reference . data . InternalId ;
261- m_ExplicitAsset . Parameters [ "@internal_referenced_explicit_assets" ] . Value = JsonConvert . SerializeObject ( reference . data . InternalReferencedExplicitAssets ) ?? "[]" ;
262- m_ExplicitAsset . Parameters [ "@internal_referenced_other_assets" ] . Value = JsonConvert . SerializeObject ( reference . data . InternalReferencedOtherAssets ) ?? "[]" ;
263- m_ExplicitAsset . Parameters [ "@labels" ] . Value = JsonConvert . SerializeObject ( reference . data . Labels ) ?? "[]" ;
264- m_ExplicitAsset . Parameters [ "@main_asset_type" ] . Value = reference . data . MainAssetType ;
265- m_ExplicitAsset . Parameters [ "@serialized_size" ] . Value = reference . data . SerializedSize ;
266- m_ExplicitAsset . Parameters [ "@streamed_size" ] . Value = reference . data . StreamedSize ;
267- m_ExplicitAsset . ExecuteNonQuery ( ) ;
218+ m_AddressablesExplicitAsset . SetTransaction ( transaction ) ;
219+ m_AddressablesExplicitAsset . SetValue ( "id" , reference . rid ) ;
220+ m_AddressablesExplicitAsset . SetValue ( "build_id" , buildId ) ;
221+ m_AddressablesExplicitAsset . SetValue ( "bundle" , reference . data . Bundle . rid ) ;
222+ m_AddressablesExplicitAsset . SetValue ( "file" , reference . data . File . rid ) ;
223+ m_AddressablesExplicitAsset . SetValue ( "asset_hash" , reference . data . AssetHash . Hash ) ;
224+ m_AddressablesExplicitAsset . SetValue ( "asset_path" , reference . data . AssetPath ) ;
225+ m_AddressablesExplicitAsset . SetValue ( "addressable_name" , reference . data . AddressableName ) ;
226+ m_AddressablesExplicitAsset . SetValue ( "externally_referenced_assets" ,
227+ JsonConvert . SerializeObject ( reference . data . ExternallyReferencedAssets ) ?? "[]" ) ;
228+ m_AddressablesExplicitAsset . SetValue ( "group_guid" , reference . data . GroupGuid ) ;
229+ m_AddressablesExplicitAsset . SetValue ( "guid" , reference . data . Guid ) ;
230+ m_AddressablesExplicitAsset . SetValue ( "internal_id" , reference . data . InternalId ) ;
231+ m_AddressablesExplicitAsset . SetValue ( "internal_referenced_explicit_assets" ,
232+ JsonConvert . SerializeObject ( reference . data . InternalReferencedExplicitAssets ) ?? "[]" ) ;
233+ m_AddressablesExplicitAsset . SetValue ( "internal_referenced_other_assets" ,
234+ JsonConvert . SerializeObject ( reference . data . InternalReferencedOtherAssets ) ?? "[]" ) ;
235+ m_AddressablesExplicitAsset . SetValue ( "labels" ,
236+ JsonConvert . SerializeObject ( reference . data . Labels ) ?? "[]" ) ;
237+ m_AddressablesExplicitAsset . SetValue ( "main_asset_type" , reference . data . MainAssetType ) ;
238+ m_AddressablesExplicitAsset . ExecuteNonQuery ( ) ;
268239 break ;
269240 }
270241 }
0 commit comments