(PS3) Add new ZIP extract mode - can extract ZIP to current directory

now
This commit is contained in:
Twinaphex 2012-07-26 13:08:08 +02:00
parent 61c5bef909
commit 468f7256df
11 changed files with 110 additions and 13 deletions

View File

@ -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)
{

View File

@ -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;

View File

@ -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

View File

@ -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';
}

View File

@ -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
{

View File

@ -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;
}

View File

@ -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

View File

@ -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;

View File

@ -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",

View File

@ -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));

View File

@ -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,