public void SubFolderFile()
		{
			WixFileElement fileElement = new WixFileElement(doc, @"C:\Projects\Setup\Files\readme.txt");
			Assert.AreEqual("readme.txt", fileElement.FileName);
			Assert.AreEqual("readme.txt", fileElement.FileName);
			Assert.AreEqual(@"Files\readme.txt", fileElement.Source);
		}
        /// <summary>
        /// Creates a new file element with the specified filename.
        /// </summary>
        public WixFileElement AddFile(string fileName)
        {
            WixFileElement fileElement = new WixFileElement(this, fileName);

            AppendChild(fileElement);
            return(fileElement);
        }
        /// <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);
        }
		public void DifferentParentFolderFile()
		{
			WixFileElement fileElement = new WixFileElement(doc, @"C:\Projects\AnotherSetup\Files\readme.txt");
			Assert.AreEqual("readme.txt", fileElement.FileName);
			Assert.AreEqual("readme.txt", fileElement.Id);
			Assert.AreEqual(@"..\AnotherSetup\Files\readme.txt", fileElement.Source);
		}		
Ejemplo n.º 5
0
        /// <summary>
        /// Adds a new directory with the specified name and id. A short name
        /// will be generated if the name is too long.
        /// </summary>
        public WixDirectoryElement AddDirectory(string name)
        {
            WixDirectoryElement directoryElement = new WixDirectoryElement((WixDocument)OwnerDocument);

            directoryElement.Id            = WixFileElement.GenerateId(name);
            directoryElement.DirectoryName = name;
            return((WixDirectoryElement)AppendChild(directoryElement));
        }
		public void SetUpFixture()
		{
			WixDocument doc = new WixDocument();
			
			WixFileElement fileElement = new WixFileElement(doc);
			fileElement.FileName = @"MyApp.exe";
			fileNameSpecifiedNode = new WixFileTreeNode(fileElement);
		}
 string GenerateUniqueChildDirectoryId(string childDirectoryId)
 {
     childDirectoryId = WixFileElement.GenerateId(childDirectoryId);
     if (!OwnerWixDocument.DirectoryIdExists(childDirectoryId))
     {
         return(childDirectoryId);
     }
     return(GenerateUniqueChildDirectoryIdUsingParentDirectoryId(childDirectoryId));
 }
        string GenerateIdFromParentDirectory(string fileName)
        {
            string fullParentDirectory = Path.GetDirectoryName(fileName);
            string lastFolder          = WixDirectoryElement.GetLastFolderInDirectoryName(fullParentDirectory);
            string id = UpperCaseFirstCharacter(lastFolder);

            id = WixFileElement.GenerateId(id);
            id = RemoveDotCharacters(id);
            return(id);
        }
Ejemplo n.º 9
0
        string GenerateIdFromParentDirectory(string parentDirectory)
        {
            string parentDirectoryName = WixDirectoryElement.GetLastFolderInDirectoryName(parentDirectory);

            if (parentDirectoryName.Length > 0)
            {
                return(WixFileElement.GenerateId(parentDirectoryName));
            }
            return(String.Empty);
        }
		public void SetUpFixture()
		{
			base.InitFixture();
			WixDirectoryElement programFilesFolderElement = (WixDirectoryElement)editor.Document.GetRootDirectory().FirstChild;
			view.SelectedElement = programFilesFolderElement;
			editor.AddDirectory(directory);
			
			appDirectoryElement = (WixDirectoryElement)programFilesFolderElement.FirstChild;
			exeFileElement = (WixFileElement)appDirectoryElement.SelectSingleNode("w:Component/w:File[@Name='MyApp.exe']", new WixNamespaceManager(editor.Document.NameTable));
			readmeFileElement = (WixFileElement)appDirectoryElement.SelectSingleNode("w:Component/w:File[@Name='readme.txt']", new WixNamespaceManager(editor.Document.NameTable));
		}
		public void SetUpFixture()
		{
			base.InitFixture();
			editor.ExcludedItems.AddRange(new string[] {"readme.txt", "obj"});
			editor.AddDirectory(directory);
			
			WixNamespaceManager nsManager = new WixNamespaceManager(editor.Document.NameTable);
			appDirectoryElement = (WixDirectoryElement)editor.Document.GetRootDirectory().FirstChild;
			docsDirectoryElement = (WixDirectoryElement)appDirectoryElement.SelectSingleNode("w:Directory[@Name='docs']", nsManager);
			srcDirectoryElement = (WixDirectoryElement)appDirectoryElement.SelectSingleNode("w:Directory[@Name='src']", nsManager);
			readmeFileElement = (WixFileElement)docsDirectoryElement.SelectSingleNode("w:Component/w:File[@Name='readme.txt']", nsManager);
		}
