public void Clear()
 {
     _recurse        = false;
     _addToPath      = false;
     _ideHeaderFiles = false;
     _ideExecutables = false;
     _ideLibrary     = false;
     _pathComponent  = new SetupComponent();
     _dirId          = MainFrame.CurrentProject.GetUniqueId();
     _patterns       = ".*";
 }
Exemple #2
0
 public void RemoveComponent(SetupComponent component)
 {
     for (int i = 0; i < _components.Count; i++)
     {
         if (_components[i].Equals(component))
         {
             _components.RemoveAt(i);
             break;
         }
     }
 }
Exemple #3
0
        public SetupFile AddFile(string path)
        {
            SetupFile file = new SetupFile();

            file.srcName      = Path.GetFileName(path);
            file.srcDirectory = Path.GetDirectoryName(path);
            file.dstName      = file.srcName;

            // Create a component
            SetupComponent component = new SetupComponent();

            component.componentFiles.Add(file);

            components.Add(component);

            // Return the file
            return(file);
        }
        /* Add one or more components to the components list, based on the contents */
        /* Return true if files were added at any sublevel */
        public bool MakeComponents(List <SetupComponent> components,
                                   string srcDirectory,
                                   string targetDirectory)
        {
            bool rval = false;
            // For now, we use one component per directory
            SetupComponent component = new SetupComponent();

            component.targetDirectory = targetDirectory;
            components.Add(component);

            Regex exclude = null;

            if ("" != excludePatterns)
            {
                exclude = new Regex(excludePatterns);
            }

            //component.componentId = component.componentGuid = "Component_"
            // + GetMd5Hash(srcDirectory + "::" + targetDirectory);

            // Build pattern
            if ((null != patterns) && ("" != patterns))
            {
                string my_pattern = patterns.Replace("\r\n", "");
                Regex  regex      = new Regex(my_pattern);

                // Add files
                foreach (string path in Directory.GetFiles(srcDirectory))
                {
                    FileAttributes attr = File.GetAttributes(path);
                    if ((attr & (FileAttributes.Device
                                 | FileAttributes.Hidden
                                 | FileAttributes.System
                                 | FileAttributes.Temporary)) != 0)
                    {
                        // Don't use
                    }
                    else
                    {
                        if ((null != exclude) && exclude.Match(path).Success)
                        {
                            continue;
                        }

                        if (regex.Match(Path.GetFileName(path)).Success)
                        {
                            SetupFile file = new SetupFile();
                            file.srcDirectory = Path.GetDirectoryName(path);
                            file.srcName      = Path.GetFileName(path);
                            file.dstName      = file.srcName;
                            //file.fileId = "ID_" + GetMd5Hash(path + "::"
                            //    + Path.Combine(file.dstDirectory, file.dstName));

                            component.componentFiles.Add(file);
                            rval = true;
                        }
                    }
                }
            }

            // Recurse
            if (recurse)
            {
                foreach (string path in Directory.GetDirectories(srcDirectory))
                {
                    FileAttributes attr = File.GetAttributes(path);
                    if ((attr & (FileAttributes.Device
                                 | FileAttributes.Hidden
                                 | FileAttributes.System
                                 | FileAttributes.Temporary)) != 0)
                    {
                        // Dont use
                    }
                    else if ((attr & FileAttributes.Directory) == FileAttributes.Directory)
                    {
                        if ((null != exclude) && (exclude.Match(path + @"\").Success))
                        {
                            continue; // Excluded
                        }
                        bool probe = MakeComponents(components,
                                                    Path.Combine(srcDirectory, Path.GetFileName(path)),
                                                    Path.Combine(targetDirectory, Path.GetFileName(path)));

                        if (!rval && probe)
                        {
                            rval = true; // We found files
                        }
                    }
                }
            }

            component.addToCreateFolder = true;

            if (preventEmptyDirectories && !rval)
            {
                components.Remove(component); // Prevent empty dirs/structures
            }
            return(rval);
        }
        private XmlElement GenerateComponent(SetupComponent component, SetupFeature feature, XmlElement feature_node)
        {
            // Make the reference from Feature
            XmlElement component_ref = doc.CreateElement("ComponentRef");
            component_ref.SetAttribute("Id", component.componentId);
            feature_node.AppendChild(component_ref);

            // Make the actual component and file
            XmlElement component_node = doc.CreateElement("Component");
            component_node.SetAttribute("Id", component.componentId);
            component_node.SetAttribute("Guid", component.componentGuid);

            if (component.addToCreateFolder)
            {
                XmlElement node = doc.CreateElement("CreateFolder");
                component_node.AppendChild(node);
            }

            // Link the component to the appropriate directory
            string target_dir_name = component.targetDirectory; // Not accessible from the UI. We use the file.dstPath in stead.

            // Now, lets see if the file overrides the default target. We only have one file
            // for each component (unless the older i sscanned, in wich case the dstPath in the
            // file is guaranteed to be empty
            if ((component.componentFiles.Count == 1)
                && ("" != component.componentFiles[0].dstPath))
            {
                target_dir_name = component.componentFiles[0].dstPath;
            }

            if ((null == target_dir_name) || ("" == target_dir_name))
            {
                target_dir_name = GetDefaultDir(feature);
                if ((null == target_dir_name) || ("" == target_dir_name))
                    target_dir_name = "[APPLICATIONFOLDER]";
                else
                    target_dir_name = "[" + target_dir_name + "]";

            }

            TargetDir target_dir = GetDirectoryNode(target_dir_name, null);
            target_dir.mXmlNode.AppendChild(component_node);

            // Path
            if ((null != component.pathEntry) && ("" != component.pathEntry))
            {
                XmlElement path_node = doc.CreateElement("Environment");
                path_node.SetAttribute("Id", GetUniqueId());
                path_node.SetAttribute("Name", "PATH");
                path_node.SetAttribute("Action", "set");
                path_node.SetAttribute("System", "yes");
                path_node.SetAttribute("Part", "last");
                path_node.SetAttribute("Value", component.pathEntry);
                component_node.AppendChild(path_node);
            }

            foreach (SetupFile file in component.componentFiles)
            {

                XmlElement file_node = doc.CreateElement("File");
                file_node.SetAttribute("Id", file.fileId);
                string src_path = Path.Combine(file.srcDirectory, file.srcName);
                file_node.SetAttribute("Source", src_path);
                if (!isMergeModle)
                    file_node.SetAttribute("DiskId", GetMedia(src_path).ToString());

                SetNameAttribute(file_node, file.dstName);

                if (file.ExecuteOnInstall)
                {
                    AddExecuteOnInstall(file);
                }

                /* TODO: Create a dedicated component for user-shortcuts (for each file)
                 * to avoid the "ICE57: Component 'IDC5A7B8F2554B02E5FC9D5ED7E684B285'
                 * has both per-user and per-machine data with a per-machine KeyPath."
                 * warning.
                 */

                //if (file.shortcutInProgramFilesMenu)
                //    file_node.AppendChild(AddShortcut(file, my_program_menu, "pf"));

                //if (file.shortcutInQuickLaunch)
                //    file_node.AppendChild(AddShortcut(file, quicklaunch, "ql"));

                //if (file.shortcutOnDesktop)
                //    file_node.AppendChild(AddShortcut(file, desktop, "dt"));

                if (file.shortcutInProgramFilesMenu)
                    AddShortcut(file, feature_node, my_program_menu, target_dir.mXmlNode);

                if (file.shortcutInQuickLaunch)
                    AddShortcut(file, feature_node, quicklaunch, target_dir.mXmlNode);

                if (file.shortcutOnDesktop)
                    AddShortcut(file, feature_node, desktop, target_dir.mXmlNode);

                if (file.shortcutInStartupFolder)
                    AddShortcut(file, feature_node, my_start_menu, target_dir.mXmlNode);

                if (file.isTrueTypeFont)
                {
                    file_node.SetAttribute("TrueType", "yes");
                    //if ((file.dstPath == null) || (file.dstPath == ""))
                }

                if (file.isComModule)
                {
                    XmlElement typelib = doc.CreateElement("TypeLib");
                    typelib.SetAttribute("Id", file.typelibGuid);
                    typelib.SetAttribute("Language", "0");
                    typelib.SetAttribute("Advertise", "yes"); // Just to avoid manual version mess
                    file_node.AppendChild(typelib);
                    if ((file.typelibGuid == null) || (file.typelibGuid == ""))
                    {
                        throw new ApplicationException(
                            "The COM/Typelib file \"" + file.srcName + "\" is missing a GUID. This must be specifield.");
                    }
                }

                if (file.service.isService)
                {
                    XmlElement svc = doc.CreateElement("ServiceInstall");
                    component_node.AppendChild(svc);

                    svc.SetAttribute("Id", file.service.id);
                    if ("" != file.service.userAccount)
                        svc.SetAttribute("Account", file.service.userAccount);
                    if ("" != file.service.userPassword)
                        svc.SetAttribute("Password", file.service.userPassword);
                    if ("" != file.service.cmdLineArguments)
                        svc.SetAttribute("Arguments", file.service.cmdLineArguments);
                    if ("" != file.service.description)
                        svc.SetAttribute("Description", file.service.description);
                    svc.SetAttribute("ErrorControl", file.service.errorControl.ToString());
                    svc.SetAttribute("Interactive", file.service.interactive ? "yes" : "no");
                    if ("" != file.service.loadOrderGroup)
                        svc.SetAttribute("LoadOrderGroup", file.service.loadOrderGroup);
                    svc.SetAttribute("Name", file.service.serviceName);
                    svc.SetAttribute("Start", file.service.startMode.ToString());
                    svc.SetAttribute("Type", "ownProcess");
                    svc.SetAttribute("Vital", file.service.vital ? "yes" : "no");

                    XmlElement svc_ctl = doc.CreateElement("ServiceControl");
                    component_node.AppendChild(svc_ctl);

                    svc_ctl.SetAttribute("Id", file.service.id);
                    svc_ctl.SetAttribute("Name", file.service.serviceName);
                    svc_ctl.SetAttribute("Remove", file.service.Remove.ToString());
                    if (file.service.StartWhenInstalled)
                        svc_ctl.SetAttribute("Start", "install");
                }

                foreach (FileExtension ext in file.fileExtensions)
                {
                    XmlElement prog_id_node = doc.CreateElement("ProgId");
                    prog_id_node.SetAttribute("Id", ext.Id);
                    prog_id_node.SetAttribute("Description", ext.Description);
                    prog_id_node.SetAttribute("Icon", file.fileId);
                    prog_id_node.SetAttribute("IconIndex", ext.IconIndex.ToString());
                    component_node.AppendChild(prog_id_node);

                    XmlElement ext_node = doc.CreateElement("Extension");
                    ext_node.SetAttribute("Id", ext.Extension);
                    ext_node.SetAttribute("ContentType", ext.MimeType);
                    prog_id_node.AppendChild(ext_node);

                    XmlElement verb_node = doc.CreateElement("Verb");
                    verb_node.SetAttribute("Id", "Open");
                    verb_node.SetAttribute("Command", "Open");
                    verb_node.SetAttribute("TargetFile", file.fileId);
                    verb_node.SetAttribute("Argument", "\"%1\""); // BUG 1944386 FIXED

                    ext_node.AppendChild(verb_node);
                }

                component_node.AppendChild(file_node);
            }

            return component_node;
        }
 public void RemoveComponent(SetupComponent component)
 {
     for (int i = 0; i < _components.Count; i++)
     {
         if (_components[i].Equals(component))
         {
             _components.RemoveAt(i);
             break;
         }
     }
 }
        public SetupFile AddFile(string path)
        {
            SetupFile file = new SetupFile();

            file.srcName = Path.GetFileName(path);
            file.srcDirectory = Path.GetDirectoryName(path);
            file.dstName = file.srcName;

            // Create a component
            SetupComponent component = new SetupComponent();
            component.componentFiles.Add(file);

            components.Add(component);

            // Return the file
            return file;
        }
        /* Add one or more components to the components list, based on the contents */
        /* Return true if files were added at any sublevel */
        public bool MakeComponents(List<SetupComponent> components, 
            string srcDirectory,
            string targetDirectory)
        {
            bool rval = false;
            // For now, we use one component per directory
            SetupComponent component = new SetupComponent();
            component.targetDirectory = targetDirectory;
            components.Add(component);

            Regex exclude = null;
            if ("" != excludePatterns)
                exclude = new Regex(excludePatterns);

            //component.componentId = component.componentGuid = "Component_"
            // + GetMd5Hash(srcDirectory + "::" + targetDirectory);

            // Build pattern
            if ((null != patterns) && ("" != patterns))
            {
                string my_pattern = patterns.Replace("\r\n", "");
                Regex regex = new Regex(my_pattern);

                // Add files
                foreach (string path in Directory.GetFiles(srcDirectory))
                {
                    FileAttributes attr = File.GetAttributes(path);
                    if ((attr & (FileAttributes.Device
                        | FileAttributes.Hidden
                        | FileAttributes.System
                        | FileAttributes.Temporary)) != 0)
                    {
                        // Don't use
                    }
                    else
                    {
                        if ((null != exclude) && exclude.Match(path).Success)
                            continue;

                        if (regex.Match(Path.GetFileName(path)).Success)
                        {
                            SetupFile file = new SetupFile();
                            file.srcDirectory = Path.GetDirectoryName(path);
                            file.srcName = Path.GetFileName(path);
                            file.dstName = file.srcName;
                            //file.fileId = "ID_" + GetMd5Hash(path + "::"
                            //    + Path.Combine(file.dstDirectory, file.dstName));

                            component.componentFiles.Add(file);
                            rval = true;
                        }
                    }
                }
            }

            // Recurse
            if (recurse)
            {
                foreach (string path in Directory.GetDirectories(srcDirectory))
                {
                    FileAttributes attr = File.GetAttributes(path);
                    if ((attr & (FileAttributes.Device
                        | FileAttributes.Hidden
                        | FileAttributes.System
                        | FileAttributes.Temporary)) != 0)
                    {
                        // Dont use
                    }
                    else if ((attr & FileAttributes.Directory) == FileAttributes.Directory)
                    {
                        if ((null != exclude) && (exclude.Match(path + @"\").Success))
                            continue; // Excluded

                        bool probe = MakeComponents(components,
                            Path.Combine(srcDirectory,  Path.GetFileName(path)),
                            Path.Combine(targetDirectory, Path.GetFileName(path)));

                        if (!rval && probe)
                            rval = true; // We found files
                    }
                }
            }

            component.addToCreateFolder = true;

            if (preventEmptyDirectories && !rval)
                components.Remove(component); // Prevent empty dirs/structures

            return rval;
        }
 public void Clear()
 {
     _recurse = false;
     _addToPath = false;
     _ideHeaderFiles = false;
     _ideExecutables = false;
     _ideLibrary = false;
     _pathComponent = new SetupComponent();
     _dirId = MainFrame.CurrentProject.GetUniqueId();
     _patterns = ".*";
 }