Beispiel #1
0
        public static void RegisterFunction(Type type)
        {
            MultiRegisterAttribute attribute = MultiRegisterAttribute.GetAttribute(type);

            string[] product = new string[attribute.Products.Length];
            for (int i = 0; i < attribute.Products.Length; i++)
            {
                product[i] = String.Format(_addinOfficeRegistryKey, MultiRegisterAttribute.RegistryEntry(attribute.Products[i]));
            }

            RegisterHandler.Proceed(type, product, InstallScope.System, OfficeRegisterKeyState.NeedToCreate);
        }
Beispiel #2
0
        private static RegExport RegExportFunction(Type type, int scope, int keyState)
        {
            if (null == type)
            {
                throw new ArgumentNullException("type");
            }
            InstallScope           currentScope    = (InstallScope)scope;
            OfficeRegisterKeyState currentKeyState = (OfficeRegisterKeyState)keyState;

            MultiRegisterAttribute attribute = MultiRegisterAttribute.GetAttribute(type);

            string[] product = new string[attribute.Products.Length];
            for (int i = 0; i < attribute.Products.Length; i++)
            {
                product[i] = MultiRegisterAttribute.RegistryEntry(attribute.Products[i]);
            }

            return(RegExportHandler.Proceed(type, new string[] { _addinOfficeRegistryKey }, currentScope, currentKeyState));
        }
Beispiel #3
0
        private static void OptimizedUnregisterFunction(Type type, int scope, int keyState)
        {
            if (null == type)
            {
                throw new ArgumentNullException("type");
            }
            InstallScope             currentScope    = (InstallScope)scope;
            OfficeUnRegisterKeyState currentKeyState = (OfficeUnRegisterKeyState)keyState;

            MultiRegisterAttribute attribute = MultiRegisterAttribute.GetAttribute(type);

            string[] product = new string[attribute.Products.Length];
            for (int i = 0; i < attribute.Products.Length; i++)
            {
                product[i] = String.Format(_addinOfficeRegistryKey, MultiRegisterAttribute.RegistryEntry(attribute.Products[i]));
            }

            COMAddinUnRegisterHandler.Proceed(type, product, currentScope, currentKeyState);
        }
Beispiel #4
0
        public static void UnregisterFunction(Type type)
        {
            try
            {
                MultiRegisterAttribute attribute = MultiRegisterAttribute.GetAttribute(type);
                string[] product = new string[attribute.Products.Length];
                for (int i = 0; i < attribute.Products.Length; i++)
                {
                    product[i] = String.Format(_addinOfficeRegistryKey, MultiRegisterAttribute.RegistryEntry(attribute.Products[i]));
                }

                COMAddinUnRegisterHandler.Proceed(type, product, InstallScope.System, OfficeUnRegisterKeyState.NeedToDelete);
            }
            catch (Exception exception)
            {
                if (!RegisterErrorHandler.RaiseStaticErrorHandlerMethod(type, RegisterErrorMethodKind.UnRegister, new NetOfficeException(exception.Message, exception)))
                {
                    throw;
                }
            }
        }
