Exemplo n.º 1
0
        /// <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));
        }
Exemplo n.º 2
0
 /// <summary>
 /// Moves the current position value in a file
 /// </summary>
 /// <param name="hf">The file handle.</param>
 /// <param name="dist">Number of bytes to move the pointer.</param>
 /// <param name="seektype">A value that specifies how the pointer should be moved.  Valid values are SEEK_CUR, SEEK_END, and SEEK_SET.</param>
 /// <param name="err">Error return.</param>
 /// <param name="userData">User data passed to the function from CAB API.</param>
 /// <returns>Returns the new file position.  Returns -1 on error.</returns>
 public static int FileSeek(
     IntPtr hf,
     int dist,
     int seektype,
     ref int err,
     object userData)
 {
     try
     {
         FileStream           f      = FileStreamFromHandle(hf);
         System.IO.SeekOrigin origin = FCntl.SeekOriginFromSeekType(seektype);
         // cast to int because FileStream.Seek returns a long
         return((int)f.Seek(dist, origin));
     }
     catch (Exception)
     {
         return(-1);
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Opens a file.
        /// </summary>
        /// <param name="fileName">The name of the file to open.</param>
        /// <param name="oflag">Windows open mode flags.</param>
        /// <param name="pmode">Windows mode flags.</param>
        /// <param name="err">Returned error flag.</param>
        /// <param name="userData">User data passed to the function (not used, but required by FDI/FCI).</param>
        /// <returns>Returns a handle to the open file.  On error, returns -1.</returns>
        /// <remarks>FCI and FDI use Windows semantics to open files.  This function converts the
        /// Windows semantics to .NET, and opens the file accordingly.</remarks>
        public static IntPtr FileOpen(
            string fileName,
            int oflag,
            int pmode,
            ref int err,
            object userData)
        {
            try
            {
                FileAccess fAccess = FCntl.FileAccessFromOFlag(oflag);
                FileMode   fMode   = FCntl.FileModeFromOFlag(oflag);
                FileShare  fShare  = FCntl.FileShareFromPMode(pmode);

                return(FileOpen(fileName, fAccess, fShare, fMode, ref err));
            }
            catch (Exception)
            {
                return((IntPtr)(-1));
            }
        }