/// <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); }
/// <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)); }
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); }
string GenerateIdFromParentDirectory(string parentDirectory) { string parentDirectoryName = WixDirectoryElement.GetLastFolderInDirectoryName(parentDirectory); if (parentDirectoryName.Length > 0) { return(WixFileElement.GenerateId(parentDirectoryName)); } return(String.Empty); }
/// <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)); }
/// <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))); }
/// <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); }