diff --git a/fileReaders/WDC2/DB2Base.cpp b/fileReaders/WDC2/DB2Base.cpp index a8b2343..5c6a12a 100644 --- a/fileReaders/WDC2/DB2Base.cpp +++ b/fileReaders/WDC2/DB2Base.cpp @@ -17,7 +17,7 @@ void DB2Base::process(HFileContent db2File, const std::string &fileName) { bytesRead = 0; readValue(header); - if (header->magic != 'WDC2') return; + if (header->magic != '2CDW') return; readValues(section_headers, header->section_count); readValues(fields, header->total_field_count); diff --git a/fileReaders/WDC3/DB2Ver3.cpp b/fileReaders/WDC3/DB2Ver3.cpp index 2a52500..25fd180 100644 --- a/fileReaders/WDC3/DB2Ver3.cpp +++ b/fileReaders/WDC3/DB2Ver3.cpp @@ -379,10 +379,14 @@ DB2Ver3::WDC3Record::WDC3Record(std::shared_ptr db2Class, int rec db2Class(db2Class), recordId(recordId), recordIndex(recordIndex), recordPointer(recordPointer), sectionIndex(sectionIndex) { + if (!db2Class->getWDCHeader()->flags.hasNonInlineId) { + auto result = getField(db2Class->getWDCHeader()->id_index, 0, 0); + this->recordId = result[0].v32s; + } } -static inline void fixPaletteValue(WDC3::DB2Ver3::WDCFieldValue &value, int externalElemSizeBytes) { +static inline void fixPaletteOrCommonValue(WDC3::DB2Ver3::WDCFieldValue &value, int externalElemSizeBytes) { if (externalElemSizeBytes > 0 && externalElemSizeBytes < 4) { uint32_t mask = (1 << (externalElemSizeBytes*8)) - 1; value.v32 = value.v32 & mask; @@ -462,6 +466,7 @@ std::vector DB2Ver3::WDC3Record::getField(int fiel auto it = db2Class->commonDataHashMap[fieldIndex].find(recordId); if (it != db2Class->commonDataHashMap[fieldIndex].end()) { fieldValue.v32 = it->second; + fixPaletteOrCommonValue(fieldValue, externalElemSizeBytes); } } break; @@ -487,7 +492,7 @@ std::vector DB2Ver3::WDC3Record::getField(int fiel auto &fieldValue = result.emplace_back(); fieldValue.v32 = db2Class->palleteDataArray[fieldIndex][properPalleteIndex];; - fixPaletteValue(fieldValue, externalElemSizeBytes); + fixPaletteOrCommonValue(fieldValue, externalElemSizeBytes); } } else { int properPalleteIndex = palleteIndex; @@ -495,11 +500,9 @@ std::vector DB2Ver3::WDC3Record::getField(int fiel auto &fieldValue = result.emplace_back(); fieldValue.v32 = db2Class->palleteDataArray[fieldIndex][properPalleteIndex]; - fixPaletteValue(fieldValue, externalElemSizeBytes); + fixPaletteOrCommonValue(fieldValue, externalElemSizeBytes); } - - break; } } diff --git a/fileReaders/WDC3/DB2Ver3.h b/fileReaders/WDC3/DB2Ver3.h index d05d58a..8882855 100644 --- a/fileReaders/WDC3/DB2Ver3.h +++ b/fileReaders/WDC3/DB2Ver3.h @@ -220,10 +220,16 @@ namespace WDC3 { const field_storage_info * const getFieldInfo(uint32_t fieldIndex) const; - const auto* const getWDCHeader() { + const auto* const getWDCHeader() const { return this->headerContent; } + bool isFieldId(int fieldIndex) const { + return (this->getWDCHeader()->id_index == fieldIndex) && !this->getWDCHeader()->flags.hasNonInlineId; + } + + + union WDCFieldValue { uint64_t v64; int64_t v64s; diff --git a/importers/CImporterClass.cpp b/importers/CImporterClass.cpp index 15f8678..10b5893 100644 --- a/importers/CImporterClass.cpp +++ b/importers/CImporterClass.cpp @@ -8,6 +8,7 @@ #include "../fileReaders/WDC3/DB2Ver3.h" #include "WDC3/WDC3Importer.h" #include "../fileReaders/WDC4/DB2Ver4.h" +#include "../fileReaders/WDC5/DB2Ver5.h" #include #include @@ -39,13 +40,15 @@ void CImporterClass::addTable(std::string &tableName, } const uint32_t fileIdent = *(uint32_t *)vec->data(); - if (fileIdent == 'WDC2') { + if (fileIdent == '2CDW') { WDC2::DB2Base db2Base; db2Base.process(vec, db2File); } else if (fileIdent == '3CDW' || fileIdent == '4CDW' || fileIdent == '5CDW') { std::shared_ptr db2Base = nullptr; - if (*(uint32_t *)vec->data() == '4CDW') { + if (*(uint32_t *)vec->data() == '5CDW') { + db2Base = std::make_shared(); + } else if (*(uint32_t *)vec->data() == '4CDW') { db2Base = std::make_shared(); } else { db2Base = std::make_shared(); diff --git a/importers/WDC3/WDC3Importer.cpp b/importers/WDC3/WDC3Importer.cpp index 7f6b22f..e4e7919 100644 --- a/importers/WDC3/WDC3Importer.cpp +++ b/importers/WDC3/WDC3Importer.cpp @@ -159,7 +159,7 @@ WDC3Importer::generateFieldsFromDB2Columns(std::shared_ptr db2Bas } else { std::string columnName = "field_" + std::to_string(i); bool isId = false; - if (i == db2Base->getWDCHeader()->id_index && !db2Base->getWDCHeader()->flags.hasNonInlineId) { + if (db2Base->isFieldId(i)) { columnName = "id"; isId = true; } @@ -328,15 +328,15 @@ bool WDC3Importer::readWDC3Record(const int recordIndex, case FieldType::INT: { if (dbdBuildColumnDef->bitSize == 64) { if (dbdBuildColumnDef->isSigned) { - fieldValues[db2FieldIndexToSQLIndex[i] + j] = std::to_string(valueVector[j].v64); - } else { fieldValues[db2FieldIndexToSQLIndex[i] + j] = std::to_string(valueVector[j].v64s); + } else { + fieldValues[db2FieldIndexToSQLIndex[i] + j] = std::to_string(valueVector[j].v64); } } else { if (dbdBuildColumnDef->isSigned) { - fieldValues[db2FieldIndexToSQLIndex[i] + j] = std::to_string(valueVector[j].v32); - } else { fieldValues[db2FieldIndexToSQLIndex[i] + j] = std::to_string(valueVector[j].v32s); + } else { + fieldValues[db2FieldIndexToSQLIndex[i] + j] = std::to_string(valueVector[j].v32); } } break;