Ejemplo n.º 1
0
        /// <summary>
        /// Try to detect the addin is loaded from system hive key
        /// </summary>
        /// <returns>null if unkown or true/false</returns>
        private bool?IsLoadedFromSystem()
        {
            if (null != _isLoadedFromSystem)
            {
                return(_isLoadedFromSystem);
            }

            ApplicationIdentifiers.ApplicationType applicationType =
                ApplicationIdentifiers.IsApplication(Application.UnderlyingType.GUID);
            if (applicationType == ApplicationIdentifiers.ApplicationType.None)
            {
                return(null);
            }

            OfficeApi.Tools.Contribution.RegistryLocationResult result = OfficeApi.Tools.Contribution.CommonUtils.TryFindAddinLoadLocation(Type,
                                                                                                                                           applicationType);
            switch (result)
            {
            case Office.Tools.Contribution.RegistryLocationResult.User:
                return(false);

            case Office.Tools.Contribution.RegistryLocationResult.System:
                return(true);

            default:
                throw new IndexOutOfRangeException();
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Try to detect the registry end for the current loaded host application(unkown)
 /// </summary>
 /// <param name="applicationProxy">application proy</param>
 /// <returns>Application name or null if failed</returns>
 private string TryDetectHostRegistryKey(object applicationProxy)
 {
     ApplicationIdentifiers.ApplicationType applicationType =
         ApplicationIdentifiers.IsApplication(applicationProxy.GetType().GUID);
     if (applicationType == ApplicationIdentifiers.ApplicationType.None)
     {
         return(null);
     }
     else
     {
         return(ApplicationIdentifiers.ConvertApplicationType(applicationType));
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates an registry tweak entry in the current addin key
        /// </summary>
        /// <param name="applicationType">target office application</param>
        /// <param name="addinType">addin class type informations</param>
        /// <param name="name">name for the tweak</param>
        /// <param name="value">value for the tweak</param>
        /// <param name="throwException">throw exception on error</param>
        /// <returns>true if value was stored otherwise false</returns>
        public static bool SetTweakPersistenceEntry(ApplicationIdentifiers.ApplicationType applicationType, Type addinType, string name, string value, bool throwException)
        {
            try
            {
                if (null == addinType)
                    return false;
                RegistryLocationAttribute location = AttributeReflector.GetRegistryLocationAttribute(addinType);
                ProgIdAttribute progID = AttributeReflector.GetProgIDAttribute(addinType);

                OfficeApi.Tools.Utils.RegistryLocationResult addinLocation =
                    Tools.Utils.CommonUtils.TryFindAddinLoadLocation(addinType, applicationType);
                if (addinLocation == Office.Tools.Utils.RegistryLocationResult.Unknown)
                    return false;

                RegistryKey regKey = null;
                switch (addinLocation)
                {
                    case Office.Tools.Utils.RegistryLocationResult.User:
                        regKey = Registry.LocalMachine.OpenSubKey(_addinOfficeRegistryKey + progID.Value, true);
                        break;
                    case Office.Tools.Utils.RegistryLocationResult.System:
                        regKey = Registry.CurrentUser.OpenSubKey(_addinOfficeRegistryKey + progID.Value, true);
                        break;
                }

                if (null == regKey)
                    return false;

                regKey.SetValue(name, value);
                regKey.Close();

                return true;
            }
            catch (Exception exception)
            {
                NetOffice.DebugConsole.Default.WriteException(exception);
                if (throwException)
                    throw;
                else
                    return false;
            }
        }