Skip to content

Commit

Permalink
Begin tool to use info in status db.
Browse files Browse the repository at this point in the history
  • Loading branch information
dillof committed Oct 9, 2024
1 parent 94e9f03 commit f68d44c
Show file tree
Hide file tree
Showing 7 changed files with 169 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ if (HAVE_LIBARCHIVE)
target_link_libraries(libckmame PRIVATE LibArchive::LibArchive)
endif()

foreach(PROGRAM ckmame dumpgame mkmamedb)
foreach(PROGRAM ckmame ckstatus dumpgame mkmamedb)
add_executable(${PROGRAM} ${PROGRAM}.cc)
target_link_libraries(${PROGRAM} PRIVATE libckmame ZLIB::ZLIB libzip::zip SQLite::SQLite3)
# for config.h
Expand Down
59 changes: 59 additions & 0 deletions src/CkStatus.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
Dumpgame.h -- print info about game (from data base)
Copyright (C) 2022 Dieter Baron and Thomas Klausner
This file is part of ckmame, a program to check rom sets for MAME.
The authors can be contacted at <ckmame@nih.at>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
3. The name of the author may not be used to endorse or promote
products derived from this software without specific prior
written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef CKSTATUS_H
#define CKSTATUS_H

#include <set>

#include "Command.h"

class CkStatus : public Command {
public:
CkStatus();

void global_setup(const ParsedCommandline &commandline) override;
bool execute(const std::vector<std::string> &arguments) override;
bool global_cleanup() override;

private:
enum Special {
RUNS
};

std::set<Special> specials;

void list_runs();
};

#endif // CKSTATUS_H
1 change: 1 addition & 0 deletions src/Command.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
class Command {
public:
Command(std::string name, std::string arguments, std::vector<Commandline::Option> options, std::unordered_set<std::string> used_variables);
virtual ~Command() = default;

int run(int argc, char *const *argv);

Expand Down
3 changes: 1 addition & 2 deletions src/Configuration.cc
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ std::vector<Commandline::Option> Configuration::commandline_options = {
Commandline::Option("saved-directory", "directory", "save needed ROMs in directory (default: 'saved')"),
Commandline::Option("set", "pattern", "check ROM sets matching pattern"),
Commandline::Option("no-status-db", "don't save status in dbfile"),
Commandline::Option("status-db", "dbfile", "save status in dbfile (default: '.ckmame-status.db')"),
Commandline::Option("status-db", "dbfile", "use status in dbfile (default: '.ckmame-status.db')"),
Commandline::Option("status-db-keep-days", "n", "remove runs older than n days from status db, 'all' for no time limit (default: 'all')"),
Commandline::Option("status-db-keep-runs", "n", "keep only n most recent runs in status db, 'all' for no run limit (default: 2)"),
Commandline::Option("unknown-directory", "directory", "save unknown files in directory (default: 'unknown')"),
Expand Down Expand Up @@ -210,7 +210,6 @@ std::unordered_map<std::string, std::string> Configuration::option_to_variable =
{ "no-report-missing-mia", "report_missing_mia" },
{ "no-report-summary", "report_summary" },
{ "no-report-no-good-dump", "report_no_good_dump" },
{ "no-status-db", "status_db" },
{ "no-update-database", "update_database" },
{ "no-warn-file-known", "warn-file-known"},
{ "no-warn-file-unknown", "warn-file-unknown"},
Expand Down
4 changes: 2 additions & 2 deletions src/StatusDB.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ std::unordered_map<int, std::string> StatusDB::queries = {
{INSERT_GAME,
"insert into game (run_id, dat_id, name, checksum, status) values (:run_id, :dat_id, :name, :checksum, :status)"},
{INSERT_RUN, "insert into run (date) values (:date)"},
{LIST_RUNS, "select run_id, date from run order by date descending"},
{LIST_RUNS, "select run_id, date from run order by date asc"},
{QUERY_GAME, "select dat_id, name, checksum, status from game where run_id = :run_id"},
{QUERY_GAME_BY_STATUS, "select name from game where run_id = :run, status = :status order by name"},
{QUERY_GAME_STATI, "select name, status from game where run_id = :run order by name"},
Expand Down Expand Up @@ -150,7 +150,7 @@ std::vector<StatusDB::GameInfo> StatusDB::get_games(int64_t run_id) {
}

std::vector<StatusDB::Run> StatusDB::list_runs() {
auto stmt = get_statement(QUERY_GAME);
auto stmt = get_statement(LIST_RUNS);

std::vector<Run> runs;

Expand Down
1 change: 1 addition & 0 deletions src/ckmame.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ std::unordered_set<std::string> ckmame_used_variables = {
"keep_old_duplicate",
"missing_list",
"move_from_extra",
"no_status_db",
"old_db",
"report_changes",
"report_correct",
Expand Down
104 changes: 104 additions & 0 deletions src/ckstatus.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
ckstatus.cc -- print info about last runs (from data base)
Copyright (C) 1999-2018 Dieter Baron and Thomas Klausner
This file is part of ckmame, a program to check rom sets for MAME.
The authors can be contacted at <ckmame@nih.at>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
3. The name of the author may not be used to endorse or promote
products derived from this software without specific prior
written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "CkStatus.h"

#include <algorithm>
#include <cerrno>
#include <cstring>

#include "compat.h"

#include "Commandline.h"
#include "Exception.h"
#include "RomDB.h"
#include "Stats.h"
#include "globals.h"
#include "util.h"

std::vector<Commandline::Option> ckstatus_options = {Commandline::Option("runs", "list runs")};

std::unordered_set<std::string> ckstatus_used_variables = {"status_db"};

int main(int argc, char** argv) {
auto command = CkStatus();

return command.run(argc, argv);
}


CkStatus::CkStatus() : Command("ckstatus", "", ckstatus_options, ckstatus_used_variables) {}

void CkStatus::global_setup(const ParsedCommandline& commandline) {
for (const auto& option : commandline.options) {
if (option.name == "runs") {
specials.insert(RUNS);
}
}
}


bool CkStatus::global_cleanup() { return true; }


bool CkStatus::execute(const std::vector<std::string>& arguments) {
if (configuration.status_db == "none") {
throw Exception("No status database configured.");
}

try {
status_db = std::make_shared<StatusDB>(configuration.status_db, DBH_WRITE | DBH_CREATE);
}
catch (const std::exception& e) {
throw Exception("Error opening status database: " + std::string(e.what()));
}

for (auto key : specials) {
switch (key) {
case RUNS:
list_runs();
break;
}
}
return true;
}

void CkStatus::list_runs() {
auto runs = status_db->list_runs();

for (const auto& run : runs) {
char date_string[20];
strftime(date_string, sizeof(date_string), "%Y-%m-%d %H:%M:%S", localtime(&run.date));
printf("%" PRId64 ": %s\n", run.run_id, date_string);
}
}

0 comments on commit f68d44c

Please sign in to comment.