Exemplo n.º 1
0
        /// <summary>
        /// Actually performs registration. The ComRegisterFunction decorated method will call this function
        /// internally with the flag appropriate for the operating system processor architecture.
        /// However, this function can also be called manually if needed.
        /// </summary>
        /// <param name="type">The type of object to register, this must be a SharpShellServer derived class.</param>
        /// <param name="registrationType">Type of the registration.</param>
        internal static void DoRegister(Type type, RegistrationType registrationType)
        {
            Logging.Log($"Preparing to register SharpShell Server {type.Name} as {registrationType}");

            //  Get the association data.
            var associationAttributes = type.GetCustomAttributes(typeof(COMServerAssociationAttribute), true)
                                        .OfType <COMServerAssociationAttribute>().ToList();

            //  Get the server type and the registration name.
            var serverType       = ServerTypeAttribute.GetServerType(type);
            var registrationName = RegistrationNameAttribute.GetRegistrationNameOrTypeName(type);

            //  Register the server associations, if there are any.
            if (associationAttributes.Any())
            {
                ServerRegistrationManager.RegisterServerAssociations(
                    type.GUID, serverType, registrationName, associationAttributes, registrationType);
            }

            //  If a DisplayName attribute has been set, then set the display name of the COM server.
            var displayName = DisplayNameAttribute.GetDisplayName(type);

            if (!string.IsNullOrEmpty(displayName))
            {
                ServerRegistrationManager.SetServerDisplayName(type.GUID, displayName, registrationType);
            }

            //  Execute the custom register function, if there is one.
            CustomRegisterFunctionAttribute.ExecuteIfExists(type, registrationType);

            //  Notify the shell we've updated associations.
            Shell32.SHChangeNotify(Shell32.SHCNE_ASSOCCHANGED, 0, IntPtr.Zero, IntPtr.Zero);
            Logging.Log($"Registration of {type.Name} completed");
        }
Exemplo n.º 2
0
        /// <summary>
        /// Actually performs registration. The ComRegisterFunction decorated method will call this function
        /// internally with the flag appropriate for the operating system processor architecture.
        /// However, this function can also be called manually if needed.
        /// </summary>
        /// <param name="type">The type of object to register, this must be a SharpShellServer derived class.</param>
        /// <param name="registrationType">Type of the registration.</param>
        internal static void DoRegister(Type type, RegistrationType registrationType)
        {
            Logging.Log($"Preparing to register SharpShell Server {type.Name} as {registrationType}");

            //  Get the assoication data.
            var assocationAttributes = type.GetCustomAttributes(typeof(COMServerAssociationAttribute), true)
                                       .OfType <COMServerAssociationAttribute>().ToList();

            //  Get the server type.
            var serverType = ServerTypeAttribute.GetServerType(type);

            //  Register the server associations, if there are any.
            if (assocationAttributes.Any())
            {
                ServerRegistrationManager.RegisterServerAssociations(
                    type.GUID, serverType, type.Name, assocationAttributes, registrationType);
            }

            //  Execute the custom register function, if there is one.
            CustomRegisterFunctionAttribute.ExecuteIfExists(type, registrationType);

            //  Notify the shell we've updated associations.
            Shell32.SHChangeNotify(Shell32.SHCNE_ASSOCCHANGED, 0, IntPtr.Zero, IntPtr.Zero);
            Logging.Log($"Registration of {type.Name} completed");
        }
Exemplo n.º 3
0
        /// <summary>
        /// Actually performs registration. The ComRegisterFunction decorated method will call this function
        /// internally with the flag appropriate for the operating system processor architecture.
        /// However, this function can also be called manually if needed.
        /// </summary>
        /// <param name="type">The type of object to register, this must be a SharpShellServer derived class.</param>
        /// <param name="registrationType">Type of the registration.</param>
        internal static void DoRegister(Type type, RegistrationType registrationType)
        {
            Logging.Log($"Preparing to register SharpShell Server {type.Name} as {registrationType}");

            //  If a DisplayName attribute has been set, then set the display name of the COM server.
            var displayName = DisplayNameAttribute.GetDisplayName(type);

            if (!string.IsNullOrEmpty(displayName))
            {
                ServerRegistrationManager.SetServerDisplayName(type.GUID, displayName, registrationType);
            }

            //  Execute the custom register function, if there is one.
            CustomRegisterFunctionAttribute.ExecuteIfExists(type, registrationType);

            Logging.Log($"Registration of {type.Name} completed");
        }
