Browse Source

WixBinding: Can now add directories in the setup files window. Unique short directory name generated. Added simple file and folder ignore list.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@1764 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Matt Ward 19 years ago
parent
commit
3a318e0152
  1. 24
      src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/AddDirectoryCommand.cs
  2. 0
      src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/AddFilesToComponentCommand.cs
  3. 12
      src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/PackageFilesView.cs
  4. 26
      src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixPackageFilesControl.cs
  5. 19
      src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixPackageFilesTreeView.cs
  6. 6
      src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixTreeNode.cs
  7. 52
      src/AddIns/BackendBindings/WixBinding/Project/Src/ShortFileName.cs
  8. 51
      src/AddIns/BackendBindings/WixBinding/Project/Src/WixDirectoryElementBase.cs
  9. 65
      src/AddIns/BackendBindings/WixBinding/Project/Src/WixPackageFilesEditor.cs
  10. 43
      src/AddIns/BackendBindings/WixBinding/Project/WixBinding.addin
  11. 3
      src/AddIns/BackendBindings/WixBinding/Project/WixBinding.csproj
  12. 12
      src/AddIns/BackendBindings/WixBinding/Test/DirectoryImport/AddDirectoryTestFixture.cs
  13. 10
      src/AddIns/BackendBindings/WixBinding/Test/DirectoryImport/AddSubDirectoryTestFixture.cs
  14. 8
      src/AddIns/BackendBindings/WixBinding/Test/DirectoryImport/DuplicateComponentIdTestFixture.cs
  15. 104
      src/AddIns/BackendBindings/WixBinding/Test/DirectoryImport/DuplicateShortDirectoryNameTestFixture.cs
  16. 103
      src/AddIns/BackendBindings/WixBinding/Test/DirectoryImport/ExcludedItemsTestFixture.cs
  17. 13
      src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/AddDirectoryTestFixture.cs
  18. 2
      src/AddIns/BackendBindings/WixBinding/Test/WixBinding.Tests.csproj

24
src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/AddDirectoryCommand.cs

@ -0,0 +1,24 @@ @@ -0,0 +1,24 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using ICSharpCode.Core;
using System;
namespace ICSharpCode.WixBinding
{
/// <summary>
/// Adds a directory and all its contents to the currently selected directory
/// node.
/// </summary>
public class AddDirectoryCommand : AbstractMenuCommand
{
public override void Run()
{
PackageFilesView.ActiveView.AddDirectory();
}
}
}

0
src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/AddFilesToComponentCommand.cs → src/AddIns/BackendBindings/WixBinding/Project/Src/Commands/AddFilesToComponentCommand.cs

12
src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/PackageFilesView.cs

@ -134,6 +134,9 @@ namespace ICSharpCode.WixBinding @@ -134,6 +134,9 @@ namespace ICSharpCode.WixBinding
packageFilesControl.RemoveSelectedElement();
}
/// <summary>
/// Adds files to the selected Component element tree node.
/// </summary>
public void AddFiles()
{
packageFilesControl.AddFiles();
@ -144,6 +147,15 @@ namespace ICSharpCode.WixBinding @@ -144,6 +147,15 @@ namespace ICSharpCode.WixBinding
packageFilesControl.ShowFiles(project, this, this);
}
/// <summary>
/// Adds a directory and all its contents to the selected Directory
/// element tree node.
/// </summary>
public void AddDirectory()
{
packageFilesControl.AddDirectory();
}
/// <summary>
/// Gets the package files view that is already open and displaying the files
/// for the specified project.

26
src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixPackageFilesControl.cs

