Ignore:
Timestamp:
1/5/2009 9:37:55 AM (3 years ago)
Author:
lowjoel
Message:

-Moved all Shell calls to ShellAPI.cs
-Empty the recycle bin after we are done with the erase
-Only erase the recycle bin that belongs to the current user

Partially fixes #139

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eraser6/Util/File.cs

    r810 r850  
    3333namespace Eraser.Util 
    3434{ 
    35     using HICON = IntPtr; 
    36     using HIMAGELIST = IntPtr; 
    37  
    3835    public static class File 
    3936    { 
     
    105102        public static string GetFileDescription(string path) 
    106103        { 
    107             SHFILEINFO shfi = new SHFILEINFO(); 
    108             SHGetFileInfo(path, 0, ref shfi, Marshal.SizeOf(shfi), 
    109                 SHGetFileInfoFlags.SHGFI_DISPLAYNAME); 
     104            ShellAPI.SHFILEINFO shfi = new ShellAPI.SHFILEINFO(); 
     105            ShellAPI.SHGetFileInfo(path, 0, ref shfi, Marshal.SizeOf(shfi), 
     106                ShellAPI.SHGetFileInfoFlags.SHGFI_DISPLAYNAME); 
    110107            return shfi.szDisplayName; 
    111108        } 
     
    121118        public static Icon GetFileIcon(string path) 
    122119        { 
    123             SHFILEINFO shfi = new SHFILEINFO(); 
    124             SHGetFileInfo(path, 0, ref shfi, Marshal.SizeOf(shfi), 
    125                 SHGetFileInfoFlags.SHGFI_SMALLICON | SHGetFileInfoFlags.SHGFI_ICON); 
     120            ShellAPI.SHFILEINFO shfi = new ShellAPI.SHFILEINFO(); 
     121            ShellAPI.SHGetFileInfo(path, 0, ref shfi, Marshal.SizeOf(shfi), 
     122                ShellAPI.SHGetFileInfoFlags.SHGFI_SMALLICON | ShellAPI.SHGetFileInfoFlags.SHGFI_ICON); 
    126123 
    127124            if (shfi.hIcon != IntPtr.Zero) 
     
    234231                    sizeof(ushort), IntPtr.Zero, 0, out bytesReturned, IntPtr.Zero); 
    235232            } 
    236         } 
    237  
    238         /// <summary> 
    239         /// Retrieves information about an object in the file system, such as a 
    240         /// file, folder, directory, or drive root. 
    241         /// </summary> 
    242         /// <param name="path">[in] A pointer to a null-terminated string of maximum 
    243         /// length MAX_PATH that contains the path and file name. Both absolute 
    244         /// and relative paths are valid. 
    245         ///  
    246         /// If the uFlags parameter includes the SHGFI_PIDL flag, this parameter 
    247         /// must be the address of an ITEMIDLIST (PIDL) structure that contains 
    248         /// the list of item identifiers that uniquely identifies the file within 
    249         /// the Shell's namespace. The pointer to an item identifier list (PIDL) 
    250         /// must be a fully qualified PIDL. Relative PIDLs are not allowed. 
    251         ///  
    252         /// If the uFlags parameter includes the SHGFI_USEFILEATTRIBUTES flag, 
    253         /// this parameter does not have to be a valid file name. The function 
    254         /// will proceed as if the file exists with the specified name and with 
    255         /// the file attributes passed in the dwFileAttributes parameter. This 
    256         /// allows you to obtain information about a file type by passing just 
    257         /// the extension for pszPath and passing FILE_ATTRIBUTE_NORMAL in 
    258         /// dwFileAttributes. 
    259         ///  
    260         /// This string can use either short (the 8.3 form) or long file names.</param> 
    261         /// <param name="fileAttributes">[in] A combination of one or more file  
    262         /// attribute flags (FILE_ATTRIBUTE_ values as defined in Winnt.h). If 
    263         /// uFlags does not include the SHGFI_USEFILEATTRIBUTES flag, this 
    264         /// parameter is ignored.</param> 
    265         /// <param name="psfi">[out] The address of a SHFILEINFO structure to 
    266         /// receive the file information.</param> 
    267         /// <param name="cbFileInfo">[in] The size, in bytes, of the SHFILEINFO 
    268         /// structure pointed to by the psfi parameter.</param> 
    269         /// <param name="uFlags">[in] The flags that specify the file information to retrieve. 
    270         /// This parameter can be a combination of the values in SHGetFileInfoFlags</param> 
    271         /// <returns>Returns a value whose meaning depends on the uFlags parameter. 
    272         ///  
    273         /// If uFlags does not contain SHGFI_EXETYPE or SHGFI_SYSICONINDEX, the return 
    274         /// value is nonzero if successful, or zero otherwise. 
    275         ///  
    276         /// If uFlags contains the SHGFI_EXETYPE flag, the return value specifies 
    277         /// the type of the executable file. It will be one of the following values. 
    278         ///     0                                               Nonexecutable file or an error condition. 
    279         ///     LOWORD = NE or PE and HIWORD = Windows version  Microsoft Windows application. 
    280         ///     LOWORD = MZ and HIWORD = 0                      Windows 95, Windows 98: Microsoft MS-DOS .exe, .com, or .bat file 
    281         ///                                                     Microsoft Windows NT, Windows 2000, Windows XP: MS-DOS .exe or .com file 
    282         ///     LOWORD = PE and HIWORD = 0                      Windows 95, Windows 98: Microsoft Win32 console application 
    283         ///                                                     Windows NT, Windows 2000, Windows XP: Win32 console application or .bat file 
    284         /// </returns> 
    285         [DllImport("Shell32.dll", CharSet = CharSet.Unicode)] 
    286         private static extern IntPtr SHGetFileInfo(string path, uint fileAttributes, 
    287             ref SHFILEINFO psfi, int fileInfo, SHGetFileInfoFlags flags); 
    288  
    289         enum SHGetFileInfoFlags 
    290         { 
    291             /// <summary> 
    292             /// Retrieve the handle to the icon that represents the file and the 
    293             /// index of the icon within the system image list. The handle is 
    294             /// copied to the hIcon member of the structure specified by psfi, 
    295             /// and the index is copied to the iIcon member. 
    296             /// </summary> 
    297             SHGFI_ICON              = 0x000000100, 
    298  
    299             /// <summary> 
    300             /// Retrieve the display name for the file. The name is copied to the 
    301             /// szDisplayName member of the structure specified in psfi. The returned 
    302             /// display name uses the long file name, if there is one, rather than 
    303             /// the 8.3 form of the file name. 
    304             /// </summary> 
    305             SHGFI_DISPLAYNAME       = 0x000000200, 
    306  
    307             /// <summary> 
    308             /// Retrieve the string that describes the file's type. The string 
    309             /// is copied to the szTypeName member of the structure specified in 
    310             /// psfi. 
    311             /// </summary> 
    312             SHGFI_TYPENAME          = 0x000000400, 
    313  
    314             /// <summary> 
    315             /// Retrieve the item attributes. The attributes are copied to the 
    316             /// dwAttributes member of the structure specified in the psfi parameter. 
    317             /// These are the same attributes that are obtained from 
    318             /// IShellFolder::GetAttributesOf. 
    319             /// </summary> 
    320             SHGFI_ATTRIBUTES        = 0x000000800, 
    321  
    322             /// <summary> 
    323             /// Retrieve the name of the file that contains the icon representing 
    324             /// the file specified by pszPath, as returned by the 
    325             /// IExtractIcon::GetIconLocation method of the file's icon handler. 
    326             /// Also retrieve the icon index within that file. The name of the 
    327             /// file containing the icon is copied to the szDisplayName member 
    328             /// of the structure specified by psfi. The icon's index is copied to 
    329             /// that structure's iIcon member. 
    330             /// </summary> 
    331             SHGFI_ICONLOCATION      = 0x000001000, 
    332  
    333             /// <summary> 
    334             /// Retrieve the type of the executable file if pszPath identifies an 
    335             /// executable file. The information is packed into the return value. 
    336             /// This flag cannot be specified with any other flags. 
    337             /// </summary> 
    338             SHGFI_EXETYPE           = 0x000002000, 
    339  
    340             /// <summary> 
    341             /// Retrieve the index of a system image list icon. If successful, 
    342             /// the index is copied to the iIcon member of psfi. The return value 
    343             /// is a handle to the system image list. Only those images whose 
    344             /// indices are successfully copied to iIcon are valid. Attempting 
    345             /// to access other images in the system image list will result in 
    346             /// undefined behavior. 
    347             /// </summary> 
    348             SHGFI_SYSICONINDEX      = 0x000004000, 
    349              
    350             /// <summary> 
    351             /// Modify SHGFI_ICON, causing the function to add the link overlay 
    352             /// to the file's icon. The SHGFI_ICON flag must also be set. 
    353             /// </summary> 
    354             SHGFI_LINKOVERLAY       = 0x000008000, 
    355  
    356             /// <summary> 
    357             /// Modify SHGFI_ICON, causing the function to blend the file's icon 
    358             /// with the system highlight color. The SHGFI_ICON flag must also 
    359             /// be set. 
    360             /// </summary> 
    361             SHGFI_SELECTED          = 0x000010000, 
    362  
    363             /// <summary> 
    364             /// Modify SHGFI_ATTRIBUTES to indicate that the dwAttributes member 
    365             /// of the SHFILEINFO structure at psfi contains the specific attributes 
    366             /// that are desired. These attributes are passed to IShellFolder::GetAttributesOf. 
    367             /// If this flag is not specified, 0xFFFFFFFF is passed to 
    368             /// IShellFolder::GetAttributesOf, requesting all attributes. This flag 
    369             /// cannot be specified with the SHGFI_ICON flag. 
    370             /// </summary> 
    371             SHGFI_ATTR_SPECIFIED    = 0x000020000, 
    372  
    373             /// <summary> 
    374             /// Modify SHGFI_ICON, causing the function to retrieve the file's 
    375             /// large icon. The SHGFI_ICON flag must also be set. 
    376             /// </summary> 
    377             SHGFI_LARGEICON         = 0x000000000, 
    378  
    379             /// <summary> 
    380             /// Modify SHGFI_ICON, causing the function to retrieve the file's 
    381             /// small icon. Also used to modify SHGFI_SYSICONINDEX, causing the 
    382             /// function to return the handle to the system image list that 
    383             /// contains small icon images. The SHGFI_ICON and/or 
    384             /// SHGFI_SYSICONINDEX flag must also be set. 
    385             /// </summary> 
    386             SHGFI_SMALLICON         = 0x000000001, 
    387  
    388             /// <summary> 
    389             /// Modify SHGFI_ICON, causing the function to retrieve the file's 
    390             /// open icon. Also used to modify SHGFI_SYSICONINDEX, causing the 
    391             /// function to return the handle to the system image list that 
    392             /// contains the file's small open icon. A container object displays 
    393             /// an open icon to indicate that the container is open. The SHGFI_ICON 
    394             /// and/or SHGFI_SYSICONINDEX flag must also be set. 
    395             /// </summary> 
    396             SHGFI_OPENICON          = 0x000000002, 
    397  
    398             /// <summary> 
    399             /// Modify SHGFI_ICON, causing the function to retrieve a Shell-sized 
    400             /// icon. If this flag is not specified the function sizes the icon 
    401             /// according to the system metric values. The SHGFI_ICON flag must 
    402             /// also be set. 
    403             /// </summary> 
    404             SHGFI_SHELLICONSIZE     = 0x000000004, 
    405              
    406             /// <summary> 
    407             /// Indicate that pszPath is the address of an ITEMIDLIST structure 
    408             /// rather than a path name. 
    409             /// </summary> 
    410             SHGFI_PIDL              = 0x000000008, 
    411  
    412             /// <summary> 
    413             /// Indicates that the function should not attempt to access the file 
    414             /// specified by pszPath. Rather, it should act as if the file specified 
    415             /// by pszPath exists with the file attributes passed in dwFileAttributes. 
    416             /// This flag cannot be combined with the SHGFI_ATTRIBUTES, SHGFI_EXETYPE, 
    417             /// or SHGFI_PIDL flags. 
    418             /// </summary> 
    419             SHGFI_USEFILEATTRIBUTES = 0x000000010, 
    420  
    421             /// <summary> 
    422             /// Version 5.0. Apply the appropriate overlays to the file's icon. 
    423             /// The SHGFI_ICON flag must also be set. 
    424             /// </summary> 
    425             SHGFI_ADDOVERLAYS       = 0x000000020, 
    426              
    427             /// <summary> 
    428             /// Version 5.0. Return the index of the overlay icon. The value of 
    429             /// the overlay index is returned in the upper eight bits of the iIcon 
    430             /// member of the structure specified by psfi. This flag requires that 
    431             /// the SHGFI_ICON be set as well. 
    432             /// </summary> 
    433             SHGFI_OVERLAYINDEX      = 0x000000040 
    434         } 
    435  
    436         [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] 
    437         private struct SHFILEINFO 
    438         { 
    439             /// <summary> 
    440             /// A handle to the icon that represents the file. You are responsible 
    441             /// for destroying this handle with DestroyIcon when you no longer need it. 
    442             /// </summary> 
    443             public HICON hIcon; 
    444  
    445             /// <summary> 
    446             /// The index of the icon image within the system image list. 
    447             /// </summary> 
    448             public int iIcon; 
    449  
    450             /// <summary> 
    451             /// An array of values that indicates the attributes of the file object. 
    452             /// For information about these values, see the IShellFolder::GetAttributesOf 
    453             /// method. 
    454             /// </summary> 
    455             public uint dwAttributes; 
    456  
    457             /// <summary> 
    458             /// A string that contains the name of the file as it appears in the 
    459             /// Microsoft Windows Shell, or the path and file name of the file 
    460             /// that contains the icon representing the file. 
    461             /// </summary> 
    462             [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)] 
    463             public string szDisplayName; 
    464  
    465             /// <summary> 
    466             /// A string that describes the type of file. 
    467             /// </summary> 
    468             [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)] 
    469             public string szTypeName; 
    470233        } 
    471234 
Note: See TracChangeset for help on using the changeset viewer.