Skip to content

Commit b4f09dc

Browse files
[#68] Generalize AssetBundle to Archive in analyze schema and code (#89)
* [#68] ANALYZE SCHEMA CHANGE - Generalize AssetBundle to Archive Unity Archives back AssetBundles, Player builds, Content Archives and ContentDirectory builds, so names that said "AssetBundle" where the concept is really "any Unity Archive" were misleading (notably for ContentDirectory builds). Rename those to "Archive", leaving genuinely AssetBundle-object- specific names (assetbundle_assets, AssetBundleHandler, etc.) untouched. Schema (user_version 2 -> 3): - Table asset_bundles -> archives; serialized_files.asset_bundle -> archive. - The asset_bundle view alias -> archive across object_view and the views that build on it (material/shader/texture/dep aliases, monoscript views, in_bundles -> in_archives). - build_report_archive_contents.assetbundle/assetbundle_content -> archive/archive_content. Code: - AddAssetBundle -> AddArchive; Begin/EndAssetBundle -> Begin/EndArchive; Context.AssetBundleId -> ArchiveId; ExtractAssetBundle/ListAssetBundle -> ExtractArchive/ListArchive; FileListAssetBundleHelper -> FileListArchiveHelper. - ReferenceFinder query column and output labels ("Archive:"). - Stripped the stale auto-generated SQL snapshot comments from Resources.Designer.cs (they drift; the .sql files are the source of truth). Tests, compare scripts and documentation updated to match; test key asset_bundles_count -> archives_count.
1 parent 74bf384 commit b4f09dc

35 files changed

Lines changed: 184 additions & 816 deletions

Analyzer/Properties/Resources.Designer.cs

Lines changed: 1 addition & 672 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Analyzer/Resources/AssetBundle.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
-- tables related to the AssetBundle and PreloadData objects
22

33
-- Do not confuse the AssetBundle Unity object (the source of much of this data)
4-
-- with the asset_bundles table, which is general to any Unity Archive.
4+
-- with the archives table, which is general to any Unity Archive.
55

66
-- The "assets" that an AssetBundle explicitly exposes: each m_Container entry of the AssetBundle
77
-- object names an object (the addressable/asset name -> object it maps to). Populated only from
@@ -34,7 +34,7 @@ SELECT
3434
FROM assetbundle_assets a INNER JOIN object_view o ON o.id = a.object;
3535

3636
CREATE VIEW IF NOT EXISTS preload_dependencies_view AS
37-
SELECT a.id, a.asset_name, a.asset_bundle, a.type, od.id dep_id, od.asset_bundle dep_asset_bundle, od.name dep_name, od.type dep_type
37+
SELECT a.id, a.asset_name, a.archive, a.type, od.id dep_id, od.archive dep_archive, od.name dep_name, od.type dep_type
3838
FROM assetbundle_asset_view a
3939
INNER JOIN preload_dependencies d ON a.id = d.object
4040
INNER JOIN object_view od ON od.id = d.dependency;

Analyzer/Resources/BuildReport.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ CREATE TABLE IF NOT EXISTS build_report_files(
3030

3131
CREATE TABLE IF NOT EXISTS build_report_archive_contents(
3232
build_report_id INTEGER NOT NULL,
33-
assetbundle TEXT NOT NULL,
34-
assetbundle_content TEXT NOT NULL,
35-
PRIMARY KEY (build_report_id, assetbundle_content),
33+
archive TEXT NOT NULL,
34+
archive_content TEXT NOT NULL,
35+
PRIMARY KEY (build_report_id, archive_content),
3636
FOREIGN KEY (build_report_id) REFERENCES build_reports(id)
3737
);
3838

Analyzer/Resources/Init.sql

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ CREATE TABLE IF NOT EXISTS types
88
-- Describes a unity archive that contains serialized files and other built content.
99
-- A common use of the unity archive is for AssetBundles but it can also be used for
1010
-- Player, Content Archive and ContentDirectory builds.
11-
--
12-
-- See issue 68 for proposed rename
13-
CREATE TABLE IF NOT EXISTS asset_bundles
11+
CREATE TABLE IF NOT EXISTS archives
1412
(
1513
id INTEGER,
1614
name TEXT,
@@ -26,12 +24,12 @@ CREATE TABLE IF NOT EXISTS asset_bundles
2624
-- "BuildPlayer-<SceneName>"; the Scriptable Build Pipeline / Addressables uses
2725
-- "CAB-<hash of scene path>"; the Multi-Process Build Pipeline uses "CAB-<scene GUID>".
2826
-- * Player builds name scenes "level0", "level1", ... in scene-list order.
29-
-- asset_bundle references the row from asset_bundles table of the unity archive containing this file,
27+
-- archive references the row from archives table of the unity archive containing this file,
3028
-- or is '' when the file is not inside an unity archive; object_view turns that '' into NULL.
3129
CREATE TABLE IF NOT EXISTS serialized_files
3230
(
3331
id INTEGER,
34-
asset_bundle INTEGER,
32+
archive INTEGER,
3533
name TEXT,
3634
PRIMARY KEY (id)
3735
);
@@ -91,7 +89,7 @@ INNER JOIN property_names pn ON r.property_path = pn.id
9189
INNER JOIN property_types pt ON r.property_type = pt.id;
9290

9391
CREATE VIEW object_view AS
94-
SELECT o.id, o.object_id, ab.name AS asset_bundle, sf.name AS serialized_file, t.name AS type, o.name, o.game_object, o.size,
92+
SELECT o.id, o.object_id, ab.name AS archive, sf.name AS serialized_file, t.name AS type, o.name, o.game_object, o.size,
9593
CASE
9694
WHEN size < 1024 THEN printf('%!5.1f B', size * 1.0)
9795
WHEN size >= 1024 AND size < (1024 * 1024) THEN printf('%!5.1f KB', size / 1024.0)
@@ -101,7 +99,7 @@ END AS pretty_size, o.crc32
10199
FROM objects o
102100
INNER JOIN types t ON o.type = t.id
103101
INNER JOIN serialized_files sf ON o.serialized_file = sf.id
104-
LEFT JOIN asset_bundles ab ON sf.asset_bundle = ab.id;
102+
LEFT JOIN archives ab ON sf.archive = ab.id;
105103

106104
CREATE VIEW view_breakdown_by_type AS
107105
SELECT *,
@@ -128,21 +126,21 @@ END AS pretty_total_size,
128126
sum(size) AS total_size,
129127
size,
130128
pretty_size,
131-
REPLACE(GROUP_CONCAT(DISTINCT IIF(asset_bundle IS NULL, serialized_file, asset_bundle)), ',', ',' || CHAR(13)) AS in_files
129+
REPLACE(GROUP_CONCAT(DISTINCT IIF(archive IS NULL, serialized_file, archive)), ',', ',' || CHAR(13)) AS in_files
132130
FROM object_view
133131
GROUP BY name, type, size, crc32
134132
HAVING instances > 1
135133
ORDER BY size DESC, instances DESC;
136134

137135
CREATE VIEW view_material_shader_refs AS
138-
SELECT m.id material_id, m.name material_name, a.name material_path, m.asset_bundle material_asset_bundle, s.id shader_id, s.name shader_name, s.asset_bundle shader_asset_bundle
136+
SELECT m.id material_id, m.name material_name, a.name material_path, m.archive material_archive, s.id shader_id, s.name shader_name, s.archive shader_archive
139137
FROM object_view m
140138
INNER JOIN refs_view r ON m.id = r.object AND r.property_path = 'm_Shader'
141139
INNER JOIN object_view s ON r.referenced_object = s.id
142140
LEFT JOIN assetbundle_assets a ON m.id = a.object;
143141

144142
CREATE VIEW view_material_texture_refs AS
145-
SELECT m.id material_id, m.name material_name, a.name material_path, m.asset_bundle material_asset_bundle, t.id texture_id, t.name texture_name, t.asset_bundle texture_asset_bundle
143+
SELECT m.id material_id, m.name material_name, a.name material_path, m.archive material_archive, t.id texture_id, t.name texture_name, t.archive texture_archive
146144
FROM object_view m
147145
INNER JOIN refs_view r ON r.object = m.id AND property_type = 'Texture'
148146
INNER JOIN object_view t ON r.referenced_object = t.id
@@ -156,8 +154,9 @@ INSERT INTO types (id, name) VALUES (-1, 'Scene');
156154
-- Database schema version. Bump when the schema changes in a way that tools relying on it
157155
-- (e.g. find-refs) cannot read from an older database. 1 = normalized refs table (issue #44);
158156
-- 2 = renamed assets/asset_dependencies tables to assetbundle_assets/preload_dependencies
159-
-- (issue #82); databases produced before versioning report 0.
160-
PRAGMA user_version = 2;
157+
-- (issue #82); 3 = renamed asset_bundles table to archives and the asset_bundle column/alias
158+
-- to archive (issue #68); databases produced before versioning report 0.
159+
PRAGMA user_version = 3;
161160

162161
PRAGMA synchronous = OFF;
163162
PRAGMA journal_mode = MEMORY;

Analyzer/Resources/MonoScript.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ CREATE VIEW monoscript_view AS
1010
SELECT
1111
o.id,
1212
o.object_id,
13-
o.asset_bundle,
13+
o.archive,
1414
o.serialized_file,
1515
m.class_name,
1616
m.namespace,
@@ -21,7 +21,7 @@ CREATE VIEW script_object_view AS
2121
SELECT
2222
mb.id,
2323
mb.object_id,
24-
mb.asset_bundle,
24+
mb.archive,
2525
mb.serialized_file,
2626
ms.class_name,
2727
ms.namespace,

Analyzer/Resources/PackedAssets.sql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ CREATE VIEW build_report_packed_assets_view AS
2727
SELECT
2828
pa.id,
2929
o.object_id,
30-
brac.assetbundle,
30+
brac.archive,
3131
pa.path,
3232
pa.file_header_size,
3333
br_obj.id as build_report_id,
@@ -36,12 +36,12 @@ FROM build_report_packed_assets pa
3636
INNER JOIN objects o ON pa.id = o.id
3737
INNER JOIN serialized_files sf ON o.serialized_file = sf.id
3838
LEFT JOIN objects br_obj ON o.serialized_file = br_obj.serialized_file AND br_obj.type = 1125
39-
LEFT JOIN build_report_archive_contents brac ON br_obj.id = brac.build_report_id AND pa.path = brac.assetbundle_content;
39+
LEFT JOIN build_report_archive_contents brac ON br_obj.id = brac.build_report_id AND pa.path = brac.archive_content;
4040

4141
CREATE VIEW build_report_packed_asset_contents_view AS
4242
SELECT
4343
sf.name as serialized_file,
44-
brac.assetbundle,
44+
brac.archive,
4545
pa.path,
4646
pac.packed_assets_id,
4747
pac.object_id,
@@ -57,5 +57,5 @@ LEFT JOIN objects o ON o.id = pa.id
5757
INNER JOIN serialized_files sf ON o.serialized_file = sf.id
5858
LEFT JOIN build_report_source_assets sa ON pac.source_asset_id = sa.id
5959
LEFT JOIN objects br_obj ON o.serialized_file = br_obj.serialized_file AND br_obj.type = 1125
60-
LEFT JOIN build_report_archive_contents brac ON br_obj.id = brac.build_report_id AND pa.path = brac.assetbundle_content;
60+
LEFT JOIN build_report_archive_contents brac ON br_obj.id = brac.build_report_id AND pa.path = brac.archive_content;
6161

Analyzer/Resources/Shader.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ CASE
6363
WHEN sum(size) >= (1024 * 1024) AND sum(size) < (1024 * 1024 * 1024) THEN printf('%!5.1f MB', sum(size) / 1024.0 / 1024)
6464
WHEN sum(size) >= (1024 * 1024 * 1024) THEN printf('%!5.1f GB', sum(size) / 1024.0 / 1024 / 1024)
6565
END AS pretty_total_size,
66-
sum(size) AS total_size, GROUP_CONCAT(asset_bundle, ',' || CHAR(13)) AS in_bundles
66+
sum(size) AS total_size, GROUP_CONCAT(archive, ',' || CHAR(13)) AS in_archives
6767
FROM shader_view
6868
GROUP BY name
6969
ORDER BY total_size DESC, instances DESC;

Analyzer/SQLite/Commands/SerializedFile/AddAssetBundle.cs renamed to Analyzer/SQLite/Commands/SerializedFile/AddArchive.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44
namespace UnityDataTools.Analyzer.SQLite.Commands.SerializedFile
55
{
66
/* TABLE DEFINITION:
7-
create table asset_bundles
7+
create table archives
88
(
99
id INTEGER,
1010
name TEXT,
1111
file_size INTEGER,
1212
PRIMARY KEY (id)
1313
);
1414
*/
15-
internal class AddAssetBundle : AbstractCommand
15+
internal class AddArchive : AbstractCommand
1616
{
17-
protected override string TableName => "asset_bundles";
17+
protected override string TableName => "archives";
1818

1919
protected override string DDLSource => null;
2020

Analyzer/SQLite/Commands/SerializedFile/AddSerializedFile.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace UnityDataTools.Analyzer.SQLite.Commands.SerializedFile
88
create table serialized_files
99
(
1010
id INTEGER,
11-
asset_bundle INTEGER,
11+
archive INTEGER,
1212
name TEXT,
1313
PRIMARY KEY (id)
1414
);
@@ -22,7 +22,7 @@ internal class AddSerializedFile : AbstractCommand
2222
protected override Dictionary<string, SqliteType> Fields => new()
2323
{
2424
{ "id", SqliteType.Integer },
25-
{ "asset_bundle", SqliteType.Integer },
25+
{ "archive", SqliteType.Integer },
2626
{ "name", SqliteType.Text }
2727
};
2828
}

Analyzer/SQLite/Handlers/BuildReportHandler.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,14 @@ public void Init(SqliteConnection db)
6060

6161
m_InsertArchiveContentCommand = db.CreateCommand();
6262
m_InsertArchiveContentCommand.CommandText = @"INSERT INTO build_report_archive_contents(
63-
build_report_id, assetbundle, assetbundle_content
63+
build_report_id, archive, archive_content
6464
) VALUES(
65-
@build_report_id, @assetbundle, @assetbundle_content
65+
@build_report_id, @archive, @archive_content
6666
)";
6767

6868
m_InsertArchiveContentCommand.Parameters.Add("@build_report_id", SqliteType.Integer);
69-
m_InsertArchiveContentCommand.Parameters.Add("@assetbundle", SqliteType.Text);
70-
m_InsertArchiveContentCommand.Parameters.Add("@assetbundle_content", SqliteType.Text);
69+
m_InsertArchiveContentCommand.Parameters.Add("@archive", SqliteType.Text);
70+
m_InsertArchiveContentCommand.Parameters.Add("@archive_content", SqliteType.Text);
7171
}
7272

7373
public void Process(Context ctx, long objectId, RandomAccessReader reader, out string name, out long streamDataSize)
@@ -106,12 +106,12 @@ public void Process(Context ctx, long objectId, RandomAccessReader reader, out s
106106
}
107107

108108
// Insert archive contents mapping
109-
foreach (var mapping in buildReport.fileListAssetBundleHelper.internalNameToArchiveMapping)
109+
foreach (var mapping in buildReport.fileListArchiveHelper.internalNameToArchiveMapping)
110110
{
111111
m_InsertArchiveContentCommand.Transaction = ctx.Transaction;
112112
m_InsertArchiveContentCommand.Parameters["@build_report_id"].Value = objectId;
113-
m_InsertArchiveContentCommand.Parameters["@assetbundle"].Value = mapping.Value;
114-
m_InsertArchiveContentCommand.Parameters["@assetbundle_content"].Value = mapping.Key;
113+
m_InsertArchiveContentCommand.Parameters["@archive"].Value = mapping.Value;
114+
m_InsertArchiveContentCommand.Parameters["@archive_content"].Value = mapping.Key;
115115
m_InsertArchiveContentCommand.ExecuteNonQuery();
116116
}
117117

0 commit comments

Comments
 (0)