/*
* Filename: VS7ProjectFileReader.cs
* Product: Versioning Controlled Build
* Solution: BuildAutoIncrement
* Project: CommandLine
* Description: Class that parses content of Visual Studio 2002 and 2003 project
* files.
* Copyright: Julijan �ribar, 2004-2013
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the author(s) be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/
using System;
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Xml;
namespace BuildAutoIncrement {
/// <summary>
/// Class that parses content of Visual Studio 2002 and 2003 project
/// files.
/// </summary>
public class VS7ProjectFileReader : ProjectFileReader {
public VS7ProjectFileReader(string projectName, string projectFilename, ProjectTypeInfo projectTypeInfo, int level) : base(projectName, projectFilename, projectTypeInfo, level) {
}
public VS7ProjectFileReader(string projectName, string projectFilename, int level) : base(projectName, projectFilename, null, level) {
}
protected override string[] GetIncludedFiles() {
ArrayList files = new ArrayList();
try {
XmlDocument doc = new XmlDocument();
doc.Load(ProjectFilename);
if (doc.DocumentElement.Name != VisualStudioProjectTag)
throw new InvalidFileFormatException(ProjectFilename);
if (m_projectTypeInfo == null) {
XmlNode firstChild = doc.FirstChild.FirstChild;
ResolveProjectType((XmlElement)firstChild);
}
XmlNodeList fileNodes = doc.GetElementsByTagName(FileTag);
for (int i = 0; i < fileNodes.Count; i++) {
XmlNode node = fileNodes[i];
XmlAttribute attr = node.Attributes[RelPathTag];
string filename = FileUtil.CombinePaths(Path.GetDirectoryName(ProjectFilename), attr.Value);
if (File.Exists(filename))
files.Add(filename);
else
m_missingFiles.Add(filename);
}
}
catch (Exception exception) {
Console.WriteLine(exception.ToString());
throw;
}
return (string[])files.ToArray(typeof(string));
}
private void ResolveProjectType(XmlElement projectTypeNode) {
switch (projectTypeNode.Name) {
case "CSHARP":
m_projectTypeInfo = ProjectTypeInfo.CSharpProject;
break;
case "VisualBasic":
m_projectTypeInfo = ProjectTypeInfo.VBProject;
break;
case "VISUALJSHARP":
m_projectTypeInfo = ProjectTypeInfo.VJSharpProject;
break;
default:
Debug.Assert(false, string.Format("Not recognized project type: {0}", projectTypeNode.Name));
break;
}
}
private const string RelPathTag = "RelPath";
private const string VisualStudioProjectTag = "VisualStudioProject";
}
}