Added metadata validator code.

This commit is contained in:
Oliver Hamlet
2015-07-19 22:23:42 +01:00
parent a08e26ac8f
commit eabfd04be9
2 changed files with 94 additions and 0 deletions
+10
View File
@@ -149,6 +149,11 @@ set (LOOT_API_SRC ${LOOT_SRC}
set (LOOT_API_HEADERS ${LOOT_HEADERS}
"${CMAKE_SOURCE_DIR}/src/api/api.h")
set (LOOT_VALIDATOR_SRC ${LOOT_SRC}
"${CMAKE_SOURCE_DIR}/src/validator/main.cpp")
set (LOOT_VALIDATOR_HEADERS ${LOOT_HEADERS})
set (LOOT_TESTS_SRC "${CMAKE_SOURCE_DIR}/src/tests/main.cpp")
set (LOOT_TESTS_HEADERS "${CMAKE_SOURCE_DIR}/src/tests/fixtures.h"
@@ -289,6 +294,11 @@ ENDIF ()
add_executable (LOOT ${LOOT_GUI_SRC} ${LOOT_GUI_HEADERS})
target_link_libraries (LOOT ${Boost_LIBRARIES} ${YAML_CPP_LIBRARIES} ${LOOT_GUI_LIBS})
# Build validator.
add_executable (metadata-validator ${LOOT_VALIDATOR_SRC} ${LOOT_VALIDATOR_HEADERS})
target_link_libraries (metadata-validator ${Boost_LIBRARIES} ${YAML_CPP_LIBRARIES} ${LOOT_LIBS})
##############################
# Set Target-Specific Flags
+84
View File
@@ -0,0 +1,84 @@
/* LOOT
A load order optimisation tool for Oblivion, Skyrim, Fallout 3 and
Fallout: New Vegas.
Copyright (C) 2014-2015 WrinklyNinja
This file is part of LOOT.
LOOT is free software: you can redistribute
it and/or modify it under the terms of the GNU General Public License
as published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
LOOT is distributed in the hope that it will
be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with LOOT. If not, see
<http://www.gnu.org/licenses/>.
*/
#ifdef TRAVIS
#pragma message("This is a Travis build, so defining BOOST_NO_CXX11_SCOPED_ENUMS to avoid boost::filesystem::copy_file() linking errors.")
#define BOOST_NO_CXX11_SCOPED_ENUMS
#endif
#include "backend/globals.h"
#include "backend/metadata_list.h"
#include <boost/log/core.hpp>
int main(int argc, char **argv) {
//Set the locale to get encoding conversions working correctly.
std::locale::global(boost::locale::generator().generate(""));
boost::filesystem::path::imbue(std::locale());
//Disable logging or else stdout will get overrun.
boost::log::core::get()->set_logging_enabled(false);
// Print help text if -h, --help or invalid args are given (including no args).
if (argc != 2 || (strcmp(argv[1], "-h") == 0) || (strcmp(argv[1], "--help") == 0)) {
std::cout << std::endl
<< "Usage: metadata-validator <arg>" << std::endl << std::endl
<< "Arguments:" << std::endl << std::endl
<< " " << "<file>" << " " << "The metadata file to validate." << std::endl
<< " " << "-v, --version" << " " << "Prints version information for this utility." << std::endl
<< " " << "-h, --help" << " " << "Prints this help text." << std::endl << std::endl;
return 1;
}
// Print version info if -v or --version are given.
if ((strcmp(argv[1], "-v") == 0) || (strcmp(argv[1], "--version") == 0)) {
std::cout << std::endl << "LOOT Metadata Validator" << std::endl
<< "v" << loot::g_version_major << "." << loot::g_version_minor
<< "." << loot::g_version_patch << std::endl
<< "build revision " << loot::g_build_revision << std::endl << std::endl;
return 0;
}
try {
std::cout << std::endl << "Validating metadata file: " << argv[1] << std::endl << std::endl;
// Test YAML parsing.
loot::MetadataList metadata;
metadata.Load(argv[1]);
// Test condition parsing.
for (auto &plugin : metadata.Plugins()) {
plugin.ParseAllConditions();
}
for (auto &message : metadata.messages) {
message.ParseCondition();
}
}
catch (std::exception& e) {
std::cout << "ERROR: " << e.what() << std::endl << std::endl;
return 1;
}
std::cout << "SUCCESS!" << std::endl << std::endl;
return 0;
}