コード例 #1
0
        public static ServerInfo GetServerinfo(ServerEntry serverEntry)
        {
            if (serverEntry == null)
            {
                return(null);
            }


            //  Get the specified associations.
            AssociationType      associationType = COMServerAssociationAttribute.GetAssociationType(serverEntry.Server.GetType());
            IEnumerable <string> associations    = COMServerAssociationAttribute.GetAssociations(serverEntry.Server.GetType());

            ServerInfo serverInfo = new ServerInfo();

            serverInfo.ServerName     = serverEntry.ServerName;
            serverInfo.ServerType     = serverEntry.ServerType.ToString();
            serverInfo.ClassId        = serverEntry.ClassId.ToString();
            serverInfo.SecurityStatus = serverEntry.GetSecurityStatus();
            serverInfo.ServerPath     = serverEntry.ServerPath;
            serverInfo.IsInvalid      = serverEntry.IsInvalid;
            serverInfo.Association    = associationType + " " + string.Join(", ", associations);
            serverInfo.Info32         = SharpShell.ServerRegistration.ServerRegistrationManager.GetServerRegistrationInfo(serverEntry.Server.ServerClsid, RegistrationType.OS32Bit);
            serverInfo.Info64         = SharpShell.ServerRegistration.ServerRegistrationManager.GetServerRegistrationInfo(serverEntry.Server.ServerClsid, RegistrationType.OS64Bit);

            return(serverInfo);
        }
