/// <summary> /// Attempts to resolve tlk file conflicts between the module tlk and any /// tlk's defined in the hifs. It does this by attempting to build a /// new tlk file containing all of the tlk entries from all tlks. If there /// are no overlapping entries in the tlks's then this will succeed and /// the name of the new tlk will be returned, if there are overlaps then /// this will fail and string.Empty will be returned. /// </summary> /// <param name="hakInfos">The HIFs being added to the module</param> /// <param name="module">The module for which we are resolving conflicts</param> /// <param name="moduleInfo">The module info for the module</param> /// <param name="conflicts">The list of files in conflict</param> /// <returns>The name of the merge hak file, or string.Empty if a merge tlk /// could not be generated.</returns> public string ResolveConflicts(HakInfo[] hakInfos, Erf module, ModuleInfo moduleInfo, OverwriteWarningCollection conflicts) { try { // Reset the message shown flag so we show the message once. conflictHakMessageShown = false; // Generate the name of the conflict resolution hak and the directory // in which to place the files that will be added to the hak. conflictHak = GetFileName(module, "hak"); conflictHakDir = NWN.NWNInfo.GetFullFilePath(conflictHak) + ".temp"; OverwriteWarningCollection copy = conflicts.Clone(); foreach (OverwriteWarning conflict in copy) { // Check to see if we can attempt to resolve the conflict, if // we can then attempt to resolve it, and if the resolution is // successful then remove the conflict from the collection. switch (Path.GetExtension(conflict.File).ToLower()) { case ".2da": DisplayConflictHakMessage(module); if (Resolve2daConflict(hakInfos, module, moduleInfo, conflict)) conflicts.Remove(conflict); break; } } // Get all of the files in the conflict hak directory, if there are none // then there is no conflict hak. if (!Directory.Exists(conflictHakDir)) return string.Empty; string[] files = Directory.GetFiles(conflictHakDir); if (0 == files.Length) return string.Empty; // We have some resolved conflicts make the merge hak. Erf hak = Erf.New(Erf.ErfType.HAK, "Auto-generated merge hak"); foreach (string file in files) hak.AddFile(file, true); hak.SaveAs(NWN.NWNInfo.GetFullFilePath(conflictHak)); return conflictHak; } finally { if (Directory.Exists(conflictHakDir)) Directory.Delete(conflictHakDir, true); } }