示例#1
0
        /// <summary>
        /// Gets the correct BaseFile class by comparing the file with the known header signatures.
        /// </summary>
        /// <param name="filePath">Filepath</param>
        /// <returns></returns>
        public static BaseFile GetTypeFromFile(string filePath)
        {
            byte[] buffer;
            using (BinaryReader reader = new BinaryReader(new FileStream(filePath, FileMode.Open)))
            {
                if (reader.BaseStream.Length < 256)
                {
                    buffer = new byte[reader.BaseStream.Length];
                    reader.Read(buffer, 0, buffer.Length);
                }
                else
                {
                    buffer = new byte[256];
                    reader.Read(buffer, 0, 256);
                }
            }

            if (BG.Compare(buffer))
            {
                return(new BGFile(filePath));
            }
            if (LZB.Compare(buffer))
            {
                return(new LZBFile(filePath));
            }
            if (PACK.Compare(buffer))
            {
                return(new PBFile(filePath));
            }
            if (SEQ.Compare(buffer))
            {
                return(new SEQFile(filePath));
            }
            if (STR.Compare(filePath))
            {
                return(new STRFile(filePath));
            }
            if (TIM.Compare(buffer))
            {
                return(new TIMFile(filePath));
            }
            if (VB.Compare(buffer))
            {
                return(new VBFile(filePath));
            }
            if (VH.Compare(buffer))
            {
                return(new VHFile(filePath));
            }
            if (XA.Compare(filePath))
            {
                return(new XAFile(filePath));
            }
            return(new BaseFile(filePath));
        }