Beispiel #5
0
        public static void RegisterFunction(Type type)
        {
            try
            {
                MethodInfo registerMethod = null;
                RegisterFunctionAttribute registerAttribute = null;
                bool registerMethodPresent = AttributeHelper.GetRegisterAttribute(type, ref registerMethod, ref registerAttribute);
                if (registerMethodPresent)
                {
                    CallDerivedRegisterMethod(type, registerMethod, registerAttribute);
                    if (registerAttribute.Value == RegisterMode.Replace)
                    {
                        return;
                    }
                }

                GuidAttribute             guid      = AttributeHelper.GetGuidAttribute(type);
                ProgIdAttribute           progId    = AttributeHelper.GetProgIDAttribute(type);
                RegistryLocationAttribute location  = AttributeHelper.GetRegistryLocationAttribute(type);
                COMAddinAttribute         addin     = AttributeHelper.GetCOMAddinAttribute(type);
                MultiRegisterAttribute    attribute = MultiRegisterAttribute.GetAttribute(type);

                Assembly    thisAssembly    = Assembly.GetAssembly(type);
                string      assemblyVersion = thisAssembly.GetName().Version.ToString();
                RegistryKey key             = Registry.ClassesRoot.CreateSubKey("CLSID\\{" + type.GUID.ToString().ToUpper() + "}\\InprocServer32\\" + assemblyVersion);
                key.SetValue("CodeBase", thisAssembly.CodeBase);
                key.Close();

                Registry.ClassesRoot.CreateSubKey(@"CLSID\{" + type.GUID.ToString().ToUpper() + @"}\Programmable");
                key = Registry.ClassesRoot.OpenSubKey(@"CLSID\{" + type.GUID.ToString().ToUpper() + @"}\InprocServer32", true);
                key.SetValue("", NetRuntimeSystem.Environment.SystemDirectory + @"\mscoree.dll", RegistryValueKind.String);
                key.Close();

                // add bypass key
                // http://support.microsoft.com/kb/948461
                key = Registry.ClassesRoot.CreateSubKey("Interface\\{000C0601-0000-0000-C000-000000000046}");
                string defaultValue = key.GetValue("") as string;
                if (null == defaultValue)
                {
                    key.SetValue("", "Office .NET Framework Lockback Bypass Key");
                }
                key.Close();

                foreach (RegisterIn item in attribute.Products)
                {
                    // register addin in Office
                    if (location.Value == RegistrySaveLocation.LocalMachine)
                    {
                        Registry.LocalMachine.CreateSubKey(string.Format(_addinOfficeRegistryKey, MultiRegisterAttribute.RegistryEntry(item)) + progId.Value);
                    }
                    else
                    {
                        Registry.CurrentUser.CreateSubKey(string.Format(_addinOfficeRegistryKey, MultiRegisterAttribute.RegistryEntry(item)) + progId.Value);
                    }

                    RegistryKey regKeyProduct = null;
                    if (location.Value == RegistrySaveLocation.LocalMachine)
                    {
                        regKeyProduct = Registry.LocalMachine.OpenSubKey(string.Format(_addinOfficeRegistryKey, MultiRegisterAttribute.RegistryEntry(item)) + progId.Value, true);
                    }
                    else
                    {
                        regKeyProduct = Registry.CurrentUser.OpenSubKey(string.Format(_addinOfficeRegistryKey, MultiRegisterAttribute.RegistryEntry(item)) + progId.Value, true);
                    }

                    regKeyProduct.SetValue("LoadBehavior", addin.LoadBehavior);
                    regKeyProduct.SetValue("FriendlyName", addin.Name);
                    regKeyProduct.SetValue("Description", addin.Description);
                    if (-1 != addin.CommandLineSafe)
                    {
                        regKeyProduct.SetValue("CommandLineSafe", addin.CommandLineSafe);
                    }

                    regKeyProduct.Close();
                }

                if ((registerMethodPresent) && (registerAttribute.Value == RegisterMode.CallBeforeAndAfter || registerAttribute.Value == RegisterMode.CallAfter))
                {
                    registerMethod.Invoke(null, new object[] { type, RegisterCall.CallAfter });
                }
            }
            catch (System.Exception exception)
            {
                NetOffice.DebugConsole.Default.WriteException(exception);
                RaiseStaticErrorHandlerMethod(type, RegisterErrorMethodKind.Register, exception);
            }
        }
Beispiel #6
0
        public static void UnregisterFunction(Type type)
        {
            try
            {
                MethodInfo registerMethod = null;
                UnRegisterFunctionAttribute registerAttribute = null;
                bool registerMethodPresent = AttributeHelper.GetUnRegisterAttribute(type, ref registerMethod, ref registerAttribute);
                if (registerMethodPresent)
                {
                    CallDerivedUnRegisterMethod(type, registerMethod, registerAttribute);
                    if (registerAttribute.Value == RegisterMode.Replace)
                    {
                        return;
                    }
                }

                ProgIdAttribute           progId    = AttributeHelper.GetProgIDAttribute(type);
                RegistryLocationAttribute location  = AttributeHelper.GetRegistryLocationAttribute(type);
                MultiRegisterAttribute    attribute = MultiRegisterAttribute.GetAttribute(type);

                // unregister addin
                Registry.ClassesRoot.DeleteSubKey(@"CLSID\{" + type.GUID.ToString().ToUpper() + @"}\Programmable", false);

                foreach (RegisterIn item in attribute.Products)
                {
                    // unregister addin in office
                    if (location.Value == RegistrySaveLocation.LocalMachine)
                    {
                        Registry.LocalMachine.DeleteSubKey(string.Format(_addinOfficeRegistryKey, MultiRegisterAttribute.RegistryEntry(item)) + progId.Value, false);
                    }
                    else
                    {
                        Registry.CurrentUser.DeleteSubKey(string.Format(_addinOfficeRegistryKey, MultiRegisterAttribute.RegistryEntry(item)) + progId.Value, false);
                    }
                }

                if ((registerMethodPresent) && (registerAttribute.Value == RegisterMode.CallBeforeAndAfter || registerAttribute.Value == RegisterMode.CallAfter))
                {
                    registerMethod.Invoke(null, new object[] { type, RegisterCall.CallAfter });
                }
            }
            catch (System.Exception exception)
            {
                NetOffice.DebugConsole.Default.WriteException(exception);
                RaiseStaticErrorHandlerMethod(type, RegisterErrorMethodKind.UnRegister, exception);
            }
        }