예제 #1
0
    public void extractDbHeaders()
    {
        Int32 nBytes;
        //dbOffset = 0;
        FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read);
        BinaryReader br = new BinaryReader(fileStream);
        try
        {
            for (int db = 0; db < dbCount; db++)
            {
                dbHeader[db] = new htbHeader();
                dbHeader[db].date           = br.ReadChars(26);
                dbHeader[db].ldate          = br.ReadInt32();//offset + 26);
                dbHeader[db].cfg_file       = br.ReadChars(14);
                dbHeader[db].pro_file = br.ReadChars(14);
                dbHeader[db].unused0 = br.ReadChars(52);
                dbHeader[db].speed = br.ReadUInt32();// offset + 110);
                dbHeader[db].alloc = br.ReadUInt32();
                dbHeader[db].offset = br.ReadInt32(); // offset + 118);
                dbHeader[db].period = br.ReadUInt32(); // GetULONG(fid, offset + 122);
                dbHeader[db].extension = br.ReadUInt32(); // GetULONG(fid, offset + 126);
                dbHeader[db].skip = br.ReadUInt16();// GetUSHORT(fid, offset + 130);
                dbHeader[db].first_channel = br.ReadUInt16();//  GetUSHORT(fid, offset + 132);
                dbHeader[db].nchannels = br.ReadUInt16();// GetUSHORT(fid, offset + 134);
                dbHeader[db].sweep_limit = br.ReadUInt16();// GetUSHORT(fid, offset + 136);
                dbHeader[db].cancel_override = br.ReadUInt32();// GetULONG(fid, offset + 138);
                dbHeader[db].func = br.ReadByte(); // GetUCHAR(fid, offset + 142);
                br.ReadByte();
                dbHeader[db].tag = br.ReadUInt16(); // GetUSHORT(fid, offset + 144);
                //br.ReadByte();
                dbHeader[db].npages = br.ReadUInt16(); //GetUSHORT(fid, offset + 146);
                dbHeader[db].nsamples = br.ReadUInt32(); //GetULONG(fid, offset + 148);
                dbHeader[db].samples_per_page = br.ReadUInt16(); //GetUSHORT(fid, offset + 152);
                dbHeader[db].sweep = br.ReadUInt16();// GetUSHORT(fid, offset + 154);
                dbHeader[db].next_page = br.ReadUInt16();// GetUSHORT(fid, offset + 156);
                dbHeader[db].next_off = br.ReadUInt16();// GetUSHORT(fid, offset + 158);
                dbHeader[db].title = br.ReadChars(80); // GetString(fid, offset + 160, 80);
                dbHeader[db].speed_units = br.ReadUInt32(); // GetULONG(fid, offset + 240);
                dbHeader[db].filler = br.ReadChars(268);

                dbOffset[0] = 0;
                for (int i = 1; i < db+1; i++)
                {
                    dbOffset[db] = dbOffset[db] + (int)dbHeader[i - 1].alloc;
                }
                br.BaseStream.Position += dbHeader[db].alloc - dbHeader[db].size() + 1;
            }
        }
        finally { br.Close(); fileStream.Close(); }
    }
예제 #2
0
    //  ~htbFile ();                           //Destructor
    //    public int getHtbCount() { return (anyError() ? (-1) : dbCount); }
    //public long getHtbOffset(int db) { return (anyError() || db >= dbCount ? (-1) : dbOffset[db]); }
    //public long getHtbSize(int db) { return (anyError() || db >= dbCount ? (-1) : dbHeader[db].alloc - sizeof(htbHeader)); }
    //public char getFileName(char str);		//returns file name containing this database this
    //note that enough memory is allocated to str pointer
    //and caller is responsible for freeing this memory
    //         htbHeader &getHtbHeader ( htbHeader &header , int db );	//returns htbHeader of requested database
    //         const htbHeader &getHtbHeader ( int db )	{ return dbHeader[db];	};	//overloaded function
    //void getHtb(int db);					//returns data included in a database, the caller is
    //responsible for freeing the allocated memory
    //Example : getHtb(0) returns first database in the file
    //void getEpoch(int db, int epoch);	//returns data includede in a database epoch, for average
    //databases this is equal to htbFile::getHtb
    //The caller is responsible for freeing allocated memory
    //Example : getEpoch(0,0) returns first Epoch of the first database
    //                (int)HTB.getEpoch ( 3 , (int)HTB.getHtbHeader(3).sweep-1 ) returns
    //                    the last epoch of 4th database number
    //char errorString(Int32 errorNum);	//returns error string associated with each error value
    public int extractDbCount()
    {
        Int32 nBytes;
        htbHeader htbheader = new htbHeader();

        int num = 0;
        Int32 offset = 0;
        FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read);
        BinaryReader br = new BinaryReader(fileStream);
        try
        {
            while (true)
            {
                try
                {
                    br.BaseStream.Position = offset + 114;
                    int n = br.ReadInt32();
                    offset += n;
                    num++;
                }
                catch { break;}
            }
        }
        finally { br.Close(); fileStream.Close(); }
        return num;
    }