using System;
using System.Runtime.InteropServices;
using Vanara.Extensions;
using Vanara.InteropServices;
using FILETIME = System.Runtime.InteropServices.ComTypes.FILETIME;
namespace Vanara.PInvoke
{
public static partial class Shell32
{
/// Exposes resource enumeration methods.
// https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nn-shobjidl_core-ienumresources
[PInvokeData("shobjidl_core.h", MSDNShortId = "NN:shobjidl_core.IEnumResources")]
[ComImport, Guid("2dd81fe3-a83c-4da9-a330-47249d345ba1"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IEnumResources
{
/// Gets the next SHELL_ITEM_RESOURCE structure.
///
/// Type: ULONG
/// The number of resources requested. Currently, must be 1.
///
///
/// Type: SHELL_ITEM_RESOURCE*
/// Receives a pointer to a SHELL_ITEM_RESOURCE structure.
///
///
/// Type: ULONG*
/// A pointer to the number of resources retrieved. Currently, not used.
///
///
/// Type: HRESULT
/// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
///
// https://docs.microsoft.com/fr-fr/windows/win32/api/shobjidl_core/nf-shobjidl_core-ienumresources-next HRESULT Next( ULONG
// celt, SHELL_ITEM_RESOURCE *psir, ULONG *pceltFetched );
[PreserveSig]
HRESULT Next(uint celt, [Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)] SHELL_ITEM_RESOURCE[] psir, out uint pceltFetched);
/// Skips a specified number of resources.
///
/// Type: ULONG
/// The number of resources to skip.
///
// https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ienumresources-skip HRESULT Skip( ULONG
// celt );
void Skip(uint celt);
/// Resets the enumeration index to 0.
// https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ienumresources-reset HRESULT Reset();
void Reset();
/// Clones a resource enumerator.
///
/// Type: IEnumResources**
/// Contains the address of an IEnumResources interface pointer.
///
// https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ienumresources-clone HRESULT Clone(
// IEnumResources **ppenumr );
IEnumResources Clone();
}
/// Exposes methods to manipulate and query Shell item resources.
// https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nn-shobjidl_core-ishellitemresources
[PInvokeData("shobjidl_core.h", MSDNShortId = "NN:shobjidl_core.IShellItemResources")]
[ComImport, Guid("ff5693be-2ce0-4d48-b5c5-40817d1acdb9"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IShellItemResources
{
/// Gets resource attributes.
///
/// Type: DWORD*
/// A pointer to resource attributes. The following are attribute values.
/// FILE_ATTRIBUTE_READONLY
/// Value is 0x00000001.
/// FILE_ATTRIBUTE_HIDDEN
/// Value is 0x00000002.
/// FILE_ATTRIBUTE_SYSTEM
/// Value is 0x00000004.
/// FILE_ATTRIBUTE_DIRECTORY
/// Value is 0x00000010.
/// FILE_ATTRIBUTE_ARCHIVE
/// Value is 0x00000020.
/// FILE_ATTRIBUTE_ENCRYPTED
/// Value is 0x00000040.
/// FILE_ATTRIBUTE_NORMAL
/// Value is 0x00000080.
/// FILE_ATTRIBUTE_TEMPORARY
/// Value is 0x00000100.
/// FILE_ATTRIBUTE_SPARSE_FILE
/// Value is 0x00000200.
/// FILE_ATTRIBUTE_REPARSE_POINT
/// Value is 0x00000400.
/// FILE_ATTRIBUTE_COMPRESSED
/// Value is 0x00000800.
/// FILE_ATTRIBUTE_OFFLINE
/// Value is 0x00001000.
/// FILE_ATTRIBUTE_CONTENT_INDEXED
/// Value is 0x00002000.
/// FILE_ATTRIBUTE_VALID_FLAGS
/// Value is 0x00001ff7.
/// FILE_ATTRIBUTE_VALID_SET_FLAGS
/// Value is 0x000011a7.
///
// https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ishellitemresources-getattributes HRESULT
// GetAttributes( DWORD *pdwAttributes );
FileFlagsAndAttributes GetAttributes();
/// Gets the source size.
///
/// Type: ULONGLONG*
/// A pointer to the source size.
///
// https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ishellitemresources-getsize HRESULT
// GetSize( ULONGLONG *pullSize );
ulong GetSize();
/// Gets file times.
/// The filetime.
/// The filetime.
/// The filetime.
// https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ishellitemresources-gettimes HRESULT
// GetTimes( FILETIME *pftCreation, FILETIME *pftWrite, FILETIME *pftAccess );
void GetTimes(out FILETIME pftCreation, out FILETIME pftWrite, out FILETIME pftAccess);
/// Sets file times.
///
/// Type: const FILETIME*
/// A pointer to a creation date and time as a FILETIME structure.
///
///
/// Type: const FILETIME*
/// A pointer to a write date and time as a FILETIME structure.
///
///
/// Type: const FILETIME*
/// A pointer to an access date and time as a FILETIME structure.
///
// https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ishellitemresources-settimes HRESULT
// SetTimes( const FILETIME *pftCreation, const FILETIME *pftWrite, const FILETIME *pftAccess );
void SetTimes([In, Optional] IntPtr pftCreation, [In, Optional] IntPtr pftWrite, [In, Optional] IntPtr pftAccess);
/// Gets a resource description.
///
/// Type: const SHELL_ITEM_RESOURCE*
/// A pointer to a SHELL_ITEM_RESOURCE resource.
///
///
/// Type: LPWSTR*
/// A pointer to a resource description as a Unicode string.
///
// https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ishellitemresources-getresourcedescription
// HRESULT GetResourceDescription( const SHELL_ITEM_RESOURCE *pcsir, LPWSTR *ppszDescription );
[return: MarshalAs(UnmanagedType.LPWStr)]
string GetResourceDescription(in SHELL_ITEM_RESOURCE pcsir);
/// Gets a resource enumerator object.
///
/// Type: IEnumResources**
/// The address of an IEnumResources interface pointer.
///
// https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ishellitemresources-enumresources HRESULT
// EnumResources( IEnumResources **ppenumr );
IEnumResources EnumResources();
/// Retrieves whether an item supports a specified resource.
/// The shell item resource.
// https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ishellitemresources-supportsresource
// HRESULT SupportsResource( const SHELL_ITEM_RESOURCE *pcsir );
void SupportsResource(in SHELL_ITEM_RESOURCE pcsir);
/// Opens a specified resource.
///
/// Type: const SHELL_ITEM_RESOURCE*
/// A pointer to a SHELL_ITEM_RESOURCE resource.
///
///
/// Type: REFIID
/// A reference to a desired IID.
///
///
/// Type: void**
/// The address of a pointer to a resource.
///
// https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ishellitemresources-openresource HRESULT
// OpenResource( const SHELL_ITEM_RESOURCE *pcsir, REFIID riid, void **ppv );
void OpenResource(in SHELL_ITEM_RESOURCE pcsir, in Guid riid, [MarshalAs(UnmanagedType.IUnknown, IidParameterIndex = 1)] out object ppv);
/// Creates a specified resource.
///
/// Type: const SHELL_ITEM_RESOURCE*
/// A pointer to an SHELL_ITEM_RESOURCE resource.
///
///
/// Type: REFIID
/// A reference to a desired IID.
///
///
/// Type: void**
/// The address of a pointer to the resource.
///
// https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ishellitemresources-createresource HRESULT
// CreateResource( const SHELL_ITEM_RESOURCE *pcsir, REFIID riid, void **ppv );
void CreateResource(in SHELL_ITEM_RESOURCE pcsir, in Guid riid, [MarshalAs(UnmanagedType.IUnknown, IidParameterIndex = 1)] out object ppv);
/// Marks for delete.
// https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ishellitemresources-markfordelete HRESULT MarkForDelete();
void MarkForDelete();
}
/// Sets file times.
/// The IShellItemResources instance.
/// An optional creation date and time.
/// An optional write date and time.
/// An optional access date and time.
public static void SetTimes(this IShellItemResources psir, DateTime? ftCreation, DateTime? ftWrite, DateTime? ftAccess) =>
psir.SetTimes((SafeCoTaskMemStruct)ftCreation?.ToFileTimeStruct(), (SafeCoTaskMemStruct)ftWrite?.ToFileTimeStruct(), (SafeCoTaskMemStruct)ftAccess?.ToFileTimeStruct());
/// Defines Shell item resource.
// https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/ns-shobjidl_core-shell_item_resource typedef struct
// SHELL_ITEM_RESOURCE { GUID guidType; WCHAR szName[260]; } SHELL_ITEM_RESOURCE;
[PInvokeData("shobjidl_core.h", MSDNShortId = "NS:shobjidl_core.SHELL_ITEM_RESOURCE")]
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct SHELL_ITEM_RESOURCE
{
///
/// Type: GUID
/// The GUID that identifies the item.
///
public Guid guidType;
///
/// Type: WCHAR[MAX_PATH]
/// The item name. A null-terminated Unicode buffer of size MAX_LENGTH characters.
///
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
public string szName;
}
}
}