/*
* Filename: DspFileReader.cs
* Product: Versioning Controlled Build
* Solution: BuildAutoIncrement
* Project: CommandLine
* Description: Class that parses content of DSP (Visual C++ 6.0 project file).
* 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.Text;
using System.Text.RegularExpressions;
namespace BuildAutoIncrement {
/// <summary>
/// Summary description for VS7ProjectFileReader.
/// </summary>
public class DspFileReader : ProjectFileReader {
public DspFileReader(string projectName, string projectFilename, ProjectTypeInfo projectTypeInfo, int level) : base(projectName, projectFilename, projectTypeInfo, level) {
}
protected override string[] GetIncludedFiles() {
Debug.Assert(ProjectFilename != null && File.Exists(ProjectFilename));
ArrayList files = new ArrayList();
try {
string fileContent = FileUtil.ReadTextFile(ProjectFilename);
Regex regex = new Regex(SourcePattern, RegexOptions.Multiline);
foreach (Match match in regex.Matches(fileContent)) {
StringBuilder sb = new StringBuilder(match.Value.TrimEnd(NewLineChars));
sb.Remove(0, SourceString.Length + 1);
//string filename = FileUtil.CombinePaths(FileUtil.ExtractDirectoryName(ProjectFilename), sb.ToString());
string filename = FileUtil.CombinePaths(Path.GetDirectoryName(ProjectFilename), sb.ToString());
Debug.Assert(File.Exists(filename));
files.Add(filename);
}
}
catch (Exception exception) {
Console.WriteLine(exception.ToString());
throw;
}
return (string[])files.ToArray(typeof(string));
}
private const string SourceString = "SOURCE";
private const string SourcePattern = SourceString + "=.+$";
public static readonly char[] NewLineChars = new char[] {'\n', '\r'};
}
}