Advertisement
Guest User

The source of the registration helper

a guest
Sep 24th, 2015
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.59 KB | None | 0 0
  1. /// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  2. /// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  3. /// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  4. /// PARTICULAR PURPOSE.
  5.  
  6. /// Copyright (c) Siemens Product Lifecycle Management Software Inc. All rights reserved.
  7.  
  8. using Microsoft.Win32;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Linq;
  12. using System.Text;
  13.  
  14. namespace SolidEdge.AddIn.Common
  15. {
  16.     /// <summary>
  17.     /// Helper class for ComRegisterFunction and ComUnregisterFunction attributes.
  18.     /// </summary>
  19.     public static class RegistrationHelper
  20.     {
  21.         public static void Register(Type t)
  22.         {
  23.             var addinInfo = (AddInInfoAttribute)AddInInfoAttribute.GetCustomAttribute(t, typeof(AddInInfoAttribute));
  24.             var environments = (AddInEnvironmentCategoryAttribute[])AddInEnvironmentCategoryAttribute.GetCustomAttributes(t, typeof(AddInEnvironmentCategoryAttribute));
  25.  
  26.             if (addinInfo == null) throw new System.Exception("Missing AddInInfoAttribute.");
  27.             if ((environments == null) || (environments.Length == 0))
  28.             {
  29.                 throw new System.Exception("Missing AddInEnvironmentCategoryAttribute.");
  30.             }
  31.  
  32.             string subkey = String.Format(@"CLSID\{0}", t.GUID.ToString("B"));
  33.             using (RegistryKey baseKey = Registry.ClassesRoot.CreateSubKey(subkey))
  34.             {
  35.                 subkey = String.Format(@"Implemented Categories\{0}", CategoryIDs.CATID_SolidEdgeAddIn);
  36.                 using (RegistryKey implementedCategoriesKey = baseKey.CreateSubKey(subkey))
  37.                 {
  38.                 }
  39.  
  40.                 foreach (var environment in environments)
  41.                 {
  42.                     subkey = String.Format(@"Environment Categories\{0}", environment.Guid.ToString("B"));
  43.                     using (RegistryKey environmentCategoryKey = baseKey.CreateSubKey(subkey))
  44.                     {
  45.                     }
  46.                 }
  47.  
  48.                 using (RegistryKey summaryKey = baseKey.CreateSubKey("Summary"))
  49.                 {
  50.                     summaryKey.SetValue("409", addinInfo.Summary);
  51.                 }
  52.  
  53.                 baseKey.SetValue("AutoConnect", addinInfo.AutoConnect ? 1 : 0);
  54.                 baseKey.SetValue("409", addinInfo.Title);
  55.             }
  56.         }
  57.  
  58.         public static void Unregister(Type t)
  59.         {
  60.             string subkey = String.Format(@"CLSID\{0}", t.GUID.ToString("B"));
  61.             Registry.ClassesRoot.DeleteSubKeyTree(subkey, false);
  62.         }
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement