/// <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="module">The module for which we are resolving conflicts</param>
        /// <param name="hifTlks">The list of tlk files from the HIFs being
        /// installed.</param>
        /// <returns>The name of the merge tlk file, or string.Empty if a merge tlk
        /// could not be generated.</returns>
        public string ResolveTlkConflict(Erf module, string[] hifTlks)
        {
            try
            {
                // Let the user know we are building a merge tlk.
                progress.SetMessage("Building merge tlk for module\n'{0}'.",
                    Path.GetFileNameWithoutExtension(module.FileName));

                // Create an array to hold all of the tlk objects.
                Tlk[] tlks = new Tlk[hifTlks.Length];

                // Load all of the tlk's.
                for (int i = 0; i < hifTlks.Length; i++)
                    tlks[i] = Tlk.LoadTlk(NWNInfo.GetFullFilePath(hifTlks[i]));

                // Generate the name of the new tlk file.
                string newTlkFileName = GetFileName(module, "tlk");
                if (null == newTlkFileName)
                    throw new NWNException("Cannot create new tlk file for module {0}", module.FileName);

                // Get the largest entry count in all of the tlk files, we cannot move any of the tlk
                // entries from where they are so the new tlk file will have as many entries as the
                // largest source tlk file.
                int count = 0;
                foreach (Tlk tlk in tlks)
                    if (tlk.Count > count) count = tlk.Count;

                // Create a new tlk file and add all of the entries from all of the tlk files
                // to it.
                Tlk newTlk = new Tlk(count);
                for (int i = 0; i < count; i++)
                {
                    // Check to see which tlk file contains this entry.  If multiple tlk
                    // files contain this entry we cannot merge the tlk's
                    Tlk.TlkEntry entry = null;
                    foreach (Tlk tlk in tlks)
                    {
                        // Ignore empty entries.
                        if (i >= tlk.Count || tlk.IsEmpty(i)) continue;

                        // If we haven't gotten an entry for this row yet
                        // then save this entry.  If we have then we cannot
                        // do the merge.
                        if (null == entry)
                            entry = tlk[i];
                        else
                        {
                            // Check to see if the data in two entries is the same.
                            // If it is then both tlk files have the same string
                            // data in the entry and we can still do the merge.  This
                            // is most likely to happen at index 0 where many tlk
                            // files place "Bad Strref".
                            if (0 == string.Compare(entry.Text, tlk[i].Text, true, CultureInfo.InvariantCulture))
                                continue;

                            throw new InvalidOperationException();
                        }
                    }

                    // Save the entry in our new tlk file.
                    if (null != entry) newTlk[i] = entry;
                }

                // Save the new tlk file and return it's file name.
                newTlk.SaveAs(NWN.NWNInfo.GetFullFilePath(newTlkFileName));
                return newTlkFileName;
            }
            catch (InvalidOperationException)
            {
                // If an error occurs return string.Empty to indicate we couldn't generate
                // a merge tlk.
                return string.Empty;
            }
        }