Skip to content

Commit 8d454d9

Browse files
committed
- Fix for Hair Conversionf or Hair 116-200
- Adjustments to cache queuing.
1 parent c5ffc45 commit 8d454d9

File tree

3 files changed

+165
-100
lines changed

3 files changed

+165
-100
lines changed

xivModdingFramework/Cache/XivCache.cs

Lines changed: 50 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2089,38 +2089,40 @@ private static string PopChildQueue()
20892089
{
20902090
db.Open();
20912091

2092-
using (var transaction = db.BeginTransaction())
2092+
var query = "select position, file from dependencies_children_queue";
2093+
using (var selectCmd = new SQLiteCommand(query, db))
20932094
{
2094-
var query = "select position, file from dependencies_children_queue";
2095-
using (var selectCmd = new SQLiteCommand(query, db))
2095+
using (var reader = new CacheReader(selectCmd.ExecuteReader()))
20962096
{
2097-
using (var reader = new CacheReader(selectCmd.ExecuteReader()))
2097+
if (!reader.NextRow())
20982098
{
2099-
if (!reader.NextRow())
2100-
{
2101-
// No entries left.
2102-
return null;
2103-
}
2104-
// Got the new item.
2105-
file = reader.GetString("file");
2106-
position = reader.GetInt32("position");
2099+
// No entries left.
2100+
return null;
21072101
}
2102+
// Got the new item.
2103+
file = reader.GetString("file");
2104+
position = reader.GetInt32("position");
21082105
}
2109-
2110-
// Delete the row we took and all others that match the filename.
2111-
query = "delete from dependencies_children_queue where file = $file";
2112-
using (var deleteCmd = new SQLiteCommand(query, db))
2113-
{
2114-
deleteCmd.Parameters.AddWithValue("file", file);
2115-
deleteCmd.ExecuteScalar();
2116-
}
2117-
2118-
transaction.Commit();
21192106
}
21202107
}
21212108
return file;
21222109
}
21232110

2111+
public static void RemoveFromChildQueue(string file)
2112+
{
2113+
using (var db = new SQLiteConnection(CacheConnectionString))
2114+
{
2115+
db.Open();
2116+
2117+
// Delete the row we took and all others that match the filename.
2118+
var query = "delete from dependencies_children_queue where file = $file";
2119+
using (var deleteCmd = new SQLiteCommand(query, db))
2120+
{
2121+
deleteCmd.Parameters.AddWithValue("file", file);
2122+
deleteCmd.ExecuteScalar();
2123+
}
2124+
}
2125+
}
21242126

21252127
private static string PopParentQueue()
21262128
{
@@ -2130,37 +2132,39 @@ private static string PopParentQueue()
21302132
{
21312133
db.Open();
21322134

2133-
using (var transaction = db.BeginTransaction())
2135+
var query = "select position, file from dependencies_parents_queue";
2136+
using (var selectCmd = new SQLiteCommand(query, db))
21342137
{
2135-
var query = "select position, file from dependencies_parents_queue";
2136-
using (var selectCmd = new SQLiteCommand(query, db))
2138+
using (var reader = new CacheReader(selectCmd.ExecuteReader()))
21372139
{
2138-
using (var reader = new CacheReader(selectCmd.ExecuteReader()))
2140+
if (!reader.NextRow())
21392141
{
2140-
if (!reader.NextRow())
2141-
{
2142-
// No entries left.
2143-
return null;
2144-
}
2145-
// Got the new item.
2146-
file = reader.GetString("file");
2147-
position = reader.GetInt32("position");
2142+
// No entries left.
2143+
return null;
21482144
}
2145+
// Got the new item.
2146+
file = reader.GetString("file");
2147+
position = reader.GetInt32("position");
21492148
}
2150-
2151-
// Delete the row we took and all others that match the filename.
2152-
query = "delete from dependencies_parents_queue where file = $file";
2153-
using (var deleteCmd = new SQLiteCommand(query, db))
2154-
{
2155-
deleteCmd.Parameters.AddWithValue("file", file);
2156-
deleteCmd.ExecuteScalar();
2157-
}
2158-
2159-
transaction.Commit();
21602149
}
21612150
}
21622151
return file;
21632152
}
2153+
public static void RemoveFromParentQueue(string file)
2154+
{
2155+
using (var db = new SQLiteConnection(CacheConnectionString))
2156+
{
2157+
db.Open();
2158+
2159+
// Delete the row we took and all others that match the filename.
2160+
var query = "delete from dependencies_parents_queue where file = $file";
2161+
using (var deleteCmd = new SQLiteCommand(query, db))
2162+
{
2163+
deleteCmd.Parameters.AddWithValue("file", file);
2164+
deleteCmd.ExecuteScalar();
2165+
}
2166+
}
2167+
}
21642168

21652169

21662170
/// <summary>
@@ -2192,6 +2196,7 @@ private static void ProcessDependencyQueue(object sender, DoWorkEventArgs e)
21922196

21932197
// Set a safety timeout here.
21942198
task.Wait(3000);
2199+
RemoveFromChildQueue(file);
21952200
continue;
21962201