@ -5,8 +5,10 @@ @@ -5,8 +5,10 @@
// <version>$Revision$</version>
// </file>
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Gui;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
@ -220,9 +222,27 @@ namespace ICSharpCode.WixBinding @@ -220,9 +222,27 @@ namespace ICSharpCode.WixBinding
{
this.project = project;
editor = new WixPackageFilesEditor(this, fileReader, documentWriter);
editor.ExcludedItems.AddRange(GetExcludedItems());
editor.ShowFiles(project);
}
/// <summary>
/// Allows the user to browse for a directory and add it to the setup package.
/// </summary>
public void AddDirectory()
{
// Save selected node since displaying a dialog will change it
// if no node is selected.
TreeNode selectedNode = packageFilesTreeView.SelectedNode;
// Allow the user to select a directory.
FolderDialog dialog = new FolderDialog();
if (dialog.DisplayDialog("Add Directory") == DialogResult.OK) {
packageFilesTreeView.SelectedNode = selectedNode;
editor.AddDirectory(dialog.Path);
}
}
/// <summary>
/// Saves the changes made to the Wix document.
/// </summary>
@ -393,5 +413,11 @@ namespace ICSharpCode.WixBinding @@ -393,5 +413,11 @@ namespace ICSharpCode.WixBinding
dialog.Title = "Add files...";
return dialog;
}
string[] GetExcludedItems()
{
List<string> extensions = AddInTree.BuildItems<string>("/AddIns/WixBinding/ExcludedItems", this);
return extensions.ToArray();
}
}
}

19
src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixPackageFilesTreeView.cs

