//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
#include <stdio.h>
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "AdvGrid"
#pragma link "BaseGrid"
#pragma resource "*.dfm"
TForm1 *Form1;
int rmdnum, count;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
    if (OpenDialog1->Execute()) {
        Screen->Cursor = crHourGlass;
        FILE *f;
        char c;
        int iTemp;
        AnsiString Value;

        f = fopen(OpenDialog1->FileName.c_str(),"rb");
        if (f == NULL) {
            ShowMessage("Error Loading File");
            Screen->Cursor = crDefault;
            return;
        }
        iTemp = fgetc(f);
        Value = "";
        for (int i=0;i<iTemp;i++) {
            c = fgetc(f);
            Value = Value + AnsiString(c);
        }
        Memo1->Lines->Clear();
        Memo1->Lines->Add(Value);
        rmdnum = fgetc(f);
        rmdnum += fgetc(f) << 8;
        rmdnum += fgetc(f) << 16;
        rmdnum += fgetc(f) << 24;
        Memo1->Lines->Add("File Num: " + IntToStr(rmdnum));

        iTemp = fgetc(f);
        iTemp += fgetc(f) << 8;
        iTemp += fgetc(f) << 16;
        iTemp += fgetc(f) << 24;
        Memo1->Lines->Add("Unknown ??: " + IntToStr(iTemp));

        iTemp = fgetc(f);
        iTemp += fgetc(f) << 8;
        iTemp += fgetc(f) << 16;
        iTemp += fgetc(f) << 24;
        Memo1->Lines->Add("Unknown ??: " + IntToStr(iTemp));

        iTemp = fgetc(f);
        Memo1->Lines->Add("Unknown ??: " + IntToStr(iTemp));

        for (int i=0;i<iTemp;i++) {
            c = fgetc(f);
        }

        iTemp = fgetc(f);
        iTemp += fgetc(f) << 8;
        iTemp += fgetc(f) << 16;
        iTemp += fgetc(f) << 24;
        Memo1->Lines->Add("Unknown ??: " + IntToStr(iTemp));

        iTemp = fgetc(f);
        iTemp += fgetc(f) << 8;
        iTemp += fgetc(f) << 16;
        iTemp += fgetc(f) << 24;
        Memo1->Lines->Add("Unknown ??: " + IntToStr(iTemp));

        iTemp = fgetc(f);
        Memo1->Lines->Add("Unknown ??: " + IntToStr(iTemp));

        count = fgetc(f);
        count += fgetc(f) << 8;
        count += fgetc(f) << 16;
        count += fgetc(f) << 24;
        Memo1->Lines->Add("Count: " + IntToStr(count));

        AdvStringGrid1->RowCount = (count*3)+1;
        AdvStringGrid1->Cells[0][0] = "";
        AdvStringGrid1->Cells[1][0] = "";
        AdvStringGrid1->Cells[2][0] = "";
        AdvStringGrid1->Cells[3][0] = "";
        AdvStringGrid1->Cells[4][0] = "";
        AdvStringGrid1->Cells[5][0] = "";
        AdvStringGrid1->Cells[6][0] = "";
        AdvStringGrid1->Cells[7][0] = "";
        AdvStringGrid1->Cells[8][0] = "";
        AdvStringGrid1->Cells[9][0] = "";
        AdvStringGrid1->Cells[10][0] = "";
        AdvStringGrid1->Cells[11][0] = "";
        AdvStringGrid1->Cells[12][0] = "";
        for (int i=0;i<AdvStringGrid1->RowCount;i++) {
            AdvStringGrid1->Cells[0][i] = "";
        }
        int iRow = 1;
        int items = 0;
        while (items < count) {
            int iNum=0;
            iNum = fgetc(f);
            iNum += fgetc(f) << 8;
            iNum += fgetc(f) << 16;
            iNum += fgetc(f) << 24;
            AdvStringGrid1->Cells[0][iRow] = IntToStr(iNum);
            for (int j=0;j<iNum;j++) {
                for (int i=1;i<13;i++) {
                    iTemp = fgetc(f);
                    iTemp += fgetc(f) << 8;
                    iTemp += fgetc(f) << 16;
                    iTemp += fgetc(f) << 24;
                    AdvStringGrid1->Cells[i][iRow] = IntToStr(iTemp);
                }
                iRow++;
            }
            items++;
        }
        AdvStringGrid1->RowCount = iRow;
        fclose(f);
        Screen->Cursor = crDefault;
    }
}
//---------------------------------------------------------------------------
