SolutionFramework /SolutionFramework/ControlProviders/ToolboxInstaller/Microsoft/VisualStudio/IDE/ToolboxControlsInstaller/ToolboxInstallerPackage.cs

Language C# Lines 942
MD5 Hash 8b1d4fcda5ff87114bef2d438365bb5f Estimated Cost $22,751 (why?)
Repository https://SolutionFramework.svn.codeplex.com/svn View Raw File
  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
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
namespace Microsoft.VisualStudio.IDE.ToolboxControlsInstaller
{
    using Microsoft.MetadataReader;
    using Microsoft.VisualStudio.OLE.Interop;
    using Microsoft.VisualStudio.Shell;
    using Microsoft.VisualStudio.Shell.Interop;
    using Microsoft.VisualStudio.Toolbox;
    using Microsoft.Win32;
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.Drawing.Design;
    using System.Globalization;
    using System.IO;
    using System.Linq;
    using System.Reflection;
    using System.Runtime.CompilerServices;
    using System.Runtime.InteropServices;
    using System.Runtime.Versioning;
    using System.Security.Cryptography;
    using System.Text;
    using System.Threading;
    using System.Windows;

    public class ToolboxInstallerPackage : Package, IVsToolboxDataProvider
    {
        private List<RegisteredAssembly> _cachedAssemblies;
        private List<RegisteredAssembly> _registeredAssemblies;
        private static readonly int _silverlightFormat = DataFormats.GetDataFormat("CF_WINFXSILVERLIGHT_TOOL").Id;
        private const string _silverlightFormatString = "CF_WINFXSILVERLIGHT_TOOL";
        private const string DefaultCategory = "General";
        private const string DefaultWPFOrSilverlightCategory = "All Controls";
        private static SHA512 hashAlgorithm = SHA512.Create();
        private const string RegKey_Toolbox = "Toolbox";
        private const string ToolboxControlsInstaller = "ToolboxControlsInstaller";
        private const string ToolboxControlsInstallerCache = "ToolboxControlsInstallerCache";
        private const string ValueName_RegistryHash = "RegistryHash";

        public ToolboxInstallerPackage()
        {
            base.ToolboxInitialized += new EventHandler(this.PackageToolbox_ToolboxInitialized);
            base.ToolboxUpgraded += new EventHandler(this.PackageToolbox_ToolboxUpgraded);
        }

