Browse Source

Fixed illegal WiX ids being generated when the filename had an extension of less than three characters and when the parent directory was concatenated with the file or component id.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@1908 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Matt Ward 20 years ago
parent
commit
a92eeffef5
  1. 17
      src/AddIns/BackendBindings/WixBinding/Project/Src/ShortFileName.cs
  2. 1
      src/AddIns/BackendBindings/WixBinding/Project/Src/WixComponentElement.cs
  3. 4
      src/AddIns/BackendBindings/WixBinding/Project/Src/WixFileElement.cs
  4. 24
      src/AddIns/BackendBindings/WixBinding/Test/DirectoryImport/DuplicateComponentIdTestFixture.cs
  5. 9
      src/AddIns/BackendBindings/WixBinding/Test/Document/ExistingFileIdGenerationTests.cs
  6. 24
      src/AddIns/BackendBindings/WixBinding/Test/Document/ExistingShortFileNameTests.cs
  7. 12
      src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/ShortFileNameGeneratorTests.cs

17
src/AddIns/BackendBindings/WixBinding/Project/Src/ShortFileName.cs

@ -140,6 +140,23 @@ namespace ICSharpCode.WixBinding
return truncatedName; return truncatedName;
} }
/// <summary>
/// Determines whether the specified filename is a long name
/// and should be converted into a short name.
/// </summary>
public static bool IsLongFileName(string fileName)
{
if (fileName == null) {
return false;
}
string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileName);
string extension = Path.GetExtension(fileName);
return fileNameWithoutExtension.Length > MaximumFileNameWithoutExtensionLength ||
extension.Length > MaximumFileNameExtensionLength;
}
/// <summary> /// <summary>
/// Truncates the filename start and adds "_N" where N produces a filename that /// Truncates the filename start and adds "_N" where N produces a filename that
/// does not exist. /// does not exist.

1
src/AddIns/BackendBindings/WixBinding/Project/Src/WixComponentElement.cs

