diff --git a/command_event.c b/command_event.c index f612497649..0000667b87 100644 --- a/command_event.c +++ b/command_event.c @@ -193,6 +193,99 @@ static void event_init_movie(void) } } +/** + * event_disk_control_set_eject: + * @new_state : Eject or close the virtual drive tray. + * false (0) : Close + * true (1) : Eject + * @print_log : Show message onscreen. + * + * Ejects/closes of the virtual drive tray. + **/ +static void event_disk_control_set_eject(bool new_state, bool print_log) +{ + char msg[PATH_MAX_LENGTH]; + global_t *global = global_get_ptr(); + const struct retro_disk_control_callback *control = + (const struct retro_disk_control_callback*)&global->system.disk_control; + bool error = false; + + if (!control->get_num_images) + return; + + *msg = '\0'; + + if (control->set_eject_state(new_state)) + snprintf(msg, sizeof(msg), "%s virtual disk tray.", + new_state ? "Ejected" : "Closed"); + else + { + error = true; + snprintf(msg, sizeof(msg), "Failed to %s virtual disk tray.", + new_state ? "eject" : "close"); + } + + if (*msg) + { + if (error) + RARCH_ERR("%s\n", msg); + else + RARCH_LOG("%s\n", msg); + + /* Only noise in menu. */ + if (print_log) + rarch_main_msg_queue_push(msg, 1, 180, true); + } +} + +/** + * event_disk_control_append_image: + * @path : Path to disk image. + * + * Appends disk image to disk image list. + **/ +void event_disk_control_append_image(const char *path) +{ + char msg[PATH_MAX_LENGTH]; + unsigned new_idx; + struct retro_game_info info = {0}; + global_t *global = global_get_ptr(); + const struct retro_disk_control_callback *control = + (const struct retro_disk_control_callback*)&global->system.disk_control; + + event_disk_control_set_eject(true, false); + + control->add_image_index(); + new_idx = control->get_num_images(); + if (!new_idx) + return; + new_idx--; + + info.path = path; + control->replace_image_index(new_idx, &info); + + snprintf(msg, sizeof(msg), "Appended disk: %s", path); + RARCH_LOG("%s\n", msg); + rarch_main_msg_queue_push(msg, 0, 180, true); + + event_command(EVENT_CMD_AUTOSAVE_DEINIT); + + /* TODO: Need to figure out what to do with subsystems case. */ + if (!*global->subsystem) + { + /* Update paths for our new image. + * If we actually use append_image, we assume that we + * started out in a single disk case, and that this way + * of doing it makes the most sense. */ + rarch_set_paths(path); + rarch_fill_pathnames(); + } + + event_command(EVENT_CMD_AUTOSAVE_INIT); + + event_disk_control_set_eject(false, false); +} + /** * event_check_disk_eject: * @control : Handle to disk control handle. @@ -203,7 +296,57 @@ static void event_check_disk_eject( const struct retro_disk_control_callback *control) { bool new_state = !control->get_eject_state(); - rarch_disk_control_set_eject(new_state, true); + event_disk_control_set_eject(new_state, true); +} + +/** + * event_disk_control_set_index: + * @idx : Index of disk to set as current. + * + * Sets current disk to @index. + **/ +static void event_disk_control_set_index(unsigned idx) +{ + char msg[PATH_MAX_LENGTH]; + unsigned num_disks; + global_t *global = global_get_ptr(); + const struct retro_disk_control_callback *control = + (const struct retro_disk_control_callback*)&global->system.disk_control; + bool error = false; + + if (!control->get_num_images) + return; + + *msg = '\0'; + + num_disks = control->get_num_images(); + + if (control->set_image_index(idx)) + { + if (idx < num_disks) + snprintf(msg, sizeof(msg), "Setting disk %u of %u in tray.", + idx + 1, num_disks); + else + strlcpy(msg, "Removed disk from tray.", sizeof(msg)); + } + else + { + if (idx < num_disks) + snprintf(msg, sizeof(msg), "Failed to set disk %u of %u.", + idx + 1, num_disks); + else + strlcpy(msg, "Failed to remove disk from tray.", sizeof(msg)); + error = true; + } + + if (*msg) + { + if (error) + RARCH_ERR("%s\n", msg); + else + RARCH_LOG("%s\n", msg); + rarch_main_msg_queue_push(msg, 1, 180, true); + } } /** @@ -227,7 +370,7 @@ static void event_check_disk_prev( if (current > 0) current--; - rarch_disk_control_set_index(current); + event_disk_control_set_index(current); } /** @@ -251,7 +394,7 @@ static void event_check_disk_next( if (current < num_disks - 1) current++; - rarch_disk_control_set_index(current); + event_disk_control_set_index(current); } /** diff --git a/command_event.h b/command_event.h index 97b665ea6d..80b6ed1628 100644 --- a/command_event.h +++ b/command_event.h @@ -195,6 +195,14 @@ enum event_command EVENT_CMD_DATA_RUNLOOP_FREE, }; +/** + * event_disk_control_append_image: + * @path : Path to disk image. + * + * Appends disk image to disk image list. + **/ +void event_disk_control_append_image(const char *path); + /** * event_command: * @cmd : Command index. diff --git a/menu/menu_entries_cbs_ok.c b/menu/menu_entries_cbs_ok.c index 9d4cc6e612..131fd2560a 100644 --- a/menu/menu_entries_cbs_ok.c +++ b/menu/menu_entries_cbs_ok.c @@ -816,7 +816,7 @@ static int action_ok_disk_image_append(const char *path, &menu_path, NULL, NULL); fill_pathname_join(image, menu_path, path, sizeof(image)); - rarch_disk_control_append_image(image); + event_disk_control_append_image(image); event_command(EVENT_CMD_RESUME); diff --git a/retroarch.c b/retroarch.c index 369559079c..1e0f6460bb 100644 --- a/retroarch.c +++ b/retroarch.c @@ -334,7 +334,7 @@ static void set_paths_redirect(const char *path) } } -static void set_paths(const char *path) +void rarch_set_paths(const char *path) { settings_t *settings = config_get_ptr(); global_t *global = global_get_ptr(); @@ -764,7 +764,7 @@ static void parse_input(int argc, char *argv[]) } } else if (!*global->subsystem && optind < argc) - set_paths(argv[optind]); + rarch_set_paths(argv[optind]); else if (*global->subsystem && optind < argc) set_special_paths(argv + optind, argc - optind); else @@ -889,149 +889,6 @@ void rarch_fill_pathnames(void) sizeof(global->ips_name)); } -/** - * rarch_disk_control_append_image: - * @path : Path to disk image. - * - * Appends disk image to disk image list. - **/ -void rarch_disk_control_append_image(const char *path) -{ - char msg[PATH_MAX_LENGTH]; - unsigned new_idx; - struct retro_game_info info = {0}; - global_t *global = global_get_ptr(); - const struct retro_disk_control_callback *control = - (const struct retro_disk_control_callback*)&global->system.disk_control; - - rarch_disk_control_set_eject(true, false); - - control->add_image_index(); - new_idx = control->get_num_images(); - if (!new_idx) - return; - new_idx--; - - info.path = path; - control->replace_image_index(new_idx, &info); - - snprintf(msg, sizeof(msg), "Appended disk: %s", path); - RARCH_LOG("%s\n", msg); - rarch_main_msg_queue_push(msg, 0, 180, true); - - event_command(EVENT_CMD_AUTOSAVE_DEINIT); - - /* TODO: Need to figure out what to do with subsystems case. */ - if (!*global->subsystem) - { - /* Update paths for our new image. - * If we actually use append_image, we assume that we - * started out in a single disk case, and that this way - * of doing it makes the most sense. */ - set_paths(path); - rarch_fill_pathnames(); - } - - event_command(EVENT_CMD_AUTOSAVE_INIT); - - rarch_disk_control_set_eject(false, false); -} - -/** - * rarch_disk_control_set_eject: - * @new_state : Eject or close the virtual drive tray. - * false (0) : Close - * true (1) : Eject - * @print_log : Show message onscreen. - * - * Ejects/closes of the virtual drive tray. - **/ -void rarch_disk_control_set_eject(bool new_state, bool print_log) -{ - char msg[PATH_MAX_LENGTH]; - global_t *global = global_get_ptr(); - const struct retro_disk_control_callback *control = - (const struct retro_disk_control_callback*)&global->system.disk_control; - bool error = false; - - if (!control->get_num_images) - return; - - *msg = '\0'; - - if (control->set_eject_state(new_state)) - snprintf(msg, sizeof(msg), "%s virtual disk tray.", - new_state ? "Ejected" : "Closed"); - else - { - error = true; - snprintf(msg, sizeof(msg), "Failed to %s virtual disk tray.", - new_state ? "eject" : "close"); - } - - if (*msg) - { - if (error) - RARCH_ERR("%s\n", msg); - else - RARCH_LOG("%s\n", msg); - - /* Only noise in menu. */ - if (print_log) - rarch_main_msg_queue_push(msg, 1, 180, true); - } -} - -/** - * rarch_disk_control_set_index: - * @idx : Index of disk to set as current. - * - * Sets current disk to @index. - **/ -void rarch_disk_control_set_index(unsigned idx) -{ - char msg[PATH_MAX_LENGTH]; - unsigned num_disks; - global_t *global = global_get_ptr(); - const struct retro_disk_control_callback *control = - (const struct retro_disk_control_callback*)&global->system.disk_control; - bool error = false; - - if (!control->get_num_images) - return; - - *msg = '\0'; - - num_disks = control->get_num_images(); - - if (control->set_image_index(idx)) - { - if (idx < num_disks) - snprintf(msg, sizeof(msg), "Setting disk %u of %u in tray.", - idx + 1, num_disks); - else - strlcpy(msg, "Removed disk from tray.", sizeof(msg)); - } - else - { - if (idx < num_disks) - snprintf(msg, sizeof(msg), "Failed to set disk %u of %u.", - idx + 1, num_disks); - else - strlcpy(msg, "Failed to remove disk from tray.", sizeof(msg)); - error = true; - } - - if (*msg) - { - if (error) - RARCH_ERR("%s\n", msg); - else - RARCH_LOG("%s\n", msg); - rarch_main_msg_queue_push(msg, 1, 180, true); - } -} - static bool init_state(void) { driver_t *driver = driver_get_ptr(); diff --git a/retroarch.h b/retroarch.h index 60052eb378..ec334d9959 100644 --- a/retroarch.h +++ b/retroarch.h @@ -130,33 +130,6 @@ void rarch_main_deinit(void); **/ void rarch_render_cached_frame(void); -/** - * rarch_disk_control_set_eject: - * @new_state : Eject or close the virtual drive tray. - * false (0) : Close - * true (1) : Eject - * @print_log : Show message onscreen. - * - * Ejects/closes of the virtual drive tray. - **/ -void rarch_disk_control_set_eject(bool state, bool log); - -/** - * rarch_disk_control_set_index: - * @index : Index of disk to set as current. - * - * Sets current disk to @index. - **/ -void rarch_disk_control_set_index(unsigned index); - -/** - * rarch_disk_control_append_image: - * @path : Path to disk image. - * - * Appends disk image to disk image list. - **/ -void rarch_disk_control_append_image(const char *path); - /** * rarch_replace_config: * @path : Path to config file to replace @@ -229,6 +202,8 @@ void rarch_verify_api_version(void); **/ void rarch_init_system_av_info(void); +void rarch_set_paths(const char *path); + #ifdef __cplusplus } #endif