@@ -133,13 +133,6 @@ public static void SetGameInfo(GameInfo gameInfo = null)
133
133
}
134
134
135
135
136
- bool restartCacheWorker = false ;
137
- if ( gameInfo . GameDirectory != _gameInfo . GameDirectory )
138
- {
139
- // Have to restart cache worker if we're changing directories.
140
- CacheWorkerEnabled = false ;
141
- restartCacheWorker = true ;
142
- }
143
136
144
137
_dbPath = new DirectoryInfo ( Path . Combine ( _gameInfo . GameDirectory . Parent . Parent . FullName , dbFileName ) ) ;
145
138
_rootCachePath = new DirectoryInfo ( Path . Combine ( _gameInfo . GameDirectory . Parent . Parent . FullName , rootCacheFileName ) ) ;
@@ -155,9 +148,6 @@ public static void SetGameInfo(GameInfo gameInfo = null)
155
148
156
149
CacheWorkerEnabled = true ;
157
150
158
- // This just triggers the cache worker to start if it's not already.
159
- CacheWorkerEnabled = CacheWorkerEnabled || restartCacheWorker ;
160
-
161
151
}
162
152
163
153
/// <summary>
@@ -231,7 +221,9 @@ private static bool CacheNeedsRebuild()
231
221
/// </summary>
232
222
public static void RebuildCache ( )
233
223
{
224
+ CacheWorkerEnabled = false ;
234
225
_REBUILDING = true ;
226
+
235
227
Task . Run ( async ( ) =>
236
228
{
237
229
if ( _gameInfo . GameLanguage == XivLanguage . None )
@@ -271,6 +263,7 @@ public static void RebuildCache()
271
263
}
272
264
} ) . Wait ( ) ;
273
265
_REBUILDING = false ;
266
+ CacheWorkerEnabled = true ;
274
267
}
275
268
276
269
#region Cache Rebuilding
@@ -1150,14 +1143,12 @@ public static async Task<List<string>> GetChildFiles(string internalFilePath, bo
1150
1143
}
1151
1144
1152
1145
1146
+
1153
1147
if ( list . Count == 0 )
1154
1148
{
1155
- // Need to pull the raw data to verify a 0 count entry .
1149
+ // No cache data, have to update .
1156
1150
list = await XivDependencyGraph . GetChildFiles ( internalFilePath ) ;
1157
- if ( list != null && list . Count > 0 )
1158
- {
1159
- await UpdateChildFiles ( internalFilePath , list ) ;
1160
- }
1151
+ await UpdateChildFiles ( internalFilePath , list ) ;
1161
1152
}
1162
1153
return list ;
1163
1154
}
@@ -1190,10 +1181,14 @@ public static async Task<List<string>> GetParentFiles(string internalFilePath, b
1190
1181
{
1191
1182
// Need to pull the raw data to verify a 0 count entry.
1192
1183
list = await XivDependencyGraph . GetParentFiles ( internalFilePath ) ;
1193
- if ( list != null && list . Count > 0 )
1194
- {
1195
- await UpdateParentFiles ( internalFilePath , list ) ;
1196
- }
1184
+ await UpdateParentFiles ( internalFilePath , list ) ;
1185
+
1186
+ // So if we updated our own parents, we have to update our children's parents too.
1187
+ // Because we may be a previously orphaned node, that now is re-attached to the main tree.
1188
+ var children = await GetChildFiles ( internalFilePath ) ;
1189
+
1190
+ // In short, any parent calculation is always cascading downwards.
1191
+ QueueParentFilesUpdate ( children ) ;
1197
1192
}
1198
1193
return list ;
1199
1194
}
@@ -1440,6 +1435,10 @@ public static Dictionary<string, List<string>> GetModListParents()
1440
1435
var modding = new Modding ( GameInfo . GameDirectory ) ;
1441
1436
var modList = modding . GetModList ( ) ;
1442
1437
var dict = new Dictionary < string , List < string > > ( modList . Mods . Count ) ;
1438
+ if ( modList . Mods . Count == 0 )
1439
+ {
1440
+ return dict ;
1441
+ }
1443
1442
1444
1443
var query = "select child, parent from dependencies_parents where child in(" ;
1445
1444
foreach ( var mod in modList . Mods )
@@ -1643,11 +1642,18 @@ private static async Task UpdateParentFiles(string internalFilePath, List<string
1643
1642
}
1644
1643
1645
1644
1645
+ /// <summary>
1646
+ /// Qeuues a given file up for cache parent file updating.
1647
+ /// </summary>
1648
+ /// <param name="file"></param>
1646
1649
public static void QueueParentFilesUpdate ( string file )
1647
1650
{
1648
1651
QueueParentFilesUpdate ( new List < string > ( ) { file } ) ;
1649
1652
}
1650
1653
1654
+ /// <summary>
1655
+ /// Qeuues a given set of files up for cache parent file updating.
1656
+ /// </summary>
1651
1657
public static void QueueParentFilesUpdate ( List < string > files )
1652
1658
{
1653
1659
try
@@ -1657,29 +1663,37 @@ public static void QueueParentFilesUpdate(List<string> files)
1657
1663
db . Open ( ) ;
1658
1664
using ( var transaction = db . BeginTransaction ( ) )
1659
1665
{
1660
- // First, clear out all the old data. This is the most important point.
1661
- var query = "delete from dependencies_parents where child = $child" ;
1662
- using ( var delCmd = new SQLiteCommand ( query , db ) )
1666
+ foreach ( var file in files )
1663
1667
{
1664
- // Then insert us into the queue.
1668
+ // First, clear out all the old data.
1669
+ var query = "delete from dependencies_parents where child = $child" ;
1670
+ using ( var delCmd = new SQLiteCommand ( query , db ) )
1671
+ {
1672
+ delCmd . Parameters . AddWithValue ( "child" , file ) ;
1673
+ delCmd . ExecuteScalar ( ) ;
1674
+ }
1675
+
1676
+ query = "delete from dependencies_update_queue where file = $file" ;
1677
+ using ( var delCmd = new SQLiteCommand ( query , db ) )
1678
+ {
1679
+ delCmd . Parameters . AddWithValue ( "$file" , file ) ;
1680
+ delCmd . ExecuteScalar ( ) ;
1681
+ }
1682
+
1683
+ // Then insert us into the back of the queue.
1665
1684
query = "insert into dependencies_update_queue (file) values ($file)" ;
1666
1685
using ( var insertCmd = new SQLiteCommand ( query , db ) )
1667
1686
{
1668
1687
1669
- foreach ( var file in files )
1688
+ var level = XivDependencyGraph . GetDependencyLevel ( file ) ;
1689
+ if ( level == XivDependencyLevel . Invalid || level == XivDependencyLevel . Root )
1670
1690
{
1671
- var level = XivDependencyGraph . GetDependencyLevel ( file ) ;
1672
- if ( level == XivDependencyLevel . Invalid || level == XivDependencyLevel . Root )
1673
- {
1674
- continue ;
1675
- }
1691
+ continue ;
1692
+ }
1676
1693
1677
- delCmd . Parameters . AddWithValue ( "child" , file ) ;
1678
- delCmd . ExecuteScalar ( ) ;
1679
1694
1680
- insertCmd . Parameters . AddWithValue ( "file" , file ) ;
1681
- insertCmd . ExecuteScalar ( ) ;
1682
- }
1695
+ insertCmd . Parameters . AddWithValue ( "file" , file ) ;
1696
+ insertCmd . ExecuteScalar ( ) ;
1683
1697
}
1684
1698
}
1685
1699
transaction . Commit ( ) ;
@@ -1761,15 +1775,10 @@ private static void ProcessDependencyQueue(object sender, DoWorkEventArgs e)
1761
1775
level = XivDependencyGraph . GetDependencyLevel ( file ) ;
1762
1776
if ( level == XivDependencyLevel . Invalid || level == XivDependencyLevel . Root ) continue ;
1763
1777
1764
- // See if we actually need an update .
1765
- var task = GetParentFiles ( file , true ) ;
1778
+ // The get call will automatically cache the data, if it needs updating .
1779
+ var task = GetParentFiles ( file , false ) ;
1766
1780
task . Wait ( ) ;
1767
- var parentFiles = task . Result ;
1768
- if ( parentFiles == null || parentFiles . Count == 0 )
1769
- {
1770
- // Update us if we do.
1771
- UpdateParentFiles ( file ) . Wait ( ) ;
1772
- }
1781
+ var parents = task . Result ;
1773
1782
}
1774
1783
} catch ( Exception ex )
1775
1784
{
@@ -1787,6 +1796,24 @@ private static void ProcessDependencyQueue(object sender, DoWorkEventArgs e)
1787
1796
}
1788
1797
1789
1798
1799
+ /// <summary>
1800
+ /// Internal function used in generating the cached parent data.
1801
+ /// This checks the child cache to help see if any orphaned modded items
1802
+ /// may reference this file still. Ex. An unused Material
1803
+ /// referencing an unused Texture File.
1804
+ /// </summary>
1805
+ /// <param name="internalFilePath"></param>
1806
+ /// <returns></returns>
1807
+ internal static async Task < List < string > > GetCacheParents ( string internalFilePath )
1808
+ {
1809
+ var wc = new WhereClause ( ) { Column = "child" , Comparer = WhereClause . ComparisonType . Equal , Value = internalFilePath } ;
1810
+ return await BuildListFromTable ( "dependencies_children" , wc , async ( reader ) =>
1811
+ {
1812
+ return reader . GetString ( "parent" ) ;
1813
+ } ) ;
1814
+
1815
+ }
1816
+
1790
1817
/// <summary>
1791
1818
/// Gets the current length of the dependency processing queue.
1792
1819
/// </summary>
0 commit comments