21972202
}
@@ -2217,6 +2222,7 @@ private static void ProcessDependencyQueue(object sender, DoWorkEventArgs e)
22172222

22182223
// Set a safety timeout here.
22192224
task.Wait(3000);
2225+
RemoveFromParentQueue(file);
22202226
continue;
22212227
}
22222228
}

xivModdingFramework/Mods/Modding.cs

Lines changed: 68 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -290,35 +290,44 @@ public async Task ToggleModPackStatus(string modPackName, bool enable)
290290
{
291291
var index = new Index(_gameDirectory);
292292

293-
var modList = GetModList();
294-
var modListDirectory = new DirectoryInfo(Path.Combine(_gameDirectory.Parent.Parent.FullName, XivStrings.ModlistFilePath));
295-
List<Mod> mods = null;
296-
297-
if (modPackName.Equals("Standalone (Non-ModPack)"))
298-
{
299-
mods = (from mod in modList.Mods
300-
where mod.modPack == null
301-
select mod).ToList();
302-
}
303-
else
293+
var workerState = XivCache.CacheWorkerEnabled;
294+
XivCache.CacheWorkerEnabled = false;
295+
try
304296
{
305-
mods = (from mod in modList.Mods
306-
where mod.modPack != null && mod.modPack.name.Equals(modPackName)
307-
select mod).ToList();
308-
}
297+
var modList = GetModList();
298+
var modListDirectory = new DirectoryInfo(Path.Combine(_gameDirectory.Parent.Parent.FullName, XivStrings.ModlistFilePath));
299+
List<Mod> mods = null;
309300

301+
if (modPackName.Equals("Standalone (Non-ModPack)"))
302+
{
303+
mods = (from mod in modList.Mods
304+
where mod.modPack == null
305+
select mod).ToList();
306+
}
307+
else
308+
{
309+
mods = (from mod in modList.Mods
310+
where mod.modPack != null && mod.modPack.name.Equals(modPackName)
311+
select mod).ToList();
312+
}
310313

311-
if (mods == null)
312-
{
313-
throw new Exception("Unable to find mods with given Mod Pack Name in modlist.");
314-
}
315314

316-
foreach (var modEntry in mods)
315+
if (mods == null)
316+
{
317+
throw new Exception("Unable to find mods with given Mod Pack Name in modlist.");
318+
}
319+
320+
foreach (var modEntry in mods)
321+
{
322+
await ToggleModUnsafe(enable, modEntry);
323+
}
324+
325+
SaveModList(modList);
326+
}
327+
finally
317328
{
318-
await ToggleModUnsafe(enable, modEntry);
329+
XivCache.CacheWorkerEnabled = workerState;
319330
}
320-
321-
SaveModList(modList);
322331
}
323332

324333
/// <summary>
@@ -540,41 +549,49 @@ where modPack.name.Equals(modPackName)
540549
// Modpack doesn't exist in the modlist.
541550
if (modPackItem == null) return;
542551

543-
modList.ModPacks.Remove(modPackItem);
552+
var cacheState = XivCache.CacheWorkerEnabled;
553+
XivCache.CacheWorkerEnabled = false;
554+
try
555+
{
556+
modList.ModPacks.Remove(modPackItem);
544557

545-
var modsToRemove = (from mod in modList.Mods
546-
where mod.modPack != null && mod.modPack.name.Equals(modPackName)
547-
select mod).ToList();
558+
var modsToRemove = (from mod in modList.Mods
559+
where mod.modPack != null && mod.modPack.name.Equals(modPackName)
560+
select mod).ToList();
548561

549-
var modRemoveCount = modsToRemove.Count;
562+
var modRemoveCount = modsToRemove.Count;
550563

551-
foreach (var modToRemove in modsToRemove)
552-
{
553-
if (modToRemove.data.originalOffset == modToRemove.data.modOffset)
564+
foreach (var modToRemove in modsToRemove)
554565
{
555-
var index = new Index(_gameDirectory);
556-
await index.DeleteFileDescriptor(modToRemove.fullPath, XivDataFiles.GetXivDataFile(modToRemove.datFile));
557-
}
558-
if (modToRemove.enabled)
559-
{
560-
await ToggleModStatus(modToRemove.fullPath, false);
561-
}
566+
if (modToRemove.data.originalOffset == modToRemove.data.modOffset)
567+
{
568+
var index = new Index(_gameDirectory);
569+
await index.DeleteFileDescriptor(modToRemove.fullPath, XivDataFiles.GetXivDataFile(modToRemove.datFile));
570+
}
571+
if (modToRemove.enabled)
572+
{
573+
await ToggleModStatus(modToRemove.fullPath, false);
574+
}
562575

563-
modToRemove.name = string.Empty;
564-
modToRemove.category = string.Empty;
565-
modToRemove.fullPath = string.Empty;
566-
modToRemove.source = string.Empty;
567-
modToRemove.modPack = null;
568-
modToRemove.enabled = false;
569-
modToRemove.data.originalOffset = 0;
570-
modToRemove.data.dataType = 0;
571-
}
576+
modToRemove.name = string.Empty;
577+
modToRemove.category = string.Empty;
578+
modToRemove.fullPath = string.Empty;
579+
modToRemove.source = string.Empty;
580+
modToRemove.modPack = null;
581+
modToRemove.enabled = false;
582+
modToRemove.data.originalOffset = 0;
583+
modToRemove.data.dataType = 0;
584+
}
572585

