Пример #1
0
        private int GetIconLocation(ExtractIconOptions uFlags, out int piIndex, out ExtractIconFlags pwFlags)
        {
            //No need for an index
            piIndex = 0;

            //Check ShellExtLib.cs for more info on these flags
            pwFlags = ExtractIconFlags.NotFilename | ExtractIconFlags.PerInstance | ExtractIconFlags.DontCache;

            //Return the name for the icon cache
            //szIconFile = Marshal.StringToHGlobalAuto(currentFile);

            //I got this under control!
            return(WinError.S_OK);
        }
Пример #2
0
 public uint GetIconLocation(ExtractIconOptions uFlags, IntPtr szIconFile, uint cchMax, out int piIndex, out ExtractIconFlags pwFlags)
 {
     piIndex = 0;
     pwFlags = ExtractIconFlags.NotFilename | ExtractIconFlags.PerInstance | ExtractIconFlags.DontCache;
     if (sFileName.Length < cchMax)
     {
         szIconFile = Marshal.StringToHGlobalAuto(sFileName); // return the name for icon cache
     }
     else
     {
         szIconFile = IntPtr.Zero;
         pwFlags = pwFlags | ExtractIconFlags.DontCache;
     }
     NativeMethods.Log("GetIconLocation: pwFlags = " + pwFlags.ToString());
     NativeMethods.Log("GetIconLocation: szIconFile = " + Marshal.PtrToStringAuto(szIconFile));
     NativeMethods.Log("GetIconLocation: piIndex = " + piIndex.ToString());
     NativeMethods.Log("GetIconLocation: ExtractIconOptions.Async = " + uFlags.ToString());
     return ((uFlags & ExtractIconOptions.Async) != 0) ? WinError.E_PENDING : WinError.S_OK;
 }
