Exemplo n.º 1
0
        public static DATArchive FromFile(string file)
        {
            DATArchive dat = new DATArchive();

            dat.stream = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read);
            dat.reader = new BinaryReader(dat.stream);

            dat.expectedFiles = dat.reader.ReadInt32();

            dat.files = new DATFileEntry[dat.expectedFiles - 1];

            for (int i = 0; i < dat.expectedFiles - 1; i++)
            {
                int startAddress = dat.reader.ReadInt32();

                string name = Encoding.ASCII.GetString(dat.reader.ReadBytes(13));

                int endAddress = dat.reader.ReadInt32();

                dat.reader.BaseStream.Seek(-4, SeekOrigin.Current);

                int firstNull = name.IndexOf('\0');
                if (firstNull != -1)
                {
                    name = name.Remove(firstNull);
                }

                dat.files[i]         = new DATFileEntry(name, startAddress, endAddress);
                dat.filesIndex[name] = i;
                dat.filesIndexCaseInsensitive[name] = i;
            }

            return(dat);
        }
Exemplo n.º 2
0
        public static DATArchive FromFile(string file)
        {
            BinaryReader binaryReader = new BinaryReader((Stream) new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read));
            DATArchive   datArchive   = new DATArchive();

            datArchive.FileName      = file;
            datArchive.ExpectedFiles = binaryReader.ReadInt32();
            datArchive.Files         = new List <DATFileEntry>();
            for (int index = 0; index < datArchive.ExpectedFiles - 1; ++index)
            {
                long   startAddress = (long)binaryReader.ReadUInt32();
                string name         = Encoding.ASCII.GetString(binaryReader.ReadBytes(13));
                long   endAddress   = (long)binaryReader.ReadUInt32();
                binaryReader.BaseStream.Seek(-4L, SeekOrigin.Current);
                int startIndex = name.IndexOf(char.MinValue);
                if (startIndex != -1)
                {
                    name = name.Remove(startIndex, 13 - startIndex);
                }
                datArchive.Files.Add(new DATFileEntry(name, startAddress, endAddress));
            }
            binaryReader.Close();
            return(datArchive);
        }