using System.Runtime.InteropServices;
using System.Text;
namespace Vanara.PInvoke
{
public static partial class Kernel32
{
/// Retrieves the original name of a compressed file, if the file was compressed by the Lempel-Ziv algorithm.
/// The name of the compressed file.
/// A pointer to a buffer that receives the original name of the compressed file.
///
/// If the function succeeds, the return value is 1.
/// If the function fails, the return value is LZERROR_BADVALUE. There is no extended error information for this function; do not call GetLastError.
///
// INT WINAPI GetExpandedName( _In_ LPTSTR lpszSource, _Out_ LPTSTR lpszBuffer); https://msdn.microsoft.com/en-us/library/windows/desktop/aa364941(v=vs.85).aspx
[DllImport(Lib.Kernel32, SetLastError = true, CharSet = CharSet.Auto)]
[PInvokeData("LzExpand.h", MSDNShortId = "aa364941")]
public static extern int GetExpandedName(string lpszSource, [Out] StringBuilder lpszBuffer);
/// Closes a file that was opened by using the LZOpenFile function.
/// A handle to the file to be closed.
/// This function does not return a value.
// void APIENTRY LZClose( _In_ INT hFile); https://msdn.microsoft.com/en-us/library/windows/desktop/aa365221(v=vs.85).aspx
[DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("LzExpand.h", MSDNShortId = "aa365221")]
public static extern void LZClose(int hFile);
///
/// Copies a source file to a destination file. If the source file has been compressed by the Lempel-Ziv algorithm, this function creates a decompressed
/// destination file. If the source file is not compressed, this function duplicates the original file.
///
/// A handle to the source file.
/// A handle to the destination file.
///
/// If the function succeeds, the return value specifies the size, in bytes, of the destination file.
///
/// If the function fails, the return value is an LZERROR_* code. These codes have values less than zero. Note that LZCopy calls neither
/// SetLastError nor SetLastErrorEx; thus, its failure does not affect a thread's last-error code.
///
/// The following is a list of error codes that LZCopy can return upon failure.
///
///
///
/// Return code
/// Description
///
/// -
/// LZERROR_BADINHANDLE
/// The handle identifying the source file is not valid. The file cannot be read.
///
/// -
/// LZERROR_BADOUTHANDLE
/// The handle identifying the destination file is not valid. The file cannot be written.
///
/// -
/// LZERROR_GLOBALLOC
/// The maximum number of open compressed files has been exceeded or local memory cannot be allocated.
///
/// -
/// LZERROR_GLOBLOCK
/// The LZ file handle cannot be locked down.
///
/// -
/// LZERROR_READ
/// The source file format is not valid.
///
///
///
/// There is no extended error information for this function; do not call GetLastError.
///
// LONG WINAPI LZCopy( _In_ INT hfSource, _In_ INT hfDest); https://msdn.microsoft.com/en-us/library/windows/desktop/aa365223(v=vs.85).aspx
[DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("LzExpand.h", MSDNShortId = "aa365223")]
public static extern int LZCopy(int hfSource, int hfDest);
/// Allocates memory for the internal data structures required to decompress files, and then creates and initializes them.
/// A handle to the file.
///
/// If the function succeeds, the return value is a new LZ file handle.
///
/// If the function fails, the return value is an LZERROR_* code. These codes have values less than zero. Note that LZInit calls neither
/// SetLastError nor SetLastErrorEx; thus, its failure does not affect a thread's last-error code.
///
/// The following is the list of the error codes that LZInit can return upon failure.
///
///
///
/// Return code
/// Description
///
/// -
/// LZERROR_BADINHANDLE
/// The handle identifying the source file is not valid. The file cannot be read.
///
/// -
/// LZERROR_GLOBALLOC
/// The maximum number of open compressed files has been exceeded or local memory cannot be allocated.
///
/// -
/// LZERROR_GLOBLOCK
/// The LZ file handle cannot be locked down.
///
/// -
/// LZERROR_UNKNOWNALG
/// The file is compressed with an unrecognized compression algorithm.
///
///
///
/// There is no extended error information for this function; do not call GetLastError.
///
// INT WINAPI LZInit( _In_ INT hfSource); https://msdn.microsoft.com/en-us/library/windows/desktop/aa365224(v=vs.85).aspx
[DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("LzExpand.h", MSDNShortId = "aa365224")]
public static extern int LZInit(int hfSource);
/// Creates, opens, reopens, or deletes the specified file.
/// The name of the file.
///
///
/// A pointer to the OFSTRUCT structure that is to receive information about the file when the file is first opened. The structure can be used in
/// subsequent calls to the LZOpenFile function to see the open file.
///
/// The szPathName member of this structure contains characters from the original equipment manufacturer (OEM) character set.
///
///
/// The action to be taken. This parameter can be one or more of the following values.
///
///
///
/// Value
/// Meaning
///
/// -
/// OF_CANCEL0x0800
/// Ignored. Provided only for compatibility with 16-bit Windows. Use the OF_PROMPT style to display a dialog box containing a Cancel button.
///
/// -
/// OF_CREATE0x1000
/// Directs LZOpenFile to create a new file. If the file already exists, it is truncated to zero length.
///
/// -
/// OF_DELETE0x0200
/// Deletes the file.
///
/// -
/// OF_EXIST0x4000
/// Opens the file and then closes it to test for a file's existence.
///
/// -
/// OF_PARSE0x0100
/// Fills the OFSTRUCT structure but carries out no other action.
///
/// -
/// OF_PROMPT0x2000
///
/// Displays a dialog box if the requested file does not exist. The dialog box informs the user that the system cannot find the file, and it contains
/// Retry and Cancel buttons. Clicking the Cancel button directs LZOpenFile to return a file not found error message.
///
///
/// -
/// OF_READ0x0000
/// Opens the file for reading only.
///
/// -
/// OF_READWRITE0x0002
/// Opens the file for reading and writing.
///
/// -
/// OF_REOPEN0x8000
/// Opens the file using information in the reopen buffer.
///
/// -
/// OF_SHARE_DENY_NONE0x0040
///
/// Opens the file without denying other processes read or write access to the file. LZOpenFile fails if the file has been opened in compatibility mode
/// by any other process.
///
///
/// -
/// OF_SHARE_DENY_READ0x0030
///
/// Opens the file and denies other processes read access to the file. LZOpenFile fails if the file has been opened in compatibility mode or has been
/// opened for read access by any other process.
///
///
/// -
/// OF_SHARE_DENY_WRITE0x0020
///
/// Opens the file and denies other processes write access to the file. LZOpenFile fails if the file has been opened in compatibility mode or has been
/// opened for write access by any other process.
///
///
/// -
/// OF_SHARE_EXCLUSIVE0x0010
///
/// Opens the file in exclusive mode, denying other processes both read and write access to the file. LZOpenFile fails if the file has been opened in any
/// other mode for read or write access, even by the current process.
///
///
/// -
/// OF_WRITE0x0001
/// Opens the file for writing only.
///
///
///
///
///
///
/// If the function succeeds and the value specified by the wStyle parameter is not OF_READ, the return value is a handle identifying the file. If
/// the file is compressed and opened with wStyle set to OF_READ, the return value is a special file handle.
///
///
/// If the function fails, the return value is an LZERROR_* code. These codes have values less than zero. There is no extended error information
/// for this function; do not call GetLastError.
///
/// The following is the list of the error codes that LZOpenFile can return upon failure.
///
///
///
/// Return code/value
/// Description
///
/// -
/// LZERROR_BADINHANDLE-1
/// The handle identifying the source file is not valid. The file cannot be read.
///
/// -
/// LZERROR_GLOBALLOC-5
/// The maximum number of open compressed files has been exceeded or local memory cannot be allocated.
///
///
///
///
// INT WINAPI LZOpenFile( _In_ LPTSTR lpFileName, _Out_ LPOFSTRUCT lpReOpenBuf, _In_ WORD wStyle); https://msdn.microsoft.com/en-us/library/windows/desktop/aa365225(v=vs.85).aspx
[DllImport(Lib.Kernel32, SetLastError = true, CharSet = CharSet.Auto)]
[PInvokeData("LzExpand.h", MSDNShortId = "aa365225")]
public static extern int LZOpenFile(string lpFileName, out OFSTRUCT lpReOpenBuf, ushort wStyle);
/// Reads (at most) the specified number of bytes from a file and copies them into a buffer.
/// A handle to the file.
/// A pointer to a buffer that receives the bytes read from the file. Ensure that this buffer is larger than cbRead.
/// The count of bytes to be read.
///
/// If the function succeeds, the return value specifies the number of bytes read.
///
/// If the function fails, the return value is an LZERROR_* code. These codes have values less than zero. Note that LZRead calls neither
/// SetLastError nor SetLastErrorEx; thus, its failure does not affect a thread's last-error code.
///
/// The following is the list of error codes that LZRead can return upon failure.
///
///
///
/// Return code
/// Description
///
/// -
/// LZERROR_BADINHANDLE
/// The handle identifying the source file is not valid. The file cannot be read.
///
/// -
/// LZERROR_BADOUTHANDLE
/// The handle identifying the destination file is not valid. The file cannot be written.
///
/// -
/// LZERROR_BADVALUE
/// One of the input parameters is not valid.
///
/// -
/// LZERROR_GLOBALLOC
/// The maximum number of open compressed files has been exceeded or local memory cannot be allocated.
///
/// -
/// LZERROR_GLOBLOCK
/// The LZ file handle cannot be locked down.
///
/// -
/// LZERROR_READ
/// The source file format is not valid.
///
/// -
/// LZERROR_WRITE
/// There is insufficient space for the output file.
///
///
///
/// There is no extended error information for this function; do not call GetLastError.
///
// INT WINAPI LZRead( _In_ INT hFile, _Out_ LPSTR lpBuffer, _In_ INT cbRead); https://msdn.microsoft.com/en-us/library/windows/desktop/aa365226(v=vs.85).aspx
[DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Ansi)]
[PInvokeData("LzExpand.h", MSDNShortId = "aa365226")]
public static extern int LZRead(int hFile, [Out] StringBuilder lpBuffer, int cbRead);
/// Moves a file pointer the specified number of bytes from a starting position.
/// A handle to the file.
/// The number of bytes by which to move the file pointer.
///
/// The starting position of the pointer. This parameter must be one of the following values.
///
///
///
/// Value
/// Meaning
///
/// -
/// 0
/// Moves the file pointer lOffset bytes from the beginning of the file.
///
/// -
/// 1
/// Moves the file pointer lOffset bytes from the current position.
///
/// -
/// 2
/// Moves the file pointer lOffset bytes from the end of the file.
///
///
///
///
///
/// If the function succeeds, the return value specifies the offset from the beginning of the file to the new pointer position.
///
/// If the function fails, the return value is an LZERROR_* code. These codes have values less than zero. Note that LZSeek calls neither
/// SetLastError nor SetLastErrorEx; thus, its failure does not affect a thread's last-error code.
///
/// The following is the list of error codes that LZSeek can return upon failure.
///
///
///
/// Return code
/// Description
///
/// -
/// LZERROR_BADINHANDLE
/// The handle identifying the source file is not valid. The file cannot be read.
///
/// -
/// LZERROR_BADVALUE
/// One of the parameters is outside the range of acceptable values.
///
/// -
/// LZERROR_GLOBLOCK
/// The LZ file handle cannot be locked down.
///
///
///
/// There is no extended error information for this function; do not call GetLastError.
///
// LONG WINAPI LZSeek( _In_ INT hFile, _In_ LONG lOffset, _In_ INT iOrigin); https://msdn.microsoft.com/en-us/library/windows/desktop/aa365227(v=vs.85).aspx
[DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("LzExpand.h", MSDNShortId = "aa365227")]
public static extern int LZSeek(int hFile, int lOffset, int iOrigin);
}
}