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;
        }
        private void loadMemoryMapToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TreeNodeData tnd = treeViewInventory.SelectedNode.Tag as TreeNodeData;
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Multiselect = false;
            ofd.Filter = "Scatter Files (*.xml)|*.xml|All Files (*.*)|*.*";
            ofd.CheckFileExists = true;

            if (DialogResult.OK == ofd.ShowDialog(this))
            {
                ComponentObjectModel.ScatterfileWrapper scatter = new ComponentObjectModel.ScatterfileWrapper(tnd.Data as MFProject);
                List<MemoryMap> maps = scatter.LoadFromFile(ofd.FileName);
                MFSolution solution = tnd.Data as MFSolution;

                //TODO: FIX
                solution.Projects[0].MemoryMap = maps[0];

                this.RefreshTree();
            }
        }