From 0d2d24a619a6f97ab71ae60e84acaacd9d13ee24 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Wed, 1 Jul 2015 22:14:37 +0200 Subject: [PATCH] Expand msg_hash --- command_event.c | 124 +++++++++++++++++++++++++++------------------ intl/msg_hash_us.c | 38 ++++++++++++++ msg_hash.h | 35 +++++++++++++ 3 files changed, 147 insertions(+), 50 deletions(-) diff --git a/command_event.c b/command_event.c index f2f351cdf0..f60cd26219 100644 --- a/command_event.c +++ b/command_event.c @@ -25,6 +25,7 @@ #include "content.h" #include "screenshot.h" #include "intl/intl.h" +#include "msg_hash.h" #include "retroarch.h" #include "dir_list_special.h" @@ -82,9 +83,12 @@ static void event_free_temporary_content(void) { const char *path = global->temporary_content->elems[i].data; - RARCH_LOG("Removing temporary content file: %s.\n", path); + RARCH_LOG("%s: %s.\n", + msg_hash_to_str(MSG_REMOVING_TEMPORARY_CONTENT_FILE), path); if (remove(path) < 0) - RARCH_ERR("Failed to remove temporary file: %s.\n", path); + RARCH_ERR("%s: %s.\n", + msg_hash_to_str(MSG_FAILED_TO_REMOVE_TEMPORARY_FILE), + path); } string_list_free(global->temporary_content); } @@ -166,32 +170,36 @@ static void event_init_movie(void) if (!(global->bsv.movie = bsv_movie_init(global->bsv.movie_start_path, RARCH_MOVIE_PLAYBACK))) { - RARCH_ERR("Failed to load movie file: \"%s\".\n", + RARCH_ERR("%s: \"%s\".\n", + msg_hash_to_str(MSG_FAILED_TO_LOAD_MOVIE_FILE), global->bsv.movie_start_path); rarch_fail(1, "event_init_movie()"); } global->bsv.movie_playback = true; - rarch_main_msg_queue_push("Starting movie playback.", 2, 180, false); - RARCH_LOG("Starting movie playback.\n"); + rarch_main_msg_queue_push_new(MSG_STARTING_MOVIE_PLAYBACK, 2, 180, false); + RARCH_LOG("%s.\n", msg_hash_to_str(MSG_STARTING_MOVIE_PLAYBACK)); settings->rewind_granularity = 1; } else if (global->bsv.movie_start_recording) { char msg[PATH_MAX_LENGTH] = {0}; - snprintf(msg, sizeof(msg), "Starting movie record to \"%s\".", + snprintf(msg, sizeof(msg), + "%s \"%s\".", + msg_hash_to_str(MSG_STARTING_MOVIE_RECORD_TO), global->bsv.movie_start_path); if (!(global->bsv.movie = bsv_movie_init(global->bsv.movie_start_path, RARCH_MOVIE_RECORD))) { - rarch_main_msg_queue_push("Failed to start movie record.", 1, 180, true); - RARCH_ERR("Failed to start movie record.\n"); + rarch_main_msg_queue_push_new(MSG_FAILED_TO_START_MOVIE_RECORD, 1, 180, true); + RARCH_ERR("%s.\n", msg_hash_to_str(MSG_FAILED_TO_START_MOVIE_RECORD)); return; } rarch_main_msg_queue_push(msg, 1, 180, true); - RARCH_LOG("Starting movie record to \"%s\".\n", + RARCH_LOG("%s \"%s\".\n", + msg_hash_to_str(MSG_STARTING_MOVIE_RECORD_TO), global->bsv.movie_start_path); settings->rewind_granularity = 1; } @@ -273,7 +281,7 @@ void event_disk_control_append_image(const char *path) info.path = path; control->replace_image_index(new_idx, &info); - strlcpy(msg, "Appended disk: ", sizeof(msg)); + snprintf(msg, sizeof(msg), "%s: ", msg_hash_to_str(MSG_APPENDED_DISK)); strlcat(msg, path, sizeof(msg)); RARCH_LOG("%s\n", msg); rarch_main_msg_queue_push(msg, 0, 180, true); @@ -684,7 +692,8 @@ static bool event_init_content(void) event_set_savestate_auto_index(); if (event_load_save_files()) - RARCH_LOG("Skipping SRAM load.\n"); + RARCH_LOG("%s.\n", + msg_hash_to_str(MSG_SKIPPING_SRAM_LOAD)); event_load_auto_state(); event_command(EVENT_CMD_BSV_MOVIE_INIT); @@ -801,9 +810,8 @@ static bool event_save_core_config(void) sizeof(config_dir)); else { - const char *message = "Config directory not set. Cannot save new config."; - rarch_main_msg_queue_push(message, 1, 180, true); - RARCH_ERR("%s\n", message); + rarch_main_msg_queue_push_new(MSG_CONFIG_DIRECTORY_NOT_SET, 1, 180, true); + RARCH_ERR("%s\n", msg_hash_to_str(MSG_CONFIG_DIRECTORY_NOT_SET)); return false; } @@ -896,9 +904,10 @@ static void event_save_state(const char *path, } if (settings->state_slot < 0) - snprintf(s, len, "Saved state to slot #-1 (auto)."); + snprintf(s, len, "%s #-1 (auto).", msg_hash_to_str(MSG_SAVED_STATE_TO_SLOT)); else - snprintf(s, len, "Saved state to slot #%d.", settings->state_slot); + snprintf(s, len, "%s #%d.", msg_hash_to_str(MSG_SAVED_STATE_TO_SLOT), + settings->state_slot); } /** @@ -915,15 +924,17 @@ static void event_load_state(const char *path, char *s, size_t len) if (!load_state(path)) { - snprintf(s, len, "Failed to load state from \"%s\".", path); + snprintf(s, len, "%s \"%s\".", + msg_hash_to_str(MSG_FAILED_TO_LOAD_STATE), + path); return; - } if (settings->state_slot < 0) - snprintf(s, len, "Loaded state from slot #-1 (auto)."); + snprintf(s, len, "%s #-1 (auto).", msg_hash_to_str(MSG_LOADED_STATE_FROM_SLOT)); else - snprintf(s, len, "Loaded state from slot #%d.", settings->state_slot); + snprintf(s, len, "%s #%d.", msg_hash_to_str(MSG_LOADED_STATE_FROM_SLOT), + settings->state_slot); } static void event_main_state(unsigned cmd) @@ -937,19 +948,25 @@ static void event_main_state(unsigned cmd) snprintf(path, sizeof(path), "%s%d", global->savestate_name, settings->state_slot); else if (settings->state_slot < 0) - fill_pathname_join_delim(path, global->savestate_name, "auto", '.', sizeof(path)); + fill_pathname_join_delim(path, + global->savestate_name, "auto", '.', sizeof(path)); else strlcpy(path, global->savestate_name, sizeof(path)); if (pretro_serialize_size()) { - if (cmd == EVENT_CMD_SAVE_STATE) - event_save_state(path, msg, sizeof(msg)); - else if (cmd == EVENT_CMD_LOAD_STATE) - event_load_state(path, msg, sizeof(msg)); + switch (cmd) + { + case EVENT_CMD_SAVE_STATE: + event_save_state(path, msg, sizeof(msg)); + break; + case EVENT_CMD_LOAD_STATE: + event_load_state(path, msg, sizeof(msg)); + break; + } } else - strlcpy(msg, "Core does not support save states.", sizeof(msg)); + strlcpy(msg, msg_hash_to_str(MSG_CORE_DOES_NOT_SUPPORT_SAVESTATES), sizeof(msg)); rarch_main_msg_queue_push(msg, 2, 180, true); RARCH_LOG("%s\n", msg); @@ -1081,7 +1098,7 @@ bool event_command(enum event_command cmd) break; case EVENT_CMD_RESET: RARCH_LOG(RETRO_LOG_RESETTING_CONTENT); - rarch_main_msg_queue_push("Reset.", 1, 120, true); + rarch_main_msg_queue_push_new(MSG_RESET, 1, 120, true); pretro_reset(); /* bSNES since v073r01 resets controllers to JOYPAD @@ -1214,11 +1231,13 @@ bool event_command(enum event_command cmd) case EVENT_CMD_AUDIO_MUTE_TOGGLE: { const char *msg = !settings->audio.mute_enable ? - "Audio muted." : "Audio unmuted."; + msg_hash_to_str(MSG_AUDIO_MUTED): + msg_hash_to_str(MSG_AUDIO_UNMUTED); if (!audio_driver_mute_toggle()) { - RARCH_ERR("Failed to unmute audio.\n"); + RARCH_ERR("%s.\n", + msg_hash_to_str(MSG_FAILED_TO_UNMUTE_AUDIO)); return false; } @@ -1249,11 +1268,15 @@ bool event_command(enum event_command cmd) break; } - driver->overlay = input_overlay_new(driver->osk_enable ? settings->osk.overlay : settings->input.overlay, - driver->osk_enable ? settings->osk.enable : settings->input.overlay_enable, - settings->input.overlay_opacity, settings->input.overlay_scale); + driver->overlay = input_overlay_new( + driver->osk_enable ? + settings->osk.overlay : settings->input.overlay, + driver->osk_enable ? + settings->osk.enable : settings->input.overlay_enable, + settings->input.overlay_opacity, + settings->input.overlay_scale); if (!driver->overlay) - RARCH_ERR("Failed to load overlay.\n"); + RARCH_ERR("%s.\n", msg_hash_to_str(MSG_FAILED_TO_LOAD_OVERLAY)); #endif break; case EVENT_CMD_OVERLAY_NEXT: @@ -1325,15 +1348,15 @@ bool event_command(enum event_command cmd) global->core_info = core_info_list_new(); break; case EVENT_CMD_CORE_DEINIT: - { - struct retro_hw_render_callback *cb = video_driver_callback(); - event_deinit_core(true); + { + struct retro_hw_render_callback *cb = video_driver_callback(); + event_deinit_core(true); - if (cb) - memset(cb, 0, sizeof(*cb)); + if (cb) + memset(cb, 0, sizeof(*cb)); - break; - } + break; + } case EVENT_CMD_CORE_INIT: if (!event_init_core()) return false; @@ -1407,7 +1430,7 @@ bool event_command(enum event_command cmd) case EVENT_CMD_PAUSE_CHECKS: if (runloop->is_paused) { - RARCH_LOG("Paused.\n"); + RARCH_LOG("%s\n", msg_hash_to_str(MSG_PAUSED)); event_command(EVENT_CMD_AUDIO_STOP); if (settings->video.black_frame_insertion) @@ -1415,7 +1438,7 @@ bool event_command(enum event_command cmd) } else { - RARCH_LOG("Unpaused.\n"); + RARCH_LOG("%s\n", msg_hash_to_str(MSG_UNPAUSED)); event_command(EVENT_CMD_AUDIO_START); } break; @@ -1608,7 +1631,8 @@ bool event_command(enum event_command cmd) event_check_disk_eject(control); } else - rarch_main_msg_queue_push("Core does not support Disk Options.", 1, 120, true); + rarch_main_msg_queue_push_new(MSG_CORE_DOES_NOT_SUPPORT_DISK_OPTIONS, + 1, 120, true); break; case EVENT_CMD_DISK_NEXT: if (system && system->disk_control.get_num_images) @@ -1626,7 +1650,8 @@ bool event_command(enum event_command cmd) event_check_disk_next(control); } else - rarch_main_msg_queue_push("Core does not support Disk Options.", 1, 120, true); + rarch_main_msg_queue_push_new(MSG_CORE_DOES_NOT_SUPPORT_DISK_OPTIONS, + 1, 120, true); break; case EVENT_CMD_DISK_PREV: if (system && system->disk_control.get_num_images) @@ -1644,7 +1669,8 @@ bool event_command(enum event_command cmd) event_check_disk_prev(control); } else - rarch_main_msg_queue_push("Core does not support Disk Options.", 1, 120, true); + rarch_main_msg_queue_push_new(MSG_CORE_DOES_NOT_SUPPORT_DISK_OPTIONS, + 1, 120, true); break; case EVENT_CMD_RUMBLE_STOP: for (i = 0; i < MAX_USERS; i++) @@ -1662,7 +1688,8 @@ bool event_command(enum event_command cmd) if (!driver->input || !input_driver_grab_mouse(grab_mouse_state)) return false; - RARCH_LOG("Grab mouse state: %s.\n", + RARCH_LOG("%s: %s.\n", + msg_hash_to_str(MSG_GRAB_MOUSE_STATE), grab_mouse_state ? "yes" : "no"); video_driver_show_mouse(!grab_mouse_state); @@ -1679,11 +1706,8 @@ bool event_command(enum event_command cmd) break; case EVENT_CMD_NONE: default: - goto error; + return false; } return true; - -error: - return false; } diff --git a/intl/msg_hash_us.c b/intl/msg_hash_us.c index 742be4ceeb..5e85b37aa5 100644 --- a/intl/msg_hash_us.c +++ b/intl/msg_hash_us.c @@ -20,6 +20,44 @@ const char *msg_hash_to_str_us(uint32_t hash) { switch (hash) { + case MSG_FAILED_TO_LOAD_MOVIE_FILE: + return "Failed to load movie file"; + case MSG_GRAB_MOUSE_STATE: + return "Grab mouse state"; + case MSG_PAUSED: + return "Paused."; + case MSG_UNPAUSED: + return "Unpaused."; + case MSG_FAILED_TO_LOAD_OVERLAY: + return "Failed to load overlay."; + case MSG_FAILED_TO_UNMUTE_AUDIO: + return "Failed to unmute audio."; + case MSG_AUDIO_MUTED: + return "Audio muted."; + case MSG_AUDIO_UNMUTED: + return "Audio unmuted."; + case MSG_RESET: + return "Reset"; + case MSG_FAILED_TO_LOAD_STATE: + return "Failed to load state from"; + case MSG_CORE_DOES_NOT_SUPPORT_SAVESTATES: + return "Core does not support save states."; + case MSG_SAVED_STATE_TO_SLOT: + return "Saved state to slot"; + case MSG_CONFIG_DIRECTORY_NOT_SET: + return "Config directory not set. Cannot save new config."; + case MSG_SKIPPING_SRAM_LOAD: + return "Skipping SRAM load."; + case MSG_APPENDED_DISK: + return "Appended disk"; + case MSG_STARTING_MOVIE_PLAYBACK: + return "Starting movie playback."; + case MSG_FAILED_TO_REMOVE_TEMPORARY_FILE: + return "Failed to remove temporary file"; + case MSG_REMOVING_TEMPORARY_CONTENT_FILE: + return "Removing temporary content file"; + case MSG_LOADED_STATE_FROM_SLOT: + return "Loaded state from slot"; case MSG_DOWNLOAD_PROGRESS: return "Download progress"; case MSG_COULD_NOT_PROCESS_ZIP_FILE: diff --git a/msg_hash.h b/msg_hash.h index 1923eeeca4..65f19e1522 100644 --- a/msg_hash.h +++ b/msg_hash.h @@ -48,6 +48,41 @@ #define MSG_COULD_NOT_PROCESS_ZIP_FILE 0xc18c89bbU #define MSG_DOWNLOAD_PROGRESS 0x35ed9411U +#define MSG_LOADED_STATE_FROM_SLOT 0xadb48582U + +#define MSG_REMOVING_TEMPORARY_CONTENT_FILE 0x7121c9e7U +#define MSG_FAILED_TO_REMOVE_TEMPORARY_FILE 0xb6707b1aU + +#define MSG_STARTING_MOVIE_PLAYBACK 0x96e545b6U + +#define MSG_APPENDED_DISK 0x814ea0f0U + +#define MSG_SKIPPING_SRAM_LOAD 0x88d4c8dbU + +#define MSG_CONFIG_DIRECTORY_NOT_SET 0xcd45252aU + +#define MSG_SAVED_STATE_TO_SLOT 0xe1e3dc3bU + +#define MSG_CORE_DOES_NOT_SUPPORT_SAVESTATES 0xd50adf46U +#define MSG_FAILED_TO_LOAD_STATE 0x91f348ebU + +#define MSG_RESET 0x10474288U + +#define MSG_AUDIO_MUTED 0xfa0c3bd5U +#define MSG_AUDIO_UNMUTED 0x0512bab8U +#define MSG_FAILED_TO_UNMUTE_AUDIO 0xf698763aU + +#define MSG_FAILED_TO_LOAD_OVERLAY 0xacf201ecU + +#define MSG_PAUSED 0x143e3307U +#define MSG_UNPAUSED 0x95aede0aU + +#define MSG_CORE_DOES_NOT_SUPPORT_DISK_OPTIONS 0x6ba5abf9U + +#define MSG_GRAB_MOUSE_STATE 0x893a7329U + +#define MSG_FAILED_TO_LOAD_MOVIE_FILE 0x9455a5a9U + const char *msg_hash_to_str(uint32_t hash); const char *msg_hash_to_str_fr(uint32_t hash);