internal Library LoadLibraryProj(string libProjFile, string path, bool fForceReload) { Project proj; string fullpath = ExpandEnvVars(libProjFile, path); Library lib = null; try { lib = m_helper.FindLibraryByProject(fullpath); Library dbLib = null; if (!fForceReload) { if (lib != null) { return lib; } } if (!File.Exists(fullpath)) { return null; } if (lib == null) { lib = new Library(); } proj = LoadProject(fullpath); path = Path.GetDirectoryName(fullpath); lib.ProjectPath = ConvertPathToEnv(fullpath); if (fullpath.ToUpper().Contains("\\CLR\\")) { lib.Level = LibraryLevel.CLR; } else if (fullpath.ToUpper().Contains("\\SUPPORT\\")) { lib.Level = LibraryLevel.Support; } else if (fullpath.ToUpper().Contains("\\PAL\\")) { lib.Level = LibraryLevel.PAL; } else { lib.Level = LibraryLevel.HAL; } if (Path.GetFileName(fullpath).ToUpper().Contains("_STUB") || fullpath.ToUpper().Contains("\\STUBS")) { lib.IsStub = true; } Dictionary<string, string> tbl = new Dictionary<string, string>(); tbl["AssemblyName"] = "Name"; tbl["ProjectGuid"] = "Guid"; LoadStringProps(proj, lib, tbl); if (!fForceReload) { dbLib = m_helper.FindLibrary(lib.Guid); if (dbLib != null) { if (!string.Equals(dbLib.Name, lib.Name, StringComparison.InvariantCultureIgnoreCase)) { System.Diagnostics.Debug.WriteLine("WARNING!!! Loaded library name doesn't match database library (possible bad project file)"); System.Diagnostics.Debug.WriteLine(dbLib.Name + " != " + lib.Name); } return dbLib; } dbLib = m_helper.FindLibraryByName(lib.Name); if (dbLib != null) return dbLib; } if (string.IsNullOrEmpty(lib.LibraryFile)) lib.LibraryFile = lib.Name + ".$(LIB_EXT)"; if (string.IsNullOrEmpty(lib.ManifestFile)) lib.ManifestFile = lib.LibraryFile + ".manifest"; foreach (ProjectPropertyGroupElement pg in proj.Xml.PropertyGroups) { foreach (ProjectPropertyElement bp in pg.Properties) { string cond = CombineConditionals(pg.Condition, bp.Condition); switch (bp.Name) { /* case "OutputType": // don't allow projects to be loaded as library if (0 == string.Compare(bp.Value.Trim(), "Executable", true)) { return null; } break; */ case "Version": string[] vers = bp.Value.Split('.'); if (vers != null) { if (vers.Length > 0) lib.Version.Major = vers[0]; if (vers.Length > 1) lib.Version.Minor = vers[1]; if (vers.Length > 2) lib.Version.Revision = vers[2]; if (vers.Length > 3) lib.Version.Build = vers[3]; } break; case "PlatformIndependentBuild": { bool fPlatIndep = false; bool.TryParse(bp.Value, out fPlatIndep); lib.PlatformIndependent = fPlatIndep; } break; default: { MFProperty prop = new MFProperty(); prop.Name = bp.Name; prop.Value = bp.Value; prop.Condition = cond; lib.Properties.Add(prop); } break; } } } if (string.IsNullOrEmpty(lib.Name)) { string dirName = Path.GetFileName(Path.GetDirectoryName(fullpath)); if (string.Compare(dirName, "GlobalLock") == 0) { lib.Name = dirName; } else { return null; } } LoadCompileItems(proj, lib, path); if (string.IsNullOrEmpty(lib.Guid)) { lib.Guid = System.Guid.NewGuid().ToString("B"); } 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": if (bi.Include.Trim().ToUpper().EndsWith(".PROJ")) { Library lib2 = LoadLibraryProj(bi.Include, path); if (lib2 != null) { lib.Dependencies.Add(new MFComponent(MFComponentType.Library, lib2.Name, lib2.Guid, bi.Include)); } else { System.Diagnostics.Debug.WriteLine("Warning! unknown library " + bi.Include); //System.Diagnostics.Debug.Assert(false); } } break; case "LibraryCategories": LibraryCategory libCat = LoadLibraryCategoryProj(bi.Include, path); lib.Dependencies.Add(new MFComponent(MFComponentType.LibraryCategory, libCat.Name, libCat.Guid, bi.Include, cond)); break; case "FastCompileCPPFile": case "Compile": case "HFiles": case "IncludePaths": // handled by LoadCompileItems break; case "SubDirectories": break; default: { MFBuildFile f = new MFBuildFile(); f.Condition = cond; f.File = bi.Include; f.ItemName = bi.ItemType; lib.OtherFiles.Add(f); } break; } } } if (lib.IsStub && lib.LibraryCategory != null && !string.IsNullOrEmpty(lib.LibraryCategory.Guid)) { LibraryCategory lc = m_helper.FindLibraryCategory(lib.LibraryCategory.Guid); if (lc != null) { lc.StubLibrary = new MFComponent(MFComponentType.Library, lib.Name, lib.Guid, lib.ProjectPath); if (lc.Level != LibraryLevel.CLR && lc.Level != LibraryLevel.Support && lc.Templates.Count == 0) { lc.Templates.Clear(); ApiTemplate api = new ApiTemplate(); api.FilePath = ConvertPathToEnv(fullpath); lc.Templates.Add(api); foreach (MFBuildFile bf in lib.SourceFiles) { api = new ApiTemplate(); api.FilePath = ConvertPathToEnv(Path.Combine(path, bf.File)); lc.Templates.Add(api); } foreach (MFBuildFile bf in lib.HeaderFiles) { if (Path.IsPathRooted(MsBuildWrapper.ExpandEnvVars(bf.File,"")) || bf.File.Contains("..")) continue; api = new ApiTemplate(); api.FilePath = ConvertPathToEnv(Path.Combine(path, bf.File)); lc.Templates.Add(api); } foreach (MFBuildFile bf in lib.FastCompileFiles) { api = new ApiTemplate(); api.FilePath = ConvertPathToEnv(Path.Combine(path, bf.File)); lc.Templates.Add(api); } } } } foreach (ProjectTargetElement targ in proj.Xml.Targets) { lib.Targets.Add(targ); } foreach (ProjectImportElement imp in proj.Xml.Imports) { switch (Path.GetExtension(imp.Project).ToUpper().Trim()) { case ".LIBCATPROJ": LibraryCategory lc = LoadLibraryCategoryProj(imp.Project, path); if (lc != null) { MFComponent cmp = new MFComponent(MFComponentType.LibraryCategory, lc.Name, lc.Guid, lc.ProjectPath); lib.Dependencies.Add(cmp); } else { System.Diagnostics.Debug.Assert(false); } break; } } m_helper.AddLibraryToInventory(lib, false, m_helper.DefaultInventory); } catch (Exception e) { System.Diagnostics.Debug.WriteLine("Error: loading Library file: " + fullpath + "\r\n", e.Message); lib = null; } return lib; }
void SaveGridView() { dataGridView.EndEdit(); if (dataGridView.Tag is EnvVars) { List<EnvVar> evc = (dataGridView.Tag as EnvVars).EnvVarCollection; evc.Clear(); foreach (DataGridViewRow row in dataGridView.Rows) { if (row.Cells[0].Value != null) { EnvVar env = new EnvVar(); env.Name = row.Cells[0].Value.ToString(); env.Value = (row.Cells[1].Value == null ? "" : row.Cells[1].Value.ToString()); env.Conditional = row.Cells[2].Value == null? "" : row.Cells[2].Value.ToString(); evc.Add(env); } } } else if (dataGridView.Tag is List<ToolFlag>) { List<ToolFlag> flags = (dataGridView.Tag as List<ToolFlag>); flags.Clear(); foreach (DataGridViewRow row in dataGridView.Rows) { if (row.Cells[0].Value != null || row.Cells[1].Value != null) { ToolFlag flag = new ToolFlag(); flag.Conditional = (row.Cells[0].Value == null ? "" : row.Cells[0].Value.ToString()); flag.Flag = (row.Cells[1].Value == null ? "" : row.Cells[1].Value.ToString()); flags.Add(flag); } } } else if (dataGridView.Tag is List<BuildParameter>) { List<BuildParameter> parms = (dataGridView.Tag as List<BuildParameter>); parms.Clear(); foreach (DataGridViewRow row in dataGridView.Rows) { if (row.Cells[0].Value != null && row.Cells[1].Value != null) { BuildParameter parm = new BuildParameter(); parm.Parameter = (string)row.Cells[0].Value; parm.Action = (string)row.Cells[1].Value; parm.Description = (string)row.Cells[2].Value; parms.Add(parm); } } } else if (dataGridView.Tag is List<MemorySymbol>) { List<MemorySymbol> msc = dataGridView.Tag as List<MemorySymbol>; msc.Clear(); foreach (DataGridViewRow row in dataGridView.Rows) { if (row.Cells[0].Value != null && row.Cells[1].Value != null) { MemorySymbol parm = new MemorySymbol(); parm.Name = (string)row.Cells[0].Value; parm.Options = (string)row.Cells[1].Value; parm.Description = (string)row.Cells[2].Value; parm.Conditional = (string)row.Cells[3].Value; msc.Add(parm); } } } else if (dataGridView.Tag is List<BuildScript>) { List<BuildScript> al = dataGridView.Tag as List<BuildScript>; al.Clear(); foreach (DataGridViewRow row in dataGridView.Rows) { if (row.Cells[1].Value != null) { BuildScript bs = new BuildScript(); bs.Conditional = row.Cells[0].Value as string; bs.Script = row.Cells[1].Value as string; al.Add(bs); } } } else if (dataGridView.Tag is List<ApiTemplate>) { List<ApiTemplate> al = dataGridView.Tag as List<ApiTemplate>; al.Clear(); foreach (DataGridViewRow row in dataGridView.Rows) { if (!string.IsNullOrEmpty(row.Cells[0].Value as string)) { ApiTemplate at = new ApiTemplate(); at.FilePath = row.Cells[0].Value as string; at.Description = row.Cells[1].Value as string; al.Add(at); } } } else if (dataGridView.Tag is MFComponent) { foreach (DataGridViewRow row in dataGridView.Rows) { /* if ((bool)row.Cells[1].Value) { Library lib = row.Tag as Library; MFComponent comp = dataGridView.Tag as MFComponent; comp.Guid = lib.Guid; comp.Name = lib.Name; break; } */ } } }