        private List<RegisteredAssembly> AddToolboxItems(List<RegisteredAssembly> assembliesToAddToToolbox)
        {
            if (assembliesToAddToToolbox.Count == 0)
            {
                return new List<RegisteredAssembly>();
            }
            List<RegisteredAssembly> list = new List<RegisteredAssembly>();
            IVsActivityLog log = base.GetService(typeof(SVsActivityLog)) as IVsActivityLog;
            log.LogEntry(3, this.ToString(), "Toolbox Controls Installer Package attempting to add Toolbox items");
            IToolboxService service = (IToolboxService) base.GetService(typeof(IToolboxService));
            ToolboxService.UnloadToolboxItems();
            XamlAssembly.UnloadAppDomain();
            List<string> list2 = new List<string>();
            List<string> list3 = new List<string>();
            foreach (RegisteredAssembly assembly in assembliesToAddToToolbox)
            {
                bool flag = false;
                try
                {
                    if (assembly is XamlAssembly)
                    {
                        try
                        {
                            if (list3.Contains(assembly.AssemblyName.Name))
                            {
                                XamlAssembly.UnloadAppDomain();
                                list3.Clear();
                            }
                            list3.Add(assembly.AssemblyName.Name);
                            flag = assembly.AddItemsToToolbox(this, this.ApplicationRegistryRoot);
                            goto Label_03FF;
                        }
                        catch (InvalidOperationException)
                        {
                            log.LogEntry(2, this.ToString(), string.Format("Error adding toolbox items from assembly {0}.  WPF toolbox items might not be supported by this version of Visual Studio.", assembly.AssemblyName.FullName));
                            continue;
                        }
                    }
                    log.LogEntry(3, this.ToString(), string.Format(CultureInfo.CurrentCulture, "Attempting to get Toolbox items from Assembly {0}", new object[] { assembly.AssemblyName.FullName }));
                    if (list2.Contains(assembly.AssemblyName.Name))
                    {
                        ToolboxService.UnloadToolboxItems();
                        list2.Clear();
                    }
                    list2.Add(assembly.AssemblyName.Name);
                    ICollection toolboxItems = ToolboxService.GetToolboxItems(assembly.AssemblyName, true);
                    if (toolboxItems.Count == 0)
                    {
                        log.LogEntry(2, this.ToString(), string.Format(CultureInfo.CurrentCulture, "Assembly {0} did not contain any toolbox items. Please go to documentation for ToolboxService.GetToolboxItems for a list of toolbox item requirements.", new object[] { assembly.AssemblyName.FullName }));
                    }
                    foreach (ToolboxItem item in toolboxItems)
                    {
                        log.LogEntry(3, this.ToString(), string.Format(CultureInfo.CurrentCulture, "Attempting to add Toolbox item {0}", new object[] { item.TypeName }));
                        string defaultCategory = assembly.DefaultCategory;
                        if (assembly.ToolboxItemCategories.ContainsKey(item.TypeName))
                        {
                            defaultCategory = assembly.ToolboxItemCategories[item.TypeName];
                        }
                        if (string.IsNullOrEmpty(defaultCategory))
                        {
                            log.LogEntry(2, this.ToString(), string.Format(CultureInfo.CurrentCulture, "No category set for toolbox item {0}. Consider setting a default category on the assembly registration or create a Categories key to specify per-item categories.", new object[] { item.TypeName }));
                            defaultCategory = "General";
                        }
                        if (string.IsNullOrEmpty(assembly.TargetFramework))
                        {
                            service.AddToolboxItem(item, defaultCategory);
                        }
                        else
                        {
                            IVsToolboxService service2 = service as IVsToolboxService;
                            FrameworkName name = null;
                            try
                            {
                                name = new FrameworkName(assembly.TargetFramework);
                            }
                            catch (ArgumentException)
                            {
                                log.LogEntry(2, this.ToString(), string.Format(CultureInfo.CurrentCulture, "Invalid framework {0} specified for toolbox item {1}. The item will be added without multi-targeting metadata.", new object[] { assembly.TargetFramework, item.TypeName }));
                            }
                            if (name == null)
                            {
                                service.AddToolboxItem(item, defaultCategory);
                            }
                            else
                            {
                                service2.AddToolboxItem(item, defaultCategory, new FrameworkName[] { name }, base.GetType().GUID);
                            }
                        }
                        flag = true;
                        assembly.RegisteredControls.Add(new DotNetControl(item.TypeName, item.DisplayName, item.Description));
                    }
                }
                catch (ArgumentException exception)
                {
                    log.LogEntry(1, this.ToString(), string.Format(CultureInfo.CurrentCulture, "{0}. Did you remember to add this assembly to the GAC or add a string value named CodeBase?", new object[] { exception.Message }));
                }
                catch (FileNotFoundException exception2)
                {
                    log.LogEntry(1, this.ToString(), exception2.Message);
                }
                catch (FileLoadException exception3)
                {
                    log.LogEntry(1, this.ToString(), exception3.Message);
                }
                catch (BadImageFormatException exception4)
                {
                    log.LogEntry(1, this.ToString(), exception4.Message);
                }
            Label_03FF:
                if (flag)
                {
                    list.Add(assembly);
                }
            }
            ToolboxService.UnloadToolboxItems();
            XamlAssembly.UnloadAppDomain();
            return list;
        }

        private void AppendRegistryContents(RegistryKey root, StringBuilder result)
        {
            result.Append(root.Name.Split(new char[] { '\\' }).Last<string>());
            foreach (string str in root.GetValueNames())
            {
                result.Append(str);
                result.Append(root.GetValue(str).ToString());
            }
            foreach (string str2 in root.GetSubKeyNames())
            {
                this.AppendRegistryContents(root.OpenSubKey(str2), result);
            }
        }

        private void ClearCache()
        {
            try
            {
                this.UserRegistryRoot.DeleteSubKeyTree("ToolboxControlsInstallerCache");
            }
            catch (ArgumentException)
            {
            }
        }

        private RegisteredAssembly CreateRegisteredAssembly(RegistryKey key, string keyName)
        {
            if (!string.IsNullOrEmpty(key.GetValue("SilverlightControls") as string))
            {
                return new SilverlightAssembly(new AssemblyName(keyName));
            }
            if (!string.IsNullOrEmpty(key.GetValue("WPFControls") as string))
            {
                return new WPFAssembly(new AssemblyName(keyName));
            }
            return new DotNetAssembly(new AssemblyName(keyName));
        }

