public void CopyTo(MiscBuildTool dest)
 {
     CopyHelper.CopyTo(this, dest);
 }
        internal void LoadTargetFile(BuildTool tool, string fileName)
        {
            Project proj;
            string fullpath = ExpandEnvVars(fileName, "");

            try
            {
                proj = LoadProject(fullpath);

                foreach (ProjectImportElement import in proj.Xml.Imports)
                {
                    if (string.IsNullOrEmpty(import.Condition))
                    {
                        LoadTargetFile(tool, ExpandVars(import.Project, Path.GetDirectoryName(fileName)));
                    }
                }

                Regex expISA = new Regex(@"'\$\(INSTRUCTION_SET\)'=='", RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);

                foreach (ProjectPropertyGroupElement pg in proj.Xml.PropertyGroups)
                {
                    if (expISA.IsMatch(pg.Condition))
                    {
                        ISA isa = LoadISASettings(pg);
                        if (isa != null)
                        {
                            tool.SupportedISAs.Add(isa);
                        }
                        continue;
                    }

                    tool.BuildOptions = LoadToolChainOptions(pg);

                    foreach (ProjectPropertyElement bp in pg.Properties)
                    {
                        string cond = CombineConditionals(pg.Condition, bp.Condition);

                        switch (bp.Name)
                        {
                            case "BuildToolName":
                                tool.Name = bp.Value;
                                break;
                            case "Documentation":
                                tool.Documentation = bp.Value;
                                break;
                            case "BuildToolGuid":
                                tool.Guid = bp.Value;
                                break;
                            case ObjExtFlag:
                                tool.ObjExt = bp.Value;
                                break;
                            case LibExtFlag:
                                tool.LibExt = bp.Value;
                                break;
                            case ExeExtFlag:
                                tool.BinExt = bp.Value;
                                break;

                            case CCompilerTag:
                                tool.CCompiler.Exec = RemoveWrapper(bp.Value);
                                break;
                            case CppCompilerTag:
                                tool.CppCompiler.Exec = RemoveWrapper(bp.Value);
                                break;
                            case AsmCompilerTag:
                                tool.AsmCompiler.Exec = RemoveWrapper(bp.Value);
                                break;
                            case ArchiverTag:
                                tool.Archiver.Exec = RemoveWrapper(bp.Value);
                                break;
                            case LinkerTag:
                                tool.Linker.Exec = RemoveWrapper(bp.Value);
                                break;
                            case FromElfTag:
                                tool.FromELF.Exec = RemoveWrapper(bp.Value);
                                break;
                            case ToolWrapperTag:
                            case AdsWrapperTag:
                            case AdiWrapperTag:
                            case ArcWrapperTag:
                                tool.BuildToolWrapper = RemoveWrapper(bp.Value);
                                break;
                            case PKUI_CpuNamesTag:
                                {
                                    List<string> pts = (List<string>)this.DeserializeXml(bp.Value, typeof(List<string>));
                                    tool.SupportedCpuNames.AddRange(pts);
                                }
                                break;
                            case "ProcessorTypes":
                            case CpuNamesTag:
                                {
                                    foreach (string sType in bp.Value.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
                                    {
                                        tool.SupportedCpuNames.Add(sType);
                                    }
                                }
                                break;
                            case PKUI_ISAsTag:
                                {
                                    List<ISA> isas = (List<ISA>)this.DeserializeXml(bp.Value, typeof(List<ISA>));
                                    tool.SupportedISAs.AddRange(isas);
                                }
                                break;
                            case ISAsTag:
                                {
                                    //legacy
                                    if (bp.Value.Contains(";"))
                                    {
                                        foreach (string sISA in bp.Value.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
                                        {
                                            ISA isa = new ISA();
                                            isa.Name = sISA;
                                            isa.Guid = System.Guid.NewGuid().ToString("B");

                                            tool.SupportedISAs.Add(isa);
                                        }
                                    }
                                }
                                break;

                            default:
                                {
                                    MFProperty prop = new MFProperty();
                                    prop.Name = bp.Name;
                                    prop.Value = bp.Value;
                                    prop.Condition = cond;

                                    tool.Properties.Add(prop);
                                }
                                break;
                        }
                    }
                }

                foreach (ProjectItemGroupElement big in proj.Xml.ItemGroups)
                {
                    foreach (ProjectItemElement bi in big.Items)
                    {
                        string cond = CombineConditionals(big.Condition, bi.Condition);

                        MFProperty prop = new MFProperty();
                        prop.Name = bi.ItemType;
                        prop.Value = bi.Include;
                        prop.Condition = cond;

                        tool.Items.Add(prop);
                    }
                }

                foreach (ProjectTargetElement targ in proj.Xml.Targets)
                {
                    switch (targ.Name)
                    {
                        case AdiAsmTargetTag:
                        case ArmAsmTargetTag:
                        case ArcAsmTargetTag:
                        case AsmCompilerTargetTag:
                            tool.AsmCompiler.Conditional = targ.Condition;
                            tool.AsmCompiler.Description = AsmCompilerTag;
                            LoadTargetTasks(targ, tool.BuildOptions.EnvironmentVariables, tool.AsmCompiler, tool.BuildOptions.AsmFlags, tool.BuildOptions.CommonFlags);
                            break;
                        case AdiCCompilerTargetTag:
                        case ArmCCompilerTargetTag:
                        case ArcCCompilerTargetTag:
                        case CCompilerTargetTag:
                            tool.CCompiler.Conditional = targ.Condition;
                            tool.CCompiler.Description = CCompilerTag;
                            LoadTargetTasks(targ, tool.BuildOptions.EnvironmentVariables, tool.CCompiler, tool.BuildOptions.CFlags, tool.BuildOptions.C_CppFlags, tool.BuildOptions.CommonFlags);
                            break;
                        case AdiCppCompilerTargetTag:
                        case ArmCppCompilerTargetTag:
                        case ArcCppCompilerTargetTag:
                        case CppCompilerTargetTag:
                            tool.CppCompiler.Conditional = targ.Condition;
                            tool.CppCompiler.Description = CppCompilerTag;
                            LoadTargetTasks(targ, tool.BuildOptions.EnvironmentVariables, tool.CppCompiler, tool.BuildOptions.CppFlags, tool.BuildOptions.C_CppFlags, tool.BuildOptions.CommonFlags);
                            break;
                        case AdiLibTargetTag:
                        case ArmLibTargetTag:
                        case ArcLibTargetTag:
                        case LibTargetTag:
                            tool.Archiver.Conditional = targ.Condition;
                            tool.Archiver.Description = ArchiverTag;
                            LoadTargetTasks(targ, tool.BuildOptions.EnvironmentVariables, tool.Archiver, tool.BuildOptions.ArchiverFlags);
                            break;
                        case AdiExeTargetTag:
                        case ArmExeTargetTag:
                        case ArcExeTargetTag:
                        case ExeTargetTag:
                            tool.Linker.Conditional = targ.Condition;
                            tool.Linker.Description = LinkerTag;
                            LoadTargetTasks(targ, tool.BuildOptions.EnvironmentVariables, tool.Linker, tool.BuildOptions.LinkerFlags);
                            break;
                        default:
                            MiscBuildTool misc = new MiscBuildTool();
                            misc.BuildTool.Conditional = targ.Condition;
                            misc.BuildTool.Exec = targ.Name;
                            misc.BuildTool.Description = targ.Name;
                            misc.Name = targ.Name;
                            LoadTargetTasks(targ, misc.EnvironmentVariables, misc.BuildTool, misc.BuildToolOptions);
                            tool.MiscTools.Add(misc);
                            break;
                    }
                }

                BuildToolDefine[] tools = new BuildToolDefine[]
            {
                tool.Archiver,
                tool.AsmCompiler,
                tool.CCompiler,
                tool.CppCompiler,
                tool.Linker,
                tool.FromELF,
            };

                //first time to determine path
                foreach (BuildToolDefine td in tools)
                {
                    ExtractToolPath(tool, td.Exec);
                }
                //second time to remove path from exec command
                foreach (BuildToolDefine td in tools)
                {
                    td.Exec = ExtractToolPath(tool, td.Exec);
                }

                tool.ProjectPath = ConvertPathToEnv(fileName);
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("Error: loading target file: " + fullpath + "\r\n", e.Message);
            }
        }
        private void addMiscToolToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TreeNodeData tnd = treeViewInventory.SelectedNode.Tag as TreeNodeData;

            if (tnd != null)
            {
                List<MiscBuildTool> mtc = tnd.Data as List<MiscBuildTool>;

                MiscBuildTool tool = new MiscBuildTool();
                tool.Guid = Guid.NewGuid().ToString("B").ToUpper();
                tool.Name = "<New Misc Tool>";
                
                mtc.Add(tool);

                treeViewInventory.SelectedNode = AddTreeElement(treeViewInventory.SelectedNode, tool.Name, tool, true, mtc, tnd.FilePath);
            
                treeViewInventory.SelectedNode.BeginEdit();
            }
        }