1
0
Files
libcmo21/Ballance/BMapInspector/BMapInspector.cpp

91 lines
2.5 KiB
C++
Raw Normal View History

2026-01-30 20:23:39 +08:00
#include "Utils.hpp"
#include "Cli.hpp"
#include "Reporter.hpp"
2026-01-30 20:40:21 +08:00
#include "Ruleset.hpp"
2026-01-30 20:23:39 +08:00
#include <VTAll.hpp>
#include <yycc.hpp>
#include <yycc/carton/termcolor.hpp>
2026-01-30 20:40:21 +08:00
#include <yycc/string/op.hpp>
2026-01-30 20:23:39 +08:00
#include <yycc/patch/stream.hpp>
#include <iostream>
2026-01-31 23:16:50 +08:00
#include <optional>
2026-01-30 20:23:39 +08:00
using namespace yycc::patch::stream;
2026-01-30 20:40:21 +08:00
namespace strop = yycc::string::op;
2026-01-30 20:23:39 +08:00
namespace termcolor = yycc::carton::termcolor;
2026-01-31 23:16:50 +08:00
static void PrintSplash() {
std::cout << termcolor::colored(u8"" BMAPINSP_NAME, termcolor::Color::LightYellow)
<< " (based on LibCmo " LIBCMO_VER_STR ") built at " __DATE__ " " __TIME__ << std::endl
<< u8"" BMAPINSP_DESC << std::endl;
}
2026-01-31 23:16:50 +08:00
static std::optional<BMapInspector::Cli::Args> AcceptArgs() {
auto request = BMapInspector::Cli::parse();
if (request.has_value()) {
return request.value();
} else {
using BMapInspector::Cli::Error;
2026-01-31 23:16:50 +08:00
std::u8string bad_words;
switch (request.error()) {
case Error::BadParse:
bad_words = u8"Can not parse given command line argument."; break;
case Error::NoFile:
bad_words = u8"You must specify a file for checking.";
break;
case Error::BadFile:
bad_words = u8"Your specified file is invalid.";
break;
case Error::NoBallance:
bad_words = u8"You must specify Ballance root directory for finding resources.";
break;
case Error::BadBallance:
bad_words = u8"Your specified Ballance root directory is invalid.";
break;
case Error::BadEncoding:
bad_words = u8"Your specified encoding name is invalid.";
break;
case Error::BadLevel:
bad_words = u8"Your specified report level filter name is invalid.";
break;
default:
bad_words = u8"Unknown error.";
break;
}
2026-01-31 23:16:50 +08:00
termcolor::cprintln(bad_words, termcolor::Color::Red);
termcolor::cprintln(u8"Please browse manual or use -h switch to see help first.", termcolor::Color::Red);
return std::nullopt;
}
}
2026-01-31 23:16:50 +08:00
static void LoadVirtools() {}
2026-01-30 20:23:39 +08:00
2026-01-31 23:16:50 +08:00
static void CheckRules() {
2026-01-30 20:23:39 +08:00
// Create reporter
BMapInspector::Reporter reporter;
2026-01-30 20:23:39 +08:00
2026-01-30 20:40:21 +08:00
// Get rule collection
BMapInspector::Ruleset::RuleCollection rule_collection;
// Show rule infos
std::cout << strop::printf(u8"Total %" PRIuSIZET " rule(s) are loaded.", rule_collection.GetRuleCount()) << std::endl
2026-01-31 23:16:50 +08:00
<< u8"Check may take few minutes. Please do not close this console..." << std::endl;
2026-01-30 20:40:21 +08:00
// Show report conclusion
2026-01-30 20:23:39 +08:00
reporter.PrintConclusion();
2026-01-30 20:40:21 +08:00
// Print report in detail
reporter.PrintReport();
2026-01-31 23:16:50 +08:00
}
int main(int argc, char *argv[]) {
auto args = AcceptArgs();
if (args.has_value()) {
PrintSplash();
std::cout << std::endl;
2026-01-30 20:23:39 +08:00
2026-01-31 23:16:50 +08:00
CheckRules();
}
return 0;
}