예제 #1
0
        /// <summary>
        /// Provides the location of the icon overlay's bitmap.
        /// </summary>
        /// <param name="pwszIconFile">A null-terminated Unicode string that contains the fully qualified path of the file containing the icon. The .dll, .exe, and .ico file types are all acceptable. You must set the ISIOI_ICONFILE flag in pdwFlags if you return a file name.</param>
        /// <param name="cchMax">The size of the pwszIconFile buffer, in Unicode characters.</param>
        /// <param name="pIndex">Pointer to an index value used to identify the icon in a file that contains multiple icons. You must set the ISIOI_ICONINDEX flag in pdwFlags if you return an index.</param>
        /// <param name="pdwFlags">Pointer to a bitmap that specifies the information that is being returned by the method. This parameter can be one or both of the following values: ISIOI_ICONFILE, ISIOI_ICONINDEX.</param>
        /// <returns>
        /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
        /// </returns>
        int IShellIconOverlayIdentifier.GetOverlayInfo(IntPtr pwszIconFile, int cchMax, out int pIndex, out ISIOI pdwFlags)
        {
            //  Set the out variables to sensible defaults.
            pdwFlags = 0;
            pIndex = 0;

            try
            {
                //  Get the icon file path.
                var iconFilePath = GetIconFilePath();

                //  If we have no file, we must fail.
                if (string.IsNullOrEmpty(iconFilePath))
                {
                    LogError("Cannot create the overlay icon path.");
                    return WinError.E_FAIL;
                }

                //  Get the file path bytes.
                var bytes = Encoding.Unicode.GetBytes(iconFilePath);

                if (bytes.Length + 2 < cchMax)
                {
                    for (int i = 0; i < bytes.Length; i++)
                    {
                        Marshal.WriteByte(pwszIconFile, i, bytes[i]);
                    }
                    Marshal.WriteByte(pwszIconFile, bytes.Length, 0);
                    Marshal.WriteByte(pwszIconFile, bytes.Length + 1, 0);
                }

                //  Set the flags, specifying we'll provide a path.
                pdwFlags = ISIOI.ISIOI_ICONFILE;

                return WinError.S_OK;
            }
            catch (Exception ex)
            {
                LogError("An exception occured getting overlay info.", ex);
                return WinError.E_FAIL;
            }
        }
예제 #2
0
        /// <summary>
        /// Provides the location of the icon overlay's bitmap.
        /// </summary>
        /// <param name="pwszIconFile">A null-terminated Unicode string that contains the fully qualified path of the file containing the icon. The .dll, .exe, and .ico file types are all acceptable. You must set the ISIOI_ICONFILE flag in pdwFlags if you return a file name.</param>
        /// <param name="cchMax">The size of the pwszIconFile buffer, in Unicode characters.</param>
        /// <param name="pIndex">Pointer to an index value used to identify the icon in a file that contains multiple icons. You must set the ISIOI_ICONINDEX flag in pdwFlags if you return an index.</param>
        /// <param name="pdwFlags">Pointer to a bitmap that specifies the information that is being returned by the method. This parameter can be one or both of the following values: ISIOI_ICONFILE, ISIOI_ICONINDEX.</param>
        /// <returns>
        /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
        /// </returns>
        int IShellIconOverlayIdentifier.GetOverlayInfo(IntPtr pwszIconFile, int cchMax, out int pIndex, out ISIOI pdwFlags)
        {
            //  Set the out variables to sensible defaults.
            pdwFlags = 0;
            pIndex   = 0;

            try
            {
                //  Get the icon file path.
                var iconFilePath = GetIconFilePath();

                //  If we have no file, we must fail.
                if (string.IsNullOrEmpty(iconFilePath))
                {
                    LogError("Cannot create the overlay icon path.");
                    return(WinError.E_FAIL);
                }

                //  Get the file path bytes.
                var bytes = Encoding.Unicode.GetBytes(iconFilePath);

                if (bytes.Length + 2 < cchMax)
                {
                    for (int i = 0; i < bytes.Length; i++)
                    {
                        Marshal.WriteByte(pwszIconFile, i, bytes[i]);
                    }
                    Marshal.WriteByte(pwszIconFile, bytes.Length, 0);
                    Marshal.WriteByte(pwszIconFile, bytes.Length + 1, 0);
                }

                //  Set the flags, specifying we'll provide a path and index.
                pdwFlags = ISIOI.ISIOI_ICONFILE | ISIOI.ISIOI_ICONINDEX;

                return(WinError.S_OK);
            }
            catch (Exception ex)
            {
                LogError("An exception occured getting overlay info.", ex);
                return(WinError.E_FAIL);
            }
        }
