コード例 #1
0
        /// <summary>
        /// Creates a new or uses the root directory to add the newly-created component with files being installed.
        /// </summary>
        private void ConvertFiles_AddToDirectory(FolderXml folderxml, Component wixComponent, DirectoryRef wixDirectoryRef)
        {
            if (folderxml.TargetRoot != TargetRootXml.InstallDir)
            {
                throw new InvalidOperationException(string.Format("Only the InstallDir target root is supported."));
            }

            // No relative path — nothing to create
            if (folderxml.TargetDir.Length == 0)
            {
                wixDirectoryRef.AddChild(wixComponent);
                return;
            }

            // Create the folder structure, add to the innermost
            string[]  arDirectoryChain = folderxml.TargetDir.Split('\\');
            Directory wixParentDir     = null;

            for (int a = 0; a < arDirectoryChain.Length; a++)
            {
                bool bInnermost = a == arDirectoryChain.Length - 1;                 // Whether this is the folder in which are the files itself

                // Create
                var wixDirectory = new Directory {
                    Name = arDirectoryChain[a]
                };

                // Mount self into the hierarchy
                if (wixParentDir != null)
                {
                    wixParentDir.AddChild(wixDirectory);                     // Previous dir
                }
                else
                {
                    wixDirectoryRef.AddChild(wixDirectory);                     // The very root
                }
                wixParentDir = wixDirectory;

                // Non-innermost folders get a suffix to their ID
                if (bInnermost)
                {
                    wixDirectory.Id = string.Format("{0}.{1}", DirectoryIdPrefix, folderxml.Id);
                }
                else
                {
                    wixDirectory.Id = string.Format("{0}.{1}.P{2}", DirectoryIdPrefix, folderxml.Id, arDirectoryChain.Length - 1 - a);
                }

                // Mount the component into the innermost dir
                if (bInnermost)
                {
                    wixDirectory.AddChild(wixComponent);
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Extract all of the data fields from a folder XML structure, validating it.
        /// </summary>
        /// <param name="folderXml"></param>
        /// <param name="id"></param>
        /// <param name="version"></param>
        /// <param name="deleted"></param>
        /// <param name="name"></param>
        /// <param name="parentFolderId"></param>
        /// <param name="typeName"></param>
        /// <param name="selectCriteriaXml"></param>
        /// <param name="invalidMessage"></param>
        /// <returns>True if the structure is valid, false otherwise.</returns>
        public static bool FromFolderXml(FolderXml folderXml, out Guid id, out long version, out bool deleted,
                                         out string name, out Guid?parentFolderId, out string typeName, out string selectCriteriaXml, out string invalidMessage)
        {
            bool valid = true;

            id                = new Guid(folderXml.id);
            version           = folderXml.version;
            deleted           = folderXml.deleted;
            invalidMessage    = string.Empty;
            name              = null;
            typeName          = null;
            parentFolderId    = null;
            selectCriteriaXml = string.Empty;


            if (folderXml.folderDetail == null)
            {
                valid          = false;
                invalidMessage = "No folder details were provided\r\n";
            }
            else
            {
                FolderDetailXml detail = folderXml.folderDetail;

                name = detail.name;
                if (string.IsNullOrEmpty(name))
                {
                    valid           = false;
                    invalidMessage += "No folder name was provided \r\n";
                }

                if (string.IsNullOrEmpty(detail.parentFolderId) == false)
                {
                    //if there's anything then it HAS to be a valid GUID.
                    try
                    {
                        parentFolderId = new Guid(detail.parentFolderId);
                    }
                    catch (Exception ex)
                    {
                        GC.KeepAlive(ex);
                        valid           = false;
                        invalidMessage += "The parent folder id wasn't valid\r\n";
                    }
                }

                FolderTypeXml folderType = detail.folderType;
                if (folderType == FolderTypeXml.search)
                {
                    selectCriteriaXml = detail.selectionCriteriaXml;
                    if (string.IsNullOrEmpty(selectCriteriaXml))
                    {
                        valid           = false;
                        invalidMessage += "No criteria were specified for the search folder\r\n";
                    }
                }
                typeName = detail.folderType.ToString();
            }

            return(valid);
        }