Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
- /// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
- /// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
- /// PARTICULAR PURPOSE.
- /// Copyright (c) Siemens Product Lifecycle Management Software Inc. All rights reserved.
- using Microsoft.Win32;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace SolidEdge.AddIn.Common
- {
- /// <summary>
- /// Helper class for ComRegisterFunction and ComUnregisterFunction attributes.
- /// </summary>
- public static class RegistrationHelper
- {
- public static void Register(Type t)
- {
- var addinInfo = (AddInInfoAttribute)AddInInfoAttribute.GetCustomAttribute(t, typeof(AddInInfoAttribute));
- var environments = (AddInEnvironmentCategoryAttribute[])AddInEnvironmentCategoryAttribute.GetCustomAttributes(t, typeof(AddInEnvironmentCategoryAttribute));
- if (addinInfo == null) throw new System.Exception("Missing AddInInfoAttribute.");
- if ((environments == null) || (environments.Length == 0))
- {
- throw new System.Exception("Missing AddInEnvironmentCategoryAttribute.");
- }
- string subkey = String.Format(@"CLSID\{0}", t.GUID.ToString("B"));
- using (RegistryKey baseKey = Registry.ClassesRoot.CreateSubKey(subkey))
- {
- subkey = String.Format(@"Implemented Categories\{0}", CategoryIDs.CATID_SolidEdgeAddIn);
- using (RegistryKey implementedCategoriesKey = baseKey.CreateSubKey(subkey))
- {
- }
- foreach (var environment in environments)
- {
- subkey = String.Format(@"Environment Categories\{0}", environment.Guid.ToString("B"));
- using (RegistryKey environmentCategoryKey = baseKey.CreateSubKey(subkey))
- {
- }
- }
- using (RegistryKey summaryKey = baseKey.CreateSubKey("Summary"))
- {
- summaryKey.SetValue("409", addinInfo.Summary);
- }
- baseKey.SetValue("AutoConnect", addinInfo.AutoConnect ? 1 : 0);
- baseKey.SetValue("409", addinInfo.Title);
- }
- }
- public static void Unregister(Type t)
- {
- string subkey = String.Format(@"CLSID\{0}", t.GUID.ToString("B"));
- Registry.ClassesRoot.DeleteSubKeyTree(subkey, false);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement