From 468f7256df8ed278c45d6aa54eb702dbbf2b13f8 Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Thu, 26 Jul 2012 13:08:08 +0200 Subject: [PATCH] (PS3) Add new ZIP extract mode - can extract ZIP to current directory now --- 360/frontend-xdk/menu.cpp | 15 +++++++++++---- console/console_settings.c | 15 ++++++++++++++- console/retroarch_config.c | 6 ++++++ console/retroarch_console.c | 15 +++++++++++++++ console/retroarch_console.h | 1 + console/retroarch_rzlib.c | 18 ++++++++++++------ console/retroarch_rzlib.h | 8 +++++++- general.h | 3 +++ ps3/frontend/menu-entries.h | 11 +++++++++++ ps3/frontend/menu.c | 30 +++++++++++++++++++++++++++++- ps3/frontend/menu.h | 1 + 11 files changed, 110 insertions(+), 13 deletions(-) diff --git a/360/frontend-xdk/menu.cpp b/360/frontend-xdk/menu.cpp index 3107092897..249ecfc48e 100644 --- a/360/frontend-xdk/menu.cpp +++ b/360/frontend-xdk/menu.cpp @@ -546,16 +546,23 @@ HRESULT CRetroArchFileBrowser::OnNotifyPress( HXUIOBJ hObjPressed, BOOL& bHandle const char *strbuffer = rarch_convert_wchar_to_const_char((const wchar_t *)m_romlist.GetText(index)); if(path_file_exists(browser->current_dir.list->elems[index].data)) { - char path_tmp[1024]; + char rom_path_temp[PATH_MAX]; + char dir_path_temp[PATH_MAX]; struct retro_system_info info; retro_get_system_info(&info); bool block_zip_extract = info.block_extract; - snprintf(path_tmp, sizeof(path_tmp), "%s\\%s", filebrowser_get_current_dir(browser), strbuffer); + snprintf(path_temp, sizeof(path_temp), "%s\\%s", filebrowser_get_current_dir(browser), strbuffer); + if((strstr(strbuffer, ".zip") || strstr(strbuffer, ".ZIP")) && !block_zip_extract) - rarch_extract_zipfile(path_tmp); + { + rarch_extract_directory(dir_path_temp, path_temp, sizeof(dir_path_temp)); + rarch_extract_zipfile(rom_path_temp, dir_path_temp); + } else - rarch_console_load_game(path_tmp); + { + rarch_console_load_game(path_temp); + } } else if(browser->current_dir.list->elems[index].attr.b) { diff --git a/console/console_settings.c b/console/console_settings.c index 8d5fe67323..1ebb221b6b 100644 --- a/console/console_settings.c +++ b/console/console_settings.c @@ -225,7 +225,17 @@ void rarch_settings_msg(unsigned setting, unsigned delay) snprintf(str, sizeof(str), "INFO - Press LEFT/RIGHT to change the controls, and press\n[RetroPad Start] to reset a button to default values."); break; case S_MSG_EXTRACTED_ZIPFILE: - snprintf(str, sizeof(str), "INFO - ZIP file successfully extracted to cache partition."); + switch(g_console.zip_extract_mode) + { + case ZIP_EXTRACT_TO_CURRENT_DIR: + snprintf(str, sizeof(str), "INFO - ZIP file successfully extracted to current directory."); + break; +#ifdef HAVE_HDD_CACHE_PARTITION + case ZIP_EXTRACT_TO_CACHE_DIR: + snprintf(str, sizeof(str), "INFO - ZIP file successfully extracted to cache partition."); + break; +#endif + } break; case S_MSG_LOADING_ROM: fill_pathname_base(tmp, g_console.rom_path, sizeof(tmp)); @@ -362,6 +372,9 @@ void rarch_settings_set_default (const input_driver_t *input) #ifdef _XBOX360 g_console.color_format = 0; #endif +#ifdef HAVE_ZLIB + g_console.zip_extract_mode = 0; +#endif // g_extern g_extern.state_slot = 0; diff --git a/console/retroarch_config.c b/console/retroarch_config.c index e8e71b3317..c3faa877a5 100644 --- a/console/retroarch_config.c +++ b/console/retroarch_config.c @@ -102,6 +102,9 @@ void rarch_config_load(const char * conf_name, const char * libretro_dir_path, c CONFIG_GET_INT_CONSOLE(viewports.custom_vp.height, "custom_viewport_height"); CONFIG_GET_INT_CONSOLE(screen_orientation, "screen_orientation"); CONFIG_GET_INT_CONSOLE(sound_mode, "sound_mode"); +#ifdef HAVE_ZLIB + CONFIG_GET_INT_CONSOLE(zip_extract_mode, "zip_extract_mode"); +#endif CONFIG_GET_STRING_CONSOLE(default_rom_startup_dir, "default_rom_startup_dir"); CONFIG_GET_FLOAT_CONSOLE(menu_font_size, "menu_font_size"); CONFIG_GET_FLOAT_CONSOLE(overscan_amount, "overscan_amount"); @@ -174,6 +177,9 @@ void rarch_config_save(const char * conf_name) config_set_string(conf, "default_rom_startup_dir", g_console.default_rom_startup_dir); config_set_float(conf, "menu_font_size", g_console.menu_font_size); config_set_float(conf, "overscan_amount", g_console.overscan_amount); +#ifdef HAVE_ZLIB + config_set_int(conf, "zip_extract_mode", g_console.zip_extract_mode); +#endif #endif // g_extern diff --git a/console/retroarch_console.c b/console/retroarch_console.c index 30497ba745..30142754f0 100644 --- a/console/retroarch_console.c +++ b/console/retroarch_console.c @@ -304,3 +304,18 @@ const char * rarch_convert_wchar_to_const_char(const wchar_t * wstr) wcstombs(str, wstr, sizeof(str)); return str; } + +void rarch_extract_directory(char *buf, const char *path, size_t size) +{ + strncpy(buf, path, size - 1); + buf[size - 1] = '\0'; + + char *base = strrchr(buf, '/'); + if (!base) + base = strrchr(buf, '\\'); + + if (base) + *base = '\0'; + else + buf[0] = '\0'; +} diff --git a/console/retroarch_console.h b/console/retroarch_console.h index 7931eac951..a96424f791 100644 --- a/console/retroarch_console.h +++ b/console/retroarch_console.h @@ -209,6 +209,7 @@ void rarch_console_rsound_stop(void); void rarch_convert_char_to_wchar(wchar_t *buf, const char * str, size_t size); const char * rarch_convert_wchar_to_const_char(const wchar_t * wstr); +void rarch_extract_directory(char *buf, const char *path, size_t size); enum { diff --git a/console/retroarch_rzlib.c b/console/retroarch_rzlib.c index 5576f0f97d..fe73feca5c 100644 --- a/console/retroarch_rzlib.c +++ b/console/retroarch_rzlib.c @@ -22,7 +22,7 @@ #include "retroarch_rzlib.h" -static int rarch_extract_currentfile_in_zip(unzFile uf) +static int rarch_extract_currentfile_in_zip(unzFile uf, const char *current_dir) { char filename_inzip[PATH_MAX]; FILE *file_out = NULL; @@ -48,9 +48,17 @@ static int rarch_extract_currentfile_in_zip(unzFile uf) char write_filename[PATH_MAX]; + switch(g_console.zip_extract_mode) + { + case ZIP_EXTRACT_TO_CURRENT_DIR: + snprintf(write_filename, sizeof(write_filename), "%s/%s", current_dir, filename_inzip); + break; #ifdef HAVE_HDD_CACHE_PARTITION - snprintf(write_filename, sizeof(write_filename), "%s%s", default_paths.cache_dir, filename_inzip); + case ZIP_EXTRACT_TO_CACHE_DIR: + snprintf(write_filename, sizeof(write_filename), "%s%s", default_paths.cache_dir, filename_inzip); + break; #endif + } err = unzOpenCurrentFile(uf); if (err != UNZ_OK) @@ -105,7 +113,7 @@ static int rarch_extract_currentfile_in_zip(unzFile uf) return err; } -int rarch_extract_zipfile(const char *zip_path) +int rarch_extract_zipfile(const char *zip_path, const char *current_dir) { unzFile uf = unzOpen(zip_path); @@ -116,7 +124,7 @@ int rarch_extract_zipfile(const char *zip_path) for (unsigned i = 0; i < gi.number_entry; i++) { - if (rarch_extract_currentfile_in_zip(uf) != UNZ_OK) + if (rarch_extract_currentfile_in_zip(uf, current_dir) != UNZ_OK) break; if ((i + 1) < gi.number_entry) @@ -130,10 +138,8 @@ int rarch_extract_zipfile(const char *zip_path) } } -#ifdef HAVE_HDD_CACHE_PARTITION if(g_console.info_msg_enable) rarch_settings_msg(S_MSG_EXTRACTED_ZIPFILE, S_DELAY_180); -#endif return 0; } diff --git a/console/retroarch_rzlib.h b/console/retroarch_rzlib.h index 440384d10a..98fd52c7bb 100644 --- a/console/retroarch_rzlib.h +++ b/console/retroarch_rzlib.h @@ -21,6 +21,12 @@ #define WRITEBUFFERSIZE (1024 * 512) -int rarch_extract_zipfile(const char *zip_path); +enum +{ + ZIP_EXTRACT_TO_CURRENT_DIR, + ZIP_EXTRACT_TO_CACHE_DIR +}; + +int rarch_extract_zipfile(const char *zip_path, const char *current_dir); #endif diff --git a/general.h b/general.h index f1c7ded0bd..b816b8a3cc 100644 --- a/general.h +++ b/general.h @@ -242,6 +242,9 @@ struct console_settings uint32_t control_timer_expiration_frame_count; uint32_t timer_expiration_frame_count; uint32_t input_loop; +#ifdef HAVE_ZLIB + uint32_t zip_extract_mode; +#endif #ifdef _XBOX uint32_t color_format; DWORD volume_device_type; diff --git a/ps3/frontend/menu-entries.h b/ps3/frontend/menu-entries.h index 650a8454d0..1a01c70661 100644 --- a/ps3/frontend/menu-entries.h +++ b/ps3/frontend/menu-entries.h @@ -269,6 +269,17 @@ item items_generalsettings[MAX_NO_OF_CONTROLS_SETTINGS] = WHITE, 0.83f, }, + { + SETTING_ZIP_EXTRACT, + "ZIP extract", + "", + 0.0f, + 0.0f, + YELLOW, + "INFO - Select the [ZIP Extract] mode. This setting controls how ZIP files are extracted.", + WHITE, + 0.83f, + }, { SETTING_RARCH_DEFAULT_EMU, "Default emulator core", diff --git a/ps3/frontend/menu.c b/ps3/frontend/menu.c index 26c02f5052..cf92b7e27f 100644 --- a/ps3/frontend/menu.c +++ b/ps3/frontend/menu.c @@ -222,6 +222,20 @@ static void set_setting_label(menu * menu_obj, unsigned currentsetting) snprintf(items_generalsettings[currentsetting].comment, sizeof(items_generalsettings[currentsetting].comment), "INFO - [Rewind] feature is set to 'OFF'."); } break; + case SETTING_ZIP_EXTRACT: + set_setting_label_color(g_console.zip_extract_mode == ZIP_EXTRACT_TO_CURRENT_DIR, currentsetting); + switch(g_console.zip_extract_mode) + { + case ZIP_EXTRACT_TO_CURRENT_DIR: + snprintf(items_generalsettings[currentsetting].setting_text, sizeof(items_generalsettings[currentsetting].setting_text), "Current dir"); + snprintf(items_generalsettings[currentsetting].comment, sizeof(items_generalsettings[currentsetting].comment), "INFO - [ZIP Extract Mode] is set to 'Current dir'.\nZIP files are extracted to the current directory."); + break; + case ZIP_EXTRACT_TO_CACHE_DIR: + snprintf(items_generalsettings[currentsetting].setting_text, sizeof(items_generalsettings[currentsetting].setting_text), "Cache dir"); + snprintf(items_generalsettings[currentsetting].comment, sizeof(items_generalsettings[currentsetting].comment), "INFO - [ZIP Extract Mode] is set to 'Cache dir'.\nZIP files are extracted to the cache directory (dev_hdd1)."); + break; + } + break; case SETTING_RARCH_DEFAULT_EMU: fill_pathname_base(fname, g_settings.libretro, sizeof(fname)); snprintf(items_generalsettings[currentsetting].setting_text, sizeof(items_generalsettings[currentsetting].setting_text), "%s", fname); @@ -1350,6 +1364,16 @@ static void producesettingentry(menu * menu_obj, unsigned switchvalue) if(input_state & (1 << RETRO_DEVICE_ID_JOYPAD_START)) g_settings.rewind_enable = false; break; + case SETTING_ZIP_EXTRACT: + if((input_state & (1 << RETRO_DEVICE_ID_JOYPAD_LEFT)) || (input_state & (1 << RETRO_DEVICE_ID_JOYPAD_RIGHT)) || (input_state & (1 << RETRO_DEVICE_ID_JOYPAD_B))) + { + g_console.zip_extract_mode = g_console.zip_extract_mode == ZIP_EXTRACT_TO_CURRENT_DIR ? ZIP_EXTRACT_TO_CACHE_DIR : ZIP_EXTRACT_TO_CURRENT_DIR; + } + if(input_state & (1 << RETRO_DEVICE_ID_JOYPAD_START)) + { + g_console.zip_extract_mode = ZIP_EXTRACT_TO_CURRENT_DIR; + } + break; case SETTING_RARCH_DEFAULT_EMU: if((input_state & (1 << RETRO_DEVICE_ID_JOYPAD_LEFT)) || (input_state & (1 << RETRO_DEVICE_ID_JOYPAD_RIGHT)) || (input_state & (1 << RETRO_DEVICE_ID_JOYPAD_B))) { @@ -1675,6 +1699,7 @@ static void menu_romselect_iterate(filebrowser_t *filebrowser, menu_romselect_ac else { char rom_path_temp[PATH_MAX]; + char dir_path_temp[PATH_MAX]; struct retro_system_info info; retro_get_system_info(&info); bool block_zip_extract = info.block_extract; @@ -1682,7 +1707,10 @@ static void menu_romselect_iterate(filebrowser_t *filebrowser, menu_romselect_ac snprintf(rom_path_temp, sizeof(rom_path_temp), filebrowser_get_current_path(filebrowser)); if((strstr(rom_path_temp, ".zip") || strstr(rom_path_temp, ".ZIP")) && !block_zip_extract) - rarch_extract_zipfile(rom_path_temp); + { + rarch_extract_directory(dir_path_temp, rom_path_temp, sizeof(dir_path_temp)); + rarch_extract_zipfile(rom_path_temp, dir_path_temp); + } else { rarch_console_load_game(filebrowser_get_current_path(filebrowser)); diff --git a/ps3/frontend/menu.h b/ps3/frontend/menu.h index f1aa52e8d9..5c891e45c6 100644 --- a/ps3/frontend/menu.h +++ b/ps3/frontend/menu.h @@ -101,6 +101,7 @@ enum SETTING_DEFAULT_AUDIO_ALL, SETTING_EMU_CURRENT_SAVE_STATE_SLOT, SETTING_EMU_SHOW_INFO_MSG, + SETTING_ZIP_EXTRACT, SETTING_RARCH_DEFAULT_EMU, SETTING_EMU_DEFAULT_ALL, SETTING_EMU_REWIND_ENABLED,