@ -19,9 +19,13 @@ namespace ICSharpCode.WixBinding @@ -19,9 +19,13 @@ namespace ICSharpCode.WixBinding
/// <summary>
/// The possible states of the tree view.
/// </summary>
[Flags]
public enum WixPackageFilesTreeViewState {
NoChildElementsAllowed = 0,
ChildElementsAllowed = 1
None = 0,
NoChildElementsAllowed = 0x1,
ChildElementsAllowed = 0x2,
NothingSelected = 0x4,
NothingSelectedAndChildElementsAllowed = 0x8
}
StringCollection allowedChildElements = new StringCollection();
@ -41,10 +45,17 @@ namespace ICSharpCode.WixBinding @@ -41,10 +45,17 @@ namespace ICSharpCode.WixBinding
/// </summary>
public Enum InternalState {
get {
if (allowedChildElements.Count > 0) {
bool itemSelected = SelectedElement != null;
bool childElementsAllowed = allowedChildElements.Count > 0;
if (childElementsAllowed && itemSelected) {
return WixPackageFilesTreeViewState.ChildElementsAllowed;
} else if (childElementsAllowed) {
return WixPackageFilesTreeViewState.NothingSelectedAndChildElementsAllowed;
} else if (itemSelected) {
return WixPackageFilesTreeViewState.NoChildElementsAllowed;
}
return WixPackageFilesTreeViewState.NoChildElementsAllowed;
return WixPackageFilesTreeViewState.NothingSelected;
}
}

6
src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixTreeNode.cs

@ -34,7 +34,11 @@ namespace ICSharpCode.WixBinding @@ -34,7 +34,11 @@ namespace ICSharpCode.WixBinding
public Enum InternalState {
get {
return WixPackageFilesTreeView.InternalState;
WixPackageFilesTreeView treeView = WixPackageFilesTreeView;
if (treeView != null) {
return treeView.InternalState;
}
return WixPackageFilesTreeView.WixPackageFilesTreeViewState.None;
}
}

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

@ -40,7 +40,7 @@ namespace ICSharpCode.WixBinding @@ -40,7 +40,7 @@ namespace ICSharpCode.WixBinding
/// does then the FileNameExists delegate is called repeatedly until it
/// finds a filename that does not exist.
/// </summary>
public delegate bool FileNameExists(string fileName);
public delegate bool NameExists(string name);
ShortFileName()
{
@ -52,7 +52,7 @@ namespace ICSharpCode.WixBinding @@ -52,7 +52,7 @@ namespace ICSharpCode.WixBinding
/// <param name="fileName">The long filename.</param>
/// <returns>The converted 8.3 filename. If the filename includes a
/// starting path then this is stripped from the returned value.</returns>
public static string Convert(string fileName, FileNameExists getFileNameExists)
public static string Convert(string fileName, NameExists getFileNameExists)
{
if (fileName == null) {
return String.Empty;
@ -98,25 +98,55 @@ namespace ICSharpCode.WixBinding @@ -98,25 +98,55 @@ namespace ICSharpCode.WixBinding
}
/// <summary>
/// Truncates the filename start and adds "_N" where N produces a filename that
/// does not exist.
/// Gets the unique name string by adding a digit until a unique name is
/// produced. The name string itself will be truncated as the number
/// increases in size to make sure the total length of the string is
/// always equal to start.Length + 1.
/// </summary>
/// <param name="start">The string to be used at the start of the </param>
/// <param name="getNameExists">Method called to check that the
/// name does not already exist.</param>
public static string GetUniqueName(string start, NameExists getNameExists)
{
return GetUniqueName(start, String.Empty, String.Empty, getNameExists);
}
/// <summary>
/// Gets the unique name string by adding a digit until a unique name is
/// produced. The name string itself will be truncated as the number
/// increases in size to make sure the total length of the string is
/// always equal to start.Length + numberPrefix.Length + 1 + end.Length.
/// </summary>
static string GetTruncatedFileName(string fileNameStart, string extension, FileNameExists getFileNameExists)
/// <param name="start">The string to be used at the start of the </param>
/// <param name="numberPrefix">The string to be prefixed to the number.</param>
/// <param name="end">The string to be added after the number.</param>
/// <param name="getNameExists">Method called to check that the
/// name does not already exist.</param>
public static string GetUniqueName(string start, string numberPrefix, string end, NameExists getNameExists)
{
int count = 0;
string truncatedFileName;
string truncatedName;
int divisor = 10;
do {
++count;
int removeCharCount = count / divisor;
if (removeCharCount > 0) {
fileNameStart = fileNameStart.Substring(0, fileNameStart.Length - 1);
start = start.Substring(0, start.Length - 1);
divisor *= divisor;
}
truncatedFileName = String.Concat(fileNameStart, "_", count.ToString(), extension).ToUpperInvariant();
} while (getFileNameExists(truncatedFileName));
return truncatedFileName;
truncatedName = String.Concat(start, numberPrefix, count.ToString(), end);
} while (getNameExists(truncatedName));
return truncatedName;
}
/// <summary>
/// Truncates the filename start and adds "_N" where N produces a filename that
/// does not exist.
/// </summary>
static string GetTruncatedFileName(string fileNameStart, string extension, NameExists getFileNameExists)
{
return GetUniqueName(fileNameStart.ToUpperInvariant(), "_", extension.ToUpperInvariant(), getFileNameExists);
}
/// <summary>

51
src/AddIns/BackendBindings/WixBinding/Project/Src/WixDirectoryElementBase.cs

@ -17,6 +17,12 @@ namespace ICSharpCode.WixBinding @@ -17,6 +17,12 @@ namespace ICSharpCode.WixBinding
/// </summary>
public abstract class WixDirectoryElementBase : XmlElement
{
/// <summary>
/// Maximum short name length that the directory element will use when
/// generating a short name from the long name.
/// </summary>
public const int MaximumDirectoryShortNameLength = 8;
public WixDirectoryElementBase(string localName, WixDocument document)
: base(document.WixNamespacePrefix, localName, WixNamespaceManager.Namespace, document)
{
@ -49,14 +55,51 @@ namespace ICSharpCode.WixBinding @@ -49,14 +55,51 @@ namespace ICSharpCode.WixBinding
}
/// <summary>
/// Adds a new directory with the specified id.
/// 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 id)
public WixDirectoryElement AddDirectory(string name)
{
WixDirectoryElement directoryElement = new WixDirectoryElement((WixDocument)OwnerDocument);
directoryElement.Id = id;
directoryElement.Id = name;
SetDirectoryName(directoryElement, name);
return (WixDirectoryElement)AppendChild(directoryElement);
}
/// <summary>
/// Sets the directory name. Generates a short name if required.
/// </summary>
void SetDirectoryName(WixDirectoryElement directoryElement, string name)
{
if (name.Length > MaximumDirectoryShortNameLength) {
directoryElement.ShortName = GetUniqueShortName(name);
directoryElement.LongName = name;
} else {
directoryElement.ShortName = name;
}
}
string GetUniqueShortName(string name)
{
// Try the truncated name on its own first.
name = name.Replace(".", String.Empty);
name = name.Substring(0, MaximumDirectoryShortNameLength);
if (!ShortNameExists(name)) {
return name;
}
// Add a digit to the name until a unique one is found.
return ShortFileName.GetUniqueName(name.Substring(0, name.Length - 1), ShortNameExists);
}
/// <summary>
/// Checks whether the short directory name exists in the document.
/// </summary>
bool ShortNameExists(string name)
{
string xpath = String.Concat("w:Directory[@Name='", name, "']");
XmlNodeList nodes = SelectNodes(xpath, new WixNamespaceManager(OwnerDocument.NameTable));
return nodes.Count > 0;
}
}
}

65
src/AddIns/BackendBindings/WixBinding/Project/Src/WixPackageFilesEditor.cs

@ -9,6 +9,7 @@ using ICSharpCode.SharpDevelop.Project; @@ -9,6 +9,7 @@ using ICSharpCode.SharpDevelop.Project;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.IO;
using System.Xml;
@ -27,6 +28,7 @@ namespace ICSharpCode.WixBinding @@ -27,6 +28,7 @@ namespace ICSharpCode.WixBinding
WixDocument document;
WixSchemaCompletionData wixSchemaCompletionData;
bool usingRootDirectoryRef;
StringCollection excludedItems = new StringCollection();
/// <summary>
/// Gets the files and directories in the specified path.
@ -159,7 +161,7 @@ namespace ICSharpCode.WixBinding @@ -159,7 +161,7 @@ namespace ICSharpCode.WixBinding
XmlElement element = null;
switch (name) {
case WixDirectoryElement.DirectoryElementName:
element = AddDirectory(parentElement as WixDirectoryElement, "NewDirectory");
element = AddDirectory(parentElement as WixDirectoryElement);
break;
case WixComponentElement.ComponentElementName:
element = AddComponent(parentElement as WixDirectoryElement, "NewComponent");
@ -219,6 +221,16 @@ namespace ICSharpCode.WixBinding @@ -219,6 +221,16 @@ namespace ICSharpCode.WixBinding
AddElementToView(directoryElement);
}
/// <summary>
/// List of files and directory names that will be excluded when
/// adding a directory to the package.
/// </summary>
public StringCollection ExcludedItems {
get {
return excludedItems;
}
}
/// <summary>
/// Adds a single file to the selected component element.
/// </summary>
@ -269,7 +281,17 @@ namespace ICSharpCode.WixBinding @@ -269,7 +281,17 @@ namespace ICSharpCode.WixBinding
}
/// <summary>
/// Adds a new directory with a autogenerated id.
/// Adds a new directory to the specified element.
/// </summary>
WixDirectoryElement AddDirectory(WixDirectoryElementBase parentElement)
{
WixDirectoryElement directoryElement = AddDirectory(parentElement, String.Empty);
directoryElement.Id = "NewDirectory";
return directoryElement;
}
/// <summary>
/// Adds a new directory with the specified name.
/// </summary>
WixDirectoryElement AddDirectory(WixDirectoryElementBase parentElement, string name)
{
@ -283,9 +305,7 @@ namespace ICSharpCode.WixBinding @@ -283,9 +305,7 @@ namespace ICSharpCode.WixBinding
}
}
}
WixDirectoryElement directoryElement = parentElement.AddDirectory(name);
directoryElement.ShortName = name;
return directoryElement;
return parentElement.AddDirectory(name);
}
WixSchemaCompletionData WixSchemaCompletionData {
@ -369,10 +389,12 @@ namespace ICSharpCode.WixBinding @@ -369,10 +389,12 @@ namespace ICSharpCode.WixBinding
void AddFiles(WixDirectoryElement directoryElement, string directory)
{
foreach (string fileName in DirectoryReader.GetFiles(directory)) {
string path = Path.Combine(directory, fileName);
string id = WixComponentElement.GenerateIdFromFileName(document, path);
WixComponentElement component = AddComponent(directoryElement, id);
AddFile(component, path);
if (!IsExcluded(fileName)) {
string path = Path.Combine(directory, fileName);
string id = WixComponentElement.GenerateIdFromFileName(document, path);
WixComponentElement component = AddComponent(directoryElement, id);
AddFile(component, path);
}
}
}
@ -390,14 +412,25 @@ namespace ICSharpCode.WixBinding @@ -390,14 +412,25 @@ namespace ICSharpCode.WixBinding
/// <param name="directory">The full path of the directory.</param>
void AddDirectoryContents(WixDirectoryElement directoryElement, string directory)
{
foreach (string subDirectoryName in DirectoryReader.GetDirectories(directory)) {
string subDirectory = Path.Combine(directory, subDirectoryName);
WixDirectoryElement subDirectoryElement = AddDirectory(directoryElement, subDirectoryName);
AddFiles(subDirectoryElement, subDirectory);
// Add the subdirectory contents.
AddDirectoryContents(subDirectoryElement, subDirectory);
foreach (string subDirectory in DirectoryReader.GetDirectories(directory)) {
string subDirectoryName = WixDirectoryElement.GetLastDirectoryName(subDirectory);
if (!IsExcluded(subDirectoryName)) {
WixDirectoryElement subDirectoryElement = AddDirectory(directoryElement, subDirectoryName);
AddFiles(subDirectoryElement, subDirectory);
// Add the subdirectory contents.
AddDirectoryContents(subDirectoryElement, subDirectory);
}
}
}
/// <summary>
/// Checks whether the specified filename or directory name should be
/// excluded.
/// </summary>
bool IsExcluded(string name)
{
return excludedItems.Contains(name);
}
}
}