Пример #3
0
        public override ExtractIconResult ExtractCustomIcon(ref string remoteName, ExtractIconFlags extractFlags,
                                                            out Icon icon)
        {
            icon = null;
            ExtractIconResult result   = ExtractIconResult.UseDefault;
            string            iconFile = null;

            remoteName = remoteName.Substring(1);
            if (remoteName.EndsWith(@"..\"))
            {
                return(ExtractIconResult.UseDefault);
            }
            if (Directory.Exists(remoteName))
            {
                iconFile = "DATABASE.ico";
                result   = ExtractIconResult.LoadFromFile;
            }
            else if (File.Exists(remoteName))
            {
                string extension = Path.GetExtension(remoteName);
                if (extension != null)
                {
                    if (extension.ToUpper().Equals(".TXT"))
                    {
                        icon     = Icon.ExtractAssociatedIcon(@"C:\WINDOWS\system32\notepad.exe");
                        result   = ExtractIconResult.Extracted;
                        iconFile = "Notepad";
                    }
                    else if (extension.ToUpper().Equals(".EXE"))
                    {
                        iconFile = "Table.ico";
                        result   = ExtractIconResult.LoadFromFile;
                    }
                }
            }
            if (!result.Equals(ExtractIconResult.UseDefault))
            {
                remoteName = Path.Combine(Settings["iconFolder"], iconFile);
            }
            return(result);
        }
Пример #4
0
        public override ExtractIconResult ExtractCustomIcon(RemotePath remoteName, ExtractIconFlags extractFlags)
        {
            WsPath wsPath = remoteName;

            switch (wsPath.Level)
            {
            case WsPathLevel.Account when wsPath.AccountName == ADD_NEW_ACCOUNT_TITLE:
                return(ExtractIconResult.Extracted(new System.Drawing.Icon(typeof(Resources.TextResource), "Add.ico")));

            case WsPathLevel.Account when remoteName.Path.EndsWith(@"\..\") == false:
                return(ExtractIconResult.Extracted(new System.Drawing.Icon(typeof(Resources.TextResource), "Account.ico")));

            case WsPathLevel.AccessLevel when wsPath.IsPrivate == true && remoteName.Path.EndsWith(@"\..\") == false:
                return(ExtractIconResult.Extracted(new System.Drawing.Icon(typeof(Resources.TextResource), "FolderPrivate.ico")));

            case WsPathLevel.AccessLevel when wsPath.IsPrivate == false:
                return(ExtractIconResult.Extracted(new System.Drawing.Icon(typeof(Resources.TextResource), "FolderPublic.ico")));

            default:
                return(ExtractIconResult.UseDefault);
            }
        }
Пример #5
0
        /// <summary>
        /// This attempts to load the Icon from the specified filePath.
        /// supply extractFlags to ensure the correct size gets loaded.
        /// </summary>
        /// <param name="filePath">a local file path (the file MUST exist)</param>
        /// <param name="extractFlags"></param>
        public static ExtractIconResult LoadFromFile(string filePath, ExtractIconFlags extractFlags)
        {
            if (string.IsNullOrEmpty(filePath))
            {
                return(ExtractIconResult.UseDefault);
            }

            const uint imageTypeIcon  = 1;             //  IMAGE_ICON
            const uint loadImageFlags = 0x10 + 0x8000; //  LR_LOADFROMFILE | LR_SHARED

            // use LoadImage, it produces better results than LoadIcon
            var extrIcon = (extractFlags & ExtractIconFlags.Small) == ExtractIconFlags.Small
                ? NativeMethods.LoadImage(IntPtr.Zero, filePath, imageTypeIcon, 16, 16, loadImageFlags)
                : NativeMethods.LoadImage(IntPtr.Zero, filePath, imageTypeIcon, 0, 0, loadImageFlags);

            if (extrIcon == IntPtr.Zero)
            {
                //var errorCode = NativeMethods.GetLastError();
                return(ExtractIconResult.UseDefault);
            }

            return(ExtractIconResult.Extracted(System.Drawing.Icon.FromHandle(extrIcon), filePath));
        }
Пример #6
0
        int IExtractIcon.GetIconLocation(ExtractIconOptions uFlags, IntPtr szIconFile, uint cchMax, out int piIndex, out ExtractIconFlags pwFlags)
        {
            piIndex = -1;

            try
            {
                FileInfo f = new FileInfo(szFileName);
                lngFileSize = f.Length;
                pwFlags     = ExtractIconFlags.DontCache | ExtractIconFlags.NotFilename;

                return(S_OK);
            }
            catch { }

            pwFlags = ExtractIconFlags.None;
            return(S_FALSE);
        }
Пример #7
0
 public override ExtractIconResult ExtractCustomIcon(RemotePath remoteName, ExtractIconFlags extractFlags)
 {
     return(ExtractIconResult.UseDefault);
 }
Пример #8
0
 public virtual ExtractIconResult ExtractCustomIcon(ref string remoteName,
                                                    ExtractIconFlags extractFlags, out Icon icon)
 {
     icon = null;
     return(ExtractIconResult.UseDefault);
 }
Пример #9
0
        int IExtractIcon.GetIconLocation(ExtractIconOptions uFlags, IntPtr szIconFile, uint cchMax, out int piIndex, out ExtractIconFlags pwFlags)
        {
            piIndex = -1;

            try
            {
                FileInfo f = new FileInfo(szFileName);
                lngFileSize = f.Length;
                pwFlags = ExtractIconFlags.DontCache | ExtractIconFlags.NotFilename;

                return S_OK;
            }
            catch { }

            pwFlags = ExtractIconFlags.None;
            return S_FALSE;
        }
Пример #10
0
        int IExtractIcon.GetIconLocation(ExtractIconOptions uFlags, IntPtr szIconFile, uint cchMax, out int piIndex, out ExtractIconFlags pwFlags)
        {
            piIndex = -1;
            pwFlags = ExtractIconFlags.None;

            icon = folderObj.GetIcon((uFlags & ExtractIconOptions.OpenIcon) == ExtractIconOptions.OpenIcon);

            if (icon is ShellIcon.FromFile)
            {
                string filename = (icon as ShellIcon.FromFile).Filename;
                byte[] data     = new byte[cchMax * 2];
                Encoding.Unicode.GetBytes(filename, 0, filename.Length, data, 0);
                Marshal.Copy(data, 0, szIconFile, data.Length);

                piIndex = (icon as ShellIcon.FromFile).Index;
                pwFlags = icon.Flags;
                return(0);
            }
            else if (icon is ShellIcon.FromIcon)
            {
                pwFlags = ExtractIconFlags.NotFilename | ExtractIconFlags.DontCache;//icon.Flags;
                return(0);
            }
            else if (icon == null)
            {
                return(1);                      // use default icon
            }

            Trace.Fail("Unreachable code");
            return(0);
        }
Пример #11
0
 /// <summary>
 /// Get the icon location
 /// </summary>
 /// <param name="uFlags"></param>
 /// <param name="szIconFile"></param>
 /// <param name="cchMax"></param>
 /// <param name="piIndex"></param>
 /// <param name="pwFlags"></param>
 /// <returns></returns>
 public uint GetIconLocation(ExtractIconOptions uFlags, IntPtr szIconFile, uint cchMax, out int piIndex, out ExtractIconFlags pwFlags)
 {
     piIndex    = -1;
     szIconFile = IntPtr.Zero;
     try {
         pwFlags = ExtractIconFlags.NotFilename | ExtractIconFlags.PerInstance | ExtractIconFlags.DontCache;
         return(((uFlags & ExtractIconOptions.Async) != 0) ? E_PENDING : S_OK);
     } catch (Exception ex) {
         //Log.Error ( ex.Message, ex );
         pwFlags = ExtractIconFlags.None;
         return(S_FALSE);
     }
 }
Пример #12
0
 /// <summary>
 /// Get the icon location
 /// </summary>
 /// <param name="uFlags"></param>
 /// <param name="szIconFile"></param>
 /// <param name="cchMax"></param>
 /// <param name="piIndex"></param>
 /// <param name="pwFlags"></param>
 /// <returns></returns>
 public uint GetIconLocation( ExtractIconOptions uFlags, IntPtr szIconFile, uint cchMax, out int piIndex, out ExtractIconFlags pwFlags )
 {
     piIndex = -1;
     szIconFile = IntPtr.Zero;
     try {
         pwFlags = ExtractIconFlags.NotFilename | ExtractIconFlags.PerInstance | ExtractIconFlags.DontCache;
         return ( ( uFlags & ExtractIconOptions.Async ) != 0 ) ? E_PENDING : S_OK;
     } catch ( Exception ex ) {
         //Log.Error ( ex.Message, ex );
         pwFlags = ExtractIconFlags.None;
         return S_FALSE;
     }
 }
Пример #13
0
 public uint GetIconLocation(ExtractIconOptions uFlags, IntPtr szIconFile, uint cchMax, out int piIndex, out ExtractIconFlags pwFlags)
 {
     piIndex = 0;
     pwFlags = ExtractIconFlags.NotFilename | ExtractIconFlags.PerInstance | ExtractIconFlags.DontCache;
     if (sFileName.Length < cchMax)
     {
         szIconFile = Marshal.StringToHGlobalAuto(sFileName); // return the name for icon cache
     }
     else
     {
         szIconFile = IntPtr.Zero;
         pwFlags    = pwFlags | ExtractIconFlags.DontCache;
     }
     NativeMethods.Log("GetIconLocation: pwFlags = " + pwFlags.ToString());
     NativeMethods.Log("GetIconLocation: szIconFile = " + Marshal.PtrToStringAuto(szIconFile));
     NativeMethods.Log("GetIconLocation: piIndex = " + piIndex.ToString());
     NativeMethods.Log("GetIconLocation: ExtractIconOptions.Async = " + uFlags.ToString());
     return(((uFlags & ExtractIconOptions.Async) != 0) ? WinError.E_PENDING : WinError.S_OK);
 }
Пример #14
0
 int IExtractIconW.GetIconLocation(ExtractIconOptions uFlags, StringBuilder szIconFile, int cchMax, out int piIndex, out ExtractIconFlags pwFlags)
 {
     return(GetIconLocation(uFlags, out piIndex, out pwFlags));
 }