/// <summary>
        /// Creates an id from the filename.
        /// </summary>
        /// <remarks>
        /// Takes the filename, removes all periods, and
        /// capitalises the first character and first extension character.
        /// </remarks>
        /// <param name="document">The Wix document is used to make sure the
        /// id generated is unique for that document.</param>
        /// <param name="fileName">The full filename including the directory to
        /// use when generating the id.</param>
        public static string GenerateIdFromFileName(WixDocument document, string fileName)
        {
            string id = GenerateIdFromFileName(fileName);

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

            // Add the parent folder to the id.
            string parentDirectory = WixDirectoryElement.GetLastDirectoryName(Path.GetDirectoryName(fileName));

            parentDirectory = FirstCharacterToUpperInvariant(parentDirectory);
            parentDirectory = WixFileElement.GenerateId(parentDirectory).Replace(".", String.Empty);
            id = String.Concat(parentDirectory, id);
            if (!document.ComponentIdExists(id))
            {
                return(id);
            }

            // Add a number to the end until we generate a unique id.
            int    count  = 0;
            string baseId = id;

            do
            {
                ++count;
                id = String.Concat(baseId, count);
            } while (document.ComponentIdExists(id));

            return(id);
        }
Пример #2
0
        /// <summary>
        /// Adds the specified directory to the selected element. This
        /// adds all the contained files and subdirectories recursively to the
        /// setup package.
        /// </summary>
        public void AddDirectory(string directory)
        {
            WixDirectoryElement parentElement = (WixDirectoryElement)view.SelectedElement;

            // Add directory.
            string directoryName = WixDirectoryElement.GetLastDirectoryName(directory);
            WixDirectoryElement directoryElement = AddDirectory(parentElement, directoryName);

            AddFiles(directoryElement, directory);

            // Adds directory contents recursively.
            AddDirectoryContents(directoryElement, directory);

            AddElementToView(directoryElement);
        }
Пример #3
0
        /// <summary>
        /// Adds any subdirectories and files to the directory element.
        /// </summary>
        /// <param name="directoryElement">The directory element to add
        /// the components and subdirectories to.</param>
        /// <param name="directory">The full path of the directory.</param>
        void AddDirectoryContents(WixDirectoryElement directoryElement, string directory)
        {
            foreach (string subDirectory in DirectoryReader.GetDirectories(directory))
            {
                string subDirectoryName = WixDirectoryElement.GetLastDirectoryName(subDirectory);
                if (!excludedNames.IsExcluded(subDirectoryName))
                {
                    WixDirectoryElement subDirectoryElement = AddDirectory(directoryElement, subDirectoryName);
                    AddFiles(subDirectoryElement, subDirectory);

                    // Add the subdirectory contents.
                    AddDirectoryContents(subDirectoryElement, subDirectory);
                }
            }
        }
Пример #4
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);
        }