Exemple #1
0
        /// <summary>
        /// Handles command status on source a node. Should be overridden by descendant nodes.
        /// </summary>
        /// <param name="node">A HierarchyNode that implements the IProjectSourceNode interface.</param>
        /// <param name="guidCmdGroup">A unique identifier of the command group. The pguidCmdGroup parameter can be NULL to specify the standard group.</param>
        /// <param name="cmd">The command to query status for.</param>
        /// <param name="result">An out parameter specifying the QueryStatusResult of the command.</param>
        /// <param name="returnCode">If the method succeeds, it returns S_OK. If it fails, it returns an error code.</param>
        /// <returns>Returns true if the status request is handled, false otherwise.</returns>
        internal static bool QueryStatusOnProjectSourceNode(HierarchyNode node, Guid guidCmdGroup, uint cmd, ref QueryStatusResult result, out int returnCode)
        {
            if (guidCmdGroup == VsMenus.guidStandardCommandSet2K)
            {
                IProjectSourceNode sourceNode = node as IProjectSourceNode;
                switch ((VsCommands2K)cmd)
                {
                case VsCommands2K.SHOWALLFILES:
                {
                    WixProjectNode projectNode = node.ProjectMgr as WixProjectNode;
                    result |= QueryStatusResult.SUPPORTED | QueryStatusResult.ENABLED;
                    if (projectNode != null && projectNode.ShowAllFilesEnabled)
                    {
                        result |= QueryStatusResult.LATCHED;         // it should be displayed as pressed
                    }

                    returnCode = VSConstants.S_OK;
                    return(true);        // handled.
                }

                case VsCommands2K.INCLUDEINPROJECT:
                    // if it is a non member item node, the we support "Include In Project" command
                    if (sourceNode != null && sourceNode.IsNonMemberItem)
                    {
                        result    |= QueryStatusResult.SUPPORTED | QueryStatusResult.ENABLED;
                        returnCode = VSConstants.S_OK;
                        return(true);    // handled.
                    }

                    break;

                case VsCommands2K.EXCLUDEFROMPROJECT:
                    // if it is a non member item node, then we don't support "Exclude From Project" command
                    if (sourceNode != null && sourceNode.IsNonMemberItem)
                    {
                        returnCode = (int)OleConstants.MSOCMDERR_E_NOTSUPPORTED;
                        return(true);    // handled.
                    }

                    break;
                }
            }

            if (VsMenus.guidStandardCommandSet97 == guidCmdGroup)
            {
                switch ((VsCommands)cmd)
                {
                case VsCommands.AddNewItem:
                case VsCommands.AddExistingItem:
                    result     = QueryStatusResult.SUPPORTED | QueryStatusResult.ENABLED;
                    returnCode = VSConstants.S_OK;
                    return(true);

                case VsCommands.SetStartupProject:
                    result     = QueryStatusResult.SUPPORTED | QueryStatusResult.INVISIBLE;
                    returnCode = VSConstants.S_OK;
                    return(true);
                }
            }

            // just an arbitrary value, it doesn't matter if method hasn't handled the request
            returnCode = VSConstants.S_FALSE;

            // not handled
            return(false);
        }
