-
Notifications
You must be signed in to change notification settings - Fork 1
/
SolutionParser.cs
122 lines (106 loc) · 2.91 KB
/
SolutionParser.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Diagnostics;
namespace SolutionBuilder
{
internal class SolutionProject
{
public String FullPath;
public String ID;
public List<String> Dependencies = new List<String>();
private String name;
public override string ToString()
{
if (name == null)
{
name = Path.GetFileName(FullPath);
}
return name;
}
}
internal class SolutionParser
{
public SolutionParser(FileInfo solution_file)
{
var map = Parse(solution_file);
Print(map);
}
private void Print(List<SolutionProject> map)
{
foreach (SolutionProject project in map)
{
Console.WriteLine("Project: {0} - {1}", project.ID, project.FullPath);
foreach (String dep in project.Dependencies)
{
int index = dep.IndexOf("3dswin\\src");
Console.WriteLine("\t{0}", dep.Substring(index+11));
}
Console.WriteLine();
}
}
private List<SolutionProject> Parse(FileInfo solutionFile)
{
String[] lines = File.ReadAllLines(solutionFile.FullName);
var comma = new char[]{','};
var quotes = new char[]{'"'};
var equals = new char[]{'='};
var results = new List<SolutionProject>();
var project_map = new Dictionary<String, String>();
SolutionProject current = null;
bool inDependencies = false;
foreach (String line in lines)
{
if (line.Contains("Project(\"{"))
{
String[] splits = line.Split(comma, StringSplitOptions.RemoveEmptyEntries);
Debug.Assert(splits.Length == 3);
var project = new SolutionProject();
project.FullPath = splits[1].Trim().Trim(quotes);
project.ID = splits[2].Trim().Trim(quotes);
results.Add(project);
project_map.Add(project.ID, project.FullPath);
current = project;
continue;
}
if (line.Contains("ProjectSection(ProjectDependencies)"))
{
inDependencies = true;
continue;
}
if (line.Contains("EndProjectSection"))
{
inDependencies = false;
continue;
}
if (String.Compare("EndProject",line) == 0)
{
current = null;
continue;
}
if (inDependencies)
{
String[] splits = line.Split(equals, StringSplitOptions.RemoveEmptyEntries);
String dependentID = splits[0].Trim();
current.Dependencies.Add(dependentID);
}
}
foreach (SolutionProject project in results)
{
var lookupDependents = new List<String>();
foreach (String dependent in project.Dependencies)
{
String dependentName = project_map[dependent];
lookupDependents.Add(dependentName);
}
lookupDependents.Sort();
// now replace it with the updated list
project.Dependencies = lookupDependents;
}
results = results.OrderBy(item => item.FullPath).ToList();
return results;
}
}
}