-
Notifications
You must be signed in to change notification settings - Fork 2
/
LocalResourcesDialog.cs
453 lines (437 loc) · 13.9 KB
/
LocalResourcesDialog.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
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Windows.Forms;
using Microsoft.Virtualization.Client.InteractiveSession.Resources;
using Microsoft.Virtualization.Client.Interop;
namespace Microsoft.Virtualization.Client.InteractiveSession
{
// Token: 0x0200000C RID: 12
internal partial class LocalResourcesDialog : Form
{
// Token: 0x060000C3 RID: 195 RVA: 0x00008DF4 File Offset: 0x00006FF4
public LocalResourcesDialog(RdpOptions options)
{
this.InitializeComponent();
this.m_ResourceList.BeginUpdate();
this.m_ResourceList.CheckBoxes = true;
this.m_ResourceList.AfterCheck += this.AfterCheck;
this.m_WindowInterceptors = new NativeWindowDoubleClickInterceptor(new List<Control>
{
this.m_ResourceList
});
this.m_ResourceList.Nodes.Add(ConnectionResources.Smartcard);
this.m_ResourceList.Nodes.Add(ConnectionResources.Drives);
this.m_ResourceList.Nodes.Add(ConnectionResources.PnpDevices);
this.m_ResourceList.Nodes.Add(ConnectionResources.UsbDevices);
this.m_UsbNodeExists = true;
this.m_RdpOptions = options;
using (RdpClient rdpClient = new RdpClient())
{
if (rdpClient != null)
{
rdpClient.BeginInit();
base.Controls.Add(rdpClient);
rdpClient.Hide();
rdpClient.EndInit();
IMsRdpClientNonScriptable3 msRdpClientNonScriptable = rdpClient.GetOcx() as IMsRdpClientNonScriptable3;
if (msRdpClientNonScriptable != null)
{
try
{
RdpDriveInfo rdpDriveInfo = new RdpDriveInfo();
IMsRdpDriveCollection driveCollection = msRdpClientNonScriptable.DriveCollection;
for (uint num = 0U; num < driveCollection.DriveCount; num += 1U)
{
IMsRdpDrive msRdpDrive = driveCollection.get_DriveByIndex(num);
TreeNode treeNode = new TreeNode();
treeNode.Name = msRdpDrive.Name[0].ToString().ToLower(CultureInfo.InvariantCulture);
treeNode.Text = rdpDriveInfo.GetDescription(msRdpDrive.Name);
treeNode.Tag = (IMsRdpDriveV2)msRdpDrive;
this.m_ResourceList.Nodes[1].Nodes.Add(treeNode);
}
this.m_ResourceList.Nodes[1].Nodes.Add(RdpOptions.DynamicDrives.ToLower(CultureInfo.InvariantCulture), ConnectionResources.AddedDrives);
IMsRdpDeviceCollection deviceCollection = msRdpClientNonScriptable.DeviceCollection;
if (deviceCollection.DeviceCount > 0U)
{
SortedDictionary<string, IMsRdpDeviceV2> sortedDictionary = new SortedDictionary<string, IMsRdpDeviceV2>(StringComparer.OrdinalIgnoreCase);
SortedDictionary<string, IMsRdpDeviceV2> sortedDictionary2 = new SortedDictionary<string, IMsRdpDeviceV2>(StringComparer.OrdinalIgnoreCase);
for (uint num2 = 0U; num2 < deviceCollection.DeviceCount; num2 += 1U)
{
IMsRdpDevice msRdpDevice = deviceCollection.get_DeviceByIndex(num2);
IMsRdpDeviceV2 msRdpDeviceV = (IMsRdpDeviceV2)msRdpDevice;
string deviceFriendlyName = this.GetDeviceFriendlyName(msRdpDeviceV);
if (!string.IsNullOrEmpty(deviceFriendlyName) && !string.IsNullOrEmpty(msRdpDevice.DeviceInstanceId))
{
if (msRdpDeviceV.IsUSBDevice())
{
sortedDictionary.Add(deviceFriendlyName, msRdpDeviceV);
}
else
{
sortedDictionary2.Add(deviceFriendlyName, msRdpDeviceV);
}
}
}
foreach (KeyValuePair<string, IMsRdpDeviceV2> keyValuePair in sortedDictionary)
{
TreeNode treeNode = new TreeNode();
treeNode.Text = keyValuePair.Key;
treeNode.Tag = keyValuePair.Value;
string text = keyValuePair.Value.DeviceInstanceId().TrimEnd(new char[1]);
treeNode.Name = text.ToLower(CultureInfo.InvariantCulture);
this.m_ResourceList.Nodes[3].Nodes.Add(treeNode);
}
foreach (KeyValuePair<string, IMsRdpDeviceV2> keyValuePair2 in sortedDictionary2)
{
TreeNode treeNode = new TreeNode();
treeNode.Text = keyValuePair2.Key;
treeNode.Tag = keyValuePair2.Value;
string text2 = keyValuePair2.Value.DeviceInstanceId().TrimEnd(new char[1]);
treeNode.Name = text2.ToLower(CultureInfo.InvariantCulture);
this.m_ResourceList.Nodes[2].Nodes.Add(treeNode);
}
}
this.m_ResourceList.Nodes[2].Nodes.Add(RdpOptions.DynamicDevices.ToLower(CultureInfo.InvariantCulture), ConnectionResources.AddedDevices);
}
catch (Exception ex)
{
VMTrace.TraceError("Exception occured while initializing device redirection settings UI.", ex);
}
}
base.Controls.Remove(rdpClient);
}
}
this.m_ResourceList.Nodes[0].Checked = this.m_RdpOptions.SmartCardsRedirection;
this.InitializeDeviceSelection(RdpOptions.RedirectedDeviceType.Drive);
this.InitializeDeviceSelection(RdpOptions.RedirectedDeviceType.Usb);
this.InitializeDeviceSelection(RdpOptions.RedirectedDeviceType.Pnp);
if (this.m_ResourceList.Nodes[3].Nodes.Count == 0)
{
this.m_ResourceList.Nodes.Remove(this.m_ResourceList.Nodes[3]);
this.m_UsbNodeExists = false;
}
this.ExpandResourceTree();
this.m_ResourceList.EndUpdate();
}
// Token: 0x060000C4 RID: 196 RVA: 0x000092D4 File Offset: 0x000074D4
private void InitializeDeviceSelection(RdpOptions.RedirectedDeviceType deviceType)
{
int index;
switch (deviceType)
{
case RdpOptions.RedirectedDeviceType.Drive:
index = 1;
break;
case RdpOptions.RedirectedDeviceType.Usb:
index = 3;
break;
case RdpOptions.RedirectedDeviceType.Pnp:
index = 2;
break;
default:
return;
}
StringCollection redirectedDeviceCollection = this.m_RdpOptions.GetRedirectedDeviceCollection(deviceType);
if (redirectedDeviceCollection != null && redirectedDeviceCollection.Count > 0)
{
if (redirectedDeviceCollection.Contains(RdpOptions.WildcardAllDevices))
{
this.m_ResourceList.Nodes[index].Checked = true;
IEnumerator enumerator = this.m_ResourceList.Nodes[index].Nodes.GetEnumerator();
{
while (enumerator.MoveNext())
{
object obj = enumerator.Current;
((TreeNode)obj).Checked = true;
}
return;
}
}
foreach (object obj2 in this.m_ResourceList.Nodes[index].Nodes)
{
TreeNode treeNode = (TreeNode)obj2;
if (redirectedDeviceCollection.Contains(treeNode.Name))
{
treeNode.Checked = true;
this.ResolveConflict(treeNode);
}
}
}
}
// Token: 0x060000C5 RID: 197 RVA: 0x00009410 File Offset: 0x00007610
private void ExpandResourceTree()
{
foreach (TreeNode treeNode in this.m_ResourceList.Nodes.Cast<TreeNode>())
{
if (!treeNode.Checked)
{
if (treeNode.Nodes.Cast<TreeNode>().Any((TreeNode childNode) => childNode.Checked))
{
treeNode.Expand();
}
}
}
}
// Token: 0x060000C6 RID: 198 RVA: 0x000094A0 File Offset: 0x000076A0
private void AfterCheck(object sender, TreeViewEventArgs e)
{
if (e.Action != TreeViewAction.Unknown)
{
e.Node.TreeView.SelectedNode = e.Node;
if (e.Node.Nodes.Count > 0)
{
IEnumerator enumerator = e.Node.Nodes.GetEnumerator();
{
while (enumerator.MoveNext())
{
object obj = enumerator.Current;
TreeNode treeNode = (TreeNode)obj;
treeNode.Checked = e.Node.Checked;
if (treeNode.Checked)
{
this.ResolveConflict(treeNode);
}
}
return;
}
}
if (e.Node.Checked)
{
this.ResolveConflict(e.Node);
}
this.UpdateParent(e.Node);
}
}
// Token: 0x060000C7 RID: 199 RVA: 0x00009570 File Offset: 0x00007770
private void UpdateParent(TreeNode changedNode)
{
if (changedNode.Parent != null)
{
if (!changedNode.Checked)
{
if (changedNode.Parent.Checked)
{
changedNode.Parent.Checked = false;
return;
}
}
else
{
bool flag = true;
IEnumerator enumerator = changedNode.Parent.Nodes.GetEnumerator();
{
while (enumerator.MoveNext())
{
if (!((TreeNode)enumerator.Current).Checked)
{
flag = false;
break;
}
}
}
if (flag)
{
changedNode.Parent.Checked = true;
}
}
}
}
// Token: 0x060000C8 RID: 200 RVA: 0x0000960C File Offset: 0x0000780C
private void ResolveConflict(TreeNode selectedNode)
{
if (!this.m_UsbNodeExists)
{
return;
}
if (selectedNode.Parent == this.m_ResourceList.Nodes[1])
{
if (selectedNode.Tag == null)
{
return;
}
try
{
IMsRdpDriveV2 msRdpDriveV = selectedNode.Tag as IMsRdpDriveV2;
int num = 1 << (int)msRdpDriveV.DriveLetterIndex();
foreach (object obj in this.m_ResourceList.Nodes[3].Nodes)
{
TreeNode treeNode = (TreeNode)obj;
if (treeNode.Checked)
{
IMsRdpDeviceV2 msRdpDeviceV = treeNode.Tag as IMsRdpDeviceV2;
if (msRdpDeviceV.IsUSBDevice())
{
int num2 = (int)msRdpDeviceV.DriveLetterBitmap();
if ((num & num2) != 0)
{
treeNode.Checked = false;
this.UpdateParent(treeNode);
}
}
}
}
return;
}
catch (Exception ex)
{
VMTrace.TraceError("Exception occured while trying to resolve conflict for the drive.", ex);
return;
}
}
if (selectedNode.Parent == this.m_ResourceList.Nodes[3])
{
try
{
int num2 = (int)(selectedNode.Tag as IMsRdpDeviceV2).DriveLetterBitmap();
foreach (object obj2 in this.m_ResourceList.Nodes[1].Nodes)
{
TreeNode treeNode2 = (TreeNode)obj2;
if (treeNode2.Checked && treeNode2.Tag != null)
{
IMsRdpDriveV2 msRdpDriveV2 = treeNode2.Tag as IMsRdpDriveV2;
int num = 1 << (int)msRdpDriveV2.DriveLetterIndex();
if ((num & num2) != 0)
{
treeNode2.Checked = false;
this.UpdateParent(treeNode2);
}
}
}
}
catch (Exception ex2)
{
VMTrace.TraceError("Exception occured while trying to resolve conflict for the USB device.", ex2);
}
}
}
// Token: 0x060000C9 RID: 201 RVA: 0x00009800 File Offset: 0x00007A00
private void SaveAll()
{
this.m_RdpOptions.SmartCardsRedirection = this.m_ResourceList.Nodes[0].Checked;
StringCollection stringCollection = new StringCollection();
if (!this.m_ResourceList.Nodes[1].Checked)
{
IEnumerator enumerator = this.m_ResourceList.Nodes[1].Nodes.GetEnumerator();
{
while (enumerator.MoveNext())
{
object obj = enumerator.Current;
TreeNode treeNode = (TreeNode)obj;
if (treeNode.Checked && !stringCollection.Contains(treeNode.Name))
{
stringCollection.Add(treeNode.Name);
}
}
goto IL_BA;
}
}
stringCollection.Add(RdpOptions.WildcardAllDevices);
IL_BA:
this.m_RdpOptions.SetRedirectedDeviceCollection(RdpOptions.RedirectedDeviceType.Drive, stringCollection);
StringCollection stringCollection2 = new StringCollection();
StringCollection stringCollection3 = new StringCollection();
if (this.m_UsbNodeExists)
{
if (!this.m_ResourceList.Nodes[3].Checked)
{
IEnumerator enumerator = this.m_ResourceList.Nodes[3].Nodes.GetEnumerator();
{
while (enumerator.MoveNext())
{
object obj2 = enumerator.Current;
TreeNode treeNode2 = (TreeNode)obj2;
if (treeNode2.Checked && !stringCollection2.Contains(treeNode2.Name))
{
stringCollection2.Add(treeNode2.Name);
}
}
goto IL_171;
}
}
stringCollection2.Add(RdpOptions.WildcardAllDevices);
}
IL_171:
if (!this.m_ResourceList.Nodes[2].Checked)
{
IEnumerator enumerator = this.m_ResourceList.Nodes[2].Nodes.GetEnumerator();
while (enumerator.MoveNext())
{
object obj3 = enumerator.Current;
TreeNode treeNode3 = (TreeNode)obj3;
if (treeNode3.Checked && !stringCollection3.Contains(treeNode3.Name))
{
stringCollection3.Add(treeNode3.Name);
}
}
goto IL_204;
}
stringCollection3.Add(RdpOptions.WildcardAllDevices);
IL_204:
this.m_RdpOptions.SetRedirectedDeviceCollection(RdpOptions.RedirectedDeviceType.Usb, stringCollection2);
this.m_RdpOptions.SetRedirectedDeviceCollection(RdpOptions.RedirectedDeviceType.Pnp, stringCollection3);
}
// Token: 0x060000CA RID: 202 RVA: 0x00009A54 File Offset: 0x00007C54
private void m_OkButton_Click(object sender, EventArgs e)
{
this.SaveAll();
}
// Token: 0x060000CB RID: 203 RVA: 0x00009A5C File Offset: 0x00007C5C
private string GetDeviceFriendlyName(IMsRdpDeviceV2 device)
{
try
{
string text = device.FriendlyName();
if (!string.IsNullOrEmpty(text))
{
return text;
}
}
catch
{
}
try
{
string text = device.DeviceText();
if (!string.IsNullOrEmpty(text))
{
return text;
}
}
catch
{
}
try
{
string text = device.DeviceDescription();
if (!string.IsNullOrEmpty(text))
{
return text;
}
}
catch
{
}
return null;
}
// Token: 0x04000096 RID: 150
private const int Smartcard = 0;
// Token: 0x04000097 RID: 151
private const int DriveNode = 1;
// Token: 0x04000098 RID: 152
private const int PnpNode = 2;
// Token: 0x04000099 RID: 153
private const int UsbNode = 3;
// Token: 0x0400009A RID: 154
private RdpOptions m_RdpOptions;
// Token: 0x0400009B RID: 155
private NativeWindowDoubleClickInterceptor m_WindowInterceptors;
// Token: 0x0400009C RID: 156
private bool m_UsbNodeExists;
}
}