public void ApplyChanges(IMEPackage package, MergeAssetCache1 assetsCache, Mod installingMod, GameTarget gameTarget) { // APPLY PROPERTY UPDATES Log.Information($@"Merging changes into {EntryName}"); var export = package.FindExport(EntryName); if (export == null) { throw new Exception(M3L.GetString(M3L.string_interp_mergefile_couldNotFindExportInPackage, package.FilePath, EntryName)); } if (PropertyUpdates != null) { var props = export.GetProperties(); foreach (var pu in PropertyUpdates) { pu.ApplyUpdate(package, props, this); } export.WriteProperties(props); } // APPLY ASSET UPDATE AssetUpdate?.ApplyUpdate(package, export, installingMod); // APPLY SCRIPT UDPATE ScriptUpdate?.ApplyUpdate(package, export, assetsCache, installingMod, gameTarget); // APPLY SEQUENCE SKIP UPDATE SequenceSkipUpdate?.ApplyUpdate(package, export, installingMod); // APPLY CONFIG FLAG REMOVAL if (DisableConfigUpdate) { DisableConfigFlag(package, export, installingMod); } }
public void ApplyChanges(GameTarget gameTarget, CaseInsensitiveDictionary <string> loadedFiles, Mod associatedMod, ref int numMergesCompleted, int numTotalMerges, Action <int, int, string, string> mergeProgressDelegate = null) { List <string> targetFiles = new List <string>(); if (ApplyToAllLocalizations) { var targetnameBase = Path.GetFileNameWithoutExtension(FileName); var targetExtension = Path.GetExtension(FileName); var localizations = StarterKitGeneratorWindow.GetLanguagesForGame(associatedMod.Game); // Ensure end name is not present on base foreach (var l in localizations) { if (targetnameBase.EndsWith($@"_{l.filecode}", StringComparison.InvariantCultureIgnoreCase)) { targetnameBase = targetnameBase.Substring(0, targetnameBase.Length - (l.filecode.Length + 1)); //_FileCode } } foreach (var l in localizations) { var targetname = $@"{targetnameBase}_{l.filecode}{targetExtension}"; if (loadedFiles.TryGetValue(targetname, out var fullpath)) { targetFiles.Add(fullpath); } else { Log.Warning($@"File not found in game: {targetname}, skipping..."); numMergesCompleted++; mergeProgressDelegate?.Invoke(numMergesCompleted, numMergesCompleted, null, null); } } } else { if (loadedFiles.TryGetValue(FileName, out var fullpath)) { targetFiles.Add(fullpath); } else { Log.Warning($@"File not found in game: {FileName}, skipping..."); numMergesCompleted++; mergeProgressDelegate?.Invoke(numMergesCompleted, numMergesCompleted, null, null); } } MergeAssetCache1 mac = new MergeAssetCache1(); foreach (var f in targetFiles) { Log.Information($@"Opening package {f}"); #if DEBUG Stopwatch sw = Stopwatch.StartNew(); #endif // Open as memorystream as we need to hash this file for tracking using MemoryStream ms = new MemoryStream(File.ReadAllBytes(f)); var existingMD5 = Utilities.CalculateMD5(ms); var package = MEPackageHandler.OpenMEPackageFromStream(ms, f); #if DEBUG Debug.WriteLine($@"Opening package {f} took {sw.ElapsedMilliseconds} ms"); #endif foreach (var pc in MergeChanges) { pc.ApplyChanges(package, mac, associatedMod, gameTarget); } var track = package.IsModified; if (package.IsModified) { Log.Information($@"Saving package {package.FilePath}"); #if DEBUG sw.Restart(); #endif package.Save(savePath: f, compress: true); #if DEBUG Debug.WriteLine($@"Saving package {f} took {sw.ElapsedMilliseconds} ms"); #endif } else { Log.Information($@"Package {package.FilePath} was not modified. This change is likely already installed, not saving package"); } numMergesCompleted++; mergeProgressDelegate?.Invoke(numMergesCompleted, numTotalMerges, track ? existingMD5 : null, track ? f : null); } }