forked from madrang/MFDebugger-Mono
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlatformInfo.cs
352 lines (291 loc) · 11.5 KB
/
PlatformInfo.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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
// Portions Copyright (c) Secret Labs LLC.
using System;
using System.IO;
using System.Text;
using System.Diagnostics;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Reflection;
using Microsoft.Win32;
using Microsoft.SPOT.Tasks;
namespace Microsoft.SPOT.Debugger
{
public class PlatformInfo
{
public class PortDefinition_PeristableEmulator : PortDefinition
{
Emulator m_emulator;
public PortDefinition_PeristableEmulator(Emulator emulator)
: base(emulator.name, null)
{
m_emulator = emulator;
}
public override string PersistName
{
get
{
return m_emulator.persistableName;
}
}
public override Stream Open()
{
throw new NotSupportedException();
}
public override string Port
{
get { throw new NotSupportedException(); }
}
public override Stream CreateStream()
{
throw new NotSupportedException();
}
}
public class Emulator
{
public string persistableName;
public string name;
public string application;
public string additionalOptions;
public string config;
public bool legacyCommandLine;
public Emulator Clone()
{
return (Emulator)this.MemberwiseClone();
}
}
class RegistryKeys
{
public const string AssemblyFoldersEx = "AssemblyFoldersEx";
public const string Emulators = "Emulators";
}
class RegistryValues
{
public const string Default = "";
public const string EmulatorConfig = "Config";
public const string EmulatorName = "Name";
public const string EmulatorOptions = "AdditionalCommandLineOptions";
public const string EmulatorPath = "Path";
public const string EmulatorLegacyCommandLine = "LegacyCommandLine";
}
string m_runtimeVersion;
string m_runtimeVersionInstalled; //The best match registration
string m_assemblyFoldersList;
string[] m_assemblyFolders;
string m_frameworkAssembliesPath;
string m_frameworkToolsPath;
Emulator[] m_emulators;
public PlatformInfo(string runtimeVersion)
{
if (!string.IsNullOrEmpty(runtimeVersion))
{
//Version ver = Version.Parse(runtimeVersion.TrimStart('v'));
Version ver = ParseVersion(runtimeVersion.TrimStart('v'));
m_runtimeVersion = "v" + ver.ToString(2);
}
else
{
m_runtimeVersion = "v4.1";
}
}
// NOTE: this is temporary code, for compatibility with .NET 3.5; it is currently untested.
private Version ParseVersion(string version)
{
int majorVersion = 0;
int minorVersion = 0;
string versionString = version;
if (versionString.IndexOf('.') >= 0)
{
majorVersion = int.Parse(versionString.Substring(0, versionString.IndexOf('.')));
versionString = versionString.Substring(versionString.IndexOf('.') + 1);
if (versionString.IndexOf('.') >= 0 )
{
minorVersion = int.Parse(versionString.Substring(0, versionString.IndexOf('.')));
}
else
{
minorVersion = int.Parse(versionString);
}
}
return new Version(majorVersion, minorVersion);
}
private void AppendEmulators(List<Emulator> emulators, RegistryKey topLevelKey)
{
using (RegistryKey key = GetDeviceFrameworkPaths.OpenDeviceFrameworkKey(topLevelKey, m_runtimeVersionInstalled, RegistryKeys.Emulators))
{
if (key != null)
{
string[] subkeyNames = key.GetSubKeyNames();
for (int iSubkey = 0; iSubkey < subkeyNames.Length; iSubkey++)
{
string subkeyName = subkeyNames[iSubkey];
using (RegistryKey subkey = key.OpenSubKey(subkeyName))
{
string path = subkey.GetValue(RegistryValues.EmulatorPath) as string;
string name = subkey.GetValue(RegistryValues.EmulatorName) as string;
string config = subkey.GetValue(RegistryValues.EmulatorConfig) as string;
string options = subkey.GetValue(RegistryValues.EmulatorOptions) as string;
int? legacyCommandLine = subkey.GetValue(RegistryValues.EmulatorLegacyCommandLine) as int?;
bool fLegacyCommandLine;
string persistableName = subkeyName;
if (string.IsNullOrEmpty(name))
{
name = persistableName;
}
fLegacyCommandLine = legacyCommandLine != null && legacyCommandLine.Value != 0;
Emulator emulator = new Emulator();
emulator.additionalOptions = options;
emulator.application = path;
emulator.config = config;
emulator.legacyCommandLine = fLegacyCommandLine;
emulator.name = name;
emulator.persistableName = persistableName;
emulators.Add(emulator);
}
}
}
}
}
public Emulator[] Emulators
{
get
{
if (m_emulators == null)
{
EnsureInitialization();
List<Emulator> emulators = new List<Emulator>();
AppendEmulators(emulators, Registry.LocalMachine);
AppendEmulators(emulators, Registry.CurrentUser);
m_emulators = emulators.ToArray();
//Add special for PRG_VW???
}
return m_emulators;
}
}
public Emulator FindEmulator(string name)
{
Emulator[] emulators = this.Emulators;
Emulator emulator = null;
for (int i = 0; i < emulators.Length; i++)
{
Emulator emulatorT = emulators[i];
if (string.Equals(name, emulatorT.persistableName))
{
emulator = emulatorT;
break;
}
}
return emulator;
}
private void EnsureInitialization(string version)
{
GetDeviceFrameworkPaths deviceFrameworkPaths = new GetDeviceFrameworkPaths();
while (true)
{
deviceFrameworkPaths.RuntimeVersion = version;
if (deviceFrameworkPaths.Execute())
{
m_frameworkAssembliesPath = deviceFrameworkPaths.FrameworkAssembliesPath;
m_frameworkToolsPath = deviceFrameworkPaths.ToolsPath;
m_runtimeVersionInstalled = version;
break;
}
Debug.Assert(version[0] == 'v');
//remove the build number from the version, and try again
int iDot = version.LastIndexOf('.');
if (iDot < 0)
break;
version = version.Substring(0, iDot);
}
}
private void EnsureInitialization()
{
if (m_frameworkAssembliesPath == null)
{
EnsureInitialization(m_runtimeVersion);
}
}
public string FrameworkAssembliesPath
{
get
{
EnsureInitialization();
return m_frameworkAssembliesPath;
}
}
public string FrameworkToolsPath
{
get
{
EnsureInitialization();
return m_frameworkToolsPath;
}
}
private void AppendFolder(List<string> folders, string folder)
{
if (!string.IsNullOrEmpty(folder) && Directory.Exists(folder))
{
folders.Add(folder);
}
}
public string AssemblyFoldersList
{
get
{
if (m_assemblyFoldersList == null)
{
EnsureInitialization();
string[] assemblyFolders = this.AssemblyFolders;
StringBuilder sb = new StringBuilder(512);
for (int iFolder = 0; iFolder < assemblyFolders.Length; iFolder++)
{
if (iFolder > 0)
{
sb.Append(';');
}
string folder = assemblyFolders[iFolder];
sb.Append(folder);
}
m_assemblyFoldersList = sb.ToString();
}
return m_assemblyFoldersList;
}
}
private void AppendFolders(List<string> folders, RegistryKey topLevelKey)
{
//Add the AssemblyFoldersEx registry entries
//HKCU settings as well? Currently just using HKLM
using (RegistryKey key = GetDeviceFrameworkPaths.OpenDeviceFrameworkKey(topLevelKey, m_runtimeVersionInstalled, RegistryKeys.AssemblyFoldersEx))
{
if (key != null)
{
string[] subkeys = key.GetSubKeyNames();
for (int iSubKey = 0; iSubKey < subkeys.Length; iSubKey++)
{
using (RegistryKey subkey = key.OpenSubKey( subkeys[iSubKey] ))
{
AppendFolder( folders, (string)subkey.GetValue( RegistryValues.Default ) );
}
}
}
}
}
public string[] AssemblyFolders
{
get
{
if (m_assemblyFolders == null)
{
EnsureInitialization();
List<string> folders = new List<string>();
//Add the framework assemblies
AppendFolder(folders, this.FrameworkAssembliesPath);
AppendFolders(folders, Registry.LocalMachine);
AppendFolders(folders, Registry.CurrentUser);
m_assemblyFolders = folders.ToArray();
}
return m_assemblyFolders;
}
}
}
}