add option to require item descriptions instead of data

This commit is contained in:
Martin Michelsen
2023-07-06 21:58:17 -07:00
parent acfa708332
commit 97daebdf83
3 changed files with 9 additions and 3 deletions
+7 -1
View File
@@ -16,16 +16,22 @@ ItemData::ItemData(const ItemData& other) {
this->data2d = other.data2d; this->data2d = other.data2d;
} }
ItemData::ItemData(const string& desc) { ItemData::ItemData(const string& desc, bool allow_raw_data) {
this->clear();
try { try {
this->parse(desc, false); this->parse(desc, false);
return; return;
} catch (const exception&) { } catch (const exception&) {
this->clear();
} }
try { try {
this->parse(desc, true); this->parse(desc, true);
return; return;
} catch (const exception&) { } catch (const exception&) {
if (!allow_raw_data) {
throw;
}
this->clear();
} }
string data = parse_data_string(desc); string data = parse_data_string(desc);
+1 -1
View File
@@ -96,7 +96,7 @@ struct ItemData { // 0x14 bytes
} __attribute__((packed)); } __attribute__((packed));
ItemData(); ItemData();
explicit ItemData(const std::string& orig_description); explicit ItemData(const std::string& orig_description, bool allow_raw_data = true);
ItemData(const ItemData& other); ItemData(const ItemData& other);
ItemData& operator=(const ItemData& other); ItemData& operator=(const ItemData& other);
+1 -1
View File
@@ -1333,7 +1333,7 @@ int main(int argc, char** argv) {
} }
case Behavior::ENCODE_ITEM: { case Behavior::ENCODE_ITEM: {
ItemData item(input_filename); ItemData item(input_filename, false);
string desc = item.name(false); string desc = item.name(false);
log_info("Data: %02hhX%02hhX%02hhX%02hhX %02hhX%02hhX%02hhX%02hhX %02hhX%02hhX%02hhX%02hhX -------- %02hhX%02hhX%02hhX%02hhX", log_info("Data: %02hhX%02hhX%02hhX%02hhX %02hhX%02hhX%02hhX%02hhX %02hhX%02hhX%02hhX%02hhX -------- %02hhX%02hhX%02hhX%02hhX",
item.data1[0], item.data1[1], item.data1[2], item.data1[3], item.data1[0], item.data1[1], item.data1[2], item.data1[3],