예제 #3
0
        /// <summary>
        /// Provides the location of the icon overlay's bitmap.
        /// </summary>
        /// <param name="pwszIconFile">A null-terminated Unicode string that contains the fully qualified path of the file containing the icon. The .dll, .exe, and .ico file types are all acceptable. You must set the ISIOI_ICONFILE flag in pdwFlags if you return a file name.</param>
        /// <param name="cchMax">The size of the pwszIconFile buffer, in Unicode characters.</param>
        /// <param name="pIndex">Pointer to an index value used to identify the icon in a file that contains multiple icons. You must set the ISIOI_ICONINDEX flag in pdwFlags if you return an index.</param>
        /// <param name="pdwFlags">Pointer to a bitmap that specifies the information that is being returned by the method. This parameter can be one or both of the following values: ISIOI_ICONFILE, ISIOI_ICONINDEX.</param>
        /// <returns>
        /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
        /// </returns>
        int IShellIconOverlayIdentifier.GetOverlayInfo(StringBuilder pwszIconFile, int cchMax, out int pIndex, out ISIOI pdwFlags)
        {
            //  Log this key event.
            Log("GetOverlayInfo called to get icon overlay.");

            //  Set empty values for the out parameters first.
            pdwFlags = ISIOI.ISIOI_ICONFILE;
            pIndex   = 0;

            //  If we're not in debug mode and we've already created the temporary icon file,
            //  we can return it. If we're in debug mode, we'll always create it.
#if !DEBUG
            if (!string.IsNullOrEmpty(temporaryIconOverlayFilePath) && File.Exists(temporaryIconOverlayFilePath))
            {
                //  Set the icon file path.
                pwszIconFile.Append(temporaryIconOverlayFilePath);
                return(WinError.S_OK);
            }
#endif

            //  Storage for the overlay icon.
            Icon overlayIcon;

            //  Always wrap calls to the abstract functions in exception handlers.
            try
            {
                //  Get the overlay icon.
                overlayIcon = GetOverlayIcon();
            }
            catch (Exception exception)
            {
                //  Log the exception.
                LogError("An exception occured when trying to get the overlay icon.", exception);

                //  Return an error.
                return(WinError.E_FAIL);
            }

            //  Create a temporary icon file path.
            try
            {
                CreateTemporaryIconFilePath();

                //  Save the file object to the icon file path.
                using (var fileStream = new FileStream(temporaryIconOverlayFilePath, FileMode.Create))
                {
                    //  Save the icon to the stream, then flush the stream.
                    overlayIcon.Save(fileStream);
                    fileStream.Flush(true);
                }

                //  Set the icon file path.
                pwszIconFile.Append(temporaryIconOverlayFilePath);
            }
            catch (Exception exception)
            {
                //  Log the exception.
                LogError("An exception occured when trying to create the overlay icon.", exception);

                //  Return an error.
                return(WinError.E_FAIL);
            }

            //  We've successfully created the icon file and set it.
            return(WinError.S_OK);
        }
예제 #4
0
 void IShellIconOverlayIdentifier.GetOverlayInfo(IntPtr iconFileBuffer, int iconFileBufferSize, out int iconIndex, out ISIOI flags)
 {
     flags = ISIOI.ISIOI_ICONFILE | ISIOI.ISIOI_ICONINDEX;
     iconIndex = IconIndex;
     WriteToIntPtr(IconFile, iconFileBuffer, iconFileBufferSize * 2);
 }
        /// <summary>
        /// Provides the location of the icon overlay's bitmap.
        /// </summary>
        /// <param name="pwszIconFile">A null-terminated Unicode string that contains the fully qualified path of the file containing the icon. The .dll, .exe, and .ico file types are all acceptable. You must set the ISIOI_ICONFILE flag in pdwFlags if you return a file name.</param>
        /// <param name="cchMax">The size of the pwszIconFile buffer, in Unicode characters.</param>
        /// <param name="pIndex">Pointer to an index value used to identify the icon in a file that contains multiple icons. You must set the ISIOI_ICONINDEX flag in pdwFlags if you return an index.</param>
        /// <param name="pdwFlags">Pointer to a bitmap that specifies the information that is being returned by the method. This parameter can be one or both of the following values: ISIOI_ICONFILE, ISIOI_ICONINDEX.</param>
        /// <returns>
        /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
        /// </returns>
        int IShellIconOverlayIdentifier.GetOverlayInfo(StringBuilder pwszIconFile, int cchMax, out int pIndex, out ISIOI pdwFlags)
        {
            //  Log this key event.
            Log("GetOverlayInfo called to get icon overlay.");

            //  Set empty values for the out parameters first.
            pdwFlags = ISIOI.ISIOI_ICONFILE;
            pIndex = 0;

            //  If we're not in debug mode and we've already created the temporary icon file, 
            //  we can return it. If we're in debug mode, we'll always create it.
#if !DEBUG
            if(!string.IsNullOrEmpty(temporaryIconOverlayFilePath) && File.Exists(temporaryIconOverlayFilePath))
            {
                //  Set the icon file path.
                pwszIconFile.Append(temporaryIconOverlayFilePath);
                return WinError.S_OK;
            }
#endif

            //  Storage for the overlay icon.
            Icon overlayIcon;

            //  Always wrap calls to the abstract functions in exception handlers.
            try
            {
                //  Get the overlay icon.
                overlayIcon = GetOverlayIcon();
            }
            catch (Exception exception)
            {
                //  Log the exception.
                LogError("An exception occured when trying to get the overlay icon.", exception);

                //  Return an error.
                return WinError.E_FAIL;
            }

            //  Create a temporary icon file path.
            try
            {
                CreateTemporaryIconFilePath();

                //  Save the file object to the icon file path.
                using (var fileStream = new FileStream(temporaryIconOverlayFilePath, FileMode.Create))
                {
                    //  Save the icon to the stream, then flush the stream.
                    overlayIcon.Save(fileStream);
                    fileStream.Flush(true);
                }

                //  Set the icon file path.
                pwszIconFile.Append(temporaryIconOverlayFilePath);
            }
            catch (Exception exception)
            {
                //  Log the exception.
                LogError("An exception occured when trying to create the overlay icon.", exception);

                //  Return an error.
                return WinError.E_FAIL;
            }

            //  We've successfully created the icon file and set it.
            return WinError.S_OK;
        }