        private IEnumerable<AssemblyFolder> GetAllAssemblyFoldersEx()
        {
            Action<string> log = null;
            foreach (string iteratorVariable0 in this.GetInstalledFrameworks())
            {
                foreach (RegistryKey iteratorVariable1 in this.GetAssemblyFoldersExKeys(iteratorVariable0))
                {
                    foreach (string iteratorVariable2 in iteratorVariable1.GetSubKeyNames())
                    {
                        using (RegistryKey iteratorVariable3 = iteratorVariable1.OpenSubKey(iteratorVariable2))
                        {
                            using (RegistryKey iteratorVariable4 = this.HighestServicePack(iteratorVariable3))
                            {
                                using (RegistryKey iteratorVariable5 = iteratorVariable4.OpenSubKey("Toolbox") ?? iteratorVariable3.OpenSubKey("Toolbox"))
                                {
                                    if (iteratorVariable5 != null)
                                    {
                                        byte[] first = this.RegistryTreeHash(iteratorVariable3);
                                        CachedAssemblyFolder cache = CachedAssemblyFolder.GetCache(this.UserRegistryRoot, iteratorVariable3.Name);
                                        if ((cache != null) && first.SequenceEqual<byte>(cache.RegistryHash))
                                        {
                                            yield return cache;
                                        }
                                        else
                                        {
                                            if (log == null)
                                            {
                                                log = delegate (string errMsg) {
                                                    (base.GetService(typeof(SVsActivityLog)) as IVsActivityLog).LogEntry(1, this.ToString(), errMsg);
                                                };
                                            }
                                            NonCachedAssemblyFolder iteratorVariable8 = new NonCachedAssemblyFolder(iteratorVariable0, iteratorVariable4.GetValue("") as string, iteratorVariable5.GetValue("TabName") as string, log);
                                            iteratorVariable8.Cache(this.UserRegistryRoot, iteratorVariable3.Name, first);
                                            yield return iteratorVariable8;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

        private IEnumerable<RegistryKey> GetAssemblyFoldersExKeys(string tfm)
        {
            return new AssemblyFoldersExKeys(-2) { __this = this, __tfm = tfm };
        }

        private List<RegisteredAssembly> GetCachedAssemblies()
        {
            if (this._cachedAssemblies == null)
            {
                this._cachedAssemblies = new List<RegisteredAssembly>();
                RegistryKey key = this.UserRegistryRoot.OpenSubKey("ToolboxControlsInstallerCache");
                foreach (string str in key.GetSubKeyNames())
                {
                    RegisteredAssembly item = new RegisteredAssembly(new AssemblyName(str));
                    this._cachedAssemblies.Add(item);
                    RegistryKey key2 = key.OpenSubKey(str);
                    item.RegistryHash = key2.GetValue("RegistryHash") as byte[];
                    foreach (string str2 in key2.GetSubKeyNames())
                    {
                        RegistryKey key3 = key2.OpenSubKey(str2);
                        if (key3.GetValue(SilverlightControl.StaticRegDescriptorValue) != null)
                        {
                            item.RegisteredControls.Add(new SilverlightControl(str2, this.GetRegValues(key3)));
                        }
                        else if (key3.GetValue(WPFControl.StaticRegDescriptorValue) != null)
                        {
                            item.RegisteredControls.Add(new WPFControl(str2, this.GetRegValues(key3)));
                        }
                        else
                        {
                            string displayName = key3.GetValue(null).ToString();
                            string description = key3.GetValue("Description").ToString();
                            item.RegisteredControls.Add(new DotNetControl(str2, displayName, description));
                        }
                    }
                }
            }
            return this._cachedAssemblies;
        }

        private IEnumerable<string> GetInstalledFrameworks()
        {
            Array prgSupportedFrameworks = null;
            (base.GetService(typeof(Microsoft.VisualStudio.Shell.Interop.SVsFrameworkMultiTargeting)) as Microsoft.VisualStudio.Shell.Interop.IVsFrameworkMultiTargeting).GetSupportedFrameworks(out prgSupportedFrameworks);
            return (from s in (string[]) prgSupportedFrameworks
                where string.IsNullOrEmpty(new FrameworkName(s).Profile)
                select s);
        }

        private List<RegisteredAssembly> GetRegisteredAssemblies()
        {
            if (this._registeredAssemblies == null)
            {
                this._registeredAssemblies = new List<RegisteredAssembly>();
                foreach (RegistryKey key2 in new List<RegistryKey> { this.UserRegistryRoot, this.ApplicationRegistryRoot })
                {
                    RegistryKey key = key2.OpenSubKey("ToolboxControlsInstaller");
                    if (key != null)
                    {
                        foreach (string str in key.GetSubKeyNames())
                        {
                            RegistryKey key3 = key.OpenSubKey(str);
                            RegisteredAssembly item = this.CreateRegisteredAssembly(key3, str);
                            item.AssemblyName.CodeBase = key3.GetValue("Codebase") as string;
                            item.DefaultCategory = key3.GetValue("") as string;
                            item.TargetFramework = key3.GetValue("TargetFramework") as string;
                            item.RegistryHash = this.RegistryTreeHash(key3);
                            RegistryKey key4 = key3.OpenSubKey("ItemCategories");
                            if (key4 != null)
                            {
                                foreach (string str2 in key4.GetValueNames())
                                {
                                    item.ToolboxItemCategories.Add(str2, key4.GetValue(str2).ToString());
                                }
                            }
                            if (!this._registeredAssemblies.Contains(item))
                            {
                                this._registeredAssemblies.Add(item);
                            }
                        }
                    }
                }
                foreach (AssemblyFolder folder in this.GetAllAssemblyFoldersEx())
                {
                    foreach (RegisteredAssembly assembly2 in folder.GetAssemblies())
                    {
                        if (!this._registeredAssemblies.Contains(assembly2))
                        {
                            this._registeredAssemblies.Add(assembly2);
                        }
                    }
                }
            }
            return this._registeredAssemblies;
        }

        private List<RegisteredAssembly> GetRegisteredNotCachedAssemblies()
        {
            List<RegisteredAssembly> cachedAssemblies = this.GetCachedAssemblies();
            return (from registeredAssembly in this.GetRegisteredAssemblies()
                where !cachedAssemblies.Contains(registeredAssembly)
                select registeredAssembly).ToList<RegisteredAssembly>();
        }

        private IDictionary GetRegValues(RegistryKey key)
        {
            IDictionary dictionary = new Hashtable();
            foreach (string str in key.GetValueNames())
            {
                dictionary.Add(str, key.GetValue(str).ToString());
            }
            return dictionary;
        }

        private List<RegisteredAssembly> GetRemovedAssemblies()
        {
            List<RegisteredAssembly> registeredAssemblies = this.GetRegisteredAssemblies();
            return (from cachedAssembly in this.GetCachedAssemblies()
                where !registeredAssemblies.Contains(cachedAssembly)
                select cachedAssembly).ToList<RegisteredAssembly>();
        }

        private IEnumerable<Microsoft.VisualStudio.OLE.Interop.IDataObject> GetToolboxDataObjects(IVsToolbox2 toolboxSvc)
        {
            new List<Microsoft.VisualStudio.OLE.Interop.IDataObject>();
            IEnumToolboxItems pEnum = null;
            toolboxSvc.EnumItems(null, out pEnum);
            Microsoft.VisualStudio.OLE.Interop.IDataObject[] rgelt = new Microsoft.VisualStudio.OLE.Interop.IDataObject[1];
            uint pceltFetched = 0;
            pEnum.Reset();
            while (true)
            {
                if ((pEnum.Next(1, rgelt, out pceltFetched) != 0) || (pceltFetched != 1))
                {
                    yield break;
                }
                yield return rgelt[0];
            }
        }

        private static bool HasReference(Assembly assembly, string referenceName)
        {
            return assembly.GetReferencedAssemblies().Any<AssemblyName>(n => (string.Compare(n.Name, referenceName, StringComparison.OrdinalIgnoreCase) == 0));
        }

        private RegistryKey HighestServicePack(RegistryKey assemblyFolderKey)
        {
            foreach (string str in from s in assemblyFolderKey.GetSubKeyNames()
                orderby s descending
                select s)
            {
                if (str != "Toolbox")
                {
                    RegistryKey key = assemblyFolderKey.OpenSubKey(str);
                    if (!string.IsNullOrEmpty(key.GetValue("") as string))
                    {
                        return key;
                    }
                }
            }
            return assemblyFolderKey;
        }

        int IVsToolboxDataProvider.FileDropped(string fileName, IVsHierarchy pHierSource, out int accepted)
        {
            accepted = 0;
            //using (DefaultUniverse universe = new DefaultUniverse())
            //{
            //    Assembly assembly = universe.LoadAssemblyFromFile(fileName);
            //    RegisteredAssembly assembly2 = null;
            //    if (HasReference(assembly, "PresentationFramework"))
            //    {
            //        assembly2 = new WPFAssembly(assembly.GetName());
            //        IVsTargetFrameworkAssemblies service = base.GetService(typeof(SVsTargetFrameworkAssemblies)) as IVsTargetFrameworkAssemblies;
            //        uint pTargetFrameworkVersion = 0;
            //        service.GetRequiredTargetFrameworkVersionFromDependency(fileName, out pTargetFrameworkVersion);
            //        if (pTargetFrameworkVersion != 0)
            //        {
            //            assembly2.TargetFramework = ".NETFramework,Version=v" + ((pTargetFrameworkVersion >> 0x10)).ToString() + "." + ((pTargetFrameworkVersion & 0xffff)).ToString();
            //        }
            //    }
            //    else if (HasReference(assembly, "System.Windows"))
            //    {
            //        assembly2 = new SilverlightAssembly(assembly.GetName());
            //    }
            //    if (assembly2 != null)
            //    {
            //        List<RegisteredAssembly> assembliesToAddToToolbox = new List<RegisteredAssembly> {
            //            assembly2
            //        };
            //        if (this.AddToolboxItems(assembliesToAddToToolbox).Count > 0)
            //        {
            //            accepted = 1;
            //        }
            //    }
            //}
            return 0;
        }

        int IVsToolboxDataProvider.GetItemInfo(Microsoft.VisualStudio.OLE.Interop.IDataObject pDO, TBXITEMINFO[] pItemInfo)
        {
            return -2147467263;
        }

        int IVsToolboxDataProvider.IsDataSupported(FORMATETC[] fetc, STGMEDIUM[] stg)
        {
            return -2147467263;
        }

        int IVsToolboxDataProvider.IsSupported(Microsoft.VisualStudio.OLE.Interop.IDataObject pDO)
        {
            return -2147467263;
        }

        public void ToolboxInitialize()
        {
            //this.ClearCache();
            this.PackageToolbox_ToolboxUpgraded(null, EventArgs.Empty);
        }

        private void PackageToolbox_ToolboxInitialized(object sender, EventArgs e)
        {
            this.ClearCache();
            this.PackageToolbox_ToolboxUpgraded(sender, e);
        }

        private void PackageToolbox_ToolboxUpgraded(object sender, EventArgs e)
        {
            //if (this.RegistryUpdated())
            //{
                List<RegisteredAssembly> registeredNotCachedAssemblies = this.GetRegisteredNotCachedAssemblies();
                List<RegisteredAssembly> removedAssemblies = this.GetRemovedAssemblies();
                this.RemoveToolboxItems(removedAssemblies);
                List<RegisteredAssembly> installedAssemblies = this.AddToolboxItems(registeredNotCachedAssemblies);
                this.UpdateCache(installedAssemblies, removedAssemblies);
            //}
        }

        private byte[] RegistryTreeHash(RegistryKey root)
        {
            StringBuilder result = new StringBuilder();
            this.AppendRegistryContents(root, result);
            return hashAlgorithm.ComputeHash(Encoding.UTF8.GetBytes(result.ToString()));
        }

        private bool RegistryUpdated()
        {
            byte[] first = new byte[0];
            using (RegistryKey key = this.UserRegistryRoot.OpenSubKey("ToolboxControlsInstallerCache"))
            {
                if (key != null)
                {
                    byte[] buffer2 = key.GetValue("RegistryHash") as byte[];
                    if (buffer2 != null)
                    {
                        first = buffer2;
                    }
                }
            }
            StringBuilder result = new StringBuilder();
            foreach (RegistryKey key2 in new RegistryKey[] { this.ApplicationRegistryRoot, this.UserRegistryRoot })
            {
                using (RegistryKey key3 = key2.OpenSubKey("ToolboxControlsInstaller"))
                {
                    if (key3 != null)
                    {
                        this.AppendRegistryContents(key3, result);
                    }
                }
            }
            foreach (string str in this.GetInstalledFrameworks())
            {
                foreach (RegistryKey key4 in this.GetAssemblyFoldersExKeys(str))
                {
                    this.AppendRegistryContents(key4, result);
                }
            }
            byte[] second = hashAlgorithm.ComputeHash(Encoding.UTF8.GetBytes(result.ToString()));
            if (first.SequenceEqual<byte>(second))
            {
                return false;
            }
            using (RegistryKey key5 = this.UserRegistryRoot.CreateSubKey("ToolboxControlsInstallerCache"))
            {
                key5.SetValue("RegistryHash", second);
            }
            return true;
        }

        private void RemoveToolboxItems(List<RegisteredAssembly> assembliesWithComponentToRemove)
        {
            if (assembliesWithComponentToRemove.Count != 0)
            {
                List<ToolboxItem> list = new List<ToolboxItem>();
                List<Microsoft.VisualStudio.OLE.Interop.IDataObject> list2 = new List<Microsoft.VisualStudio.OLE.Interop.IDataObject>();
                IVsToolbox2 toolboxSvc = base.GetService(typeof(SVsToolbox)) as IVsToolbox2;
                IToolboxService service = (IToolboxService) base.GetService(typeof(IToolboxService));
                if ((service != null) && (toolboxSvc != null))
                {
                    ToolboxItemCollection toolboxItems = null;
                    foreach (RegisteredAssembly assembly in assembliesWithComponentToRemove)
                    {
                        foreach (RegisteredControl control in assembly.RegisteredControls)
                        {
                            DictionaryControl control2 = control as DictionaryControl;
                            if (control2 != null)
                            {
                                foreach (Microsoft.VisualStudio.OLE.Interop.IDataObject obj2 in this.GetToolboxDataObjects(toolboxSvc))
                                {
                                    if (control2.IsEqualTo(obj2))
                                    {
                                        list2.Add(obj2);
                                    }
                                }
                            }
                            else
                            {
                                DotNetControl control3 = control as DotNetControl;
                                if (control3 != null)
                                {
                                    if (toolboxItems == null)
                                    {
                                        toolboxItems = service.GetToolboxItems();
                                    }
                                    foreach (ToolboxItem item in toolboxItems)
                                    {
                                        if (((item.TypeName == control3.TypeName) && (item.DisplayName == control3.DisplayName)) && (item.AssemblyName.FullName == assembly.AssemblyName.FullName))
                                        {
                                            list.Add(item);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    foreach (ToolboxItem item2 in list)
                    {
                        service.RemoveToolboxItem(item2);
                    }
                    foreach (Microsoft.VisualStudio.OLE.Interop.IDataObject obj3 in list2)
                    {
                        toolboxSvc.RemoveItem(obj3);
                    }
                }
            }
        }

        private void UpdateCache(List<RegisteredAssembly> installedAssemblies, List<RegisteredAssembly> uninstalledAssemblies)
        {
            RegistryKey key = this.UserRegistryRoot.CreateSubKey("ToolboxControlsInstallerCache");
            foreach (RegisteredAssembly assembly in uninstalledAssemblies)
            {
                try
                {
                    key.DeleteSubKeyTree(assembly.AssemblyName.FullName);
                }
                catch (ArgumentException)
                {
                }
            }
            foreach (RegisteredAssembly assembly2 in installedAssemblies)
            {
                if (key.OpenSubKey(assembly2.AssemblyName.FullName) != null)
                {
                    throw new ArgumentException("Assembly has to be uninstalled before it can be installed");
                }
                RegistryKey key2 = key.CreateSubKey(assembly2.AssemblyName.FullName);
                key2.SetValue("RegistryHash", assembly2.RegistryHash);
                foreach (RegisteredControl control in assembly2.RegisteredControls)
                {
                    RegistryKey key3 = key2.CreateSubKey(control.TypeName);
                    DictionaryControl control2 = control as DictionaryControl;
                    if (control2 != null)
                    {
                        key3.SetValue("CreationAssemblyName", control2.Properties["CreationAssemblyName"], RegistryValueKind.String);
                        key3.SetValue("CreationTypeName", control2.Properties["CreationTypeName"], RegistryValueKind.String);
                        key3.SetValue("ToolTypeName", control2.Properties["ToolTypeName"], RegistryValueKind.String);
                    }
                    else
                    {
                        DotNetControl control3 = control as DotNetControl;
                        if (control3 != null)
                        {
                            key3.SetValue(null, control3.DisplayName, RegistryValueKind.String);
                            key3.SetValue("description", control3.Description, RegistryValueKind.String);
                        }
                    }
                    if (!string.IsNullOrEmpty(control.RegDescriptorValue))
                    {
                        key3.SetValue(control.RegDescriptorValue, 1, RegistryValueKind.DWord);
                    }
                }
            }
        }


        [CompilerGenerated]
        private sealed class AssemblyFoldersExKeys : IEnumerable<RegistryKey>, IEnumerable, IEnumerator<RegistryKey>, IEnumerator, IDisposable
        {
            private int state;
            private RegistryKey current;
            public string __tfm;
            public ToolboxInstallerPackage __this;
            public RegistryKey[] __wrap33;
            public int __wrap34;
            public string[] __wrap37;
            public int __wrap38;
            public string[] __wrap3a;
            public int __wrap3b;
            private int initialThreadId;
            public RegistryKey afeKey5__2e;
            public RegistryKey fxKey_5__2d;
            public string fxName_5__2c;
            public RegistryKey fxRootKey_5__2b;
            public string fxRootPath_5__28;
            public FrameworkName name_5__27;
            public RegistryKey root_5__2a;
            public RegistryKey[] roots_5__26;
            public RegistryKey subAfeKey_5__31;
            public RegistryKey subkey_5__30;
            public string subkeyName_5__2f;
            public string tfmVersion_5__29;
            public string tfm;

            [DebuggerHidden]
            public AssemblyFoldersExKeys(int state)
            {
                this.state = state;
                this.initialThreadId = Thread.CurrentThread.ManagedThreadId;
            }

            private void m__Finally32()
            {
                this.state = -1;
            }

            private void m__Finally35()
            {
                this.state = 1;
                if (this.fxRootKey_5__2b != null)
                {
                    this.fxRootKey_5__2b.Dispose();
                }
            }

            private void m__Finally36()
            {
                this.state = 2;
            }

            private void m__Finally39()
            {
                this.state = 3;
            }

            private void m__Finally3c()
            {
                this.state = 5;
                if (this.subkey_5__30 != null)
                {
                    this.subkey_5__30.Dispose();
                }
            }

            public bool MoveNext()
            {
                try
                {
                    int num = this.state;
                    if (num != 0)
                    {
                        //if (num == 4)
                        //{
                        //    goto Label_01E3;
                        //}
                        //if (num == 7)
                        //{
                        //    goto Label_027C;
                        //}
                    }
                    else
                    {
                        this.state = -1;
                        this.roots_5__26 = new RegistryKey[] { Registry.CurrentUser, Registry.LocalMachine };
                        this.name_5__27 = new FrameworkName(this.tfm);
                        if (string.Compare(this.name_5__27.Identifier, "silverlight", StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            this.fxRootPath_5__28 = @"Software\Microsoft\Microsoft SDKs\" + this.name_5__27.Identifier;
                        }
                        else
                        {
                            this.fxRootPath_5__28 = @"Software\Microsoft\" + this.name_5__27.Identifier;
                        }
                        this.tfmVersion_5__29 = "v" + this.name_5__27.Version;
                        this.state = 1;
                        this.__wrap33 = this.roots_5__26;
                        this.__wrap34 = 0;
                        while (this.__wrap34 < this.__wrap33.Length)
                        {
                            this.root_5__2a = this.__wrap33[this.__wrap34];
                            this.fxRootKey_5__2b = this.root_5__2a.OpenSubKey(this.fxRootPath_5__28);
                            this.state = 2;
                            if (this.fxRootKey_5__2b != null)
                            {
                                this.state = 3;
                                this.__wrap37 = this.fxRootKey_5__2b.GetSubKeyNames();
                                this.__wrap38 = 0;
                                while (this.__wrap38 < this.__wrap37.Length)
                                {
                                    {
                                        this.fxName_5__2c = this.__wrap37[this.__wrap38];
                                        if ((this.fxName_5__2c.Length < this.tfmVersion_5__29.Length) || (string.Compare(this.fxName_5__2c.Substring(0, this.tfmVersion_5__29.Length), this.tfmVersion_5__29, StringComparison.OrdinalIgnoreCase) != 0))
                                        {
                                            goto Label_02B0;
                                        }
                                        this.fxKey_5__2d = this.fxRootKey_5__2b.OpenSubKey(this.fxName_5__2c);
                                        this.afeKey5__2e = this.fxKey_5__2d.OpenSubKey("AssemblyFoldersEx");
                                        if (this.afeKey5__2e == null)
                                        {
                                            goto Label_01EF;
                                        }
                                        this.current = this.afeKey5__2e;
                                        this.state = 4;
                                        return true;
                                    }

                                Label_01E3:
                                    this.state = 3;
                                    goto Label_02B0;
                                Label_01EF:
                                    this.state = 5;
                                    this.__wrap3a = this.fxKey_5__2d.GetSubKeyNames();
                                    this.__wrap3b = 0;
                                    while (this.__wrap3b < this.__wrap3a.Length)
                                    {
                                        this.subkeyName_5__2f = this.__wrap3a[this.__wrap3b];
                                        this.subkey_5__30 = this.fxKey_5__2d.OpenSubKey(this.subkeyName_5__2f);
                                        this.state = 6;
                                        this.subAfeKey_5__31 = this.subkey_5__30.OpenSubKey("AssemblyFoldersEx");
                                        if (this.subAfeKey_5__31 == null)
                                        {
                                            goto Label_0283;
                                        }
                                        this.current = this.subAfeKey_5__31;
                                        this.state = 7;
                                        return true;
                                    Label_027C:
                                        this.state = 6;
                                    Label_0283:
                                        this.m__Finally3c();
                                        this.__wrap3b++;
                                    }
                                    this.m__Finally39();
                                Label_02B0:
                                    this.__wrap38++;
                                }
                                this.m__Finally36();
                            }
                            this.m__Finally35();
                            this.__wrap34++;
                        }
                        this.m__Finally32();
                    }
                    return false;
                }
                catch
                {
                    return false;
                }

                return true;
            }

            [DebuggerHidden]
            IEnumerator<RegistryKey> IEnumerable<RegistryKey>.GetEnumerator()
            {
                ToolboxInstallerPackage.AssemblyFoldersExKeys d__;
                if ((Thread.CurrentThread.ManagedThreadId == this.initialThreadId) && (this.state == -2))
                {
                    this.state = 0;
                    d__ = this;
                }
                else
                {
                    d__ = new ToolboxInstallerPackage.AssemblyFoldersExKeys(0) {
                        __this = this.__this
                    };
                }
                d__.tfm = this.__tfm;
                return d__;
            }

            [DebuggerHidden]
            IEnumerator IEnumerable.GetEnumerator()
            {
                return null;

                //return System.Collections.Generic.IEnumerable<Microsoft.Win32.RegistryKey>.GetEnumerator();
            }

            [DebuggerHidden]
            void IEnumerator.Reset()
            {
                throw new NotSupportedException();
            }

            void IDisposable.Dispose()
            {
                switch (this.state)
                {
                    case 1:
                    case 2:
                    case 3:
                    case 4:
                    case 5:
                    case 6:
                    case 7:
                        switch (this.state)
                        {
                            case 2:
                            case 3:
                            case 4:
                            case 5:
                            case 6:
                            case 7:
                                try
                                {
                                    switch (this.state)
                                    {
                                        case 3:
                                        case 4:
                                        case 5:
                                        case 6:
                                        case 7:
                                            switch (this.state)
                                            {
                                            }
                                            goto Label_00C1;

                                        default:
                                            break;
                                    }
                                    switch (this.state)
                                    {
                                        case 6:
                                        case 7:
                                            try
                                            {
                                            }
                                            finally
                                            {
                                                this.m__Finally3c();
                                            }
                                            break;
                                    }
                                    this.m__Finally39();
                                Label_00C1:
                                    this.m__Finally36();
                                }
                                finally
                                {
                                    this.m__Finally35();
                                }
                                break;
                        }
                        break;

                    default:
                        return;
                }
                this.m__Finally32();
            }

            RegistryKey IEnumerator<RegistryKey>.Current
            {
                [DebuggerHidden]
                get
                {
                    return this.current;
                }
            }

            object IEnumerator.Current
            {
                [DebuggerHidden]
                get
                {
                    return this.current;
                }
            }
        }

    }
}
Back to Top