TrinityCore
Loading...
Searching...
No Matches
DBCStore.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include "DBCStore.h"
19#include "DBCDatabaseLoader.h"
20
21DBCStorageBase::DBCStorageBase(char const* fmt) : _fieldCount(0), _fileFormat(fmt), _dataTable(nullptr), _indexTableSize(0)
22{
23}
24
26{
27 delete[] _dataTable;
28 for (char* strings : _stringPool)
29 delete[] strings;
30}
31
32bool DBCStorageBase::Load(char const* path, char**& indexTable)
33{
34 indexTable = nullptr;
35
36 DBCFileLoader dbc;
37 // Check if load was sucessful, only then continue
38 if (!dbc.Load(path, _fileFormat))
39 return false;
40
41 _fieldCount = dbc.GetCols();
42
43 // load raw non-string data
45
46 // load strings from dbc data
47 if (char* stringBlock = dbc.AutoProduceStrings(_fileFormat, _dataTable))
48 _stringPool.push_back(stringBlock);
49
50 // error in dbc file at loading if NULL
51 return indexTable != nullptr;
52}
53
54bool DBCStorageBase::LoadStringsFrom(char const* path, char** indexTable)
55{
56 // DBC must be already loaded using Load
57 if (!indexTable)
58 return false;
59
60 DBCFileLoader dbc;
61 // Check if load was successful, only then continue
62 if (!dbc.Load(path, _fileFormat))
63 return false;
64
65 // load strings from another locale dbc data
66 if (char* stringBlock = dbc.AutoProduceStrings(_fileFormat, _dataTable))
67 _stringPool.push_back(stringBlock);
68
69 return true;
70}
71
72void DBCStorageBase::LoadFromDB(char const* table, char const* format, char const* index, char**& indexTable)
73{
74 _stringPool.push_back(DBCDatabaseLoader(table, format, index, _fileFormat, _stringPool).Load(_indexTableSize, indexTable));
75}
char * AutoProduceStrings(char const *fmt, char *dataTable)
bool Load(const char *filename, const char *fmt)
uint32 GetCols() const
char * AutoProduceData(char const *fmt, uint32 &count, char **&indexTable)
virtual ~DBCStorageBase()
Definition DBCStore.cpp:25
char const * _fileFormat
Definition DBCStore.h:46
virtual bool Load(char const *path)=0
std::vector< char * > _stringPool
Definition DBCStore.h:48
virtual bool LoadStringsFrom(char const *path)=0
uint32 _indexTableSize
Definition DBCStore.h:49
uint32 _fieldCount
Definition DBCStore.h:45
char * _dataTable
Definition DBCStore.h:47
virtual void LoadFromDB(char const *table, char const *format, char const *index)=0
DBCStorageBase(char const *fmt)
Definition DBCStore.cpp:21