From f1157429ba9aafffb2437c54a40d3bdef694214a Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Fri, 20 Mar 2020 18:58:47 +0100 Subject: [PATCH] Add some temporary options for choosing what to print. I'm planning to let users pass in some format string in the future instead, but for now this is what I've got. --- src/cli/main.cpp | 20 +++++++++++++++++++- src/cli/memcard.cpp | 28 +++++++++++++++++----------- src/cli/memcard.hpp | 13 ++++++++++++- 3 files changed, 48 insertions(+), 13 deletions(-) diff --git a/src/cli/main.cpp b/src/cli/main.cpp index ed5c3f8..b732d33 100644 --- a/src/cli/main.cpp +++ b/src/cli/main.cpp @@ -25,6 +25,13 @@ int main(int argc, char* argv[]) { ("h,help", "Show this help and quit") ("version", "Print version info") ("i,input", "Path to the input memory card file", cxxopts::value()->default_value("")) + ("blocknum", "Print the block number for each savegame") + ("usedblocks", "Print how many blocks are used for each savegame if more than 1") + ("pocketstation", "Print a 'P' to mark when a savegame contains PocketStation data") + ("countrycode", "Print the country code of each savegame") + ("productcode", "Print the product code of the game") + ("identifier", "Print the unique savegame identifier") + ("toccheck", "Print the TOC checksum for each savegame") ; auto command = options.parse(argc, argv); @@ -46,6 +53,17 @@ int main(int argc, char* argv[]) { return 2; } - print_blocks(mc_path); + { + PrintOptions opts; + opts.title = true; + opts.block_num = command.count("blocknum") > 0; + opts.used_blocks = command.count("usedblocks") > 0; + opts.has_pocket_station_content = command.count("pocketstation") > 0; + opts.country_code = command.count("countrycode") > 0; + opts.product_code = command.count("productcode") > 0; + opts.savegame_identifier = command.count("identifier") > 0; + opts.toc_checksum = command.count("toccheck") > 0; + print_blocks(mc_path, opts); + } return 0; } diff --git a/src/cli/memcard.cpp b/src/cli/memcard.cpp index 3205762..886ae05 100644 --- a/src/cli/memcard.cpp +++ b/src/cli/memcard.cpp @@ -4,7 +4,7 @@ #include #include -void print_blocks (const std::string& mc_path) { +void print_blocks (const std::string& mc_path, const PrintOptions& opts) { using mc::psx::MemoryCard; using mc::psx::make_memory_card; @@ -19,16 +19,22 @@ void print_blocks (const std::string& mc_path) { for (const auto& blk : mc) { if (blk.has_magic()) { - std::cout << "Block " << std::setfill(' ') << std::setw(2) << blk.index() - << ": \"" << blk.title() << '"'; - if (blk.block_count() > 1) { - std::cout << " (x" << blk.block_count() << ')'; - } - if (blk.has_pocket_station_content()) - std::cout << " P"; - std::cout << " [" << to_char(blk.country_code()) << ']'; - std::cout << ' ' << blk.product_code(); - std::cout << " '" << blk.identifier() << '\''; + if (opts.block_num) + std::cout << "Block " << std::setfill(' ') << std::setw(2) << blk.index() << ": "; + if (opts.title) + std::cout << '"' << blk.title() << "\" "; + if (opts.used_blocks and blk.block_count() > 1) + std::cout << "(x" << blk.block_count() << ") "; + if (opts.has_pocket_station_content and blk.has_pocket_station_content()) + std::cout << "P "; + if (opts.country_code) + std::cout << '[' << to_char(blk.country_code()) << "] "; + if (opts.product_code) + std::cout << blk.product_code() << ' '; + if (opts.savegame_identifier) + std::cout << '\'' << blk.identifier() << "' "; + if (opts.toc_checksum) + std::cout << "0x" << std::setfill('0') << std::setw(2) << std::hex << static_cast(blk.toc_checksum()) << std::dec << ' '; std::cout << '\n'; } } diff --git a/src/cli/memcard.hpp b/src/cli/memcard.hpp index 17e15a9..d51e606 100644 --- a/src/cli/memcard.hpp +++ b/src/cli/memcard.hpp @@ -2,4 +2,15 @@ #include -void print_blocks (const std::string& mc_path); +struct PrintOptions { + bool title; + bool block_num; + bool used_blocks; + bool has_pocket_station_content; + bool country_code; + bool product_code; + bool savegame_identifier; + bool toc_checksum; +}; + +void print_blocks (const std::string& mc_path, const PrintOptions& opts);