Exemple #2
0
        /// <summary>
        /// Excludes the file and folder items from their corresponding maps if they are part of the build.
        /// </summary>
        /// <param name="project">The project to modify.</param>
        /// <param name="fileList">List containing relative files paths.</param>
        /// <param name="folderList">List containing relative folder paths.</param>
        private static void ExcludeProjectBuildItems(WixProjectNode project, IList <string> fileList, IList <string> folderList)
        {
            if (project.BuildProject.Items == null)
            {
                return; // do nothig, just ignore it.
            }
            else if (fileList == null && folderList == null)
            {
                throw new ArgumentNullException("folderList");
            }

            // we need these maps becuase we need to have both lowercase and actual case path information.
            // we use lower case paths for case-insesitive search of file entries and actual paths for
            // creating hierarchy node. if we don't do that, we will end up with duplicate nodes when the
            // case of path in .wixproj file doesn't match with the actual file path on the disk.
            IDictionary <string, string> folderMap = null;
            IDictionary <string, string> fileMap   = null;

            if (folderList != null)
            {
                folderMap = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);
                foreach (string folder in folderList)
                {
                    folderMap.Add(folder, folder);
                }
            }

            if (fileList != null)
            {
                fileMap = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);
                foreach (string file in fileList)
                {
                    fileMap.Add(file, file);
                }
            }

            foreach (ProjectItem buildItem in project.BuildProject.Items)
            {
                if (folderMap != null &&
                    folderMap.Count > 0 &&
                    String.Equals(buildItem.ItemType, ProjectFileConstants.Folder, StringComparison.OrdinalIgnoreCase))
                {
                    string relativePath = buildItem.EvaluatedInclude;
                    if (Path.IsPathRooted(relativePath)) // if not the relative path, make it relative
                    {
                        relativePath = WixHelperMethods.GetRelativePath(project.ProjectFolder, relativePath);
                    }

                    if (folderMap.ContainsKey(relativePath))
                    {
                        folderList.Remove(folderMap[relativePath]); // remove it from the actual list.
                        folderMap.Remove(relativePath);
                    }
                }
                else if (fileMap != null &&
                         fileMap.Count > 0 &&
                         WixProjectMembers.IsWixFileItem(buildItem))
                {
                    string relativePath = buildItem.EvaluatedInclude;
                    if (Path.IsPathRooted(relativePath)) // if not the relative path, make it relative
                    {
                        relativePath = WixHelperMethods.GetRelativePath(project.ProjectFolder, relativePath);
                    }

                    if (fileMap.ContainsKey(relativePath))
                    {
                        fileList.Remove(fileMap[relativePath]); // remove it from the actual list.
                        fileMap.Remove(relativePath);
                    }
                }
            }
        }
Exemple #3
0
        // =========================================================================================
        // Constructors
        // =========================================================================================

        /// <summary>
        /// Initializes a new instance of the <see cref="WixProjectNodeProperties"/> class.
        /// </summary>
        /// <param name="node">The <see cref="WixProjectNode"/> from which the properties are read.</param>
        public WixProjectNodeProperties(WixProjectNode node)
            : base(node)
        {
        }
Exemple #4
0
        int IProjectSourceNode.ExcludeFromProject()
        {
            WixProjectNode projectNode = this.ProjectMgr as WixProjectNode;

            if (projectNode == null || projectNode.IsClosed)
            {
                return((int)OleConstants.OLECMDERR_E_NOTSUPPORTED);
            }
            else if (this.IsNonMemberItem)
            {
                return(VSConstants.S_OK); // do nothing, just ignore it.
            }

            using (WixHelperMethods.NewWaitCursor())
            {
                // Check out the project file.
                if (!projectNode.QueryEditProjectFile(false))
                {
                    throw Marshal.GetExceptionForHR(VSConstants.OLE_E_PROMPTSAVECANCELLED);
                }

                // remove children, if any, before removing from the hierarchy
                for (HierarchyNode child = this.FirstChild; child != null; child = child.NextSibling)
                {
                    IProjectSourceNode node = child as IProjectSourceNode;
                    if (node != null)
                    {
                        int result = node.ExcludeFromProject();
                        if (result != VSConstants.S_OK)
                        {
                            return(result);
                        }
                    }
                }

                if (projectNode != null && projectNode.ShowAllFilesEnabled && Directory.Exists(this.Url))
                {
                    string url = this.Url;
                    this.SetProperty((int)__VSHPROPID.VSHPROPID_IsNonMemberItem, true);
                    this.ItemNode.RemoveFromProjectFile();
                    this.ItemNode = new ProjectElement(this.ProjectMgr, null, true);  // now we have to create a new ItemNode to indicate that this is virtual node.
                    this.ItemNode.Rename(url);
                    this.ItemNode.SetMetadata(ProjectFileConstants.Name, this.Url);
                    this.ReDraw(UIHierarchyElement.Icon); // we have to redraw the icon of the node as it is now not a member of the project and shoul be drawn using a different icon.
                }
                else if (this.Parent != null)             // the project node has no parentNode
                {
                    // this is important to make it non member item. otherwise, the multi-selection scenario would
                    // not work if it has any parent child relation.
                    this.SetProperty((int)__VSHPROPID.VSHPROPID_IsNonMemberItem, true);

                    // remove from the hierarchy
                    this.OnItemDeleted();
                    this.Parent.RemoveChild(this);
                    this.ItemNode.RemoveFromProjectFile();
                }

                // refresh property browser...
                WixHelperMethods.RefreshPropertyBrowser();
            }

            return(VSConstants.S_OK);
        }
