From aa5d19b863eea46c0d90baf239f9bb9a8d2eb8e8 Mon Sep 17 00:00:00 2001 From: Tom Stellard Date: Thu, 31 Dec 2020 13:20:43 -0800 Subject: [PATCH] Move country file validation out of main_init() We only need to do this validation on program startup and main_init() may be called multiple times (e.g. if someone starts multiple new games without exiting) --- src/main.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/main.c b/src/main.c index 1db67212..eeab9d3a 100644 --- a/src/main.c +++ b/src/main.c @@ -338,6 +338,16 @@ static void validate_country_file(gpointer country_file, gpointer user_data) xml_country_read(country_file, &country); } +static void validate_country_files() +{ + GPtrArray *country_files = file_get_country_files(); + + if(country_files->len == 0) + main_exit_program(EXIT_NO_COUNTRY_FILES, + "Didn't find any country definition files in the support directories."); + g_ptr_array_foreach(country_files, validate_country_file, NULL); +} + /** Process the command line arguments and do some things that have to be done at the beginning (like initializing the @@ -389,14 +399,6 @@ main_init(gint *argc, gchar ***argv, Bygfoot *bygfoot) load_last_save = FALSE; main_parse_cl_arguments(argc, argv, bygfoot); - - /* Validate XML */ - country_files = file_get_country_files(); - - if(country_files->len == 0) - main_exit_program(EXIT_NO_COUNTRY_FILES, - "Didn't find any country definition files in the support directories."); - g_ptr_array_foreach(country_files, validate_country_file, NULL); } /** @@ -429,6 +431,8 @@ main (gint argc, gchar *argv[]) main_init(&argc, &argv, &bygfoot); + validate_country_files(); + if((load_last_save && !load_game_from_command_line(&bygfoot, "last_save")) || (!load_last_save && (argc == 1 || (argc > 1 && !load_game_from_command_line(&bygfoot, argv[1])))))