Skip to content

Commit 9731007

Browse files
committed
FIx suffix-only-duplicates.
1 parent 8a6ce07 commit 9731007

6 files changed

Lines changed: 16 additions & 5 deletions

File tree

docs/ckmamerc.mdoc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
.\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
2727
.\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2828
.\" SUCH DAMAGE.
29-
.Dd May 7, 2026
29+
.Dd May 15, 2026
3030
.Dt CKMAMERC 5
3131
.Os
3232
.Sh NAME
@@ -162,6 +162,10 @@ Boolean.
162162
.El
163163
.It roms-zipped
164164
Boolean.
165+
.It suffix-only-duplicates
166+
Boolean. If true, the
167+
.It game_name_suffix
168+
will only be used for games that would otherwise have duplicate names.
165169
.It use-central-cache-directory
166170
Boolean.
167171
Put the cache databases generated by

src/Configuration.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ TomlSchema::TypePtr Configuration::section_schema = TomlSchema::table(
130130
TomlSchema::alternatives({TomlSchema::integer(), TomlSchema::constant("all")}, "integer or 'all'")},
131131
{"status-db-keep-runs",
132132
TomlSchema::alternatives({TomlSchema::integer(), TomlSchema::constant("all")}, "integer or 'all'")},
133+
{"suffix-only-duplicates", TomlSchema::boolean()},
133134
{"unknown-directory", TomlSchema::string()},
134135
{"update-database", TomlSchema::boolean()},
135136
{"use-central-cache-directory", TomlSchema::boolean()},
@@ -304,6 +305,7 @@ void Configuration::reset() {
304305
}
305306
status_db = StatusDB::default_name();
306307
status_db_keep_runs = 2;
308+
suffix_only_duplicates = false;
307309
unknown_directory = "unknown";
308310
update_database = false;
309311
use_central_cache_directory = false;
@@ -654,6 +656,7 @@ void Configuration::merge_config_table(const toml::table* table_pointer) {
654656
set_bool(table, "roms-zipped", roms_zipped);
655657
set_string(table, "saved-directory", saved_directory);
656658
set_string(table, "status-db", status_db);
659+
set_bool(table, "suffix-only-duplicates", suffix_only_duplicates);
657660
set_integer_or_all(table, "status-db-keep-days", status_db_keep_days);
658661
set_integer_or_all(table, "status-db-keep-runs", status_db_keep_runs);
659662
set_string(table, "unknown-directory", unknown_directory);
@@ -823,7 +826,7 @@ bool Configuration::dat_create_fixdat(const std::string& dat) {
823826
bool Configuration::dat_suffix_only_duplicates(const std::string& dat) {
824827
auto it = dat_options.find(dat);
825828
if (it == dat_options.end() || !it->second.suffix_only_duplicates.has_value()) {
826-
return false;
829+
return suffix_only_duplicates;
827830
}
828831
return *it->second.suffix_only_duplicates;
829832
}

src/Configuration.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ class Configuration {
134134
bool use_torrentzip; // use TORRENTZIP format for zip archives in ROM set.
135135
bool verbose; // print all actions taken to fix ROM set
136136
bool allow_empty_dat; // Update RomDB even if dat is empty.
137+
bool suffix_only_duplicates; // use game_name_suffix only for names that would otherwise be duplicates.
137138

138139
// TODO: Are these needed? They have no command line options.
139140
/* file_correct */

src/OutputContext.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ bool OutputContext::finish() {
221221
auto original_name = game->name;
222222
auto new_name = game->name;
223223
if (!suffix.empty()) {
224-
new_name += " " + suffix;
224+
new_name += suffix;
225225
}
226226
if (counts[new_name] > 0) {
227227
new_name += " (" + std::to_string(counts[new_name]) + ")";
@@ -330,6 +330,7 @@ const std::string& OutputContext::final_game_name(size_t dat_no, const std::stri
330330
DatOptions::DatOptions(std::optional<std::string> dat_name) {
331331
if (dat_name) {
332332
game_name_suffix = configuration.dat_game_name_suffix(*dat_name);
333+
suffix_only_duplicates = configuration.dat_suffix_only_duplicates(*dat_name);
333334
use_description_as_name = configuration.dat_use_description_as_name(*dat_name);
334335
}
335336
else {

src/OutputContext.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ class DatOptions {
7979
* @return The suffix to add to the game name.
8080
*/
8181

82+
std::string name_suffix() const { return suffix_only_duplicates ? "" : game_name_suffix; }
8283
std::string duplicate_name_suffix() const {return suffix_only_duplicates ? game_name_suffix : "";}
8384
};
8485

src/Parser.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,8 +426,9 @@ void Parser::set_game_name(std::string name) {
426426
std::replace(g->name.begin(), g->name.end(), ':', '-');
427427
}
428428

429-
if (!options.game_name_suffix.empty()) {
430-
g->name += options.game_name_suffix;
429+
auto suffix = options.name_suffix();
430+
if (!suffix.empty()) {
431+
g->name += suffix;
431432
}
432433
}
433434

0 commit comments

Comments
 (0)