From 200857478da360a088ad84f52bc4cc02500d25f9 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sun, 7 Aug 2022 02:07:01 +0300 Subject: [PATCH 25/25] Ruledit: Add Sanity Check button See osdn #43103 Signed-off-by: Marko Lindqvist --- server/rssanity.c | 3 +- server/rssanity.h | 5 ++- server/ruleset.c | 2 +- tools/ruledit/conversion_log.cpp | 4 +-- tools/ruledit/conversion_log.h | 4 +-- tools/ruledit/ruledit_qt.cpp | 2 +- tools/ruledit/tab_misc.cpp | 55 ++++++++++++++++++++++++++------ tools/ruledit/tab_misc.h | 1 + 8 files changed, 58 insertions(+), 18 deletions(-) diff --git a/server/rssanity.c b/server/rssanity.c index 549b2bf4e1..58686543fc 100644 --- a/server/rssanity.c +++ b/server/rssanity.c @@ -726,7 +726,7 @@ static bool sanity_check_boolean_effects(void) Returns TRUE iff everything ok. **************************************************************************/ -bool sanity_check_ruleset_data(bool ignore_retired) +bool sanity_check_ruleset_data(struct rscompat_info *compat) { int num_utypes; int i; @@ -735,6 +735,7 @@ bool sanity_check_ruleset_data(bool ignore_retired) * one. */ bool default_gov_failed = FALSE; bool obsoleted_by_loop = FALSE; + bool ignore_retired = (compat != NULL && compat->compat_mode); if (!sanity_check_metadata()) { ok = FALSE; diff --git a/server/rssanity.h b/server/rssanity.h index 9f24257e5c..dbf0759506 100644 --- a/server/rssanity.h +++ b/server/rssanity.h @@ -20,9 +20,12 @@ extern "C" { /* common */ #include "fc_types.h" +/* server */ +#include "rscompat.h" + bool autoadjust_ruleset_data(void); bool autolock_settings(void); -bool sanity_check_ruleset_data(bool ignore_retired); +bool sanity_check_ruleset_data(struct rscompat_info *compat); bool sanity_check_server_setting_value_in_req(ssetv ssetval); diff --git a/server/ruleset.c b/server/ruleset.c index 55302a0bca..2a8e2f2336 100644 --- a/server/ruleset.c +++ b/server/ruleset.c @@ -8042,7 +8042,7 @@ static bool load_rulesetdir(const char *rsdir, bool compat_mode, actions_rs_pre_san_gen(); ok = autoadjust_ruleset_data() - && sanity_check_ruleset_data(compat_info.compat_mode); + && sanity_check_ruleset_data(&compat_info); } if (ok) { diff --git a/tools/ruledit/conversion_log.cpp b/tools/ruledit/conversion_log.cpp index cd51259ad2..d36f67fb1c 100644 --- a/tools/ruledit/conversion_log.cpp +++ b/tools/ruledit/conversion_log.cpp @@ -27,7 +27,7 @@ /**********************************************************************//** Setup conversion_log object **************************************************************************/ -conversion_log::conversion_log() : QDialog() +conversion_log::conversion_log(QString title) : QDialog() { QGridLayout *main_layout = new QGridLayout(this); QPushButton *close_button; @@ -43,7 +43,7 @@ conversion_log::conversion_log() : QDialog() main_layout->addWidget(close_button, row++, 0); setLayout(main_layout); - setWindowTitle(QString::fromUtf8(R__("Old ruleset to a new format"))); + setWindowTitle(title); setVisible(false); } diff --git a/tools/ruledit/conversion_log.h b/tools/ruledit/conversion_log.h index ac20d9ef6f..c0eb31a6fe 100644 --- a/tools/ruledit/conversion_log.h +++ b/tools/ruledit/conversion_log.h @@ -1,4 +1,4 @@ -/********************************************************************** +/*********************************************************************** Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -27,7 +27,7 @@ class conversion_log : public QDialog Q_OBJECT public: - explicit conversion_log(); + explicit conversion_log(QString title); void add(const char *msg); private: diff --git a/tools/ruledit/ruledit_qt.cpp b/tools/ruledit/ruledit_qt.cpp index 6ba2805fb0..54b68f7e2c 100644 --- a/tools/ruledit/ruledit_qt.cpp +++ b/tools/ruledit/ruledit_qt.cpp @@ -211,7 +211,7 @@ void ruledit_gui::launch_now() { QByteArray rn_bytes; - convlog = new conversion_log(); + convlog = new conversion_log(QString::fromUtf8(R__("Old ruleset to a new format"))); rn_bytes = ruleset_select->text().toUtf8(); sz_strlcpy(game.server.rulesetdir, rn_bytes.data()); diff --git a/tools/ruledit/tab_misc.cpp b/tools/ruledit/tab_misc.cpp index 555c0079a4..c11dc5afdf 100644 --- a/tools/ruledit/tab_misc.cpp +++ b/tools/ruledit/tab_misc.cpp @@ -40,9 +40,11 @@ #include "specialist.h" // server +#include "rscompat.h" #include "rssanity.h" // ruledit +#include "conversion_log.h" #include "ruledit.h" #include "ruledit_qt.h" #include "rulesave.h" @@ -60,8 +62,7 @@ tab_misc::tab_misc(ruledit_gui *ui_in) : QWidget() QLabel *label; QLabel *name_label; QLabel *version_label; - QPushButton *save_button; - QPushButton *refresh_button; + QPushButton *button; int row = 0; QTableWidgetItem *item; char ttbuf[2048]; @@ -116,9 +117,9 @@ tab_misc::tab_misc(ruledit_gui *ui_in) : QWidget() main_layout->addWidget(save_ver_label, row, 0); savedir_version = new QCheckBox(this); main_layout->addWidget(savedir_version, row++, 1); - save_button = new QPushButton(QString::fromUtf8(R__("Save now")), this); - connect(save_button, SIGNAL(pressed()), this, SLOT(save_now())); - main_layout->addWidget(save_button, row++, 1); + button = new QPushButton(QString::fromUtf8(R__("Save now")), this); + connect(button, SIGNAL(pressed()), this, SLOT(save_now())); + main_layout->addWidget(button, row++, 1); label = new QLabel(QString::fromUtf8(R__("Description from file"))); label->setParent(this); @@ -133,6 +134,10 @@ tab_misc::tab_misc(ruledit_gui *ui_in) : QWidget() desc_file = new QLineEdit(this); main_layout->addWidget(desc_file, row++, 1); + button = new QPushButton(QString::fromUtf8(R__("Sanity check rules")), this); + connect(button, SIGNAL(pressed()), this, SLOT(sanity_check())); + main_layout->addWidget(button, row++, 1); + stats = new QTableWidget(this); stats->setColumnCount(8); stats->setRowCount(7); @@ -216,13 +221,13 @@ tab_misc::tab_misc(ruledit_gui *ui_in) : QWidget() stats->horizontalHeader()->setVisible(false); stats->setEditTriggers(QAbstractItemView::NoEditTriggers); main_layout->addWidget(stats, row++, 0, 1, 2); - refresh_button = new QPushButton(QString::fromUtf8(R__("Refresh Stats")), this); - connect(refresh_button, SIGNAL(pressed()), this, SLOT(refresh_stats())); - main_layout->addWidget(refresh_button, row++, 0, 1, 2); + button = new QPushButton(QString::fromUtf8(R__("Refresh Stats")), this); + connect(button, SIGNAL(pressed()), this, SLOT(refresh_stats())); + main_layout->addWidget(button, row++, 0, 1, 2); // Stats never change except with experimental features. Hide useless // button. - show_experimental(refresh_button); + show_experimental(button); refresh(); @@ -276,7 +281,7 @@ void tab_misc::save_now() strncpy(game.control.version, ba_bytes.data(), sizeof(game.control.version) - 1); - if (!autoadjust_ruleset_data() || !sanity_check_ruleset_data(false)) { + if (!autoadjust_ruleset_data() || !sanity_check_ruleset_data(NULL)) { QMessageBox *box = new QMessageBox(); box->setText("Current data fails sanity checks. Save anyway?"); @@ -446,3 +451,33 @@ void tab_misc::desc_file_toggle(bool checked) { desc_file->setEnabled(checked); } + +static conversion_log *sanitylog; + +/************************************************************************** + Ruleset conversion log callback +**************************************************************************/ +static void sanity_log_cb(const char *msg) +{ + sanitylog->add(msg); +} + +/************************************************************************** + Run sanity check for current rules +**************************************************************************/ +void tab_misc::sanity_check() +{ + struct rscompat_info compat_info; + + sanitylog = new conversion_log(QString::fromUtf8(R__("Sanity Check"))); + + rscompat_init_info(&compat_info); + compat_info.compat_mode = FALSE; + compat_info.log_cb = sanity_log_cb; + + if (!sanity_check_ruleset_data(&compat_info)) { + ui->display_msg(R__("Sanity check failed!")); + } else { + ui->display_msg(R__("Sanity check success")); + } +} diff --git a/tools/ruledit/tab_misc.h b/tools/ruledit/tab_misc.h index 57591e5479..31a6f2bb37 100644 --- a/tools/ruledit/tab_misc.h +++ b/tools/ruledit/tab_misc.h @@ -37,6 +37,7 @@ class tab_misc : public QWidget void save_now(); void refresh_stats(); void desc_file_toggle(bool checked); + void sanity_check(); private: ruledit_gui *ui; -- 2.35.1