Exemple #5
0
        // =========================================================================================
        // Constructors
        // =========================================================================================

        /// <summary>
        /// Initializes a new instance of the <see cref="WixFolderNode"/> class.
        /// </summary>
        /// <param name="root">The root <see cref="WixProjectNode"/> that contains this node.</param>
        /// <param name="directoryPath">Root of the hierarchy.</param>
        /// <param name="element">The element that contains MSBuild properties.</param>
        public WixFolderNode(WixProjectNode root, string directoryPath, ProjectElement element)
            : this(root, directoryPath, element, false)
        {
        }
Exemple #6
0
 public WixFileNode(WixProjectNode root, ProjectElement element, bool isNonMemberItem)
     : base(root, element)
 {
     this.isNonMemberItem = isNonMemberItem;
 }
Exemple #7
0
 /// <summary>
 /// Creates a new project config instance.
 /// </summary>
 /// <param name="project">Parent project node.</param>
 /// <param name="configName">Configuration name such as "Debug".</param>
 /// <param name="platformName">Platform name such as "x86".</param>
 public WixProjectConfig(WixProjectNode project, string configName, string platformName)
     : base(project, new ConfigCanonicalName(configName, platformName))
 {
 }
Exemple #8
0
        int IProjectSourceNode.ExcludeFromProject()
        {
            if (this.ProjectMgr == null || this.ProjectMgr.IsClosed)
            {
                return((int)OleConstants.OLECMDERR_E_NOTSUPPORTED);
            }
            else if (this.IsNonMemberItem)
            {
                return(VSConstants.S_OK); // do nothing, just ignore it.
            }

            using (WixHelperMethods.NewWaitCursor())
            {
                // Ask Document tracker listeners if we can remove the item.
                { // just to limit the scope.
                    string   documentToRemove = this.GetMkDocument();
                    string[] filesToBeDeleted = new string[1] {
                        documentToRemove
                    };
                    VSQUERYREMOVEFILEFLAGS[] queryRemoveFlags = this.GetQueryRemoveFileFlags(filesToBeDeleted);
                    if (!this.ProjectMgr.Tracker.CanRemoveItems(filesToBeDeleted, queryRemoveFlags))
                    {
                        return((int)OleConstants.OLECMDERR_E_CANCELED);
                    }

                    // Close the document if it has a manager.
                    DocumentManager manager = this.GetDocumentManager();
                    if (manager != null)
                    {
                        if (manager.Close(__FRAMECLOSE.FRAMECLOSE_PromptSave) == VSConstants.E_ABORT)
                        {
                            // User cancelled operation in message box.
                            return(VSConstants.OLE_E_PROMPTSAVECANCELLED);
                        }
                    }

                    // Check out the project file.
                    if (!this.ProjectMgr.QueryEditProjectFile(false))
                    {
                        throw Marshal.GetExceptionForHR(VSConstants.OLE_E_PROMPTSAVECANCELLED);
                    }
                }

                // close the document window if open.
                this.CloseDocumentWindow(this);

                WixProjectNode projectNode = this.ProjectMgr as WixProjectNode;

                if (projectNode != null && projectNode.ShowAllFilesEnabled && File.Exists(this.Url))
                {
                    // need to store before removing the node.
                    string url     = this.Url;
                    string include = this.ItemNode.GetMetadata(ProjectFileConstants.Include);

                    this.ItemNode.RemoveFromProjectFile();
                    this.ProjectMgr.Tracker.OnItemRemoved(url, VSREMOVEFILEFLAGS.VSREMOVEFILEFLAGS_NoFlags);
                    this.SetProperty((int)__VSHPROPID.VSHPROPID_IsNonMemberItem, true); // Set it as non member item
                    this.ItemNode = new ProjectElement(this.ProjectMgr, null, true);    // now we have to set a new ItemNode to indicate that this is virtual node.
                    this.ItemNode.Rename(include);
                    this.ItemNode.SetMetadata(ProjectFileConstants.Name, url);

                    ////this.ProjectMgr.OnItemAdded(this.Parent, this);
                    this.ReDraw(UIHierarchyElement.Icon);     // We have to redraw the icon of the node as it is now not a member of the project and should be drawn using a different icon.
                    this.ReDraw(UIHierarchyElement.SccState); // update the SCC state icon.
                }
                else if (this.Parent != null)                 // the project node has no parentNode
                {
                    // Remove from the Hierarchy
                    this.OnItemDeleted();
                    this.Parent.RemoveChild(this);
                    this.ItemNode.RemoveFromProjectFile();
                }

                this.ResetProperties();

                // refresh property browser...
                WixHelperMethods.RefreshPropertyBrowser();
            }

            return(VSConstants.S_OK);
        }
