[7443] Better error reporting at DBC files extraction in ad.exe. No functionlity chnages in normal work case.

This commit is contained in:
VladimirMangos 2009-03-12 10:01:34 +03:00
parent 498ab2df07
commit 719991d381
5 changed files with 42 additions and 14 deletions

View file

@ -153,7 +153,12 @@ uint32 ReadMapDBC()
{ {
printf("Read Map.dbc file... "); printf("Read Map.dbc file... ");
DBCFile dbc("DBFilesClient\\Map.dbc"); DBCFile dbc("DBFilesClient\\Map.dbc");
dbc.open();
if(!dbc.open())
{
printf("Fatal error: Invalid Map.dbc file format!\n");
exit(1);
}
size_t map_count = dbc.getRecordCount(); size_t map_count = dbc.getRecordCount();
map_ids = new map_id[map_count]; map_ids = new map_id[map_count];
@ -170,7 +175,12 @@ void ReadAreaTableDBC()
{ {
printf("Read AreaTable.dbc file..."); printf("Read AreaTable.dbc file...");
DBCFile dbc("DBFilesClient\\AreaTable.dbc"); DBCFile dbc("DBFilesClient\\AreaTable.dbc");
dbc.open();
if(!dbc.open())
{
printf("Fatal error: Invalid AreaTable.dbc file format!\n");
exit(1);
}
size_t area_count = dbc.getRecordCount(); size_t area_count = dbc.getRecordCount();
size_t maxid = dbc.getMaxId(); size_t maxid = dbc.getMaxId();
@ -189,7 +199,12 @@ void ReadLiquidTypeTableDBC()
{ {
printf("Read LiquidType.dbc file..."); printf("Read LiquidType.dbc file...");
DBCFile dbc("DBFilesClient\\LiquidType.dbc"); DBCFile dbc("DBFilesClient\\LiquidType.dbc");
dbc.open(); if(!dbc.open())
{
printf("Fatal error: Invalid LiquidType.dbc file format!\n");
exit(1);
}
size_t LiqType_count = dbc.getRecordCount(); size_t LiqType_count = dbc.getRecordCount();
size_t LiqType_maxid = dbc.getMaxId(); size_t LiqType_maxid = dbc.getMaxId();
LiqType = new uint16[LiqType_maxid + 1]; LiqType = new uint16[LiqType_maxid + 1];

Binary file not shown.

View file

@ -9,29 +9,42 @@ DBCFile::DBCFile(const std::string &filename):
{ {
} }
void DBCFile::open() bool DBCFile::open()
{ {
MPQFile f(filename.c_str()); MPQFile f(filename.c_str());
char header[4]; char header[4];
unsigned int na,nb,es,ss; unsigned int na,nb,es,ss;
f.read(header,4); // Number of records if(f.read(header,4)!=4) // Number of records
assert(header[0]=='W' && header[1]=='D' && header[2]=='B' && header[3] == 'C'); return false;
f.read(&na,4); // Number of records
f.read(&nb,4); // Number of fields if(header[0]!='W' || header[1]!='D' || header[2]!='B' || header[3]!='C')
f.read(&es,4); // Size of a record return false;
f.read(&ss,4); // String size
if(f.read(&na,4)!=4) // Number of records
return false;
if(f.read(&nb,4)!=4) // Number of fields
return false;
if(f.read(&es,4)!=4) // Size of a record
return false;
if(f.read(&ss,4)!=4) // String size
return false;
recordSize = es; recordSize = es;
recordCount = na; recordCount = na;
fieldCount = nb; fieldCount = nb;
stringSize = ss; stringSize = ss;
assert(fieldCount*4 == recordSize); if(fieldCount*4 != recordSize)
return false;
data = new unsigned char[recordSize*recordCount+stringSize]; data = new unsigned char[recordSize*recordCount+stringSize];
stringTable = data + recordSize*recordCount; stringTable = data + recordSize*recordCount;
f.read(data,recordSize*recordCount+stringSize);
size_t data_size = recordSize*recordCount+stringSize;
if(f.read(data,data_size)!=data_size)
return false;
f.close(); f.close();
return true;
} }
DBCFile::~DBCFile() DBCFile::~DBCFile()
{ {

View file

@ -10,7 +10,7 @@ public:
~DBCFile(); ~DBCFile();
// Open database. It must be openened before it can be used. // Open database. It must be openened before it can be used.
void open(); bool open();
// Database exceptions // Database exceptions
class Exception class Exception

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__ #ifndef __REVISION_NR_H__
#define __REVISION_NR_H__ #define __REVISION_NR_H__
#define REVISION_NR "7442" #define REVISION_NR "7443"
#endif // __REVISION_NR_H__ #endif // __REVISION_NR_H__