Ejemplo n.º 1
0
        public static bool IsZipRelatedFile(Delimon.Win32.IO.FileInfo file1)
        {
            bool blZipExtension = false;

            byte[] Zipbytes = { 0x50, 0x4B };
            //504B


            using (FileStream fs = file1.Open(Delimon.Win32.IO.FileMode.Open, Delimon.Win32.IO.FileAccess.Read, Delimon.Win32.IO.FileShare.ReadWrite))
            {
                if (fs == null)
                {
                    return(false);
                }
                else
                {
                    int read = 2;

                    byte[] buffer    = new byte[read];
                    int    readCount = fs.Read(buffer, 0, read);

                    using (MemoryStream ms = new MemoryStream(buffer))
                    {
                        ms.Seek(0, SeekOrigin.Begin);

                        byte[] realBuffer = new byte[readCount];
                        ms.Read(realBuffer, 0, readCount);

                        blZipExtension = realBuffer == Zipbytes;
                    }
                }
                try
                {
                    fs.Close();
                }
                catch (Exception)
                {
                }
            }


            return(blZipExtension);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Matches the file.
 /// </summary>
 /// <param name="filePath">The file path.</param>
 /// <param name="ignoreExtension">if set to <c>true</c>
 /// [ignore extension].</param>
 /// <returns></returns>
 public bool MatchesFile(
     Delimon.Win32.IO.FileInfo filePath,
     bool ignoreExtension)
 {
     if (filePath == null || !filePath.Exists || filePath.Length <= 0)
     {
         return(false);
     }
     else
     {
         if (ignoreExtension ||
             MatchesFileExtension(filePath.Extension))
         {
             using (FileStream fs = filePath.Open(Delimon.Win32.IO.FileMode.Open, Delimon.Win32.IO.FileAccess.Read, Delimon.Win32.IO.FileShare.ReadWrite))
             {
                 return(MatchesStream(fs));
             }
         }
         else
         {
             return(false);
         }
     }
 }