43
src/AddIns/BackendBindings/WixBinding/Project/WixBinding.addin

@ -188,6 +188,9 @@ @@ -188,6 +188,9 @@
</Path>
<Path name = "/AddIns/WixBinding/PackageFilesView/ContextMenu/DirectoryTreeNode">
<MenuItem id = "AddDirectory"
label = "Add Directory..."
class = "ICSharpCode.WixBinding.AddDirectoryCommand"/>
<Include path = "/AddIns/WixBinding/PackageFilesView/ContextMenu/Common"/>
</Path>
@ -207,7 +210,20 @@ @@ -207,7 +210,20 @@
</Path>
<Path name = "/AddIns/WixBinding/PackageFilesView/ContextMenu/Common">
<Condition name = "Ownerstate" ownerstate = "ChildElementsAllowed" action = "Exclude">
<ComplexCondition action = "Exclude">
<Or>
<Condition name = "Ownerstate" ownerstate = "NothingSelected"/>
<Condition name = "Ownerstate" ownerstate = "NothingSelectedAndChildElementsAllowed"/>
</Or>
<MenuItem id = "AddDirectory"
label = "Add Directory..."
class = "ICSharpCode.WixBinding.AddDirectoryCommand"/>
</ComplexCondition>
<ComplexCondition action = "Exclude">
<Or>
<Condition name = "Ownerstate" ownerstate = "ChildElementsAllowed"/>
<Condition name = "Ownerstate" ownerstate = "NothingSelectedAndChildElementsAllowed"/>
</Or>
<MenuItem id="AddChildElements"
label = "Add"
type = "Menu">
@ -215,11 +231,17 @@ @@ -215,11 +231,17 @@
type = "Builder"
class = "ICSharpCode.WixBinding.AddChildElementsMenuBuilder"/>
</MenuItem>
</Condition>
<MenuItem id = "Remove"
label = "${res:Global.RemoveButtonText}"
icon = "Icons.16x16.DeleteIcon"
class = "ICSharpCode.WixBinding.RemoveElementCommand"/>
</ComplexCondition>
<ComplexCondition action = "Exclude">
<Or>
<Condition name = "Ownerstate" ownerstate = "ChildElementsAllowed"/>
<Condition name = "Ownerstate" ownerstate = "NoChildElementsAllowed"/>
</Or>
<MenuItem id = "Remove"
label = "${res:Global.RemoveButtonText}"
icon = "Icons.16x16.DeleteIcon"
class = "ICSharpCode.WixBinding.RemoveElementCommand"/>
</ComplexCondition>
</Path>
<!--
@ -231,4 +253,13 @@ @@ -231,4 +253,13 @@
<String id="PubCa" text="Microsoft.Tools.WindowsInstallerXml.PcaCompiler, pcaext|COM+ and Message Queue Extension (pubca)"/>
<String id="VS" text="Microsoft.Tools.WindowsInstallerXml.Extensions.VSCompiler, WixVSExtension|Visual Studio Extension"/>
</Path>
<!--
List of filenames and folder names that will excluded
when adding directories to the setup package
-->
<Path name="/AddIns/WixBinding/ExcludedItems">
<String id="svn" text=".svn"/>
<String id="obj" text="obj"/>
</Path>
</AddIn>

