tools/dumpnbt: Switch from using the validator to using the parser, update some strings

Soda
BodgeMaster 2022-10-16 07:40:00 +02:00
parent cdc23e7468
commit 8d2f3f2fa5
1 changed files with 6 additions and 7 deletions

View File

@ -25,6 +25,7 @@
#define EXIT_USAGE 2 #define EXIT_USAGE 2
#define EXIT_UNIMPLEMENTED 3 #define EXIT_UNIMPLEMENTED 3
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
std::vector<CLI::Flag> flags; std::vector<CLI::Flag> flags;
flags.push_back(CLI::Flag('h', "help", "print help and exit")); flags.push_back(CLI::Flag('h', "help", "print help and exit"));
@ -32,9 +33,9 @@ int main(int argc, char* argv[]) {
flags.push_back(CLI::Flag('x', "hexadecimal", "print numbers in hex format")); flags.push_back(CLI::Flag('x', "hexadecimal", "print numbers in hex format"));
std::vector<CLI::Option> options; std::vector<CLI::Option> options;
std::vector<CLI::Argument> arguments; std::vector<CLI::Argument> arguments;
arguments.push_back(CLI::Argument("FILE", "path of the file to work on")); arguments.push_back(CLI::Argument("FILE", "path of the file to dump"));
CLI::ArgumentsParser cliParser = CLI::ArgumentsParser(argc, argv, flags, options, arguments, "Present NBT in human or machine readable formats - preliminary implementation."); CLI::ArgumentsParser cliParser = CLI::ArgumentsParser(argc, argv, flags, options, arguments, "Present NBT in human or machine readable formats");
if (cliParser.getFlag("help").value){ if (cliParser.getFlag("help").value){
std::cout << cliParser.getUsage() << std::endl; std::cout << cliParser.getUsage() << std::endl;
@ -70,7 +71,7 @@ int main(int argc, char* argv[]) {
std::ifstream fileStream; std::ifstream fileStream;
fileStream.open(cliParser.getArgument(0).value, std::ios::in | std::ios::binary | std::ios::ate); fileStream.open(cliParser.getArgument(0).value, std::ios::in | std::ios::binary | std::ios::ate);
if (!fileStream.is_open()) { if (!fileStream.is_open()) {
std::cerr << argv[0] << ": File not found: " << cliParser.getArgument(0).value << std::endl; std::cerr << argv[0] << ": Could not open file: " << cliParser.getArgument(0).value << std::endl;
return EXIT_RUNTIME; return EXIT_RUNTIME;
} }
@ -86,10 +87,8 @@ int main(int argc, char* argv[]) {
} }
fileStream.close(); fileStream.close();
bool isValidData = NBT::validateRawNBTData(data, fileSize); ErrorOr<std::vector<NBT::Tag::Generic*>> tags = NBT::deserialize(data, fileSize);
if (isValidData) { if (tags.isError) {
std::cerr << "Valid data." << std::endl;
} else {
std::cerr << "Invalid data." << std::endl; std::cerr << "Invalid data." << std::endl;
return EXIT_RUNTIME; return EXIT_RUNTIME;
} }