public NewProjectWizard(SolutionWrapper Solution)
        {
            InitializeComponent();

            Param.Solution = Solution;
            Param.OldProject = null;

            MFProject tmpProj = new MFProject();
            Param.NewProject = ProjectWrapper.Wrap<ProjectWrapper>(tmpProj);

            mPDP = new ProjectDescriptionPage(Param);
            mPDP.IsCLREvent += new EventHandler<IsCLREventArgs>(mPDP_IsCLREvent);

            mMFP = new ManageFeaturesPage(Param);

            mPageList.Add(new ProjectTemplatePage(Param));
            mPageList.Add(mPDP);
            mPageList.Add(mMFP);
            mPageList.Add(new ManageLibrariesPage(Param));

            foreach (BasePage bp in mPageList)
            {
                bp.ShowBackBtnEvent += new EventHandler<ShowBtnEventArgs>(bp_ShowBackBtnEvent);
                bp.ShowNextBtnEvent += new EventHandler<ShowBtnEventArgs>(bp_ShowNextBtnEvent);
            }

            this.Initialize();
        }
        /// <summary>
        /// Устанавливает MFProject для генерации
        /// </summary>
        /// <param name="LibCat"></param>
        public void SetProject(MFProject Proj)
        {
            this.Proj = Proj;
            LogRtb.Clear();
            LogAddText(Strings.MFProject + ": " + Proj.Name + "\r\n");
            LogAddText(Strings.Description + ": " + Proj.Description + "\r\n");
            LogAddText(Strings.Documentation + ": " + Proj.Documentation + "\r\n");
            LogAddText(Strings.ProjectPath + ": " + Proj.ProjectPath + "\r\n");

            GeneratedTextTB.Clear();

            m_worker.RunWorkerAsync(this.Proj);
        }
        public void SetProject(SolutionWrapper Solution, ProjectWrapper Project)
        {

            MFProject tmpProj = new MFProject();

            Project.InnerObject.CopyTo(tmpProj, Solution.Name);

            Param.NewProject = ProjectWrapper.Wrap<ProjectWrapper>(tmpProj);
            Param.OldProject = Project;
            Param.Solution = Solution;

            if (Project.IsClrProject)
                mPageList.Add(new ManageFeaturesPage(Param));
            mPageList.Add(new ManageLibrariesPage(Param));
            //mPageList.Add(new ManageLibrariesPageTest(Solution, Project, NewProject));

            this.Initialize();
        }
        public override void BeforeCloseOnNext()
        {
            if (selectedProject != null)
            {
                string str = @"$(SPOCLIENT)\Solutions\" + Params.Solution.Name + @"\";

                MFProject tmpProj = new MFProject();


                selectedProject.InnerObject.CopyTo(tmpProj, Params.Solution.Name);
                if (tmpProj != null)
                {
                    tmpProj.ProjectPath = str + Path.GetFileName(tmpProj.Directory) + @"\" + Path.GetFileName(tmpProj.ProjectPath);
                    tmpProj.SettingsFile = str + Params.Solution.Name + ".settings";                    
                }

                Params.NewProject = ProjectWrapper.Wrap<ProjectWrapper>(tmpProj);
            }
        }
        internal void CopyProjFilesFromClone(MFProject proj, MFSolution solution)
        {
            if (proj.m_cloneProj != null)
            {
                string dirSource = MsBuildWrapper.ExpandEnvVars(Path.GetDirectoryName(proj.m_cloneProj.ProjectPath), "");
                string dirTarg = MsBuildWrapper.ExpandEnvVars(Path.GetDirectoryName(proj.ProjectPath), "");
                string dirSourceRoot = Path.GetDirectoryName(dirSource);
                string dirTargRoot = Path.GetDirectoryName(dirTarg);

                try
                {
                    CopyClonedFiles(dirSourceRoot, dirTargRoot, solution.m_cloneSolution == null ? "$(PLATFORM)" : solution.m_cloneSolution.Name, solution.Name, false);
                    CopyClonedFiles(dirSource, dirTarg, solution.m_cloneSolution == null ? "$(PLATFORM)" : solution.m_cloneSolution.Name, solution.Name, true);
                }
                catch (Exception e)
                {
                    System.Diagnostics.Debug.WriteLine("Error: Copying clone files\r\n\tsrc:" + dirSource + "\r\n\tdst:" + dirTarg + "\r\n", e.Message);
                }
                
            }
        }
        internal MFProject LoadProjectProj(string projFile, string path)
        {
            MFProject mfproj = new MFProject();
            Project proj;
            string fullpath = ExpandEnvVars(projFile, path);

            List<MFComponent> driverLibCheck = new List<MFComponent>();

            try
            {
                proj = LoadProject(fullpath);

                path = Path.GetDirectoryName(fullpath);

                mfproj.ProjectPath = ConvertPathToEnv(projFile);

                Dictionary<string, string> tbl = new Dictionary<string, string>();
                tbl["AssemblyName"] = "Name";
                tbl["MFSettingsFile"] = "SettingsFile";
                tbl["ProjectGuid"] = "Guid";

                LoadStringProps(proj, mfproj, tbl);

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

                        switch (bp.Name)
                        {
                            case "AssemblyName":
                            case "MFSettingsFile":
                            case "ProjectGuid":
                            case "Description":
                            case "Documentation":
                                // handled by loadstringprops
                                break;
                            case "IsClrProject":
                                mfproj.IsClrProject = Boolean.Parse(bp.Value);
                                break;
                            case "EXEScatterFileDefinition":
                                {
                                    MFBuildFile file = new MFBuildFile();

                                    file.Condition = cond;
                                    file.File = bp.Value;
                                    file.ItemName = bp.Name;

                                    mfproj.ScatterFile = file;
                                }
                                break;
                            default:
                                {
                                    MFProperty prop = new MFProperty();
                                    prop.Name = bp.Name;
                                    prop.Value = bp.Value;
                                    prop.Condition = cond;
                                    mfproj.Properties.Add(prop);
                                }
                                break;
                        }
                    }
                }

                LoadCompileItems(proj, mfproj, path);

                Dictionary<string, MFComponent> libLookup = new Dictionary<string, MFComponent>();
                foreach (ProjectItemGroupElement big in proj.Xml.ItemGroups)
                {
                    foreach (ProjectItemElement bi in big.Items)
                    {
                        string cond = CombineConditionals(big.Condition, bi.Condition);

                        switch (bi.ItemType)
                        {
                            case "RequiredProjects":
                                string ext = Path.GetExtension(bi.Include).ToUpper();
                                if (ext == ".FEATUREPROJ" || ext == ".LIBCATPROJ")
                                {
                                    System.Diagnostics.Debug.Assert(false, ".FeatureProj and .LibCatProj files can only be imported");
                                }
                                else if (ext == ".PROJ")
                                {
                                    Library lib = m_helper.FindLibraryByProject(ExpandEnvVars(bi.Include, path));
                                    MFComponent comp = null;

                                    if (lib == null)
                                    {
                                        lib = LoadLibraryProj(bi.Include, path);
                                    }

                                    if (lib != null)
                                    {
                                        if (libLookup.ContainsKey(lib.Guid.ToLower()))
                                        {
                                            comp = libLookup[lib.Guid.ToLower()];

                                            if (string.IsNullOrEmpty(comp.Conditional))
                                            {
                                                comp.Conditional = cond;
                                            }
                                            break;
                                        }

                                        comp = new MFComponent(MFComponentType.Library, lib.Name, lib.Guid, bi.Include);
                                        comp.Conditional = cond;
                                    }

                                    if (comp != null)
                                    {
                                        mfproj.Libraries.Add(comp);

                                        libLookup[comp.Guid.ToLower()] = comp;
                                    }
                                    else
                                    {
                                        // we should pick this up in the driverlibs/platformlibs
                                        /*
                                        string name = Path.GetFileName(Path.GetDirectoryName(bi.Include));
                                        comp = new MFComponent(MFComponentType.Library, name, System.Guid.NewGuid().ToString("B"), bi.Include);
                                        comp.Conditional = cond;

                                        mfproj.Libraries.Add(comp);

                                        libLookup[comp.Guid.ToLower()] = comp;

                                        Console.WriteLine("Error: Library not found " + bi.Include);
                                        */
                                    }
                                }
                                else
                                {
                                    Console.WriteLine("Warning! Skipping dependency item " + bi.Include);
                                }
                                break;
                            case "InteropFeature":
                                mfproj.InteropFeatures.Add(bi.Include);
                                break;
                            case "PlatformIndependentLibs":
                                goto case "DriverLibs";
                            case "DriverLibs":
                                driverLibCheck.Add(new MFComponent(MFComponentType.Unknown, "", "", bi.Include, cond));
                                break;
                            case "MMP_DAT_CreateDatabase":
                                if (!mfproj.ExtraAssemblies.Contains(bi.Include))
                                {
                                    mfproj.ExtraAssemblies.Add(bi.Include);
                                }
                                break;
                            case "FastCompileCPPFile":
                            case "Compile":
                            case "HFiles":
                            case "IncludePaths":
                                // handled by LoadCompileItems
                                break;

                            // todo: do we want to get rid of subdirectories?
                            //case "SubDirectories":
                            //break;

                            default:
                                {
                                    MFBuildFile f = new MFBuildFile();
                                    f.Condition = cond;
                                    f.File = bi.Include;
                                    f.ItemName = bi.ItemType;
                                    mfproj.OtherFiles.Add(f);
                                }
                                break;
                        }
                    }
                }

                Hashtable featLookup = new Hashtable();

                foreach (ProjectImportElement imp in proj.Xml.Imports)
                {
                    string ext = Path.GetExtension(imp.Project).ToUpper();

                    if (ext == ".FEATUREPROJ")
                    {
                        Feature feat = LoadFeatureProj(imp.Project, path);
                        MFComponent comp = null;

                        if (feat == null)
                        {
                            feat = m_helper.FindFeatureByName(Path.GetFileNameWithoutExtension(imp.Project));
                        }

                        if (feat == null)
                        {
                            string name = Path.GetFileNameWithoutExtension(imp.Project);
                            comp = new MFComponent(MFComponentType.Feature, name, System.Guid.NewGuid().ToString("B"), imp.Project);
                            comp.Conditional = imp.Condition;

                            mfproj.Features.Add(comp);

                            featLookup.Add(comp.Guid.ToLower(), comp);

                            //Console.WriteLine("Error: Feature not found " + imp.Project);
                        }
                        else if(!featLookup.ContainsKey(feat.Guid.ToLower()))
                        {
                            comp = new MFComponent(MFComponentType.Feature, feat.Name, feat.Guid, imp.Project);
                            comp.Conditional = imp.Condition;

                            mfproj.Features.Add(comp);

                            featLookup.Add(feat.Guid.ToLower(), comp);
                        }
                    }
                    else if (ext == ".LIBCATPROJ")
                    {
                        LibraryCategory libcat = LoadLibraryCategoryProj(imp.Project, path);
                        MFComponent comp = null;

                        if (libcat == null)
                        {
                            libcat = m_helper.FindLibraryCategoryByName(Path.GetFileNameWithoutExtension(imp.Project));
                        }

                        if (libcat != null)
                        {
                            comp = new MFComponent(MFComponentType.LibraryCategory, libcat.Name, libcat.Guid, imp.Project);
                            comp.Conditional = imp.Condition;

                            mfproj.LibraryCategories.Add(comp);
                        }
                        else
                        {
                            string name = Path.GetFileNameWithoutExtension(imp.Project);
                            comp = new MFComponent(MFComponentType.LibraryCategory, name, System.Guid.NewGuid().ToString("B"), imp.Project);
                            comp.Conditional = imp.Condition;

                            mfproj.LibraryCategories.Add(comp);

                            Console.WriteLine("Error: LibraryCategory not found " + imp.Project);
                        }
                    }
                }


                ScatterfileWrapper sw = new ScatterfileWrapper(mfproj);
                string scatter = "";

                if (mfproj.ScatterFile != null && !string.IsNullOrEmpty(mfproj.ScatterFile.File))
                {
                    string tmp = ExpandEnvVars(mfproj.ScatterFile.File, "");
                    if (File.Exists(tmp))
                    {
                        scatter = tmp;
                    }
                }

                if (scatter == "")
                {
                    foreach (string scatterfile in Directory.GetFiles(Path.GetDirectoryName(projFile), "scatter*.xml"))
                    {
                        if (scatterfile.ToLower().Contains("ram_functions")) continue;
                        if (scatterfile.ToLower().Contains("_gcc.")) continue;

                        List<MemoryMap> maps = sw.LoadFromFile(scatterfile);

                        if(maps != null && maps.Count > 0)
                        {
                            mfproj.MemoryMap = maps[0];
                        }
                    }
                }
                else
                {
                    // todo add support for GCC?
                    if (!scatter.ToLower().Contains("_gcc"))
                    {
                        mfproj.MemoryMap = sw.LoadFromFile(scatter)[0];
                    }
                }

                foreach (ProjectTargetElement targ in proj.Xml.Targets)
                {
                    mfproj.Targets.Add(targ);
                }

                foreach(MFComponent comp in driverLibCheck)
                {
                    Library lib = m_helper.FindLibraryByFile(comp.ProjectPath);

                    if (lib == null)
                    {
                        lib = m_helper.FindLibraryByName(Path.GetFileNameWithoutExtension(comp.ProjectPath));
                    }

                    if (lib == null)
                    {
                        mfproj.Libraries.Add(comp);

                        libLookup[comp.Guid.ToLower()] = comp;

                        Console.WriteLine("Warning: Library not found " + comp.ProjectPath + ". Delay loading...");
                    }
                }

            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("Error: loading project file: " + fullpath + "\r\n", e.Message);
                mfproj = null;
            }

            return mfproj;
        }
        internal void SaveProjectProj(MFProject mfproj)
        {
            if (!string.IsNullOrEmpty(mfproj.ProjectPath))
            {
                try
                {
                    string fullpath = ExpandEnvVars(mfproj.ProjectPath, "");
                    string dir = Path.GetDirectoryName(fullpath);

                    // normalize the path (no xxx\..\yyy)
                    fullpath = Path.GetFullPath(fullpath);
                    mfproj.ProjectPath = ConvertPathToEnv(fullpath);

                    Project proj = LoadProject(fullpath);

                    // clear the project
                    proj.ProjectCollection.UnloadProject(proj);

                    proj = new Project();
                    proj.Xml.DefaultTargets = "Build";

                    proj.FullPath = fullpath;

                    if (!Directory.Exists(dir))
                    {
                        Directory.CreateDirectory(dir);
                    }

                    mfproj.Directory = RemoveSpoClient(Path.GetDirectoryName(fullpath));

                    Dictionary<string, string> tbl = new Dictionary<string, string>();
                    tbl["Name"] = "AssemblyName";
                    tbl["SettingsFile"] = "MFSettingsFile";
                    tbl["Guid"] = "ProjectGuid";

                    ProjectPropertyGroupElement bpg = SaveStringProps(proj, mfproj, tbl);

                    ProjectImportElement pi = proj.Xml.AddImport(@"$(SPOCLIENT)\tools\targets\Microsoft.SPOT.System.Settings");

                    if (mfproj.IsClrProject)
                    {
                        proj.Xml.AddImport(@"$(SPOCLIENT)\tools\Targets\Microsoft.SPOT.Build.Targets");
                    }

                    proj.Save(fullpath);

                    bpg = proj.Xml.AddPropertyGroup();
                    foreach (MFProperty prop in mfproj.Properties)
                    {
                        if(!tbl.ContainsKey(prop.Name) || tbl[prop.Name] != prop.Value)
                        {
                            ProjectPropertyElement bp = bpg.AddProperty(prop.Name, prop.Value);
                            bp.Condition = prop.Condition;
                            tbl[prop.Name] = prop.Value;
                        }
                    }

                    if (mfproj.BuildTool != null)
                    {
                        List<BuildToolRef> lst = new List<BuildToolRef>();
                        lst.Add(mfproj.BuildTool);
                        SaveBuildToolRef(lst, proj);
                    }

                    if (mfproj.ScatterFile != null)
                    {
                        bpg.AddProperty("EXEScatterFileDefinition", mfproj.ScatterFile.File);
                    }

                    ProjectItemGroupElement bigCompile = proj.Xml.AddItemGroup();

                    // copy from cloned solution if necessary
                    SaveCompileItems(proj, mfproj.FastCompileFiles, mfproj.HeaderFiles, mfproj.SourceFiles, mfproj.OtherFiles, mfproj.IncludePaths);

                    ProjectItemGroupElement big = null;
                    foreach (MFComponent feat in mfproj.Features)
                    {
                        ProjectImportElement pie = proj.Xml.AddImport(feat.ProjectPath);
                        pie.Condition = feat.Conditional;
                    }

                    proj.Save(fullpath);

                    big = null;
                    foreach (string interop in mfproj.InteropFeatures)
                    {
                        if (big == null)
                        {
                            big = proj.Xml.AddItemGroup();
                        }

                        big.AddItem("InteropFeature", interop);
                    }
                    if (mfproj.IsClrProject)
                    {
                        proj.Xml.AddImport(@"$(SPOCLIENT)\tools\targets\Microsoft.SPOT.System.Interop.Settings");
                    }

                    proj.Save(fullpath);

                    SaveDependentLibs(proj, mfproj.Libraries);

                    big = null;
                    foreach (string asm in mfproj.ExtraAssemblies)
                    {
                        if (big == null)
                        {
                            big = proj.Xml.AddItemGroup();
                        }

                        big.AddItem("MMP_DAT_CreateDatabase", asm);
                    }

                    foreach (ProjectTargetElement targ in mfproj.Targets)
                    {
                        ProjectTargetElement t = proj.Xml.AddTarget(targ.Name);

                        t.Condition = targ.Condition;
                        t.DependsOnTargets = targ.DependsOnTargets;
                        t.Inputs = targ.Inputs;
                        t.Outputs = targ.Outputs;

                        foreach (ProjectTaskElement task in targ.Tasks)
                        {
                            ProjectTaskElement tsk = t.AddTask(task.Name);
                            tsk.Condition = task.Condition;
                            tsk.ContinueOnError = task.ContinueOnError;

                            foreach (KeyValuePair<string,string> param in task.Parameters)
                            {
                                tsk.SetParameter(param.Key, param.Value);
                            }
                        }
                    }

                    proj.Xml.AddImport(@"$(SPOCLIENT)\tools\targets\Microsoft.SPOT.System.Targets");

                    proj.Save(fullpath);

                    // post process project file to assure proper placement of imports
                    XmlDocument doc = new XmlDocument();
                    doc.Load(fullpath);

                    XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
                    nsmgr.AddNamespace("ns", "http://schemas.microsoft.com/developer/msbuild/2003");

                    XmlNode root = doc.DocumentElement;

                    string expr = "descendant::ns:PropertyGroup";
                    XmlNode dst = root.SelectSingleNode(expr, nsmgr);
                    expr = @"descendant::ns:Import";
                    XmlNodeList imports = root.SelectNodes(expr, nsmgr);

                    XmlNode sysSettings = null;
                    XmlNode bldTargs = null;
                    XmlNode intSettings = null;
                    List<XmlNode> featureProjs = new List<XmlNode>();

                    foreach (XmlNode n in imports)
                    {
                        string prj = n.Attributes["Project"].InnerText;

                        if (prj.Equals(@"$(SPOCLIENT)\tools\targets\Microsoft.SPOT.System.Settings", StringComparison.OrdinalIgnoreCase))
                        {
                            sysSettings = n;
                        }
                        else if (prj.Equals(@"$(SPOCLIENT)\tools\Targets\Microsoft.SPOT.Build.Targets", StringComparison.OrdinalIgnoreCase))
                        {
                            bldTargs = n;
                        }
                        else if (prj.Equals(@"$(SPOCLIENT)\tools\targets\Microsoft.SPOT.System.Interop.Settings", StringComparison.OrdinalIgnoreCase))
                        {
                            intSettings = n;
                        }
                        else if (prj.EndsWith(".featureproj", StringComparison.OrdinalIgnoreCase))
                        {
                            featureProjs.Add(n);
                        }
                    }

                    //[@ns:Project='$(SPOCLIENT)\tools\targets\Microsoft.SPOT.System.Settings']
                    root.RemoveChild(sysSettings);
                    dst = root.InsertAfter(sysSettings, dst);

                    if (mfproj.IsClrProject)
                    {
                        //expr = @"descendant::ns:Import[@ns:Project='$(SPOCLIENT)\tools\Targets\Microsoft.SPOT.Build.Targets']";
                        //src = root.SelectSingleNode(expr, nsmgr);
                        root.RemoveChild(bldTargs);
                        root.InsertAfter(bldTargs, dst);

                        expr = "descendant::ns:ItemGroup/ns:Compile";
                        dst = root.SelectSingleNode(expr, nsmgr).ParentNode;
                        //expr = "descendant::ns:Import[@ns:Project='*.featureproj']";
                        //XmlNodeList list = root.SelectNodes(expr, nsmgr);
                        foreach (XmlNode n in featureProjs)
                        {
                            root.RemoveChild(n);
                            dst = root.InsertAfter(n, dst);
                        }
                        //expr = @"descendant::ns:Import[@ns:Project='$(SPOCLIENT)\tools\targets\Microsoft.SPOT.System.Interop.Settings']";
                        //src = root.SelectSingleNode(expr, nsmgr);
                        root.RemoveChild(intSettings);
                        root.InsertAfter(intSettings, dst);
                    }

                    doc.Save(fullpath);
                }
                catch
                {
                    Console.WriteLine("Error: Invalid project file " + mfproj.ProjectPath);
                }
            }
        }
        //Hashtable m_symOrderMap  = new Hashtable();
        //Hashtable m_symToNavNode = new Hashtable();


        public ScatterfileWrapper(MFProject project)
        {
            m_project = project;
        }
        public Library[] GetLibrariesOfType(LibraryCategory LibraryCategory, MFProject proj, MFSolution solution)
        {
            List<Library> ret = new List<Library>();

            foreach (Inventory inv in m_invs)
            {
                foreach (Library lib in inv.Libraries)
                {
                    if (lib.LibraryCategory != null)
                    {
                        if (string.IsNullOrEmpty(lib.LibraryCategory.Guid)) continue;

                        if (0 == string.Compare(lib.LibraryCategory.Guid, LibraryCategory.Guid, true))
                        {
                            ret.Add(lib);
                        }
                    }
                }
            }

            return ret.ToArray();
        }
        public void CopyTo(MFProject dest, string newName, string solutionName)
        {
            if (dest.m_cloneProj == null)
            {
                dest.m_cloneProj = this;
            }

            Dictionary<string, string> hash = new Dictionary<string, string>();

            hash[this.nameField] = newName;
            hash[@"\$\(PLATFORM\)"] = solutionName;
            hash[@"\$\(TARGETPLATFORM\)"] = solutionName;

            CopyHelper.CopyTo(this, dest, hash);
        }
        private void wpChooseProjects_CloseFromNext(object sender, Gui.Wizard.PageEventArgs e)
        {
            m_HasClrProj = false;

            Dictionary<string, MFProject> projLookup = new Dictionary<string, MFProject>();
            List<MFProject> projRemoveList = new List<MFProject>();

            foreach (MFProject prj in m_solution.Projects)
            {
                projLookup[prj.Name.ToLower()] = prj;
            }
            //m_solution.Projects.Clear();

            string solutionRoot = "$(SPOCLIENT)\\Solutions\\" + m_solution.Name + "\\";

            foreach (TreeNode tn in tv_SelectedProjects.Nodes["NativeProjects"].Nodes)
            {
                MFProject projClone = tn.Tag as MFProject;
                string key = projClone.Name.ToLower();

                if (tn.Checked)
                {
                    if (projLookup.ContainsKey(key))
                    {
                        continue;
                    }

                    MFProject proj = new MFProject();

                    projClone.CopyTo(proj, m_solution.Name);

                    if (proj != null)
                    {
                        proj.ProjectPath = solutionRoot + Path.GetFileName(proj.Directory) + "\\" + Path.GetFileName(proj.ProjectPath);

                        proj.SettingsFile = solutionRoot + m_solution.Name + ".settings";

                        m_solution.Projects.Add(proj);

                        projLookup[key] = proj;
                    }
                }
                else if (projLookup.ContainsKey(key))
                {
                    projRemoveList.Add(projLookup[key]);
                    projLookup.Remove(key);
                }
            }

            foreach (TreeNode tn in tv_SelectedProjects.Nodes["ClrProjects"].Nodes)
            {
                MFProject projClone = tn.Tag as MFProject;
                string key = projClone.Name.ToLower();

                if (tn.Checked)
                {
                    if (projLookup.ContainsKey(key))
                    {
                        m_HasClrProj = true;
                        continue;
                    }

                    MFProject proj = new MFProject();

                    projClone.CopyTo(proj, m_solution.Name);

                    if (proj != null)
                    {
                        proj.ProjectPath = solutionRoot + Path.GetFileName(proj.Directory) + "\\" + Path.GetFileName(proj.ProjectPath);

                        proj.SettingsFile = solutionRoot + m_solution.Name + ".settings";

                        m_solution.Projects.Add(proj);

                        m_HasClrProj = true;

                        projLookup[key] = proj;
                    }
                }
                else if (projLookup.ContainsKey(key))
                {
                    projRemoveList.Add(projLookup[key]);
                    projLookup.Remove(key);
                }
            }

            foreach (MFProject prj in projRemoveList)
            {
                m_solution.Projects.Remove(prj);
            }

            MFProject projAll = new MFProject();
            projAll.Name = Properties.Resources.AllProjects;
            projAll.Guid = m_allProjectsGuid;
            projAll.IsClrProject = true;

            m_solution.Projects.Insert(0, projAll); 

            if (m_solution.m_cloneSolution != null)
            {
                MFProject defProj = null;

                foreach (MFProject prj in m_solution.m_cloneSolution.Projects)
                {
                    string key = prj.Name.ToLower();

                    if (0 == string.Compare(key, "tinyclr"))
                    {
                        defProj = prj;
                    }

                    if (projLookup.ContainsKey(key))
                    {
                        projLookup[key].Features.AddRange(prj.Features);
                        projLookup[key].Libraries.AddRange(prj.Libraries);
                    }
                }

                if (defProj != null)
                {
                    foreach (MFProject proj in m_solution.Projects)
                    {
                        if (proj.IsClrProject && proj.Features.Count == 0)
                        {
                            foreach (MFComponent f in defProj.Features)
                            {
                                MFComponent fCopy = new MFComponent();
                                f.CopyTo(fCopy);
                                proj.Features.Add(fCopy);
                            }
                        }
                        // tinybooter has 1 library to start with
                        if (proj.Libraries.Count < 2)
                        {
                            foreach (MFComponent l in defProj.Libraries)
                            {
                                MFComponent lCopy = new MFComponent();
                                l.CopyTo(lCopy);
                                proj.Libraries.Add(lCopy);
                            }
                        }
                    }
                }
            }

            //tv_LibraryView.Nodes.Clear();
            //cbProjectSelect_Library.Items.Clear();

            if (m_HasClrProj)
            {
                tv_FeatureView.Nodes.Clear();
                cbProjectSelect_Feature.Items.Clear();

                e.Page = wpChooseFeatures;
            }
            else if (m_solution.Projects.Count > 0)
            {
                e.Page = wpChooseLibraries;
            }
            else
            {
                MessageBox.Show(this, Properties.Resources.ErrorNoProjects, Properties.Resources.SolutionWizard, MessageBoxButtons.OK, MessageBoxIcon.Error );
                e.Page = wpChooseProjects;
            }
        }
 internal ProjectComboData(string name, MFProject proj)
 {
     Name = name;
     Proj = proj;
     CompLookup = new Dictionary<string,ComponentTreeNode>();
 }
        public override void BeforeCloseOnNext()
        {
            Params.Solution.Projects.Clear();
            foreach (BaseNode BN in _treeView.AllNodes)
            {
                ComponentNode CN = BN as ComponentNode;

                if (CN == null) continue;
                if (!CN.Checked) continue;
                else
                {
                    string str = @"$(SPOCLIENT)\Solutions\" + Params.Solution.Name + @"\";

                    ProjectWrapper Template = FindProjectTemplate(CN.TypedContent);

                    MFProject tmpProj = new MFProject();
                    Template.InnerObject.CopyTo(tmpProj, Params.Solution.Name);
                    if (tmpProj != null)
                    {
                        tmpProj.ProjectPath = str + Path.GetFileName(tmpProj.Directory) + @"\" + Path.GetFileName(tmpProj.ProjectPath);
                        tmpProj.SettingsFile = str + Params.Solution.Name + ".settings";
                        Params.Solution.Projects.Add(ProjectWrapper.Wrap<ProjectWrapper>(tmpProj));
                    }
                }
            }

            this.OnShowNextBtn(true);
        }