/// <summary> /// Get information about a file. /// </summary> /// <param name="fileName">Name of the file for which information is requested.</param> /// <param name="rDate">A reference parameter into which the file date is stored.</param> /// <param name="rTime">A reference parameter into which the file time is stored.</param> /// <param name="attribs">A reference parameter into which file attributes are stored.</param> /// <param name="err">Error return value.</param> /// <param name="pUserData">User data object.</param> /// <returns>On success, returns a handle to the open file, and the rDate, rTime, and attribs parameters are filled. /// Returns -1 on error.</returns> /// <remarks>The File Compression Interface calls this function to open a file and return information about it.</remarks> protected virtual IntPtr GetOpenInfo( string fileName, // ref short rDate, ref short rTime, ref short attribs, ref int err, IntPtr pUserData) { Trace.WriteLine(string.Format("GetOpenInfo {0}", fileName)); try { // Get file date/time and attributes FileAttributes fattr = File.GetAttributes(fileName); DateTime fdate = File.GetLastWriteTime(fileName); // Convert to format that FCI understands attribs = FCntl.FAttrsFromFileAttributes(fattr); FCntl.DosDateTimeFromDateTime(fdate, ref rDate, ref rTime); // open file and return handle return(CabIO.FileOpen(fileName, FileAccess.Read, FileShare.None, FileMode.Open, ref err)); } catch (Exception ex) { Trace.WriteLine(ex); err = 1; } return((IntPtr)(-1)); }
/// <summary> /// Allocate a block of memory. /// </summary> /// <param name="cb">The number of bytes to be allocated.</param> /// <returns>An IntPtr that references the allocated memory.</returns> /// <remarks>The File Decompression Interface (FDI) calls this function to allocate memory /// for its internal use.</remarks> protected virtual IntPtr MemAlloc(int cb) { IntPtr m = CabIO.MemAlloc(cb); Trace.WriteLine(string.Format("MemAlloc {0} = {1}", cb, m)); return(m); }
/// <summary> /// Reads bytes from a file. /// </summary> /// <param name="hf">The file handle from which to read.</param> /// <param name="buffer">The buffer where read bytes are placed.</param> /// <param name="cb">Size of the read buffer.</param> /// <param name="err">Error return value.</param> /// <param name="pUserData">User data object.</param> /// <returns>Returns the number of bytes read.</returns> /// <remarks>The File Compression Interface (FCI) calls this function to read from a file.</remarks> protected virtual int FileRead(IntPtr hf, byte[] buffer, int cb, ref int err, IntPtr pUserData) { Trace.WriteLine(string.Format("FileRead {0}", hf)); int bytesRead = CabIO.FileRead(hf, buffer, cb, ref err, ((GCHandle)pUserData).Target); Trace.WriteLine(string.Format("Returning {0}", bytesRead)); return(bytesRead); }
/// <summary> /// Sets the current position in a file to the given value. /// </summary> /// <param name="hf">The handle of an open file.</param> /// <param name="dist">The number of bytes to move the pointer.</param> /// <param name="seekType">The starting position for the move. Values are SEEK_CUR, SEEK_END, or SEEK_SET.</param> /// <returns>Returns the new file position. Returns -1 on error.</returns> /// <remarks>The File Decompression Interface (FDI) calls this function to position the file pointer.</remarks> protected virtual int FileSeek(IntPtr hf, int dist, int seektype) { Trace.WriteLine(string.Format("FileSeek {0}", hf)); int err = 0; try { return(CabIO.FileSeek(hf, dist, seektype, ref err, userData)); } finally { erf.ErrorType = err; } }
/// <summary> /// Closes a file. /// </summary> /// <param name="hf">Handle to the file to be closed.</param> /// <returns>Returns 0 on success. Returns -1 on error.</returns> /// <remarks>The File Decompression Interface (FDI) calls this function to close a file.</remarks> protected virtual int FileClose(IntPtr hf) { Trace.WriteLine(string.Format("FileWrite {0}", hf)); int err = 0; try { return(CabIO.FileClose(hf, ref err, userData)); } finally { erf.ErrorType = err; } }
/// <summary> /// Reads bytes from a file. /// </summary> /// <param name="hf">The file handle from which to read.</param> /// <param name="buffer">The buffer where read bytes are placed.</param> /// <param name="cb">Size of the read buffer.</param> /// <returns>Returns the number of bytes read.</returns> /// <remarks>The File Decompression Interface (FDI) calls this function to read from a file.</remarks> protected virtual int FileRead(IntPtr hf, byte[] buffer, int cb) { Trace.WriteLine(string.Format("FileRead {0}", hf)); int err = 0; try { return(CabIO.FileRead(hf, buffer, cb, ref err, userData)); } finally { erf.ErrorType = err; } }
/// <summary> /// Opens a file. /// </summary> /// <param name="fileName">The path name of the file to be opened.</param> /// <param name="oflag">Open mode flags.</param> /// <param name="pmode">Share mode flags.</param> /// <returns>Returns an IntPtr that references the open file handle. Returns -1 on error.</returns> /// <remarks>The File Decompression Interface (FDI) calls this function to open files.</remarks> protected virtual IntPtr FileOpen(string fileName, int oflag, int pmode) { Trace.WriteLine("FileOpen {0}", fileName); int err = 0; try { return(CabIO.FileOpen(fileName, oflag, pmode, ref err, userData)); } finally { erf.ErrorType = err; } }
/// <summary> /// Frees a block of memory previously allocated by MemAlloc. /// </summary> /// <param name="mem">An IntPtr that references the memory to be freed.</param> /// <remarks>The File Decompression Interface (FDI) calls this function to free /// memory that it allocated with a call to <see cref="MemAlloc"/>.</remarks> protected virtual void MemFree(IntPtr mem) { Trace.WriteLine(string.Format("MemFree {0}", mem)); CabIO.MemFree(mem); }
/// <summary> /// Delete a file. /// </summary> /// <param name="fileName">The name of the file to be deleted.</param> /// <param name="err">Error return value.</param> /// <param name="pUserData">User data object.</param> /// <returns>Returns 0 on success. Returns -1 on error.</returns> /// <remarks>The File Compression Interface (FCI) calls this function to delete a file.</remarks> protected virtual int FileDelete(string fileName, ref int err, IntPtr pUserData) { Trace.WriteLine(string.Format("FileDelete {0}", fileName)); return(CabIO.FileDelete(fileName, ref err, ((GCHandle)pUserData).Target)); }
/// <summary> /// Sets the current position in a file to the given value. /// </summary> /// <param name="hf">The handle of an open file.</param> /// <param name="dist">The number of bytes to move the pointer.</param> /// <param name="seekType">The starting position for the move. Values are SEEK_CUR, SEEK_END, or SEEK_SET.</param> /// <param name="err">Error return value.</param> /// <param name="pUserData">User data object.</param> /// <returns>Returns the new file position. Returns -1 on error.</returns> /// <remarks>The File Compression Interface (FCI) calls this function to position the file pointer.</remarks> protected virtual int FileSeek(IntPtr hf, int dist, int seekType, ref int err, IntPtr pUserData) { Trace.WriteLine(string.Format("FileSeek {0}", hf)); return(CabIO.FileSeek(hf, dist, seekType, ref err, ((GCHandle)pUserData).Target)); }
/// <summary> /// Closes a file. /// </summary> /// <param name="hf">Handle to the file to be closed.</param> /// <param name="err">Error return value.</param> /// <param name="pUserData">User data object.</param> /// <returns>Returns 0 on success. Returns -1 on error.</returns> /// <remarks>The File Compression Interface (FCI) calls this function to close a file.</remarks> protected virtual int FileClose(IntPtr hf, ref int err, IntPtr pUserData) { Trace.WriteLine(string.Format("FileClose {0}", hf)); return(CabIO.FileClose(hf, ref err, ((GCHandle)pUserData).Target)); }
/// <summary> /// Opens a file. /// </summary> /// <param name="fileName">The path name of the file to be opened.</param> /// <param name="oflag">Open mode flags.</param> /// <param name="pmode">Share mode flags.</param> /// <param name="err">Error return value.</param> /// <param name="pUserData">User data object.</param> /// <returns>Returns an IntPtr that references the open file handle. Returns -1 on error.</returns> /// <remarks>The File Compression Interface (FCI) calls this function to open files.</remarks> protected virtual IntPtr FileOpen(string fileName, int oflag, int pmode, ref int err, IntPtr pUserData) { Trace.WriteLine(string.Format("FileOpen {0}", fileName)); return(CabIO.FileOpen(fileName, oflag, pmode, ref err, ((GCHandle)pUserData).Target)); }