Exemplo n.º 1
0
        public File(Component parent, string name, string source, bool numberedID)
            : base(parent.Element, "File", "REPLACE_ID")
        {
            if (string.IsNullOrEmpty(name))
            {
                name = source;
            }

            string filePart = Path.GetFileNameWithoutExtension(name);

            string ext = Path.GetExtension(name);

            if(ext.Length > 0) ext = ext.Substring(1);

            thisElement.Attributes["Id"].Value =
                    numberedID
                    ? "file" + fileCount++
                    : IdFromNameAndComponent(source, parent);

            WiXElement.AppendAttribute(
                thisElement,
                "Name",
                Path.GetFileName(name));

            WiXElement.AppendAttribute(
                thisElement, "Source", source);

            WiXElement.AppendAttribute(
                thisElement, "DiskId", "1");


            /* FIX THIS TO ADD REMOVEFILE FOR EACH FILE */
            if (parent.Element.OwnerDocument != null)
            {
                new RemoveFile(parent.Element, name);
            }
        }
Exemplo n.º 2
0
 private Shortcut(Component component, WiXElement target, string name, DirectoryRef directory)
     : this(component, name, directory)
 {
     Target = string.Format("[{0}]", target.Id);
 }
Exemplo n.º 3
0
 public Shortcut(Component component, File target, string name, DirectoryRef directory)
     : this(component, (WiXElement)target, name, directory)
 {
 }
Exemplo n.º 4
0
 public File(Component parent, string name, string source)
     : this(parent, name, source, false)
 {
 }
Exemplo n.º 5
0
 private static string IdFromNameAndComponent(string name, Component component)
 {
     string prefix = Environment.GetEnvironmentVariable(@"SPOCLIENT");
     if ( !String.IsNullOrEmpty(prefix) )
     {
         prefix += @"\";
         if ( name.StartsWith(prefix) )
             name = name.Substring(prefix.Length);
     }
     return "id" + ((UInt32)(component.Guid.GetHashCode())).ToString() + ((UInt32)name.GetHashCode()).ToString();
 }
Exemplo n.º 6
0
 public File(Component parent, string source, bool numberedID)
     : this(parent, null, source, numberedID)
 {
 }
Exemplo n.º 7
0
 public CreateFolder(Component component, Directory directory)
     : this(component, directory.Id)
 {
 }
Exemplo n.º 8
0
 public ComponentRef(ComponentGroup parent, Component component)
     : base(parent.Element, "ComponentRef", component.Id)
 {
     this.component = component;
 }
Exemplo n.º 9
0
 public void AppendComponent(Component component)
 {
     new ComponentRef(this, component);
 }
Exemplo n.º 10
0
 public CreateFolder(Component component, string directoryId)
     :
     base(component.Element.OwnerDocument, "CreateFolder")
 {
     this.AppendAttribute("Directory", directoryId);
     component.Element.AppendChild(thisElement);
 }
        public override bool Execute()
        {
            try
            {
                //
                // Do some setup
                //
                this.Log.LogMessage("Create Assembly Fragment Task");

                string assemblyRoot = Path.GetFileNameWithoutExtension(assemblyName);

                if (fragmentId == null)
                {
                    fragmentId = "Fragment" + assemblyEndian + assemblyName;
                }

                componentId = "Component" + assemblyEndian + assemblyName;

                //
                // Build WiX file
                //
                Fragment fragment = new Fragment(fragmentId);

                if (includeFiles != null)
                {
                    foreach (ITaskItem item in includeFiles)
                    {
                        if (item == null) continue;
                        fragment.PrependInclude(item.ItemSpec);
                    }
                }

                DirectoryRef dirref = new DirectoryRef(
                    fragment,
                    directoryRef);


                Component fileComponent = null;

                // Create Component and add files
                if (componentGuid != Guid.Empty)
                {
                    // Generate new GUID for BE files, else BE files will be stranded upon uninstall
                    if ( assemblyEndian == "_be_" )
                    {
                        componentGuid = Guid.NewGuid();
                    }
 
                    fileComponent = new Component(
                        dirref,
                        componentId,
                        componentGuid);

                    fragment.PrependDefine(
                        string.Format("COMPONENTID=\"{0}\"", fileComponent.Id));

                    foreach (ITaskItem item in componentFiles)
                    {
                        if (item == null) continue;
                        string fileName = item.ItemSpec;

                        string assemblyType = item.GetMetadata("AssemblyType");
                        assemblyType = String.IsNullOrEmpty(assemblyType) ? "" : assemblyType.ToLower();

                        if ( assemblyType != "" )
                        {
                            if ( assemblyType != ".net" && assemblyType != "win32" && assemblyType != "no" )
                            {
                                throw new ApplicationException("Invalid assemblyType \"" + assemblyType + "\" in file metadata ");
                            }
                        }

                        Microsoft.SPOT.WiX.File file = new Microsoft.SPOT.WiX.File(
                            fileComponent,
                            item.GetMetadata("Name"),
                            fileName,
                            false);

                        file.Id = file.Id + assemblyEndian;

                        fragment.PrependDefine(
                                string.Format("ID{0}=\"{1}\"", file.Name.Replace('.', '_'), file.Id));

                        if(!string.IsNullOrEmpty(assemblyShortcut) && fileName.ToLower().EndsWith(".exe"))
                        {
                            Shortcut sc = new Shortcut(file, assemblyShortcut, new DirectoryRef(fragment,"ProgramMenuDir"));
                        }
                    }

                    if (componentIncludeFiles != null)
                    {
                        foreach (ITaskItem item in componentIncludeFiles)
                        {
                            if (item == null) continue;
                            fileComponent.AppendInclude(item.ItemSpec);
                        }
                    }
                }

                if (postIncludeFiles != null)
                {
                    foreach (ITaskItem item in postIncludeFiles)
                    {
                        if (item == null) continue;
                        fragment.AppendInclude(item.ItemSpec);
                    }
                }

                // Save Fragment File
                string fragmentFileDirectory = Path.GetDirectoryName(fragmentFileName);

                if (!System.IO.Directory.Exists(fragmentFileDirectory))
                {
                    System.IO.Directory.CreateDirectory(fragmentFileDirectory);
                }

                fragment.Element.OwnerDocument.Save(fragmentFileName);

                return true;
            }
            catch (Exception e)
            {
                this.Log.LogErrorFromException(e);
                return false;
            }
        }