Ejemplo n.º 12
0
        public WixFileElement[] GetFiles()
        {
            List <WixFileElement> files = new List <WixFileElement>();

            foreach (XmlNode childNode in ChildNodes)
            {
                WixFileElement childElement = childNode as WixFileElement;
                if (childElement != null)
                {
                    files.Add(childElement);
                }
            }
            return(files.ToArray());
        }
Ejemplo n.º 13
0
        /// <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>
        public string GenerateIdFromFileName(string fileName)
        {
            string fileNameWithoutExtension = UpperCaseFirstCharacterOfFileNameWithoutExtension(fileName);

            fileNameWithoutExtension = RemoveDotCharacters(fileNameWithoutExtension);

            string extension = GetFileExtensionWithoutDotCharacter(fileName);

            extension = UpperCaseFirstCharacter(extension);

            string modifiedFileName = String.Concat(fileNameWithoutExtension, extension);

            return(WixFileElement.GenerateId(modifiedFileName));
        }
Ejemplo n.º 14
0
		public void SetUpFixture()
		{
			base.InitFixture();
			editor.AddDirectory(directory);
			
			WixNamespaceManager nsManager = new WixNamespaceManager(editor.Document.NameTable);
			appDirectoryElement = (WixDirectoryElement)editor.Document.GetRootDirectory().FirstChild;
			myAppExeFileComponentElement = (WixComponentElement)appDirectoryElement.SelectSingleNode("w:Component", nsManager);
			myAppExeFileElement = (WixFileElement)myAppExeFileComponentElement.LastChild;
			docsDirectoryElement = (WixDirectoryElement)appDirectoryElement.SelectSingleNode("w:Directory[@Name='docs']", nsManager);
			srcDirectoryElement = (WixDirectoryElement)appDirectoryElement.SelectSingleNode("w:Directory[@Name='src']", nsManager);
			cssDirectoryElement = (docsDirectoryElement.GetDirectories())[0];
			readmeFileElement = (WixFileElement)docsDirectoryElement.SelectSingleNode("w:Component/w:File[@Name='readme.txt']", nsManager);
		}
