Ejemplo n.º 1
0
        /// <summary>
        /// Analyze a COMAddin for the TweakAttribute and try to set given arguments(registry) if exists
        /// </summary>
        /// <param name="factory">current used factory or null for default</param>
        /// <param name="addinInstance">COMAddin instance</param>
        /// <param name="addinType">Type info from COMAddin instance</param>
        /// <param name="registryEndPoint">specific office registry key endpoint</param>
        /// <param name="useSystemRegistryKey">Try read in HKEY_LOCAL_Machine otherwise HKEY_CURRENT_USER</param>
        public static void ApplyTweaks(Core factory, object addinInstance, Type addinType, string registryEndPoint, IsLoadedFromSystemKeyDelegate useSystemRegistryKey)
        {
            try
            {
                if (null == addinInstance)
                    return;
                if (null == factory)
                    factory = Core.Default;

                TweakAttribute tweakAttribute = AttributeReflector.GetTweakAttribute(addinType);
                if (null == tweakAttribute || false == tweakAttribute.Enabled)
                    return;

                ProgIdAttribute progIDAttribute = AttributeReflector.GetProgIDAttribute(addinType, false);
                if (null == progIDAttribute)
                    return;

                bool? systemKey = useSystemRegistryKey();
                if (null == systemKey)
                    return;

                RegistryKey hiveKey = systemKey == true ? Registry.LocalMachine : Registry.CurrentUser;
                 
                RegistryKey key = hiveKey.OpenSubKey("Software\\Microsoft\\Office\\" + registryEndPoint + "\\Addins\\" + progIDAttribute.Value);
                if (null != key)
                {
                    TweakConsoleMode(factory, addinInstance, addinType, key);
                    TweakSharedOutput(factory, addinInstance, addinType, key);
                    TweakAddHocLoading(factory, addinInstance, addinType, key);
                    TweakDeepLoading(factory, addinInstance, addinType, key);
                    TweakDebugOutput(factory, addinInstance, addinType, key);
                    TweakExceptionHandling(factory, addinInstance, addinType, key);
                    TweakExceptionMessage(factory, addinInstance, addinType, key);
                    TweakThreadCulture(factory, addinInstance, addinType, key);
                    TweakMessageFilter(factory, addinInstance, addinType, key);
                    TweakSafeMode(factory, addinInstance, addinType, key);
                    TweakEventOutput(factory, addinInstance, addinType, key);
                    Dictionary<string, string> customTweaks = ApplyCustomTweaks(factory, addinInstance, addinType, key);
                    AddCustomAppliedTweaks(addinInstance.GetHashCode(), customTweaks);
                    key.Close();
                }
                hiveKey.Close();
            }
            catch (Exception exception)
            {
                factory.Console.WriteException(exception);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Analyze a COMAddin for the TweakAttribute and try to set given arguments(registry) if exists
        /// </summary>
        /// <param name="factory">current used factory or null for default</param>
        /// <param name="addinInstance">COMAddin instance</param>
        /// <param name="addinType">Type info from COMAddin instance</param>
        /// <param name="registryEndPoint">specific office registry key endpoint</param>
        /// <param name="useSystemRegistryKey">Try read in HKEY_LOCAL_Machine otherwise HKEY_CURRENT_USER</param>
        public static void ApplyTweaks(Core factory, object addinInstance, Type addinType, string registryEndPoint, IsLoadedFromSystemKeyDelegate useSystemRegistryKey)
        {
            try
            {
                if (null == addinInstance)
                {
                    return;
                }
                if (null == useSystemRegistryKey)
                {
                    return;
                }
                if (null == factory)
                {
                    factory = Core.Default;
                }

                TweakAttribute tweakAttribute = AttributeReflector.GetTweakAttribute(addinType);
                if (null == tweakAttribute || false == tweakAttribute.Enabled)
                {
                    return;
                }

                ProgIdAttribute progIDAttribute = AttributeReflector.GetProgIDAttribute(addinType, false);
                if (null == progIDAttribute)
                {
                    return;
                }

                bool?systemKey = useSystemRegistryKey();
                if (null == systemKey)
                {
                    return;
                }

                RegistryKey hiveKey = systemKey == true ? Registry.LocalMachine : Registry.CurrentUser;

                RegistryKey key = hiveKey.OpenSubKey("Software\\Microsoft\\Office\\" + registryEndPoint + "\\Addins\\" + progIDAttribute.Value);
                if (null != key)
                {
                    TweakConsoleMode(factory, addinInstance, addinType, key);
                    TweakSharedOutput(factory, addinInstance, addinType, key);
                    TweakAddHocLoading(factory, addinInstance, addinType, key);
                    TweakDeepLoading(factory, addinInstance, addinType, key);
                    TweakDebugOutput(factory, addinInstance, addinType, key);
                    TweakExceptionHandling(factory, addinInstance, addinType, key);
                    TweakExceptionMessage(factory, addinInstance, addinType, key);
                    TweakThreadCulture(factory, addinInstance, addinType, key);
                    TweakMessageFilter(factory, addinInstance, addinType, key);
                    TweakSafeMode(factory, addinInstance, addinType, key);
                    TweakEventOutput(factory, addinInstance, addinType, key);
                    Dictionary <string, string> customTweaks = ApplyCustomTweaks(factory, addinInstance, addinType, key);
                    AddCustomAppliedTweaks(addinInstance.GetHashCode(), customTweaks);
                    key.Close();
                }
                hiveKey.Close();
            }
            catch (Exception exception)
            {
                factory.Console.WriteException(exception);
            }
        }