inline void LoadDB2(uint32& availableDb2Locales, DB2StoreProblemList& errlist, DB2Storage<T>& storage, std::string const& db2_path, std::string const& filename) { // compatibility format and C++ structure sizes ASSERT(DB2FileLoader::GetFormatRecordSize(storage.GetFormat()) == sizeof(T) || LoadDB2_assert_print(DB2FileLoader::GetFormatRecordSize(storage.GetFormat()), sizeof(T), filename)); ++DB2FilesCount; std::string db2_filename = db2_path + filename; if (storage.Load(db2_filename.c_str(), uint32(sWorld->GetDefaultDbcLocale()))) { for (uint32 i = 0; i < TOTAL_LOCALES; ++i) { if (!(availableDb2Locales & (1 << i))) continue; if (uint32(sWorld->GetDefaultDbcLocale()) == i) continue; std::string localizedName(db2_path); localizedName.append(localeNames[i]); localizedName.push_back('/'); localizedName.append(filename); if (!storage.LoadStringsFrom(localizedName.c_str(), i)) availableDb2Locales &= ~(1<<i); // mark as not available for speedup next checks } } else { // sort problematic db2 to (1) non compatible and (2) nonexistent if (FILE* f = fopen(db2_filename.c_str(), "rb")) { std::ostringstream stream; stream << db2_filename << " exists, and has " << storage.GetFieldCount() << " field(s) (expected " << strlen(storage.GetFormat()) << "). Extracted file might be from wrong client version or a database-update has been forgotten."; std::string buf = stream.str(); errlist.push_back(buf); fclose(f); } else errlist.push_back(db2_filename); } DB2Stores[storage.GetHash()] = &storage; }
inline void LoadDB2(uint32& availableDb2Locales, DB2StoreProblemList& errlist, DB2Storage<T>& storage, std::string const& db2_path, std::string const& filename) { // compatibility format and C++ structure sizes if (!(DB2FileLoader::GetFormatRecordSize(storage.GetFormat()) == sizeof(T) || LoadDB2_assert_print(DB2FileLoader::GetFormatRecordSize(storage.GetFormat()), sizeof(T), filename))) return; ++DB2FilesCount; std::string db2_filename = db2_path + filename; if (storage.Load(db2_filename.c_str(), uint32(sWorld->GetDefaultDbcLocale()))) { for (uint32 i = 0; i < TOTAL_LOCALES; ++i) { if (!(availableDb2Locales & (1 << i))) continue; if (uint32(sWorld->GetDefaultDbcLocale()) == i) continue; std::string localizedName(db2_path); localizedName.append(localeNames[i]); localizedName.push_back('/'); localizedName.append(filename); if (!storage.LoadStringsFrom(localizedName.c_str(), i)) availableDb2Locales &= ~(1<<i); // mark as not available for speedup next checks } } else { // sort problematic db2 to (1) non compatible and (2) nonexistent if (FILE* f = fopen(db2_filename.c_str(), "rb")) { char buf[100]; snprintf(buf, 100,"(exist, but have %d fields instead " SIZEFMTD ") Wrong client version DBC file?", storage.GetFieldCount(), strlen(storage.GetFormat())); errlist.push_back(db2_filename + buf); fclose(f); } else errlist.push_back(db2_filename); } DB2Stores[storage.GetHash()] = &storage; }
inline void LoadDB2(uint32& availableDb2Locales, DB2StoreProblemList& errlist, DB2Manager::StorageMap& stores, DB2Storage<T>* storage, std::string const& db2_path) { // compatibility format and C++ structure sizes ASSERT(DB2FileLoader::GetFormatRecordSize(storage->GetFormat()) == sizeof(T), "Size of '%s' set by format string (%u) not equal size of C++ structure (" SZFMTD ").", storage->GetFileName().c_str(), DB2FileLoader::GetFormatRecordSize(storage->GetFormat()), sizeof(T)); ++DB2FilesCount; if (storage->Load(db2_path, uint32(sWorld->GetDefaultDbcLocale()))) { storage->LoadFromDB(); for (uint32 i = 0; i < TOTAL_LOCALES; ++i) { if (uint32(sWorld->GetDefaultDbcLocale()) == i) continue; if (availableDb2Locales & (1 << i)) if (!storage->LoadStringsFrom((db2_path + localeNames[i] + '/'), i)) availableDb2Locales &= ~(1 << i); // mark as not available for speedup next checks storage->LoadStringsFromDB(i); } } else { // sort problematic db2 to (1) non compatible and (2) nonexistent if (FILE* f = fopen((db2_path + storage->GetFileName()).c_str(), "rb")) { std::ostringstream stream; stream << storage->GetFileName() << " exists, and has " << storage->GetFieldCount() << " field(s) (expected " << strlen(storage->GetFormat()) << "). Extracted file might be from wrong client version."; std::string buf = stream.str(); errlist.push_back(buf); fclose(f); } else errlist.push_back(storage->GetFileName()); } stores[storage->GetHash()] = storage; }