/// <summary> /// Create a new C++ project that loads the specified .vcproj file. /// </summary> public CppProject(ProjectLoadInformation info) { this.Name = info.ProjectName; this.FileName = info.FileName; this.TypeGuid = "{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}"; using (StreamReader r = new StreamReader(info.FileName, Encoding.Default)) { try { document.Load(r); } catch (Exception ex) { throw new ProjectLoadException(ex.Message, ex); } } if (document.DocumentElement.Name != "VisualStudioProject") throw new ProjectLoadException("The project is not a visual studio project."); XmlElement filesElement = document.DocumentElement["Files"]; if (filesElement != null) { foreach (XmlElement filterElement in filesElement.ChildNodes.OfType<XmlElement>()) { if (filterElement.Name == "Filter") { FileGroup group = new FileGroup(this, filterElement); groups.Add(group); foreach (XmlElement fileElement in filterElement.ChildNodes.OfType<XmlElement>()) { if (fileElement.Name == "File" && fileElement.HasAttribute("RelativePath")) { items.Add(new FileItem(group, fileElement)); } } } } } }
/// <summary> /// Loads a file item from XML. /// </summary> public FileItem(FileGroup group, XmlElement fileElement) { this.XmlElement = fileElement; string relativePath = fileElement.GetAttribute("RelativePath"); if (relativePath.StartsWith(".\\")) { // SharpDevelop doesn't like paths starting with ".\", so strip it away: relativePath = relativePath.Substring(2); } this.ProjectItem = new FileProjectItem(group.Project, group.ItemType, relativePath); }
/// <summary> /// Create a new C++ project that loads the specified .vcproj file. /// </summary> public CppProject(ProjectLoadInformation info) : base(info) { this.Name = info.ProjectName; this.FileName = info.FileName; using (StreamReader r = new StreamReader(info.FileName, Encoding.Default)) { try { document.Load(r); } catch (Exception ex) { throw new ProjectLoadException(ex.Message, ex); } } if (document.DocumentElement.Name != "VisualStudioProject") { throw new ProjectLoadException("The project is not a visual studio project."); } XmlElement filesElement = document.DocumentElement["Files"]; if (filesElement != null) { foreach (XmlElement filterElement in filesElement.ChildNodes.OfType <XmlElement>()) { if (filterElement.Name == "Filter") { FileGroup group = new FileGroup(this, filterElement); groups.Add(group); foreach (XmlElement fileElement in filterElement.ChildNodes.OfType <XmlElement>()) { if (fileElement.Name == "File" && fileElement.HasAttribute("RelativePath")) { items.Add(new FileItem(group, fileElement)); } } } } } this.projectItems = new CppProjectItemsCollection(this); }
public override void Save(string fileName) { lock (SyncRoot) { // file item types may have changed, so remove all items from their parent elements // and re-add them to the correct Filter elements foreach (FileItem item in items) { item.SaveChanges(); if (item.XmlElement.ParentNode != null) { item.XmlElement.ParentNode.RemoveChild(item.XmlElement); } } foreach (FileItem item in items) { FileGroup group = groups.Find(fg => fg.ItemType == item.ProjectItem.ItemType); if (group != null) { group.XmlElement.AppendChild(item.XmlElement); } else { LoggingService.Warn("Couldn't find filter for item type " + item.ProjectItem.ItemType + ", the item was not saved!"); } } watcher.Disable(); using (XmlWriter writer = XmlWriter.Create(fileName, new XmlWriterSettings { NewLineOnAttributes = true, Indent = true, IndentChars = "\t", Encoding = Encoding.Default })) { document.Save(writer); } watcher.Enable(); } }
/// <summary> /// Create a new C++ project that loads the specified .vcproj file. /// </summary> public CppProject(string fileName, string projectName) { this.Name = projectName; this.FileName = fileName; this.TypeGuid = "{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}"; using (StreamReader r = new StreamReader(fileName, Encoding.Default)) { try { document.Load(r); } catch (Exception ex) { throw new ProjectLoadException(ex.Message, ex); } } if (document.DocumentElement.Name != "VisualStudioProject") { throw new ProjectLoadException("The project is not a visual studio project."); } XmlElement filesElement = document.DocumentElement["Files"]; if (filesElement != null) { foreach (XmlElement filterElement in filesElement.ChildNodes.OfType <XmlElement>()) { if (filterElement.Name == "Filter") { FileGroup group = new FileGroup(this, filterElement); groups.Add(group); foreach (XmlElement fileElement in filterElement.ChildNodes.OfType <XmlElement>()) { if (fileElement.Name == "File" && fileElement.HasAttribute("RelativePath")) { items.Add(new FileItem(group, fileElement)); } } } } } }