Exemple #9
0
        // =========================================================================================
        // Constructors
        // =========================================================================================

        /// <summary>
        /// Initializes a new instance of the <see cref="WixFileNode"/> class.
        /// </summary>
        /// <param name="root">The root <see cref="WixProjectNode"/> that contains this node.</param>
        /// <param name="element">The element that contains MSBuild properties.</param>
        public WixFileNode(WixProjectNode root, ProjectElement element)
            : this(root, element, false)
        {
        }
        // =========================================================================================
        // Constructors
        // =========================================================================================

        /// <summary>
        /// Initializes a new instance of the <see cref="WixExtensionReferenceNode"/> class.
        /// </summary>
        /// <param name="root">The root <see cref="WixProjectNode"/> that contains this node.</param>
        /// <param name="element">The element that contains MSBuild properties.</param>
        public WixExtensionReferenceNode(WixProjectNode root, ProjectElement element)
            : base(root, element)
        {
            this.InitializeFileChangeEvents();
        }
Exemple #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="WixLibraryReferenceNode"/> class.
 /// </summary>
 /// <param name="root">The root <see cref="WixProjectNode"/> that contains this node.</param>
 /// <param name="referencePath">The path to the wixlib reference file.</param>
 public WixLibraryReferenceNode(WixProjectNode root, string referencePath)
     : base(root, referencePath, WixProjectFileConstants.WixLibrary)
 {
 }
Exemple #12
0
        // =========================================================================================
        // Constructors
        // =========================================================================================

        /// <summary>
        /// Initializes a new instance of the <see cref="WixLibraryReferenceNode"/> class.
        /// </summary>
        /// <param name="root">The root <see cref="WixProjectNode"/> that contains this node.</param>
        /// <param name="element">The element that contains MSBuild properties.</param>
        public WixLibraryReferenceNode(WixProjectNode root, ProjectElement element)
            : base(root, element)
        {
        }
        // =========================================================================================
        // Constructors
        // =========================================================================================

        /// <summary>
        /// Initializes a new instance of the <see cref="WixReferenceContainerNode"/> class.
        /// </summary>
        /// <param name="root">The root <see cref="WixProjectNode"/> that contains this node.</param>
        public WixReferenceContainerNode(WixProjectNode root)
            : base(root)
        {
        }
Exemple #14
0
 /// <summary>
 /// Creates a new config provider for WiX projects.
 /// </summary>
 /// <param name="project">Parent project node</param>
 public WixConfigProvider(WixProjectNode project)
     : base(project)
 {
     this.wixProjectNode = project;
 }