2
using System.Collections.Generic;
5
using System.Text.RegularExpressions;
7
namespace FreeImageNET_SFM
11
static private Regex searchPattern = new Regex("#include[ \\t]*\"(.*)\"", RegexOptions.Compiled);
12
static private FileStream fStream = null;
13
static private TextWriter textOut = null;
14
private const string baseFolder = @"..\..\..\Library\";
15
private const string templateName = @"FreeImage.cs.template";
17
static int Main(string[] args)
21
if (!File.Exists(templateName))
23
Console.WriteLine(templateName + " not found."); return 1;
28
fStream = new FileStream(@"FreeImage.cs", FileMode.Create);
32
Console.WriteLine("Unable to create output file."); return 2;
35
textOut = new StreamWriter(fStream);
37
string[] content = File.ReadAllLines(templateName);
39
for (int lineNumber = 0; lineNumber < content.Length; lineNumber++)
41
string line = content[lineNumber].Trim();
42
Match match = searchPattern.Match(line);
44
if (match.Success && match.Groups.Count == 2 && match.Groups[1].Value != null)
46
if (!File.Exists(baseFolder + match.Groups[1].Value))
48
throw new FileNotFoundException(baseFolder + match.Groups[1].Value + " does not exist.");
51
ParseFile(baseFolder + match.Groups[1].Value);
55
textOut.WriteLine(content[lineNumber]);
63
Console.WriteLine(ex.ToString());
64
//Console.WriteLine("Error while parsing.");
77
private static void ParseFile(string fileName)
82
string[] content = File.ReadAllLines(fileName);
84
if (fileName.Contains("AssemblyInfo.cs"))
86
while (content[lineNumber].Trim().StartsWith("using") && lineNumber < content.Length)
94
while (!(content[lineNumber].Trim().StartsWith("namespace")) && lineNumber < content.Length)
101
for (; lineNumber < content.Length; lineNumber++)
103
line = content[lineNumber].Trim();
104
match = searchPattern.Match(line);
106
if (match.Success && match.Groups.Count == 2 && match.Groups[1].Value != null)
108
if (!File.Exists(baseFolder + match.Groups[1].Value))
110
throw new FileNotFoundException(baseFolder + match.Groups[1].Value + " does not exist.");
113
ParseFile(baseFolder + match.Groups[1].Value);
117
textOut.WriteLine(content[lineNumber]);
b'\\ No newline at end of file'