@@ -28,7 +28,7 @@ public static class RootCloner
28
28
/// <param name="Destination">Destination root to copy to.</param>
29
29
/// <param name="ApplicationSource">Application to list as the source for the resulting mod entries.</param>
30
30
/// <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 )
32
32
{
33
33
34
34
var df = IOUtil . GetDataFileFromPath ( Source . ToString ( ) ) ;
@@ -38,7 +38,16 @@ public static async Task CloneRoot(XivDependencyRoot Source, XivDependencyRoot D
38
38
var _dat = new Dat ( XivCache . GameInfo . GameDirectory ) ;
39
39
var _index = new Index ( XivCache . GameInfo . GameDirectory ) ;
40
40
var _mtrl = new Mtrl ( XivCache . GameInfo . GameDirectory , df , XivCache . GameInfo . GameLanguage ) ;
41
+ var _modding = new Modding ( XivCache . GameInfo . GameDirectory ) ;
41
42
43
+
44
+
45
+
46
+
47
+ if ( ProgressReporter != null )
48
+ {
49
+ ProgressReporter . Report ( "Analyzing items and variants..." ) ;
50
+ }
42
51
// First, try to get everything, to ensure it's all valid.
43
52
var originalMetadata = await ItemMetadata . GetMetadata ( Source ) ;
44
53
var originalModelPaths = await Source . GetModelFiles ( ) ;
@@ -80,6 +89,10 @@ public static async Task CloneRoot(XivDependencyRoot Source, XivDependencyRoot D
80
89
Dictionary < string , string > newTexturePaths = new Dictionary < string , string > ( ) ;
81
90
Dictionary < string , string > newAvfxPaths = new Dictionary < string , string > ( ) ;
82
91
92
+ if ( ProgressReporter != null )
93
+ {
94
+ ProgressReporter . Report ( "Calculating files to copy..." ) ;
95
+ }
83
96
84
97
// For each path, replace any instances of our primary and secondary types.
85
98
foreach ( var path in originalModelPaths )
@@ -112,6 +125,31 @@ public static async Task CloneRoot(XivDependencyRoot Source, XivDependencyRoot D
112
125
var iCat = destItem . SecondaryCategory ;
113
126
var iName = destItem . Name ;
114
127
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
+
115
153
// Load, Edit, and resave the model files.
116
154
foreach ( var kv in newModelPaths )
117
155
{
@@ -136,6 +174,10 @@ public static async Task CloneRoot(XivDependencyRoot Source, XivDependencyRoot D
136
174
await _dat . WriteToDat ( bytes . ToList ( ) , null , dst , iCat , iName , df , ApplicationSource , 3 ) ;
137
175
}
138
176
177
+ if ( ProgressReporter != null )
178
+ {
179
+ ProgressReporter . Report ( "Copying textures..." ) ;
180
+ }
139
181
// Raw Copy all Texture files to the new destinations to avoid having the MTRL save functions auto-generate blank textures.
140
182
foreach ( var kv in newTexturePaths )
141
183
{
@@ -145,6 +187,11 @@ public static async Task CloneRoot(XivDependencyRoot Source, XivDependencyRoot D
145
187
await _dat . CopyFile ( src , dst , iCat , iName , ApplicationSource , true ) ;
146
188
}
147
189
190
+
191
+ if ( ProgressReporter != null )
192
+ {
193
+ ProgressReporter . Report ( "Copying materials..." ) ;
194
+ }
148
195
HashSet < string > CopiedMaterials = new HashSet < string > ( ) ;
149
196
// Load every Material file and edit the texture references to the new texture paths.
150
197
foreach ( var kv in newMaterialPaths )
@@ -178,6 +225,10 @@ public static async Task CloneRoot(XivDependencyRoot Source, XivDependencyRoot D
178
225
}
179
226
}
180
227
228
+ if ( ProgressReporter != null )
229
+ {
230
+ ProgressReporter . Report ( "Copying VFX..." ) ;
231
+ }
181
232
// Copy VFX files.
182
233
foreach ( var kv in newAvfxPaths )
183
234
{
@@ -187,6 +238,10 @@ public static async Task CloneRoot(XivDependencyRoot Source, XivDependencyRoot D
187
238
await _dat . CopyFile ( src , dst , iCat , iName , ApplicationSource , true ) ;
188
239
}
189
240
241
+ if ( ProgressReporter != null )
242
+ {
243
+ ProgressReporter . Report ( "Creating missing variants..." ) ;
244
+ }
190
245
// Check to see if we need to add any variants
191
246
var cloneNum = newMetadata . ImcEntries . Count >= 2 ? 1 : 0 ;
192
247
while ( originalDestinationMetadata . ImcEntries . Count > newMetadata . ImcEntries . Count )
@@ -195,11 +250,19 @@ public static async Task CloneRoot(XivDependencyRoot Source, XivDependencyRoot D
195
250
newMetadata . ImcEntries . Add ( ( XivImc ) newMetadata . ImcEntries [ cloneNum ] . Clone ( ) ) ;
196
251
}
197
252
253
+ if ( ProgressReporter != null )
254
+ {
255
+ ProgressReporter . Report ( "Copying metdata..." ) ;
256
+ }
198
257
// Save the new Metadata file.
199
258
await ItemMetadata . SaveMetadata ( newMetadata , ApplicationSource ) ;
200
259
201
260
202
261
262
+ if ( ProgressReporter != null )
263
+ {
264
+ ProgressReporter . Report ( "Filling in missing material sets..." ) ;
265
+ }
203
266
// Validate all variants/material sets for valid materials, and copy materials as needed to fix.
204
267
if ( Imc . UsesImc ( Destination ) )
205
268
{
@@ -237,6 +300,12 @@ public static async Task CloneRoot(XivDependencyRoot Source, XivDependencyRoot D
237
300
}
238
301
}
239
302
}
303
+
304
+
305
+ if ( ProgressReporter != null )
306
+ {
307
+ ProgressReporter . Report ( "Root copy complete." ) ;
308
+ }
240
309
}
241
310
242
311
const string CommonPath = "chara/common/" ;
0 commit comments