Skip to content

Commit 38c9f86

Browse files
committed
Auto disable mods in the destination root before copying root over.
1 parent 984328d commit 38c9f86

File tree

1 file changed

+70
-1
lines changed

1 file changed

+70
-1
lines changed

xivModdingFramework/Mods/RootCloner.cs

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public static class RootCloner
2828
/// <param name="Destination">Destination root to copy to.</param>
2929
/// <param name="ApplicationSource">Application to list as the source for the resulting mod entries.</param>
3030
/// <returns></returns>
31-
public static async Task CloneRoot(XivDependencyRoot Source, XivDependencyRoot Destination, string ApplicationSource)
31+
public static async Task CloneRoot(XivDependencyRoot Source, XivDependencyRoot Destination, string ApplicationSource, IProgress<string> ProgressReporter = null)
3232
{
3333

3434
var df = IOUtil.GetDataFileFromPath(Source.ToString());
@@ -38,7 +38,16 @@ public static async Task CloneRoot(XivDependencyRoot Source, XivDependencyRoot D
3838
var _dat = new Dat(XivCache.GameInfo.GameDirectory);
3939
var _index = new Index(XivCache.GameInfo.GameDirectory);
4040
var _mtrl = new Mtrl(XivCache.GameInfo.GameDirectory, df, XivCache.GameInfo.GameLanguage);
41+
var _modding = new Modding(XivCache.GameInfo.GameDirectory);
4142

43+
44+
45+
46+
47+
if (ProgressReporter != null)
48+
{
49+
ProgressReporter.Report("Analyzing items and variants...");
50+
}
4251
// First, try to get everything, to ensure it's all valid.
4352
var originalMetadata = await ItemMetadata.GetMetadata(Source);
4453
var originalModelPaths = await Source.GetModelFiles();
@@ -80,6 +89,10 @@ public static async Task CloneRoot(XivDependencyRoot Source, XivDependencyRoot D
8089
Dictionary<string, string> newTexturePaths = new Dictionary<string, string>();
8190
Dictionary<string, string> newAvfxPaths = new Dictionary<string, string>();
8291

92+
if (ProgressReporter != null)
93+
{
94+
ProgressReporter.Report("Calculating files to copy...");
95+
}
8396

8497
// For each path, replace any instances of our primary and secondary types.
8598
foreach (var path in originalModelPaths)
@@ -112,6 +125,31 @@ public static async Task CloneRoot(XivDependencyRoot Source, XivDependencyRoot D
112125
var iCat = destItem.SecondaryCategory;
113126
var iName = destItem.Name;
114127

128+
if (ProgressReporter != null)
129+
{
130+
ProgressReporter.Report("Getting modlist...");
131+
}
132+
var modlist = await _modding.GetModListAsync();
133+
134+
if (ProgressReporter != null)
135+
{
136+
ProgressReporter.Report("Removing existing modifications to destination root...");
137+
}
138+
139+
var dPath = Destination.Info.GetRootFolder();
140+
foreach(var mod in modlist.Mods)
141+
{
142+
if (mod.fullPath.StartsWith(dPath))
143+
{
144+
await _modding.DeleteMod(mod.fullPath, false);
145+
}
146+
}
147+
148+
if (ProgressReporter != null)
149+
{
150+
ProgressReporter.Report("Copying models...");
151+
}
152+
115153
// Load, Edit, and resave the model files.
116154
foreach (var kv in newModelPaths)
117155
{
@@ -136,6 +174,10 @@ public static async Task CloneRoot(XivDependencyRoot Source, XivDependencyRoot D
136174
await _dat.WriteToDat(bytes.ToList(), null, dst, iCat, iName, df, ApplicationSource, 3);
137175
}
138176

177+
if (ProgressReporter != null)
178+
{
179+
ProgressReporter.Report("Copying textures...");
180+
}
139181
// Raw Copy all Texture files to the new destinations to avoid having the MTRL save functions auto-generate blank textures.
140182
foreach (var kv in newTexturePaths)
141183
{
@@ -145,6 +187,11 @@ public static async Task CloneRoot(XivDependencyRoot Source, XivDependencyRoot D
145187
await _dat.CopyFile(src, dst, iCat, iName, ApplicationSource, true);
146188
}
147189

190+
191+
if (ProgressReporter != null)
192+
{
193+
ProgressReporter.Report("Copying materials...");
194+
}
148195
HashSet<string> CopiedMaterials = new HashSet<string>();
149196
// Load every Material file and edit the texture references to the new texture paths.
150197
foreach(var kv in newMaterialPaths)
@@ -178,6 +225,10 @@ public static async Task CloneRoot(XivDependencyRoot Source, XivDependencyRoot D
178225
}
179226
}
180227

228+
if (ProgressReporter != null)
229+
{
230+
ProgressReporter.Report("Copying VFX...");
231+
}
181232
// Copy VFX files.
182233
foreach (var kv in newAvfxPaths)
183234
{
@@ -187,6 +238,10 @@ public static async Task CloneRoot(XivDependencyRoot Source, XivDependencyRoot D
187238
await _dat.CopyFile(src, dst, iCat, iName, ApplicationSource, true);
188239
}
189240

241+
if (ProgressReporter != null)
242+
{
243+
ProgressReporter.Report("Creating missing variants...");
244+
}
190245
// Check to see if we need to add any variants
191246
var cloneNum = newMetadata.ImcEntries.Count >= 2 ? 1 : 0;
192247
while(originalDestinationMetadata.ImcEntries.Count > newMetadata.ImcEntries.Count)
@@ -195,11 +250,19 @@ public static async Task CloneRoot(XivDependencyRoot Source, XivDependencyRoot D
195250
newMetadata.ImcEntries.Add((XivImc)newMetadata.ImcEntries[cloneNum].Clone());
196251
}
197252

253+
if (ProgressReporter != null)
254+
{
255+
ProgressReporter.Report("Copying metdata...");
256+
}
198257
// Save the new Metadata file.
199258
await ItemMetadata.SaveMetadata(newMetadata, ApplicationSource);
200259

201260

202261

262+
if (ProgressReporter != null)
263+
{
264+
ProgressReporter.Report("Filling in missing material sets...");
265+
}
203266
// Validate all variants/material sets for valid materials, and copy materials as needed to fix.
204267
if (Imc.UsesImc(Destination))
205268
{
@@ -237,6 +300,12 @@ public static async Task CloneRoot(XivDependencyRoot Source, XivDependencyRoot D
237300
}
238301
}
239302
}
303+
304+
305+
if (ProgressReporter != null)
306+
{
307+
ProgressReporter.Report("Root copy complete.");
308+
}
240309
}
241310

242311
const string CommonPath = "chara/common/";

0 commit comments

Comments
 (0)