예제 #1
0
        /// <summary>
        /// Generates a unique id for the entire document that this file element
        /// belongs to.
        /// </summary>
        /// <param name="parentDirectory">The full path of the parent directory
        /// for the filename.</param>
        /// <param name="fileName">The name of the file to generate a unique
        /// id for. This does not include any path.</param>
        string GenerateUniqueId(string parentDirectory, string fileName)
        {
            string      id       = GenerateId(fileName);
            WixDocument document = (WixDocument)OwnerDocument;

            if (!document.FileIdExists(id))
            {
                return(id);
            }

            // Add the file's parent directory to the id.
            string parentDirectoryName = WixDirectoryElement.GetLastDirectoryName(parentDirectory);

            if (parentDirectoryName.Length > 0)
            {
                id = String.Concat(WixFileElement.GenerateId(parentDirectoryName), ".", id);
                if (!document.FileIdExists(id))
                {
                    return(id);
                }
                fileName = id;
            }

            // Add a number to the file name until we get a unique id.
            int    count     = 0;
            string idStart   = Path.GetFileNameWithoutExtension(fileName);
            string extension = Path.GetExtension(fileName);

            do
            {
                ++count;
                id = String.Concat(idStart, count, extension);
            } while (document.FileIdExists(id));

            return(id);
        }