From 7995399daf392be604c462a53909254beb5a5750 Mon Sep 17 00:00:00 2001 From: Jose Cadete Date: Thu, 16 May 2024 12:19:46 +0100 Subject: [PATCH] Some bug and code warning fixes --- src/figure/phrase.c | 5 +++-- src/platform/file_manager.c | 3 +++ src/translation/english.c | 5 +++-- src/translation/translation.h | 1 + src/window/config.c | 4 ++-- src/window/logo.c | 2 +- 6 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/figure/phrase.c b/src/figure/phrase.c index 0235c158e0..f7778d6b22 100644 --- a/src/figure/phrase.c +++ b/src/figure/phrase.c @@ -11,6 +11,7 @@ #include "city/resource.h" #include "city/sentiment.h" #include "core/calc.h" +#include "core/file.h" #include "figure/trader.h" #include "figuretype/trader.h" #include "sound/speech.h" @@ -268,8 +269,8 @@ enum { static void play_sound_file(int sound_id, int phrase_id) { if (sound_id >= 0 && phrase_id >= 0) { - char path[SOUND_FILENAME_MAX]; - snprintf(path, SOUND_FILENAME_MAX, "wavs/%s", FIGURE_SOUNDS[sound_id][phrase_id]); + char path[FILE_NAME_MAX]; + snprintf(path, FILE_NAME_MAX, "wavs/%s", FIGURE_SOUNDS[sound_id][phrase_id]); sound_speech_play_file(path); } } diff --git a/src/platform/file_manager.c b/src/platform/file_manager.c index b9faec7702..57b67cc127 100644 --- a/src/platform/file_manager.c +++ b/src/platform/file_manager.c @@ -597,6 +597,9 @@ const char *platform_file_manager_get_directory_for_location(int location, const int platform_file_manager_is_directory_writeable(const char *directory) { char file_name[FILE_NAME_MAX]; + if (!directory || !*directory) { + directory = "."; + } int attempt = 0; do { snprintf(file_name, FILE_NAME_MAX, "%s/test_%d.txt", directory, random_from_stdlib()); diff --git a/src/translation/english.c b/src/translation/english.c index 61ec68bb93..c1a8462d41 100644 --- a/src/translation/english.c +++ b/src/translation/english.c @@ -1481,8 +1481,9 @@ static translation_string all_strings[] = { {TR_USER_DIRECTORIES_CANCELLED_TITLE, "Directory selection canceled"}, {TR_USER_DIRECTORIES_CANCELLED_TEXT, "You have decided not to set a user directory. The C3 install directory will be used.\n" "You can change your settings later in the configuration window."}, - {TR_USER_DIRECTORIES_NOT_WRITEABLE_TITLE, "Directory not writeable"}, - {TR_USER_DIRECTORIES_NOT_WRITEABLE_TEXT, "The selected directory is not writeable.\n\nPlease select a different directory."}, + {TR_USER_DIRECTORIES_NOT_WRITEABLE_TITLE, "User directory not writeable"}, + {TR_USER_DIRECTORIES_NOT_WRITEABLE_TEXT, "The selected user directory is not writeable.\n\nPlease select a different user directory."}, + {TR_USER_DIRECTORIES_NOT_WRITEABLE_TEXT_DETAILED, "The selected user directory is not writeable.\n\nYou will not be able to save your games.\nPlease select a different user directory from the options window on the main menu."}, {TR_USER_DIRECTORIES_WINDOW_TITLE, "Set user directory"}, {TR_USER_DIRETORIES_WINDOW_USER_PATH, "User directory:" }, {TR_USER_DIRECTORIES_USER_PATH_CHANGED_TITLE, "User path changed"}, diff --git a/src/translation/translation.h b/src/translation/translation.h index 916d5eed57..b7ad1fa2bf 100644 --- a/src/translation/translation.h +++ b/src/translation/translation.h @@ -1475,6 +1475,7 @@ typedef enum { TR_USER_DIRECTORIES_CANCELLED_TEXT, TR_USER_DIRECTORIES_NOT_WRITEABLE_TITLE, TR_USER_DIRECTORIES_NOT_WRITEABLE_TEXT, + TR_USER_DIRECTORIES_NOT_WRITEABLE_TEXT_DETAILED, TR_USER_DIRECTORIES_WINDOW_TITLE, TR_USER_DIRETORIES_WINDOW_USER_PATH, TR_USER_DIRECTORIES_USER_PATH_CHANGED_TITLE, diff --git a/src/window/config.c b/src/window/config.c index 1d8f5d58b7..bb041159db 100644 --- a/src/window/config.c +++ b/src/window/config.c @@ -1147,8 +1147,8 @@ static void cancel_values(void) data.config_values[i].new_value = data.config_values[i].original_value; } for (int i = 0; i < CONFIG_STRING_MAX_ALL; i++) { - snprintf(data.config_string_values[i].new_value, CONFIG_STRING_VALUE_MAX, "%s", - data.config_string_values[i].original_value); + memcpy(data.config_string_values[i].new_value, data.config_string_values[i].original_value, + CONFIG_STRING_VALUE_MAX); } } diff --git a/src/window/logo.c b/src/window/logo.c index ca3fe91b3e..03be875a84 100644 --- a/src/window/logo.c +++ b/src/window/logo.c @@ -44,7 +44,7 @@ static int process_pending_actions(void) } if (pending_actions & ACTION_SHOW_MESSAGE_USER_DIR_NOT_WRITABLE) { window_plain_message_dialog_show(TR_USER_DIRECTORIES_NOT_WRITEABLE_TITLE, - TR_USER_DIRECTORIES_NOT_WRITEABLE_TEXT, 0); + TR_USER_DIRECTORIES_NOT_WRITEABLE_TEXT_DETAILED, 0); pending_actions ^= ACTION_SHOW_MESSAGE_USER_DIR_NOT_WRITABLE; return 1; }