Skip to content

Commit 73dc64c

Browse files
committed
rename writer and load schemas on demand
1 parent 686bd48 commit 73dc64c

File tree

4 files changed

+29
-19
lines changed

4 files changed

+29
-19
lines changed

Analyzer/SQLite/Parsers/AddressablesBuildLayoutParser.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
using Newtonsoft.Json.Linq;
44
using System;
55
using System.IO;
6-
using UnityDataTools.Analyzer.SQLite.Parsers.Models;
76
using UnityDataTools.Analyzer.SQLite.Handlers;
7+
using UnityDataTools.Analyzer.SQLite.Parsers.Models;
88
using UnityDataTools.Analyzer.SQLite.Writers;
99

1010
namespace UnityDataTools.Analyzer.SQLite.Parsers
@@ -23,7 +23,6 @@ public void Dispose()
2323
public void Init(SqliteConnection db)
2424
{
2525
m_Writer = new AddressablesBuildLayoutSQLWriter(db);
26-
m_Writer.Init();
2726
m_Writer.Verbose = Verbose;
2827
}
2928

@@ -74,6 +73,8 @@ public bool CanParse(string filename)
7473

7574
public void Parse(string filename)
7675
{
76+
// only init our writer if we are actually parsing a file
77+
m_Writer.Init();
7778
using (StreamReader reader = File.OpenText(filename))
7879
{
7980
JsonSerializer serializer = new JsonSerializer();

Analyzer/SQLite/Parsers/SerializedFileParser.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
1-
using UnityDataTools.Analyzer.SQLite.Writers;
2-
using Microsoft.Data.Sqlite;
1+
using Microsoft.Data.Sqlite;
32
using System;
43
using System.Collections.Generic;
54
using System.IO;
6-
using System.Linq;
7-
using System.Text;
8-
using System.Threading.Tasks;
95
using UnityDataTools.Analyzer.SQLite.Handlers;
6+
using UnityDataTools.Analyzer.SQLite.Writers;
107
using UnityDataTools.FileSystem;
118

129
namespace UnityDataTools.Analyzer.SQLite.Parsers
1310
{
1411
public class SerializedFileParser : ISQLiteFileParser
1512
{
16-
private AssetBundleSQLiteWriter m_Writer;
13+
private SerializedFileSQLiteWriter m_Writer;
1714

1815
public bool Verbose { get; set; }
1916
public bool SkipReferences { get; set; }
@@ -31,12 +28,13 @@ public void Dispose()
3128

3229
public void Init(SqliteConnection db)
3330
{
34-
m_Writer = new AssetBundleSQLiteWriter(db, SkipReferences);
35-
m_Writer.Init();
31+
m_Writer = new SerializedFileSQLiteWriter(db, SkipReferences);
3632
}
3733

3834
public void Parse(string filename)
3935
{
36+
// only init our writer if we are actually parsing a file
37+
m_Writer.Init();
4038
ProcessFile(filename, Path.GetDirectoryName(filename));
4139
}
4240

Analyzer/SQLite/Writers/AddressablesBuildLayoutSQLWriter.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
using Newtonsoft.Json;
33
using System;
44
using System.IO;
5-
using UnityDataTools.Analyzer.SQLite.Parsers.Models;
65
using UnityDataTools.Analyzer.SQLite.Commands.AddressablesBuildReport;
6+
using UnityDataTools.Analyzer.SQLite.Parsers.Models;
77

88
namespace UnityDataTools.Analyzer.SQLite.Writers
99
{
@@ -45,16 +45,22 @@ internal class AddressablesBuildLayoutSQLWriter : IDisposable
4545

4646
private SqliteCommand m_LastId = new SqliteCommand();
4747

48+
private bool m_Initialized;
4849
private SqliteConnection m_Database;
4950
public bool Verbose { get; set; }
5051

5152
public AddressablesBuildLayoutSQLWriter(SqliteConnection database)
5253
{
54+
m_Initialized = false;
5355
m_Database = database;
5456
}
5557

5658
public void Init()
5759
{
60+
if (m_Initialized)
61+
return;
62+
63+
m_Initialized = true;
5864
// build addressables file commands
5965
m_AddressablesBuild.CreateCommand(m_Database);
6066
// Build Bundle Tables

Analyzer/SQLite/Writers/AssetBundleSQLiteWriter.cs renamed to Analyzer/SQLite/Writers/SerializedFileSQLiteWriter.cs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1+
using Microsoft.Data.Sqlite;
12
using System;
23
using System.Collections.Generic;
3-
using Microsoft.Data.Sqlite;
44
using System.IO;
55
using System.Text.RegularExpressions;
6+
using UnityDataTools.Analyzer.SQLite.Commands.SerializedFile;
67
using UnityDataTools.Analyzer.SQLite.Handlers;
8+
using UnityDataTools.Analyzer.Util;
79
using UnityDataTools.FileSystem;
810
using UnityDataTools.FileSystem.TypeTreeReaders;
9-
using UnityDataTools.Analyzer.SQLite.Commands.SerializedFile;
10-
using UnityDataTools.Analyzer;
11-
using UnityDataTools.Analyzer.Util;
1211

1312
namespace UnityDataTools.Analyzer.SQLite.Writers;
1413

15-
public class AssetBundleSQLiteWriter : IDisposable
14+
public class SerializedFileSQLiteWriter : IDisposable
1615
{
1716
private HashSet<int> m_TypeSet = new();
1817

@@ -27,7 +26,7 @@ public class AssetBundleSQLiteWriter : IDisposable
2726
private Regex m_RegexSceneFile = new(@"BuildPlayer-([^\.]+)(?:\.sharedAssets)?");
2827

2928
// Used to map PPtr fileId to its corresponding serialized file id in the database.
30-
Dictionary<int, int> m_LocalToDbFileId = new ();
29+
Dictionary<int, int> m_LocalToDbFileId = new();
3130

3231
private Dictionary<string, ISQLiteHandler> m_Handlers = new()
3332
{
@@ -47,17 +46,23 @@ public class AssetBundleSQLiteWriter : IDisposable
4746
private AddType m_AddTypeCommand = new AddType();
4847
private AddAssetDependency m_InsertDepCommand = new AddAssetDependency();
4948

49+
private bool m_Initialized;
5050
private SqliteConnection m_Database;
5151
private SqliteCommand m_LastId = new SqliteCommand();
5252
private SqliteTransaction m_CurrentTransaction = null;
53-
public AssetBundleSQLiteWriter(SqliteConnection database, bool skipReferences)
53+
public SerializedFileSQLiteWriter(SqliteConnection database, bool skipReferences)
5454
{
55+
m_Initialized = false;
5556
m_Database = database;
5657
m_SkipReferences = skipReferences;
5758
}
5859

5960
public void Init()
60-
{
61+
{
62+
if (m_Initialized)
63+
return;
64+
65+
m_Initialized = true;
6166
foreach (var handler in m_Handlers.Values)
6267
{
6368
handler.Init(m_Database);

0 commit comments

Comments
 (0)