コード例 #2
0
        public void Initialise(ServerEntry serverEntry)
        {
            if (serverEntry != null)
            {
                textBoxServerName.Text     = serverEntry.ServerName;
                textBoxServerType.Text     = serverEntry.ServerType.ToString();
                textBoxServerCLSID.Text    = serverEntry.ClassId.ToString();
                textBoxServerSecurity.Text = serverEntry.GetSecurityStatus();
                textBoxAssemblyPath.Text   = serverEntry.ServerPath;

                //  Get the specified associations.
                var associationType = COMServerAssociationAttribute.GetAssociationType(serverEntry.Server.GetType());
                var associations    = COMServerAssociationAttribute.GetAssociations(serverEntry.Server.GetType());
                textBoxAssociations.Text = associationType.ToString() + " " + string.Join(", ", associations);


                //  Now use the server registration manager to get the registration info
                //  for the different operating system architectures.
                var info32 = ServerRegistrationManager.GetServerRegistrationInfo(serverEntry.Server.ServerClsid, RegistrationType.OS32Bit);
                var info64 = ServerRegistrationManager.GetServerRegistrationInfo(serverEntry.Server.ServerClsid, RegistrationType.OS64Bit);

                //  By default, our installation info is going to be empty.
                textBox32BitServer.Text = "Not Installed";
                textBox64BitServer.Text = "Not Installed";

                //  Do we have 32 bit registration info?
                if (info32 != null)
                {
                    //  Do we have a codebase?
                    if (!string.IsNullOrEmpty(info32.CodeBase))
                    {
                        textBox32BitServer.Text = info32.CodeBase;
                    }
                    else if (!string.IsNullOrEmpty(info32.Assembly))
                    {
                        textBox32BitServer.Text = info32.Assembly + " (GAC)";
                    }
                }

                //  Do we have 32 bit registration info?
                if (info64 != null)
                {
                    //  Do we have a codebase?
                    if (!string.IsNullOrEmpty(info64.CodeBase))
                    {
                        textBox64BitServer.Text = info64.CodeBase;
                    }
                    else if (!string.IsNullOrEmpty(info64.Assembly))
                    {
                        textBox64BitServer.Text = info64.Assembly + " (GAC)";
                    }
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Actually performs unregistration. The ComUnregisterFunction 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 unregister, this must be a SharpShellServer derived class.</param>
        /// <param name="registrationType">Type of the registration to unregister.</param>
        internal static void DoUnregister(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);

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

            //  Execute the custom unregister function, if there is one.
            CustomUnregisterFunctionAttribute.ExecuteIfExists(type, registrationType);
        }
コード例 #4
0
        /// <summary>
        /// Determines whether a server is associated with a shell item.
        /// </summary>
        /// <param name="server">The server.</param>
        /// <param name="shellItem">The shell item.</param>
        /// <returns>
        ///   <c>true</c> if a server is associated with the shell item; otherwise, <c>false</c>.
        /// </returns>
        private bool IsServerAssociatedWithShellItem(ISharpShellServer server, ShellItem shellItem)
        {
            //  If we don't have the server, bail.
            if (server == null || shellItem == null)
            {
                return(false);
            }

            //  Get the associations.
            var associationType = COMServerAssociationAttribute.GetAssociationType(server.GetType());
            var associations    = COMServerAssociationAttribute.GetAssociations(server.GetType());

            //  TODO: This is potentially a very useful check - maybe it should be moved into the
            //  COMServerAssociationAttribute class so that it can be reused.

            //  We have a special case for icon overlays.
            if (server is SharpIconOverlayHandler && TestIconOverlayHandler != null && shellItem.Attributes.HasFlag(SFGAO.SFGAO_FILESYSTEM))
            {
                if (((IShellIconOverlayIdentifier)TestIconOverlayHandler).IsMemberOf(shellItem.Path, FILE_ATTRIBUTE.FILE_ATTRIBUTE_NORMAL) == 0)
                {
                    return(true);
                }
            }

            //  Based on the assocation type, we can check the shell item.
            switch (associationType)
            {
            case AssociationType.FileExtension:

                //  File extensions are easy to check.
                if (shellItem.Attributes.HasFlag(SFGAO.SFGAO_FILESYSTEM))
                {
                    return
                        (associations.Any(
                             a =>
                             string.Compare(Path.GetExtension(shellItem.DisplayName), a,
                                            StringComparison.OrdinalIgnoreCase) == 0));
                }

                break;

            case AssociationType.ClassOfExtension:

                //  TODO must be tested.
                if (shellItem.Attributes.HasFlag(SFGAO.SFGAO_FILESYSTEM))
                {
                    //  Get our class.
                    var fileClass = ServerRegistrationManager.GetClassForExtension(Path.GetExtension(shellItem.DisplayName));

                    //  Do we match it?
                    return(associations.Any(a => string.Compare(fileClass, ServerRegistrationManager.GetClassForExtension(a), StringComparison.InvariantCultureIgnoreCase) == 0));
                }

                break;

            case AssociationType.Class:
                //  TODO must be tested.
                break;

            case AssociationType.AllFiles:

                //  TODO must be tested.
                return(shellItem.Attributes.HasFlag(SFGAO.SFGAO_FILESYSTEM) && shellItem.IsFolder == false);

            case AssociationType.Directory:

                //  Directories are filesystem, not streams, and folder.
                return(shellItem.Attributes.HasFlag(SFGAO.SFGAO_FILESYSTEM) && !shellItem.Attributes.HasFlag(SFGAO.SFGAO_STREAM) && shellItem.IsFolder);

            case AssociationType.Drive:

                //  TODO must be tested.
                return(shellItem.Attributes.HasFlag(SFGAO.SFGAO_STORAGEANCESTOR));

            case AssociationType.UnknownFiles:
                //  TODO must be tested.
                break;
            }

            return(false);
        }
コード例 #5
0
        /// <summary>
        /// Determines whether a server is associated with a shell item.
        /// </summary>
        /// <param name="server">The server.</param>
        /// <param name="shellItem">The shell item.</param>
        /// <returns>
        ///   <c>true</c> if a server is associated with the shell item; otherwise, <c>false</c>.
        /// </returns>
        private bool IsServerAssociatedWithShellItem(ISharpShellServer server, ShellItem shellItem)
        {
            //  If we don't have the server, bail.
            if (server == null || shellItem == null)
            {
                return(false);
            }

            //  Get the associations.
            var associationType = COMServerAssociationAttribute.GetAssociationType(server.GetType());
            var associations    = COMServerAssociationAttribute.GetAssociations(server.GetType());

            //  TODO: This is potentially a very useful check - maybe it should be moved into the
            //  COMServerAssociationAttribute class so that it can be reused.

            //  Based on the assocation type, we can check the shell item.
            switch (associationType)
            {
            case AssociationType.FileExtension:

                //  TODO must be tested.
                //  File extensions are easy to check.
                if (shellItem.Attributes.HasFlag(SFGAOF.SFGAO_FILESYSTEM))
                {
                    return
                        (associations.Any(
                             a =>
                             string.Compare(Path.GetExtension(shellItem.DisplayName), "." + a,
                                            StringComparison.OrdinalIgnoreCase) == 0));
                }

                break;

            case AssociationType.ClassOfExtension:

                //  TODO must be tested.
                if (shellItem.Attributes.HasFlag(SFGAOF.SFGAO_FILESYSTEM))
                {
                    //  Get our class.
                    var fileClass = ServerRegistrationManager.GetClassForExtension(Path.GetExtension(shellItem.DisplayName));

                    //  Do we match it?
                    return(associations.Any(a => string.Compare(fileClass, ServerRegistrationManager.GetClassForExtension(a), StringComparison.InvariantCultureIgnoreCase) == 0));
                }

                break;

            case AssociationType.Class:
                //  TODO must be tested.
                break;

            case AssociationType.AllFiles:

                //  TODO must be tested.
                return(shellItem.Attributes.HasFlag(SFGAOF.SFGAO_FILESYSTEM) && shellItem.IsFolder == false);

            case AssociationType.Directory:

                //  Directories are filesystem, not streams, and folder.
                return(shellItem.Attributes.HasFlag(SFGAOF.SFGAO_FILESYSTEM) && !shellItem.Attributes.HasFlag(SFGAOF.SFGAO_STREAM) && shellItem.IsFolder);

            case AssociationType.Drive:

                //  TODO must be tested.
                return(shellItem.Attributes.HasFlag(SFGAOF.SFGAO_STORAGEANCESTOR));

            case AssociationType.UnknownFiles:
                //  TODO must be tested.
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            return(false);
        }