3
src/AddIns/BackendBindings/WixBinding/Project/WixBinding.csproj

@ -120,7 +120,7 @@ @@ -120,7 +120,7 @@
<Compile Include="Src\Gui\WixPackageFilesTreeView.cs" />
<Compile Include="Src\Commands\AddElementCommand.cs" />
<Compile Include="Src\Commands\RemoveElementCommand.cs" />
<Compile Include="Src\Gui\AddFilesToComponentCommand.cs" />
<Compile Include="Src\Commands\AddFilesToComponentCommand.cs" />
<Compile Include="Src\WixComponentElement.cs" />
<Compile Include="Src\WixDirectoryRefElement.cs" />
<Compile Include="Src\WixDirectoryElementBase.cs" />
@ -138,6 +138,7 @@ @@ -138,6 +138,7 @@
<EmbeddedResource Include="Resources\LibraryParametersPanel.xfrm" />
<Compile Include="Src\Gui\LibraryParametersPanel.cs" />
<Compile Include="Src\IDirectoryReader.cs" />
<Compile Include="Src\Commands\AddDirectoryCommand.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="WixBinding.addin">

12
src/AddIns/BackendBindings/WixBinding/Test/DirectoryImport/AddDirectoryTestFixture.cs

@ -41,7 +41,7 @@ namespace WixBinding.Tests.DirectoryImport @@ -41,7 +41,7 @@ namespace WixBinding.Tests.DirectoryImport
string[] srcFiles = new string[] {"MyProj.sln", "MyProj.csproj", "Main.cs"};
string[] docFiles = new string[] {"readme.txt", "license.txt"};
[TestFixtureSetUp]
[SetUp]
public void SetUpFixture()
{
base.InitFixture();
@ -81,6 +81,12 @@ namespace WixBinding.Tests.DirectoryImport @@ -81,6 +81,12 @@ namespace WixBinding.Tests.DirectoryImport
Assert.AreEqual(String.Empty, appDirectoryElement.LongName);
}
[Test]
public void AppDirectoryLongNameAttributeDoesNotExist()
{
Assert.IsFalse(appDirectoryElement.HasAttribute("LongName"));
}
[Test]
public void AppDirectoryId()
{
@ -162,9 +168,9 @@ namespace WixBinding.Tests.DirectoryImport @@ -162,9 +168,9 @@ namespace WixBinding.Tests.DirectoryImport
public override string[] GetDirectories(string path)
{
if (path == directory) {
return new string[] {"docs", "src"};
return new string[] {docsDirectory, srcDirectory};
} else if (path == docsDirectory) {
return new string[] {"css"};
return new string[] {cssDirectory};
}
return new string[0];
}

10
src/AddIns/BackendBindings/WixBinding/Test/DirectoryImport/AddSubDirectoryTestFixture.cs

@ -27,7 +27,7 @@ namespace WixBinding.Tests.DirectoryImport @@ -27,7 +27,7 @@ namespace WixBinding.Tests.DirectoryImport
WixDirectoryElement appDirectoryElement;
WixFileElement exeFileElement;
WixFileElement readmeFileElement;
string directory = @"C:\Projects\Setup\MyApp";
string directory = @"C:\Projects\Setup\MyApplication";
string[] files = new string[] {"MyApp.exe", "readme.txt"};
[TestFixtureSetUp]
@ -58,7 +58,13 @@ namespace WixBinding.Tests.DirectoryImport @@ -58,7 +58,13 @@ namespace WixBinding.Tests.DirectoryImport
[Test]
public void AppDirectoryName()
{
Assert.AreEqual("MyApp", appDirectoryElement.ShortName);
Assert.AreEqual("MyApplic", appDirectoryElement.ShortName);
}
[Test]
public void AppDirectoryLongName()
{
Assert.AreEqual("MyApplication", appDirectoryElement.LongName);
}
[Test]

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

@ -42,12 +42,8 @@ namespace WixBinding.Tests.DirectoryImport @@ -42,12 +42,8 @@ namespace WixBinding.Tests.DirectoryImport
WixNamespaceManager nsManager = new WixNamespaceManager(editor.Document.NameTable);
appDirectoryElement = (WixDirectoryElement)editor.Document.RootDirectory.SelectSingleNode("w:Directory[@Name='MyApp']", nsManager);;
XmlNode fileElement = appDirectoryElement.SelectSingleNode("w:Component/w:File[@Name='readme.txt']", nsManager);
readmeComponentElement = (WixComponentElement)fileElement.ParentNode;
fileElement = appDirectoryElement.SelectSingleNode("w:Component/w:File[@Name='license.txt']", nsManager);
licenseComponentElement = (WixComponentElement)fileElement.ParentNode;
readmeComponentElement = (WixComponentElement)appDirectoryElement.SelectSingleNode("w:Component[w:File/@Name='readme.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);
}

104
src/AddIns/BackendBindings/WixBinding/Test/DirectoryImport/DuplicateShortDirectoryNameTestFixture.cs

@ -0,0 +1,104 @@ @@ -0,0 +1,104 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.WixBinding;
using NUnit.Framework;
using System;
using System.Collections;
using System.Collections.Specialized;
using System.IO;
using System.Xml;
using WixBinding.Tests.PackageFiles;
using WixBinding.Tests.Utils;
namespace WixBinding.Tests.DirectoryImport
{
/// <summary>
/// This test fixture checks that unique short directory names are generated.
/// </summary>
[TestFixture]
public class DuplicateShortDirectoryNameTestFixture : PackageFilesTestFixtureBase
{
WixDirectoryElement appDirectoryElement;
WixDirectoryElement directoryElementA;
WixDirectoryElement directoryElementB;
WixDirectoryElement directoryElementC;
WixDirectoryElement directoryElementD;
string directory = @"C:\Projects\Test\MyApp";
string[] directories = new string[] {"DirectoryA", "DirectoryB", "DirectoryC", "Dire.ctoryD"};
[TestFixtureSetUp]
public void SetUpFixture()
{
base.InitFixture();
view.SelectedElement = editor.Document.RootDirectory;
editor.AddDirectory(directory);
WixNamespaceManager nsManager = new WixNamespaceManager(editor.Document.NameTable);
appDirectoryElement = (WixDirectoryElement)editor.Document.RootDirectory.SelectSingleNode("w:Directory[@Name='MyApp']", nsManager);;
directoryElementA = (WixDirectoryElement)appDirectoryElement.SelectSingleNode("w:Directory[@LongName='DirectoryA']", nsManager);
directoryElementB = (WixDirectoryElement)appDirectoryElement.SelectSingleNode("w:Directory[@LongName='DirectoryB']", nsManager);
directoryElementC = (WixDirectoryElement)appDirectoryElement.SelectSingleNode("w:Directory[@LongName='DirectoryC']", nsManager);
directoryElementD = (WixDirectoryElement)appDirectoryElement.SelectSingleNode("w:Directory[@LongName='Dire.ctoryD']", nsManager);
}
[Test]
public void DirectoryElementAShortName()
{
Assert.AreEqual("Director", directoryElementA.ShortName);
}
[Test]
public void DirectoryElementBShortName()
{
Assert.AreEqual("Directo1", directoryElementB.ShortName);
}
[Test]
public void DirectoryElementCShortName()
{
Assert.AreEqual("Directo2", directoryElementC.ShortName);
}
[Test]
public void DirectoryElementDShortName()
{
Assert.AreEqual("Directo3", directoryElementD.ShortName);
}
public override string[] GetFiles(string path)
{
return new string[0];
}
public override string[] GetDirectories(string path)
{
if (path == directory) {
return directories;
}
return new string[0];
}
protected override string GetWixXml()
{
return "<Wix xmlns=\"http://schemas.microsoft.com/wix/2003/01/wi\">\r\n" +
"\t<Product Name=\"MySetup\" \r\n" +
"\t Manufacturer=\"\" \r\n" +
"\t Id=\"F4A71A3A-C271-4BE8-B72C-F47CC956B3AA\" \r\n" +
"\t Language=\"1033\" \r\n" +
"\t Version=\"1.0.0.0\">\r\n" +
"\t\t<Package Id=\"6B8BE64F-3768-49CA-8BC2-86A76424DFE9\"/>\r\n" +
"\t\t<Directory Id=\"TARGETDIR\" SourceName=\"SourceDir\">\r\n" +
"\t\t</Directory>\r\n" +
"\t</Product>\r\n" +
"</Wix>";
}
}
}

103
src/AddIns/BackendBindings/WixBinding/Test/DirectoryImport/ExcludedItemsTestFixture.cs

@ -0,0 +1,103 @@ @@ -0,0 +1,103 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.WixBinding;
using NUnit.Framework;
using System;
using System.Collections;
using System.Collections.Specialized;
using System.IO;
using System.Xml;
using WixBinding.Tests.PackageFiles;
using WixBinding.Tests.Utils;
namespace WixBinding.Tests.DirectoryImport
{
/// <summary>
/// Tests that files and folders are ignored if they are on the package editor's
/// ignore list.
/// </summary>
[TestFixture]
public class ExcludedItemsTestFixture : PackageFilesTestFixtureBase
{
WixDirectoryElement appDirectoryElement;
WixDirectoryElement docsDirectoryElement;
WixDirectoryElement srcDirectoryElement;
WixFileElement readmeFileElement;
string docsDirectory = @"C:\Projects\Test\MyApp\docs";
string objDirectory = @"C:\Projects\Test\MyApp\docs\obj";
string srcDirectory = @"C:\Projects\Test\MyApp\src";
string directory = @"C:\Projects\Test\MyApp";
string myAppExeFile = "MyApp.exe";
string[] srcFiles = new string[] {"MyProj.sln", "MyProj.csproj", "Main.cs"};
string[] docFiles = new string[] {"readme.txt", "license.txt"};
[SetUp]
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.RootDirectory.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);
}
[Test]
public void ReadmeFileNotAdded()
{
Assert.IsNull(readmeFileElement);
}
[Test]
public void ObjDirectoryNotAdded()
{
Assert.AreEqual(0, docsDirectoryElement.GetDirectories().Length);
}
public override string[] GetFiles(string path)
{
if (path == docsDirectory) {
return docFiles;
} else if (path == srcDirectory) {
return srcFiles;
} else if (path == objDirectory) {
return new string[0];
}
return new string[] {myAppExeFile};
}
public override string[] GetDirectories(string path)
{
if (path == directory) {
return new string[] {docsDirectory, srcDirectory};
} else if (path == docsDirectory) {
return new string[] {objDirectory};
}
return new string[0];
}
protected override string GetWixXml()
{
return "<Wix xmlns=\"http://schemas.microsoft.com/wix/2003/01/wi\">\r\n" +
"\t<Product Name=\"MySetup\" \r\n" +
"\t Manufacturer=\"\" \r\n" +
"\t Id=\"F4A71A3A-C271-4BE8-B72C-F47CC956B3AA\" \r\n" +
"\t Language=\"1033\" \r\n" +
"\t Version=\"1.0.0.0\">\r\n" +
"\t\t<Package Id=\"6B8BE64F-3768-49CA-8BC2-86A76424DFE9\"/>\r\n" +
"\t\t<Directory Id=\"TARGETDIR\" SourceName=\"SourceDir\">\r\n" +
"\t\t</Directory>\r\n" +
"\t</Product>\r\n" +
"</Wix>";
}
}
}