Exemplo n.º 4
0
        /// <summary>
        /// Actually performs registration. The ComRegisterFunction decorated method will call this function
        /// internally with the flag appropriate for the operating system processor architecture.
        /// However, this function can also be called manually if needed.
        /// </summary>
        /// <param name="type">The type of object to register, this must be a SharpShellServer derived class.</param>
        /// <param name="registrationType">Type of the registration.</param>
        /// <param name="registrationLocation">Location of the registration.</param>
        internal static void DoRegister(Type type, RegistrationType registrationType, RegistrationLocation registrationLocation)
        {
            //  Get the assoication data.
            var assocationAttributes = type.GetCustomAttributes(typeof(COMServerAssociationAttribute), true)
                                       .OfType <COMServerAssociationAttribute>().ToList();

            //  Get the server type.
            var serverType = ServerTypeAttribute.GetServerType(type);

            //  Register the server associations, if there are any.
            if (assocationAttributes.Any())
            {
                ServerRegistrationManager.RegisterServerAssociations(
                    type.GUID, serverType, type.Name, assocationAttributes, registrationType, registrationLocation);
            }

            //  Execute the custom register function, if there is one.
            CustomRegisterFunctionAttribute.ExecuteIfExists(type, registrationType);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Actually performs registration. The ComRegisterFunction decorated method will call this function
        /// internally with the flag appropriate for the operating system processor architecture.
        /// However, this function can also be called manually if needed.
        /// </summary>
        /// <param name="type">The type of object to register, this must be a SharpShellServer derived class.</param>
        /// <param name="registrationType">Type of the registration.</param>
        internal static void DoRegister(Type type, RegistrationType registrationType)
        {
            //  Get the assoication data.
            var associationType = COMServerAssociationAttribute.GetAssociationType(type);
            var associations    = COMServerAssociationAttribute.GetAssociations(type);

            //  Get the server type.
            var serverType = ServerTypeAttribute.GetServerType(type);

            //  Register the server associations, if there are any.
            if (associationType != AssociationType.None)
            {
                ServerRegistrationManager.RegisterServerAssociations(
                    type.GUID, serverType, type.Name, associationType, associations, registrationType);
            }

            //  Execute the custom register function, if there is one.
            CustomRegisterFunctionAttribute.ExecuteIfExists(type, registrationType);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Actually performs registration. The ComRegisterFunction decorated method will call this function
        /// internally with the flag appropriate for the operating system processor architecture.
        /// However, this function can also be called manually if needed.
        /// </summary>
        /// <param name="type">The type of object to register, this must be a SharpShellServer derived class.</param>
        /// <param name="registrationType">Type of the registration.</param>
        internal static void DoRegister(Type type, RegistrationType registrationType)
        {
            Logging.Log($"Preparing to register SharpShell Server {type.Name} as {registrationType}");

            //  Get the association data.
            var associationAttributes = type.GetCustomAttributes(typeof(COMServerAssociationAttribute), true)
                                        .OfType <COMServerAssociationAttribute>().ToList();

            //  Get the server type and the registration name.
            var serverType       = ServerTypeAttribute.GetServerType(type);
            var registrationName = RegistrationNameAttribute.GetRegistrationNameOrTypeName(type);

            //  Register the server associations, if there are any.
            if (associationAttributes.Any())
            {
                ServerRegistrationManager.RegisterServerAssociations(
                    type.GUID, serverType, registrationName, associationAttributes, registrationType);
            }

            //  If a DisplayName attribute has been set, then set the display name of the COM server.
            var displayName = DisplayNameAttribute.GetDisplayName(type);

            if (!string.IsNullOrEmpty(displayName))
            {
                ServerRegistrationManager.SetServerDisplayName(type.GUID, displayName, registrationType);
            }

            //  If we are a *file* thumbnail handler, we must disable process isolation.
            //  See: https://docs.microsoft.com/en-us/previous-versions/windows/desktop/legacy/cc144118(v%3Dvs.85)#thumbnail-processes
            if (serverType == ServerType.ShellItemThumbnailHandler)
            {
                Logging.Log($"Disabling process isolation for SharpFileThumbnailHandler named '{type.Name}'.");
                ServerRegistrationManager.SetDisableProcessIsolationValue(type.GUID, registrationType, 1 /* i.e. disabled */);
            }

            //  Execute the custom register function, if there is one.
            CustomRegisterFunctionAttribute.ExecuteIfExists(type, registrationType);

            //  Notify the shell we've updated associations.
            Shell32.SHChangeNotify(Shell32.SHCNE_ASSOCCHANGED, 0, IntPtr.Zero, IntPtr.Zero);
            Logging.Log($"Registration of {type.Name} completed");
        }