@ -95,6 +95,7 @@ namespace ICSharpCode.WixBinding
// Add the parent folder to the id. // Add the parent folder to the id.
string parentDirectory = WixDirectoryElement.GetLastDirectoryName(Path.GetDirectoryName(fileName)); string parentDirectory = WixDirectoryElement.GetLastDirectoryName(Path.GetDirectoryName(fileName));
parentDirectory = FirstCharacterToUpperInvariant(parentDirectory); parentDirectory = FirstCharacterToUpperInvariant(parentDirectory);
parentDirectory = WixFileElement.GenerateId(parentDirectory);
id = String.Concat(parentDirectory, id); id = String.Concat(parentDirectory, id);
if (!document.ComponentIdExists(id)) { if (!document.ComponentIdExists(id)) {
return id; return id;

4
src/AddIns/BackendBindings/WixBinding/Project/Src/WixFileElement.cs

@ -184,7 +184,7 @@ namespace ICSharpCode.WixBinding
string longFileName = null; string longFileName = null;
string shortFileName = Path.GetFileName(sourceFileName); string shortFileName = Path.GetFileName(sourceFileName);
string idFileName = shortFileName; string idFileName = shortFileName;
if (shortFileName.Length > ShortFileName.MaximumFileNameLength) { if (ShortFileName.IsLongFileName(shortFileName)) {
longFileName = shortFileName; longFileName = shortFileName;
shortFileName = ShortFileName.Convert(shortFileName, ShortFileNameExists); shortFileName = ShortFileName.Convert(shortFileName, ShortFileNameExists);
idFileName = longFileName; idFileName = longFileName;
@ -217,7 +217,7 @@ namespace ICSharpCode.WixBinding
// Add the file's parent directory to the id. // Add the file's parent directory to the id.
string parentDirectoryName = WixDirectoryElement.GetLastDirectoryName(parentDirectory); string parentDirectoryName = WixDirectoryElement.GetLastDirectoryName(parentDirectory);
if (parentDirectoryName.Length > 0) { if (parentDirectoryName.Length > 0) {
id = String.Concat(parentDirectoryName, ".", id); id = String.Concat(WixFileElement.GenerateId(parentDirectoryName), ".", id);
if (!document.FileIdExists(id)) { if (!document.FileIdExists(id)) {
return id; return id;
} }

24
src/AddIns/BackendBindings/WixBinding/Test/DirectoryImport/DuplicateComponentIdTestFixture.cs

@ -31,17 +31,19 @@ namespace WixBinding.Tests.DirectoryImport
WixComponentElement readmeComponentElement; WixComponentElement readmeComponentElement;
WixComponentElement licenseComponentElement; WixComponentElement licenseComponentElement;
WixComponentElement exeComponentElement; WixComponentElement exeComponentElement;
WixNamespaceManager nsManager;
string directory = @"C:\Projects\Test\MyApp"; string directory = @"C:\Projects\Test\MyApp";
string directory2 = @"C:\Projects\Test\a-app";
string[] files = new string[] {"MyApp.exe", "readme.txt", "license.txt"}; string[] files = new string[] {"MyApp.exe", "readme.txt", "license.txt"};
[TestFixtureSetUp] [SetUp]
public void SetUpFixture() public void Init()
{ {
base.InitFixture(); base.InitFixture();
editor.AddDirectory(directory); editor.AddDirectory(directory);
WixNamespaceManager nsManager = new WixNamespaceManager(editor.Document.NameTable); nsManager = new WixNamespaceManager(editor.Document.NameTable);
appDirectoryElement = (WixDirectoryElement)editor.Document.RootDirectory.SelectSingleNode("w:Directory[@Name='MyApp']", nsManager);; appDirectoryElement = (WixDirectoryElement)editor.Document.RootDirectory.SelectSingleNode("w:Directory[@Name='MyApp']", nsManager);
readmeComponentElement = (WixComponentElement)appDirectoryElement.SelectSingleNode("w:Component[w:File/@Name='readme.txt']", nsManager); readmeComponentElement = (WixComponentElement)appDirectoryElement.SelectSingleNode("w:Component[w:File/@Name='readme.txt']", nsManager);
licenseComponentElement = (WixComponentElement)appDirectoryElement.SelectSingleNode("w:Component[w:File/@Name='license.txt']", nsManager); licenseComponentElement = (WixComponentElement)appDirectoryElement.SelectSingleNode("w:Component[w:File/@Name='license.txt']", nsManager);
exeComponentElement = (WixComponentElement)appDirectoryElement.SelectSingleNode("w:Component[w:File/@Name='MyApp.exe']", nsManager); exeComponentElement = (WixComponentElement)appDirectoryElement.SelectSingleNode("w:Component[w:File/@Name='MyApp.exe']", nsManager);
@ -68,10 +70,24 @@ namespace WixBinding.Tests.DirectoryImport
Assert.AreEqual("MyAppMyAppExe2", exeComponentElement.Id); Assert.AreEqual("MyAppMyAppExe2", exeComponentElement.Id);
} }
[Test]
public void AddDirectoryWithHyphen()
{
view.SelectedElement = null;
editor.AddDirectory(directory2);
WixDirectoryElement directoryElement = (WixDirectoryElement)editor.Document.RootDirectory.SelectSingleNode("w:Directory[@Name='a-app']", nsManager);
WixComponentElement exeComponentElement = (WixComponentElement)directoryElement.SelectSingleNode("w:Component[w:File/@Name='MyApp.exe']", nsManager);
Assert.AreEqual("A_appMyAppExe", exeComponentElement.Id);
}
public override string[] GetFiles(string path) public override string[] GetFiles(string path)
{ {
if (path == directory) { if (path == directory) {
return files; return files;
} else if (path == directory2) {
return files;
} }
return new string[0]; return new string[0];
} }

9
src/AddIns/BackendBindings/WixBinding/Test/Document/ExistingFileIdGenerationTests.cs

@ -84,6 +84,14 @@ namespace WixBinding.Tests.Document
Assert.IsFalse(doc.FileIdExists("lice'nse.txt")); Assert.IsFalse(doc.FileIdExists("lice'nse.txt"));
} }
[Test]
public void FileIdAlreadyExistsAndParentDirectoryUsingHyphen()
{
WixFileElement fileElement = new WixFileElement(doc, @"C:/Projects/Setup/a-docs/readme.rtf");
Assert.AreEqual("a_docs.readme.rtf", fileElement.Id);
}
string GetWixXml() string GetWixXml()
{ {
return "<Wix xmlns=\"http://schemas.microsoft.com/wix/2003/01/wi\">\r\n" + return "<Wix xmlns=\"http://schemas.microsoft.com/wix/2003/01/wi\">\r\n" +
@ -104,6 +112,7 @@ namespace WixBinding.Tests.Document
"\t\t\t\t\t\t\t<File Source=\"doc\\license.txt\" Name=\"license.txt\" Id=\"license.txt\" />\r\n" + "\t\t\t\t\t\t\t<File Source=\"doc\\license.txt\" Name=\"license.txt\" Id=\"license.txt\" />\r\n" +
"\t\t\t\t\t\t\t<File Source=\"doc\\readme.rtf\" Name=\"readme.rtf\" Id=\"readme.rtf\" />\r\n" + "\t\t\t\t\t\t\t<File Source=\"doc\\readme.rtf\" Name=\"readme.rtf\" Id=\"readme.rtf\" />\r\n" +
"\t\t\t\t\t\t\t<File Source=\"doc\\SharpDevelopInfoResources.txt\" Name=\"Resource.txt\" Id=\"SharpDevelopInfoResources.txt\" LongName=\"SharpDevelopInfoResources.txt\" />\r\n" + "\t\t\t\t\t\t\t<File Source=\"doc\\SharpDevelopInfoResources.txt\" Name=\"Resource.txt\" Id=\"SharpDevelopInfoResources.txt\" LongName=\"SharpDevelopInfoResources.txt\" />\r\n" +
"\t\t\t\t\t\t\t<File Source=\"a-docs\\readme.rtf\" Name=\"readme.rtf\" Id=\"readme.rtf\" />\r\n" +
"\t\t\t\t\t\t</Component>\r\n" + "\t\t\t\t\t\t</Component>\r\n" +
"\t\t\t\t\t</Directory>\r\n" + "\t\t\t\t\t</Directory>\r\n" +
"\t\t\t</Directory>\r\n" + "\t\t\t</Directory>\r\n" +

24
src/AddIns/BackendBindings/WixBinding/Test/Document/ExistingShortFileNameTests.cs

@ -50,6 +50,30 @@ namespace WixBinding.Tests.Document
WixFileElement fileElement = (WixFileElement)myAppComponent.LastChild; WixFileElement fileElement = (WixFileElement)myAppComponent.LastChild;
Assert.AreEqual("CHANGE_1.XML", fileElement.ShortName); Assert.AreEqual("CHANGE_1.XML", fileElement.ShortName);
} }
/// <summary>
/// Tests that the short name generated is correct when
/// the file extension has only two characters.
/// </summary>
[Test]
public void TwoCharacterExtension()
{
myAppComponent.AddFile(@"C:\Projects\Setup\doc\ebcdic-it.so");
WixFileElement fileElement = (WixFileElement)myAppComponent.LastChild;
Assert.AreEqual("EBCDIC_1.SO", fileElement.ShortName);
}
/// <summary>
/// Tests that the short name generated is correct when
/// the file extension has more than three characters.
/// </summary>
[Test]
public void FourCharacterExtension()
{
myAppComponent.AddFile(@"C:\Projects\Setup\doc\abc.text");
WixFileElement fileElement = (WixFileElement)myAppComponent.LastChild;
Assert.AreEqual("ABC.TEX", fileElement.ShortName);
}
string GetWixXml() string GetWixXml()
{ {

12
src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/ShortFileNameGeneratorTests.cs

@ -97,6 +97,18 @@ namespace WixBinding.Tests.PackageFiles
string name = "boo.exe.config"; string name = "boo.exe.config";
Assert.AreEqual("BOOEXE.CON", ShortFileName.Convert(name)); Assert.AreEqual("BOOEXE.CON", ShortFileName.Convert(name));
} }
[Test]
public void NullFileNameIsNotTooLong()
{
Assert.IsFalse(ShortFileName.IsLongFileName(null));
}
[Test]
public void EmptyStringIsNotTooLong()
{
Assert.IsFalse(ShortFileName.IsLongFileName(String.Empty));
}
bool GetFileNameExists(string fileName) bool GetFileNameExists(string fileName)
{ {

Loading…
Cancel
Save