573-
modList.emptyCount += modRemoveCount;
574-
modList.modCount -= modRemoveCount;
575-
modList.modPackCount -= 1;
586+
modList.emptyCount += modRemoveCount;
587+
modList.modCount -= modRemoveCount;
588+
modList.modPackCount -= 1;
576589

577-
SaveModList(modList);
590+
SaveModList(modList);
591+
} finally
592+
{
593+
XivCache.CacheWorkerEnabled = cacheState;
594+
}
578595
}
579596
}
580597
}

xivModdingFramework/Mods/RootCloner.cs

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.IO;
44
using System.Linq;
5+
using System.Security.Cryptography;
56
using System.Text;
67
using System.Text.RegularExpressions;
78
using System.Threading.Tasks;
@@ -460,12 +461,27 @@ private static string UpdatePath(XivDependencyRoot Source, XivDependencyRoot Des
460461

461462
private static string UpdateFolder(XivDependencyRoot Source, XivDependencyRoot Destination, string path)
462463
{
463-
if(Source.Info.PrimaryType == XivItemType.human && Path.GetExtension(path) == ".mtrl")
464+
if(Destination.Info.PrimaryType == XivItemType.human && Destination.Info.SecondaryType == XivItemType.hair && Path.GetExtension(path) == ".mtrl")
464465
{
465-
// For hair MTRLs we have to keep the same MTRL folder.
466-
path = Path.GetDirectoryName(path);
467-
path = path.Replace('\\', '/');
468-
return path;
466+
// Hair material paths are actually hard-coded into the game, so there's some wild stuff that has to go on here.
467+
if (Destination.Info.SecondaryId > 115 && Destination.Info.SecondaryId <= 200)
468+
{
469+
// Hairs between 115 and 200 have forced material path sharing enabled.
470+
var digit3 = Destination.Info.SecondaryId / 100;
471+
var race = digit3 % 2 == 0 ? 101 : 201;
472+
473+
// Force the race code to the appropriate one.
474+
var raceReplace = new Regex("/c[0-9]{4}");
475+
path = raceReplace.Replace(path, "/c" + race.ToString().PadLeft(4, '0'));
476+
477+
var hairReplace= new Regex("/h[0-9]{4}");
478+
path = hairReplace.Replace(path, "/h" + Destination.Info.SecondaryId.ToString().PadLeft(4, '0'));
479+
480+
// Hairs between 115 and 200 have forced material path sharing enabled.
481+
path = Path.GetDirectoryName(path);
482+
path = path.Replace('\\', '/');
483+
return path;
484+
}
469485
}
470486

471487
// So first off, just copy anything from the old root folder to the new one.
@@ -493,6 +509,32 @@ private static string UpdateFileName(XivDependencyRoot Source, XivDependencyRoot
493509
{
494510
var file = Path.GetFileName(path);
495511

512+
if (Destination.Info.PrimaryType == XivItemType.human && Destination.Info.SecondaryType == XivItemType.hair && Path.GetExtension(path) == ".mtrl")
513+
{
514+
// Hair material paths are actually hard-coded into the game, so there's some wild stuff that has to go on here.
515+
if (Destination.Info.SecondaryId > 115 && Destination.Info.SecondaryId <= 200)
516+
{
517+
// Hairs between 115 and 200 have forced material path sharing enabled.
518+
var digit3 = Destination.Info.SecondaryId / 100;
519+
var race = digit3 % 2 == 0 ? 101 : 201;
520+
521+
// Force the race code to the appropriate one.
522+
var raceReplace = new Regex("^mt_c[0-9]{4}h[0-9]{4}");
523+
file = raceReplace.Replace(file, "mt_c" + race.ToString().PadLeft(4, '0') + "h" + Destination.Info.SecondaryId.ToString().PadLeft(4, '0'));
524+
525+
// So for these, the first half of the filename is hard-coded locked (the c#### part)
526+
// We have to get gimmicky and play around with the suffixing.
527+
var initialPartRex = new Regex("^(mt_c[0-9]{4}h[0-9]{4})(?:_c[0-9]{4})?(.+)$");
528+
var m = initialPartRex.Match(file);
529+
530+
// ???
531+
if (!m.Success) return file;
532+
533+
file = m.Groups[1].Value + "_c" + Destination.Info.PrimaryId.ToString().PadLeft(4, '0') + m.Groups[2].Value;
534+
return file;
535+
}
536+
}
537+
496538
var rex = new Regex("[a-z][0-9]{4}([a-z][0-9]{4})");
497539
var match = rex.Match(file);
498540
if(!match.Success)

0 commit comments

Comments
 (0)