13
src/AddIns/BackendBindings/WixBinding/Test/PackageFiles/AddDirectoryTestFixture.cs

@ -61,6 +61,19 @@ namespace WixBinding.Tests.PackageFiles @@ -61,6 +61,19 @@ namespace WixBinding.Tests.PackageFiles
Assert.AreEqual("NewDirectory", directoryElement.GetAttribute("Id"));
}
[Test]
public void DirectoryShortName()
{
Assert.AreEqual(String.Empty, directoryElement.GetAttribute("Name"));
}
[Test]
public void DirectoryLongName()
{
Assert.AreEqual(String.Empty, directoryElement.GetAttribute("LongName"));
}
[Test]
public void SecondDirectoryAdded()
{

2
src/AddIns/BackendBindings/WixBinding/Test/WixBinding.Tests.csproj

@ -197,6 +197,8 @@ @@ -197,6 +197,8 @@
<Compile Include="DirectoryImport\AddSubDirectoryTestFixture.cs" />
<Compile Include="PackageFiles\GenerateComponentIdTests.cs" />
<Compile Include="DirectoryImport\DuplicateComponentIdTestFixture.cs" />
<Compile Include="DirectoryImport\DuplicateShortDirectoryNameTestFixture.cs" />
<Compile Include="DirectoryImport\ExcludedItemsTestFixture.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Project\WixBinding.csproj">

Loading…
Cancel
Save