Skip to content

Commit

Permalink
Allow specifying which games are mia. Require C++ 20.
Browse files Browse the repository at this point in the history
  • Loading branch information
dillof committed Jun 26, 2024
1 parent 4e202a4 commit b57651c
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 19 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ project(ckmame
VERSION 2.1
LANGUAGES C CXX)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 20)

option(RUN_REGRESS "Run regression tests" ON)

Expand Down
2 changes: 1 addition & 1 deletion INSTALL.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ckmame is written in C++17 and uses [cmake](https://cmake.org) to build.
ckmame is written in C++20 and uses [cmake](https://cmake.org) to build.

To use ckmame, you need
- [zlib](http://www.zlib.net/) (at least version 1.1.2)
Expand Down
9 changes: 9 additions & 0 deletions regress/mamedb-mia-games.dump
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
>>> table dat (dat_idx, name, description, author, version)
0|ckmame test db|<null>|<null>|1
>>> table file (game_id, file_type, file_idx, name, merge, status, location, size, crc, md5, sha1, sha256, missing)
1|0|0|04.rom|<null>|0|0|4|3632233996|<098f6bcd4621d373cade4e832627b4f6>|<a94a8fe5ccb19ba61c4c0873d391e987982fbbd3>|<null>|0
1|0|1|0c.rom|<null>|0|0|12|103008562|<b60c52bf4849067f0b57c8bd30985466>|<2f2d205d5451d3256cf1c693982b40101e9989bf>|<null>|1
>>> table game (game_id, name, parent, description, dat_idx)
1|2-4c|<null>|<null>|0
>>> table rule (rule_idx, start_offset, end_offset, operation)
>>> table test (rule_idx, test_idx, type, offset, size, mask, value, result)
13 changes: 13 additions & 0 deletions regress/mkmamedb-mia-games.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
description test mkmamedb database creation, ok
return 0
program mkmamedb
arguments --mia-games mia-games mamedb.dat
file .ckmamerc <inline>
[global]
delete-unknown-pattern = "04*"
end-of-inline-data
file mia-games <inline>
2-4c
end-of-inline-data
file mamedb.dat mamedb-one-game-two-roms.dat
file mame.db {} mamedb-mia-games.dump
13 changes: 12 additions & 1 deletion src/Parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ bool Parser::file_hash(filetype_t ft, int ht, const std::string& attr) {
return true;
}

if (attr == "") {
if (attr.empty()) {
/* some dat files have empty strings for hashes, skip them */
return true;
}
Expand Down Expand Up @@ -376,6 +376,17 @@ bool Parser::game_end() {
g->cloneof[0] = "";
}

if (options.mia_games.contains(g->name)) {
// TODO: disks
for (auto& rom: g->files[TYPE_ROM]) {
if (!configuration.delete_unknown_pattern.empty() &&
fnmatch(configuration.delete_unknown_pattern.c_str(), rom.name.c_str(), 0) == 0) {
continue;
}
rom.mia = true;
}
}

ok = output_context->game(g, g->name == original_game_name ? "" : original_game_name);
}

Expand Down
1 change: 1 addition & 0 deletions src/Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class Parser {
bool full_archive_names;
std::string game_name_suffix;
bool use_description_as_name;
std::unordered_set<std::string> mia_games;
};

static ParserPtr create(const ParserSourcePtr& source, const std::unordered_set<std::string>& exclude,
Expand Down
38 changes: 22 additions & 16 deletions src/mkmamedb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
#include "RomDB.h"
#include "globals.h"
#include "update_romdb.h"
#include "util.h"

std::vector<Commandline::Option> mkmamedb_options = {
Commandline::Option("detector", "xml-file", "use header detector"),
Expand All @@ -61,6 +62,7 @@ std::vector<Commandline::Option> mkmamedb_options = {
Commandline::Option("hash-types", 'C', "types", "specify hash types to compute (default: all)"),
Commandline::Option("list-available-dats", "list all dats found in dat-directories"),
Commandline::Option("list-dats", "list dats used by current set"),
Commandline::Option("mia-games", "file", "mark games listed in file as mia"),
Commandline::Option("no-directory-cache", "don't create cache of scanned input directory"),
Commandline::Option("only-files", "pattern", "only use zip members matching shell glob pattern"),
Commandline::Option("output", 'o', "dbfile", "write to database dbfile (default: mame.db)"),
Expand Down Expand Up @@ -101,19 +103,19 @@ void MkMameDB::global_setup(const ParsedCommandline &commandline) {
hashtypes = Hashes::TYPE_CRC | Hashes::TYPE_MD5 | Hashes::TYPE_SHA1 | Hashes::TYPE_SHA256;

for (const auto &option : commandline.options) {
if (option.name == "detector") {
if (option.name == "detector") {
detector_name = option.argument;
}
else if (option.name == "directory-cache") {
else if (option.name == "directory-cache") {
cache_directory = true;
}
else if (option.name == "exclude") {
else if (option.name == "exclude") {
exclude.insert(option.argument);
}
else if (option.name == "force") {
else if (option.name == "force") {
force = true;
}
else if (option.name == "format") {
else if (option.name == "format") {
if (option.argument == "cm") {
fmt = OutputContext::FORMAT_CM;
}
Expand All @@ -131,41 +133,45 @@ void MkMameDB::global_setup(const ParsedCommandline &commandline) {
exit(1);
}
}
else if (option.name == "hash-types") {
else if (option.name == "hash-types") {
hashtypes = Hashes::types_from_string(option.argument);
if (hashtypes == 0) {
fprintf(stderr, "%s: illegal hash types '%s'\n", ProgramName::get().c_str(), option.argument.c_str());
exit(1);
}
}
else if (option.name == "list-available-dats") {
else if (option.name == "list-available-dats") {
list_available_dats = true;
}
else if (option.name == "list-dats") {
else if (option.name == "list-dats") {
list_dats = true;
}
else if (option.name == "no-directory-cache") {
else if (option.name == "mia-games") {
auto list = slurp_lines(option.argument);
parser_options.mia_games.insert(list.begin(), list.end());
}
else if (option.name == "no-directory-cache") {
cache_directory = false;
}
else if (option.name == "only-files") {
else if (option.name == "only-files") {
file_patterns.push_back(option.argument);
}
else if (option.name == "output") {
else if (option.name == "output") {
dbname = option.argument;
}
else if (option.name == "prog-description") {
else if (option.name == "prog-description") {
dat.description = option.argument;
}
else if (option.name == "prog-name") {
else if (option.name == "prog-name") {
dat.name = option.argument;
}
else if (option.name == "prog-version") {
else if (option.name == "prog-version") {
dat.version = option.argument;
}
else if (option.name == "runtest") {
else if (option.name == "runtest") {
runtest = true;
}
else if (option.name == "skip-files") {
else if (option.name == "skip-files") {
skip_files.insert(option.argument);
}
}
Expand Down

0 comments on commit b57651c

Please sign in to comment.