-
Notifications
You must be signed in to change notification settings - Fork 2
/
uVisionProject.cs
215 lines (171 loc) · 6.6 KB
/
uVisionProject.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace PKStudio.uVision.Project
{
/// <summary>
/// Описывает проект Keil uVision
/// </summary>
class uVisionProject
{
#region properties
private SortedList<int, Target> targetList = new SortedList<int, Target>();
private SortedList<int, Group> groupList = new SortedList<int, Group>();
private SortedList<int, File> fileList = new SortedList<int, File>();
#endregion
public SortedList<int, Target> TargetList { get { return this.targetList; } set { this.targetList = value; } }
public SortedList<int, Group> GroupList { get { return this.groupList; } set { this.groupList = value; } }
public SortedList<int, File> FileList { get { return this.fileList; } set { this.fileList = value; } }
#region Metods
public void AddFile(string path, string group)//, ParamCollection pars)
{
string ext = System.IO.Path.GetExtension(path).Trim();
if (!System.IO.File.Exists(path))
{
if (
(string.Compare(ext, ".lib", StringComparison.InvariantCultureIgnoreCase) != 0)
&&
(string.Compare(ext, ".o", StringComparison.InvariantCultureIgnoreCase) != 0)
&&
(string.Compare(ext, ".obj", StringComparison.InvariantCultureIgnoreCase) != 0)
)
{
throw new Exception("File missing");
}
}
if (this.ContainsFile(path)) return;
File file = new File();
file.Type = File.FILE_TYPE.TEXT_DOCUMENT_FILE;
if (string.Compare(ext, ".cpp", StringComparison.InvariantCultureIgnoreCase) == 0)
file.Type = File.FILE_TYPE.CPP_FILE;
if (string.Compare(ext, ".c", StringComparison.InvariantCultureIgnoreCase) == 0)
file.Type = File.FILE_TYPE.C_FILE;
if (string.Compare(ext, ".h", StringComparison.InvariantCultureIgnoreCase) == 0)
file.Type = File.FILE_TYPE.TEXT_DOCUMENT_FILE;
if (string.Compare(ext, ".s", StringComparison.InvariantCultureIgnoreCase) == 0)
file.Type = File.FILE_TYPE.ASM_FILE;
if (string.Compare(ext, ".a", StringComparison.InvariantCultureIgnoreCase) == 0)
file.Type = File.FILE_TYPE.ASM_FILE;
if (string.Compare(ext, ".lib", StringComparison.InvariantCultureIgnoreCase) == 0)
file.Type = File.FILE_TYPE.LIB_FILE;
if (string.Compare(ext, ".o", StringComparison.InvariantCultureIgnoreCase) == 0)
file.Type = File.FILE_TYPE.OBJ_FILE;
if (string.Compare(ext, ".obj", StringComparison.InvariantCultureIgnoreCase) == 0)
file.Type = File.FILE_TYPE.OBJ_FILE;
file.Path = path;
file.Name = System.IO.Path.GetFileName(path);
file.Group = this.AddGroup(group);
file.Num = this.FileList.Count + 1;
this.FileList.Add(file.Num, file);
}
public bool ContainsFile(string path)
{
foreach (File f in this.FileList.Values)
{
if (String.Compare(Path.GetFullPath(path).TrimEnd('\\'), Path.GetFullPath(f.Path).TrimEnd('\\'), StringComparison.InvariantCultureIgnoreCase) == 0) return true;
}
return false;
}
private Group AddGroup(string name)
{
if (!this.ContainsGroup(name))
{
Group gt = new Group(name, this.GroupList.Count + 1);
this.GroupList.Add(gt.Num, gt);
return gt;
}
else
{
return this.FindGroup(name);
}
}
public bool ContainsGroup(string name)
{
foreach (Group g in this.GroupList.Values)
{
if (g.Name == name) return true;
}
return false;
}
public Group FindGroup(string name)
{
if (!ContainsGroup(name)) return null;
foreach (Group g in this.GroupList.Values)
{
if (g.Name == name) return g;
}
return null;
}
public File FindFile(string path)
{
foreach (File file in this.FileList.Values)
{
if (file.Path.Contains(path)) return file;
}
return null;
}
public void SortGroups()
{
List<Group> tmplist = new List<Group>(this.GroupList.Values);
tmplist.Sort();
this.GroupList = new SortedList<int, Group>();
foreach (Group g in tmplist)
{
g.Num = GroupList.Count+1;
this.GroupList.Add(g.Num, g);
}
}
#region strings
public List<string> GetGroupsStrings()
{
List<string> result = new List<string>();
foreach (Group group in this.GroupList.Values)
{
result.Add("Group (" + group.Name + ")");
}
result.Add("");
return result;
}
public List<string> GetFilesStrings()
{
List<string> result = new List<string>();
foreach (File file in this.FileList.Values)
{
result.Add(file.GetFileString());
}
result.Add("");
return result;
}
public List<string> GetAllProjectStrings()
{
List<string> result = new List<string>();
result.Add("### uVision2 Project, (C) Keil Software");
result.Add("### Do not modify !");
result.Add("");
foreach (Target t in this.TargetList.Values)
{
result.Add(t.GetTargetString());
}
result.Add("");
result.AddRange(this.GetGroupsStrings());
result.Add("");
result.AddRange(this.GetFilesStrings());
result.Add("");
foreach (Target t in this.TargetList.Values)
{
result.AddRange(t.GetSolutionOptionsStrings());
result.Add("");
}
foreach (Target t in this.TargetList.Values)
{
result.AddRange(t.GetFilesOptionsStrings());
}
result.Add("");
return result;
}
#endregion
#endregion
}
}