Ejemplo n.º 15
0
        /// <summary>
        /// Adds a file to the specified component element.
        /// </summary>
        WixFileElement AddFile(WixComponentElement componentElement, string fileName, bool keyPath)
        {
            WixFileElement fileElement = componentElement.AddFile(fileName);

            if (!componentElement.HasDiskId)
            {
                componentElement.DiskId = "1";
            }
            if (keyPath)
            {
                fileElement.KeyPath = "yes";
            }
            return(fileElement);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Adds a single file to the selected component element.
        /// </summary>
        void AddFile(string fileName)
        {
            WixComponentElement componentElement = view.SelectedElement as WixComponentElement;
            WixDirectoryElement directoryElement = view.SelectedElement as WixDirectoryElement;

            if (componentElement != null)
            {
                WixFileElement fileElement = AddFile(componentElement, fileName, false);
                view.AddElement(fileElement);
                view.IsDirty = true;
            }
            else if (directoryElement != null)
            {
                componentElement = AddFileWithParentComponent(directoryElement, fileName);
                view.AddElement(componentElement);
                view.IsDirty = true;
            }
        }
Ejemplo n.º 17
0
        /// <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>
        public static string GenerateIdFromFileName(string fileName)
        {
            string fileNameNoExtension = Path.GetFileNameWithoutExtension(fileName);
            string idStart             = String.Empty;

            if (fileNameNoExtension.Length > 0)
            {
                idStart = FirstCharacterToUpperInvariant(fileNameNoExtension).Replace(".", String.Empty);
            }

            // Remove period from extension and uppercase first extension char.
            string extension = Path.GetExtension(fileName);
            string idEnd     = String.Empty;

            if (extension.Length > 1)
            {
                idEnd = FirstCharacterToUpperInvariant(extension.Substring(1));
            }
            return(WixFileElement.GenerateId(String.Concat(idStart, idEnd)));
        }
Ejemplo n.º 18
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);
        }
		public void FileIdAlreadyExistsAndParentDirectoryIsRoot()
		{
			WixFileElement fileElement = new WixFileElement(doc, @"C:\license.txt");
			Assert.AreEqual("license1.txt", fileElement.Id);
		}
		public void FileIdWithNumberAlreadyExists()
		{
			component.AddFile(@"license.txt");
			WixFileElement fileElement = new WixFileElement(doc, @"license.txt");
			Assert.AreEqual("license2.txt", fileElement.Id);
		}
		public void FileIdExists()
		{
			WixFileElement fileElement = new WixFileElement(doc, @"C:\Projects\Setup\doc\license.txt");
			Assert.IsTrue(doc.FileIdExists("license.txt"));
		}
		public void FileIdAlreadyExistsAndParentDirectoryUsingAltDirSeparator()
		{
			WixFileElement fileElement = new WixFileElement(doc, @"C:/Projects/Setup/doc/license.txt");
			Assert.AreEqual("doc.license.txt", fileElement.Id);
		}
		/// <summary>
		/// Creates a new file element with the specified filename.
		/// </summary>
		public WixFileElement AddFile(string fileName)
		{
			WixFileElement fileElement = new WixFileElement(this, fileName);
			return (WixFileElement)AppendChild(fileElement);
		}
		public void FileIdAlreadyExists()
		{
			WixFileElement fileElement = new WixFileElement(doc, @"C:\Projects\Setup\doc\license.txt");
			Assert.AreEqual("doc.license.txt", fileElement.Id);
		}
Ejemplo n.º 25
0
		public void LongFileName()
		{
			WixFileElement fileElement = new WixFileElement(doc, @"C:\Projects\Setup\Files\LongFileName.LongExtension");
			Assert.AreEqual("LongFileName.LongExtension", fileElement.Id);
		}		
Ejemplo n.º 26
0
		public void NewWixFileElement()
		{
			WixFileElement fileElement = new WixFileElement(doc, @"C:\Projects\Setup\Files\readme.txt");
			Assert.AreEqual("readme.txt", fileElement.Id);
		}
Ejemplo n.º 27
0
 public WixFileTreeNode(WixFileElement element) : base(element)
 {
     fileElement = element;
     ContextmenuAddinTreePath = "/AddIns/WixBinding/PackageFilesView/ContextMenu/FileTreeNode";
     Refresh();
 }
		public void FileIdWithParentDirectoryAndNumberExists()
		{
			component.AddFile(@"C:/Projects/Setup/doc/license.txt");
			WixFileElement fileElement = new WixFileElement(doc, @"C:/Projects/Setup/doc/license.txt");
			Assert.AreEqual("doc.license1.txt", fileElement.Id);
		}
Ejemplo n.º 29
0
		List<string> GetFileNames(WixFileElement[] fileElements)
		{
			List<string> fileNames = new List<string>();
			foreach (WixFileElement fileElement in fileElements) {
				fileNames.Add(fileElement.GetSourceFullPath());
			}
			return fileNames;
		}
		public void FileIdAlreadyExistsAndParentDirectoryUsingHyphen()
		{
			WixFileElement fileElement = new WixFileElement(doc, @"C:/Projects/Setup/a-docs/readme.rtf");
			Assert.AreEqual("a_docs.readme.rtf", fileElement.Id);
		}
Ejemplo n.º 31
0
		public WixFileTreeNode(WixFileElement element) : base(element)
		{
			fileElement = element;
			ContextmenuAddinTreePath = "/AddIns/WixBinding/PackageFilesView/ContextMenu/FileTreeNode";
			Refresh();
		}