コード例 #1
0
ファイル: DATReader.cs プロジェクト: Venseer/tools
        // Based on code by Dims
        public static DAT ReadDat(string filename, out DatReaderError error)
        {
            if (String.IsNullOrEmpty(filename))
            {
                error = new DatReaderError(DatError.IOError, "Invalid filename: '" + filename + "'");
                return(null);
            }

            List <string> dirs = new List <string>();

            DAT dat = new DAT();

            dat.DatFileName = filename;
            BinaryReader br = null;

            try
            {
                br = new BinaryReader(File.Open(filename, FileMode.Open));
            }
            catch (IOException io)
            {
                error = new DatReaderError(DatError.IOError, io.Message);
                return(null);
            }
            dat.br = br;
            br.BaseStream.Seek(-8, SeekOrigin.End);
            dat.TreeSize        = br.ReadInt32();
            dat.FileSizeFromDat = br.ReadInt32();

            br.BaseStream.Seek(0, SeekOrigin.Begin);
            ulong F1DirCount = ToLittleEndian((ulong)br.ReadInt32());

            if (F1DirCount == 0x01 || F1DirCount == 0x33) // Check if it's Fallout 1 dat
            {
                error = new DatReaderError(DatError.IOError, "Fallout 1 DATs not supported.");
                return(null);
            }

            if (br.BaseStream.Length != dat.FileSizeFromDat)
            {
                error = new DatReaderError(DatError.WrongSize, "Size is incorrect.");
                return(null);
            }
            br.BaseStream.Seek(-(dat.TreeSize + 8), SeekOrigin.End);
            dat.FilesTotal = br.ReadInt32();
            byte[] buff = new byte[dat.TreeSize];
            br.Read(buff, 0, (int)(dat.TreeSize - 4));
            dat.FileList = FindFiles(dat, br);

            error = new DatReaderError(DatError.Success, "");
            return(dat);
        }
コード例 #2
0
        // Based on code by Dims
        public static DAT ReadDat(string filename, out DatReaderError error)
        {
            if (String.IsNullOrEmpty(filename))
            {
                error = new DatReaderError(DatError.IOError, "Invalid filename: '" + filename  + "'");
                return null;
            }

            List<string> dirs = new List<string>();

            DAT dat = new DAT();
            dat.DatFileName = filename;
            BinaryReader br=null;
            try
            {
                br = new BinaryReader(File.Open(filename, FileMode.Open));
            }
            catch (IOException io)
            {
                error = new DatReaderError(DatError.IOError, io.Message);
                return null;
            }
            dat.br = br;
            br.BaseStream.Seek(-8, SeekOrigin.End);
            dat.TreeSize = br.ReadInt32();
            dat.FileSizeFromDat = br.ReadInt32();

            br.BaseStream.Seek(0, SeekOrigin.Begin);
            ulong F1DirCount = ToLittleEndian((ulong)br.ReadInt32());
            if (F1DirCount == 0x01 || F1DirCount == 0x33) // Check if it's Fallout 1 dat
            {
                error = new DatReaderError(DatError.IOError, "Fallout 1 DATs not supported.");
                return null;
            }

            if (br.BaseStream.Length != dat.FileSizeFromDat)
            {
                error = new DatReaderError(DatError.WrongSize, "Size is incorrect.");
                return null;
            }
            br.BaseStream.Seek(-(dat.TreeSize+8), SeekOrigin.End);
            dat.FilesTotal = br.ReadInt32();
            byte[] buff = new byte[dat.TreeSize];
            br.Read(buff, 0, (int)(dat.TreeSize - 4));
            dat.FileList = FindFiles(dat, br);

            error = new DatReaderError(DatError.Success, "");
            return dat;
        }