/// <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> /// 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); }