Skip to content

Commit a759447

Browse files
committed
Auto migration for DB files.
1 parent d510fce commit a759447

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

xivModdingFramework/Cache/XivCache.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public static class XivCache
7777
private static GameInfo _gameInfo;
7878
private static DirectoryInfo _dbPath;
7979
private static DirectoryInfo _rootCachePath;
80-
public static readonly Version CacheVersion = new Version("1.0.3.4");
80+
public static readonly Version CacheVersion = new Version("1.0.3.5");
8181
private const string dbFileName = "mod_cache.db";
8282
private const string rootCacheFileName = "item_sets.db";
8383
private const string creationScript = "CreateCacheDB.sql";

xivModdingFramework/Models/DataContainers/TTModel.cs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using System.Text.RegularExpressions;
1515
using System.Threading.Tasks;
1616
using xivModdingFramework.Cache;
17+
using xivModdingFramework.General;
1718
using xivModdingFramework.General.Enums;
1819
using xivModdingFramework.Helpers;
1920
using xivModdingFramework.Items.Enums;
@@ -1391,6 +1392,9 @@ public static TTModel LoadFromFile(string filePath, Action<bool, string> logging
13911392
{
13921393
db.Open();
13931394
SetPragmas(db);
1395+
1396+
MigrateImportDb(db);
1397+
13941398
// Using statements help ensure we don't accidentally leave any connections open and lock the file handle.
13951399

13961400
// Load Mesh Groups
@@ -1641,6 +1645,49 @@ public static TTModel LoadFromFile(string filePath, Action<bool, string> logging
16411645
return model;
16421646
}
16431647

1648+
private static void MigrateImportDb(SQLiteConnection db)
1649+
{
1650+
//cmd.Parameters.AddWithValue("value", typeof(XivCache).Assembly.GetName().Version);
1651+
Version version = null;
1652+
1653+
bool hasUv3 = false;
1654+
var query = @"PRAGMA table_info(vertices);";
1655+
using (var cmd = new SQLiteCommand(query, db))
1656+
{
1657+
using (var sqlReader = cmd.ExecuteReader())
1658+
{
1659+
while (sqlReader.Read())
1660+
{
1661+
var name = sqlReader.GetString(1);
1662+
if(name == "uv_3_u")
1663+
{
1664+
hasUv3 = true;
1665+
}
1666+
}
1667+
1668+
if (!sqlReader.IsClosed)
1669+
{
1670+
sqlReader.Close();
1671+
}
1672+
}
1673+
}
1674+
1675+
if (!hasUv3)
1676+
{
1677+
query = "ALTER TABLE vertices ADD COLUMN uv_3_u INTEGER NOT NULL DEFAULT 0;";
1678+
using (var cmd = new SQLiteCommand(query, db))
1679+
{
1680+
cmd.ExecuteScalar();
1681+
}
1682+
query = "ALTER TABLE vertices ADD COLUMN uv_3_v INTEGER NOT NULL DEFAULT 0;";
1683+
using (var cmd = new SQLiteCommand(query, db))
1684+
{
1685+
cmd.ExecuteScalar();
1686+
}
1687+
}
1688+
1689+
}
1690+
16441691

16451692
/// <summary>
16461693
/// Saves the TTModel to a .DB file for use with external importers/exporters.

0 commit comments

Comments
 (0)