示例#1
0
        private void SetupDirectoryPermissions(string dirPath, XmlElement parent, string parentDirectoryId, XmlDocument doc, IdToGuidDatabase guidDatabase)
        {
            if (_giveAllPermissions)
            {
                /*	Need to add one of these in order to set the permissions on the directory
                 * <Component Id="biatahCacheDir" Guid="492F2725-9DF9-46B1-9ACE-E84E70AFEE99">
                 *                      <CreateFolder Directory="biatahCacheDir">
                 *                              <Permission GenericAll="yes" User="******" />
                 *                      </CreateFolder>
                 *              </Component>
                 */

                string id = GetSafeDirectoryId(string.Empty, parentDirectoryId);

                XmlElement componentElement = doc.CreateElement("Component", XMLNS);
                componentElement.SetAttribute("Id", id);
                componentElement.SetAttribute("Guid", guidDatabase.GetGuid(id, this.CheckOnly));

                XmlElement createFolderElement = doc.CreateElement("CreateFolder", XMLNS);
                createFolderElement.SetAttribute("Directory", id);
                AddPermissionElement(doc, createFolderElement);

                componentElement.AppendChild(createFolderElement);
                parent.AppendChild(componentElement);

                m_components.Add(id);
            }
        }
示例#2
0
        private void ProcessFile(XmlElement parent, string path, XmlDocument doc, IdToGuidDatabase guidDatabase, bool isFirst, string directoryId)
        {
            string guid;
            string name = Path.GetFileName(path);
            string id   = directoryId + "." + name; //includ the parent directory id so that files with the same name (e.g. "index.html") found twice in the system will get different ids.

            const int kMaxLength = 50;              //I have so far not found out what the max really is

            if (id.Length > kMaxLength)
            {
                id = id.Substring(id.Length - kMaxLength, kMaxLength); //get the last chunk of it
            }
            if (!Char.IsLetter(id[0]) && id[0] != '_')                 //probably not needed now that we're prepending the parent directory id, accept maybe at the root?
            {
                id = '_' + id;
            }
            id = Regex.Replace(id, @"[^\p{Lu}\p{Ll}\p{Nd}._]", "_");

            LogMessage(MessageImportance.Normal, "Adding file {0} with id {1}", path, id);
            string key = id.ToLower();

            if (m_suffixes.ContainsKey(key))
            {
                int suffix = m_suffixes[key] + 1;
                m_suffixes[key] = suffix;
                id += suffix.ToString();
            }
            else
            {
                m_suffixes[key] = 0;
            }

            // Create <Component> and <File> for this file
            XmlElement elemComp = doc.CreateElement("Component", XMLNS);

            elemComp.SetAttribute("Id", id);
            guid = guidDatabase.GetGuid(id, this.CheckOnly);
            if (guid == null)
            {
                m_filesChanged = true;                        // this file is new
            }
            else
            {
                elemComp.SetAttribute("Guid", guid.ToUpper());
            }
            parent.AppendChild(elemComp);

            XmlElement elemFile = doc.CreateElement("File", XMLNS);

            elemFile.SetAttribute("Id", id);
            elemFile.SetAttribute("Name", name);
            if (isFirst)
            {
                elemFile.SetAttribute("KeyPath", "yes");
            }
            string relativePath;

            if (String.IsNullOrEmpty(_installerSourceDirectory))
            {
                relativePath = PathUtil.RelativePathTo(Path.GetDirectoryName(_outputFilePath), path);
            }
            else
            {
                relativePath = PathUtil.RelativePathTo(_installerSourceDirectory, path);
            }
            elemFile.SetAttribute("Source", relativePath);

            if (GiveAllPermissions)
            {
                AddPermissionElement(doc, elemFile);
            }


            elemComp.AppendChild(elemFile);
            InsertFileDeletionInstruction(elemComp);
            m_components.Add(id);

            // check whether the file is newer
            if (File.GetLastWriteTime(path) > m_refDate)
            {
                m_filesChanged = true;
            }
        }