Add Blargg's file_extractor library and integrate 7zip/RAR support
This commit is contained in:
parent
80e169d9fb
commit
823cac2932
11
VBA.sln
11
VBA.sln
|
@ -2,9 +2,10 @@ Microsoft Visual Studio Solution File, Format Version 9.00
|
|||
# Visual Studio 2005
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "VisualBoyAdvance", "VBA.vcproj", "{6D4C5EC8-933F-4C05-A1BF-498E658576DF}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{7AEC599C-7C82-4F00-AA60-411E0A359CB0} = {7AEC599C-7C82-4F00-AA60-411E0A359CB0}
|
||||
{B938FBD9-C7F9-4BF7-8C27-68865D1FA092} = {B938FBD9-C7F9-4BF7-8C27-68865D1FA092}
|
||||
{DB5C12E9-BCD3-4517-8708-475C0D1D88CE} = {DB5C12E9-BCD3-4517-8708-475C0D1D88CE}
|
||||
{96E945F7-0377-48DA-A5F8-1C192DE9F25F} = {96E945F7-0377-48DA-A5F8-1C192DE9F25F}
|
||||
{DB5C12E9-BCD3-4517-8708-475C0D1D88CE} = {DB5C12E9-BCD3-4517-8708-475C0D1D88CE}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zlib", "..\dependencies\zlib\zlib.vcproj", "{B938FBD9-C7F9-4BF7-8C27-68865D1FA092}"
|
||||
|
@ -13,6 +14,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libpng", "..\dependencies\l
|
|||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cximage", "..\dependencies\cximage\cximage.vcproj", "{DB5C12E9-BCD3-4517-8708-475C0D1D88CE}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "File_Extractor", "..\dependencies\File_Extractor-0.4.2\File_Extractor.vcproj", "{7AEC599C-7C82-4F00-AA60-411E0A359CB0}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Win32 = Debug|Win32
|
||||
|
@ -44,6 +47,12 @@ Global
|
|||
{DB5C12E9-BCD3-4517-8708-475C0D1D88CE}.Optimized|Win32.Build.0 = Release|Win32
|
||||
{DB5C12E9-BCD3-4517-8708-475C0D1D88CE}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{DB5C12E9-BCD3-4517-8708-475C0D1D88CE}.Release|Win32.Build.0 = Release|Win32
|
||||
{7AEC599C-7C82-4F00-AA60-411E0A359CB0}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{7AEC599C-7C82-4F00-AA60-411E0A359CB0}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{7AEC599C-7C82-4F00-AA60-411E0A359CB0}.Optimized|Win32.ActiveCfg = Release|Win32
|
||||
{7AEC599C-7C82-4F00-AA60-411E0A359CB0}.Optimized|Win32.Build.0 = Release|Win32
|
||||
{7AEC599C-7C82-4F00-AA60-411E0A359CB0}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{7AEC599C-7C82-4F00-AA60-411E0A359CB0}.Release|Win32.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
|
12
VBA.vcproj
12
VBA.vcproj
|
@ -51,8 +51,8 @@
|
|||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""$(SolutionDir)..\dependencies\zlib";"$(SolutionDir)..\dependencies\libpng";"$(SolutionDir)..\dependencies\cximage""
|
||||
PreprocessorDefinitions="WIN32;_WINDOWS;_DEBUG;DEV_VERSION;BKPT_SUPPORT;MMX;_CRT_SECURE_NO_WARNINGS"
|
||||
AdditionalIncludeDirectories=""$(SolutionDir)..\dependencies\zlib";"$(SolutionDir)..\dependencies\libpng";"$(SolutionDir)..\dependencies\cximage";$(SolutionDir)..\dependencies\File_Extractor-0.4.2\fex"
|
||||
PreprocessorDefinitions="WIN32;_WINDOWS;_DEBUG;DEV_VERSION;BKPT_SUPPORT;MMX;_CRT_SECURE_NO_WARNINGS;HAS_FILE_EXTRACTOR"
|
||||
StringPooling="false"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
|
@ -163,8 +163,8 @@
|
|||
InlineFunctionExpansion="2"
|
||||
FavorSizeOrSpeed="1"
|
||||
WholeProgramOptimization="true"
|
||||
AdditionalIncludeDirectories=""$(SolutionDir)..\dependencies\zlib";"$(SolutionDir)..\dependencies\libpng";"$(SolutionDir)..\dependencies\cximage""
|
||||
PreprocessorDefinitions="WIN32;WINVER=0x0500;NDEBUG;_WINDOWS;OEMRESOURCE;MMX;ASM;FINAL_VERSION;BKPT_SUPPORT;_CRT_SECURE_NO_DEPRECATE"
|
||||
AdditionalIncludeDirectories=""$(SolutionDir)..\dependencies\zlib";"$(SolutionDir)..\dependencies\libpng";"$(SolutionDir)..\dependencies\cximage";$(SolutionDir)..\dependencies\File_Extractor-0.4.2\fex"
|
||||
PreprocessorDefinitions="WIN32;WINVER=0x0500;NDEBUG;_WINDOWS;OEMRESOURCE;MMX;ASM;FINAL_VERSION;BKPT_SUPPORT;_CRT_SECURE_NO_DEPRECATE;HAS_FILE_EXTRACTOR"
|
||||
RuntimeLibrary="0"
|
||||
BufferSecurityCheck="false"
|
||||
EnableEnhancedInstructionSet="1"
|
||||
|
@ -283,8 +283,8 @@
|
|||
EnableIntrinsicFunctions="true"
|
||||
FavorSizeOrSpeed="1"
|
||||
OmitFramePointers="true"
|
||||
AdditionalIncludeDirectories=""$(SolutionDir)..\dependencies\zlib";"$(SolutionDir)..\dependencies\libpng";"$(SolutionDir)..\dependencies\cximage""
|
||||
PreprocessorDefinitions="WIN32;_WINDOWS;NDEBUG;FINAL_VERSION;MMX;_CRT_SECURE_NO_WARNINGS"
|
||||
AdditionalIncludeDirectories=""$(SolutionDir)..\dependencies\zlib";"$(SolutionDir)..\dependencies\libpng";"$(SolutionDir)..\dependencies\cximage";$(SolutionDir)..\dependencies\File_Extractor-0.4.2\fex"
|
||||
PreprocessorDefinitions="WIN32;_WINDOWS;NDEBUG;FINAL_VERSION;MMX;_CRT_SECURE_NO_WARNINGS;HAS_FILE_EXTRACTOR"
|
||||
IgnoreStandardIncludePath="false"
|
||||
GeneratePreprocessedFile="0"
|
||||
KeepComments="false"
|
||||
|
|
260
src/Util.cpp
260
src/Util.cpp
|
@ -25,8 +25,10 @@ extern "C" {
|
|||
#include <png.h>
|
||||
}
|
||||
|
||||
#if 0
|
||||
#include "unrarlib.h"
|
||||
#ifdef HAS_FILE_EXTRACTOR
|
||||
#include <Zip_Extractor.h>
|
||||
#include <Rar_Extractor.h>
|
||||
#include <Zip7_Extractor.h>
|
||||
#endif
|
||||
|
||||
#include "System.h"
|
||||
|
@ -541,11 +543,11 @@ bool utilIsZipFile(const char *file)
|
|||
return false;
|
||||
}
|
||||
|
||||
#if 0
|
||||
#ifdef HAS_FILE_EXTRACTOR
|
||||
bool utilIsRarFile(const char *file)
|
||||
{
|
||||
if(strlen(file) > 4) {
|
||||
char * p = strrchr(file,'.');
|
||||
const char * p = strrchr(file,'.');
|
||||
|
||||
if(p != NULL) {
|
||||
if(_stricmp(p, ".rar") == 0)
|
||||
|
@ -555,6 +557,21 @@ bool utilIsRarFile(const char *file)
|
|||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool utilIs7ZipFile(const char *file)
|
||||
{
|
||||
if(strlen(file) > 3) {
|
||||
const char * p = strrchr(file,'.');
|
||||
|
||||
if(p != NULL) {
|
||||
if(_stricmp(p, ".7z") == 0)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
bool utilIsGzipFile(const char *file)
|
||||
|
@ -588,7 +605,70 @@ void utilGetBaseName(const char *file, char *buffer)
|
|||
IMAGE_TYPE utilFindType(const char *file)
|
||||
{
|
||||
char buffer[2048];
|
||||
#ifdef HAS_FILE_EXTRACTOR
|
||||
int type = -1;
|
||||
if (utilIsZipFile(file)) type = 0;
|
||||
else if (utilIsRarFile(file)) type = 1;
|
||||
else if (utilIs7ZipFile(file)) type = 2;
|
||||
|
||||
if(type >= 0) {
|
||||
|
||||
Std_File_Reader in;
|
||||
File_Extractor * ex = 0;
|
||||
|
||||
switch (type) {
|
||||
case 0: ex = new Zip_Extractor; break;
|
||||
case 1: ex = new Rar_Extractor; break;
|
||||
case 2: ex = new Zip7_Extractor; break;
|
||||
default: type = -1; break;
|
||||
}
|
||||
|
||||
if (!ex) {
|
||||
systemMessage(MSG_OUT_OF_MEMORY, N_("Failed to allocate memory for %s"),
|
||||
"archive extractor");
|
||||
return IMAGE_UNKNOWN;
|
||||
}
|
||||
|
||||
if(in.open(file) != NULL) {
|
||||
delete ex;
|
||||
systemMessage(MSG_CANNOT_OPEN_FILE, N_("Cannot open file %s"), file);
|
||||
return IMAGE_UNKNOWN;
|
||||
}
|
||||
|
||||
if(ex->open(&in) != NULL) {
|
||||
delete ex;
|
||||
systemMessage(MSG_BAD_ZIP_FILE, N_("Bad archive file %s"), file);
|
||||
return IMAGE_UNKNOWN;
|
||||
}
|
||||
|
||||
ex->scan_only();
|
||||
|
||||
IMAGE_TYPE found = IMAGE_UNKNOWN;
|
||||
|
||||
while(!ex->done()) {
|
||||
if(utilIsGBAImage(ex->name())) {
|
||||
found = IMAGE_GBA;
|
||||
break;
|
||||
}
|
||||
|
||||
if(utilIsGBImage(ex->name())) {
|
||||
found = IMAGE_GB;
|
||||
break;
|
||||
}
|
||||
|
||||
if(ex->next() != NULL)
|
||||
break;
|
||||
}
|
||||
delete ex;
|
||||
|
||||
if(found == IMAGE_UNKNOWN) {
|
||||
systemMessage(MSG_NO_IMAGE_ON_ZIP,
|
||||
N_("No image found on archive file %s"), file);
|
||||
return found;
|
||||
}
|
||||
return found;
|
||||
|
||||
#else
|
||||
if(utilIsZipFile(file)) {
|
||||
unzFile unz = unzOpen(file);
|
||||
|
||||
|
@ -648,30 +728,6 @@ IMAGE_TYPE utilFindType(const char *file)
|
|||
return found;
|
||||
}
|
||||
return found;
|
||||
#if 0
|
||||
} else if(utilIsRarFile(file)) {
|
||||
IMAGE_TYPE found = IMAGE_UNKNOWN;
|
||||
|
||||
ArchiveList_struct *rarList = NULL;
|
||||
if(urarlib_list((void *)file, (ArchiveList_struct *)&rarList)) {
|
||||
ArchiveList_struct *p = rarList;
|
||||
|
||||
while(p) {
|
||||
if(utilIsGBAImage(p->item.Name)) {
|
||||
found = IMAGE_GBA;
|
||||
break;
|
||||
}
|
||||
|
||||
if(utilIsGBImage(p->item.Name)) {
|
||||
found = IMAGE_GB;
|
||||
break;
|
||||
}
|
||||
p = p->next;
|
||||
}
|
||||
|
||||
urarlib_freelist(rarList);
|
||||
}
|
||||
return found;
|
||||
#endif
|
||||
} else {
|
||||
if(utilIsGzipFile(file))
|
||||
|
@ -695,6 +751,94 @@ static int utilGetSize(int size)
|
|||
return res;
|
||||
}
|
||||
|
||||
#ifdef HAS_FILE_EXTRACTOR
|
||||
static u8 *utilLoadFromFE(const char *file,
|
||||
int type,
|
||||
bool (*accept)(const char *),
|
||||
u8 *data,
|
||||
int &size)
|
||||
{
|
||||
Std_File_Reader in;
|
||||
File_Extractor * ex = 0;
|
||||
|
||||
switch (type) {
|
||||
case 0: ex = new Zip_Extractor; break;
|
||||
case 1: ex = new Rar_Extractor; break;
|
||||
case 2: ex = new Zip7_Extractor; break;
|
||||
default: type = -1; break;
|
||||
}
|
||||
|
||||
if (!ex) {
|
||||
if (type >= 0) {
|
||||
systemMessage(MSG_OUT_OF_MEMORY, N_("Failed to allocate memory for %s"),
|
||||
"data");
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(in.open(file) != NULL) {
|
||||
delete ex;
|
||||
systemMessage(MSG_CANNOT_OPEN_FILE, N_("Cannot open file %s"), file);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(ex->open(&in) != NULL) {
|
||||
delete ex;
|
||||
systemMessage(MSG_BAD_ZIP_FILE, N_("Bad archive file %s"), file);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool found = false;
|
||||
|
||||
while(!ex->done()) {
|
||||
if(accept(ex->name())) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if(ex->next() != NULL)
|
||||
break;
|
||||
}
|
||||
|
||||
if(!found) {
|
||||
delete ex;
|
||||
systemMessage(MSG_NO_IMAGE_ON_ZIP,
|
||||
N_("No image found on archive file %s"), file);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int fileSize = ex->size();
|
||||
if(size == 0 || data == NULL)
|
||||
size = fileSize;
|
||||
int read = fileSize <= size ? fileSize : size;
|
||||
|
||||
u8 *image = data;
|
||||
if(image == NULL)
|
||||
{
|
||||
image = (u8 *)malloc(utilGetSize(size));
|
||||
if(image == NULL) {
|
||||
delete ex;
|
||||
systemMessage(MSG_OUT_OF_MEMORY, N_("Failed to allocate memory for %s"),
|
||||
"data");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
Mem_Writer mwimage(image, size, 1);
|
||||
const char * err = ex->extract(mwimage);
|
||||
|
||||
if(err != NULL) {
|
||||
systemMessage(MSG_ERROR_READING_IMAGE,
|
||||
N_("Error reading image %s"), ex->name());
|
||||
delete ex;
|
||||
if (data==NULL)
|
||||
free(image);
|
||||
return NULL;
|
||||
}
|
||||
delete ex;
|
||||
size = fileSize;
|
||||
return image;
|
||||
}
|
||||
#else
|
||||
static u8 *utilLoadFromZip(const char *file,
|
||||
bool (*accept)(const char *),
|
||||
u8 *data,
|
||||
|
@ -798,6 +942,7 @@ static u8 *utilLoadFromZip(const char *file,
|
|||
|
||||
return image;
|
||||
}
|
||||
#endif
|
||||
|
||||
static u8 *utilLoadGzipFile(const char *file,
|
||||
bool (*accept)(const char *),
|
||||
|
@ -854,62 +999,23 @@ static u8 *utilLoadGzipFile(const char *file,
|
|||
return image;
|
||||
}
|
||||
|
||||
#if 0
|
||||
static u8 *utilLoadRarFile(const char *file,
|
||||
bool (*accept)(const char *),
|
||||
u8 *data,
|
||||
int &size)
|
||||
{
|
||||
char buffer[2048];
|
||||
|
||||
ArchiveList_struct *rarList = NULL;
|
||||
if(urarlib_list((void *)file, (ArchiveList_struct *)&rarList)) {
|
||||
ArchiveList_struct *p = rarList;
|
||||
|
||||
bool found = false;
|
||||
while(p) {
|
||||
if(accept(p->item.Name)) {
|
||||
strcpy(buffer, p->item.Name);
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
p = p->next;
|
||||
}
|
||||
if(found) {
|
||||
void *memory = NULL;
|
||||
unsigned long lsize = 0;
|
||||
size = p->item.UnpSize;
|
||||
int r = urarlib_get((void *)&memory, &lsize, buffer, (void *)file, "");
|
||||
if(!r) {
|
||||
systemMessage(MSG_ERROR_READING_IMAGE,
|
||||
N_("Error reading image %s"), buffer);
|
||||
urarlib_freelist(rarList);
|
||||
return NULL;
|
||||
}
|
||||
u8 *image = (u8 *)memory;
|
||||
if(data != NULL) {
|
||||
memcpy(image, data, size);
|
||||
}
|
||||
urarlib_freelist(rarList);
|
||||
return image;
|
||||
}
|
||||
systemMessage(MSG_NO_IMAGE_ON_ZIP,
|
||||
N_("No image found on RAR file %s"), file);
|
||||
urarlib_freelist(rarList);
|
||||
return NULL;
|
||||
}
|
||||
// nothing found
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
u8 *utilLoad(const char *file,
|
||||
bool (*accept)(const char *),
|
||||
u8 *data,
|
||||
int &size)
|
||||
{
|
||||
#ifdef HAS_FILE_EXTRACTOR
|
||||
int type = -1;
|
||||
if (utilIsZipFile(file)) type = 0;
|
||||
else if (utilIsRarFile(file)) type = 1;
|
||||
else if (utilIs7ZipFile(file)) type = 2;
|
||||
|
||||
if(type>=0) {
|
||||
return utilLoadFromFE(file, type, accept, data, size);
|
||||
#else
|
||||
if(utilIsZipFile(file)) {
|
||||
return utilLoadFromZip(file, accept, data, size);
|
||||
#endif
|
||||
}
|
||||
if(utilIsGzipFile(file)) {
|
||||
return utilLoadGzipFile(file, accept, data, size);
|
||||
|
|
|
@ -2058,8 +2058,8 @@ BEGIN
|
|||
IDS_FAILED_TO_LOAD_LIBRARY "Failed to load library %s"
|
||||
IDS_FAILED_TO_GET_LOCINFO "Failed to get locale information"
|
||||
IDS_SELECT_CHEAT_LIST_NAME "Select cheat list name"
|
||||
IDS_FILTER_BIOS "Gameboy Advance_*.BIN;*.AGB;*.GBA;*.BIOS;*.ZIP;*.Z;*.GZ__"
|
||||
IDS_FILTER_ROM "All Gameboy Advance_*.BIN;*.AGB;*.GBA;*.MB;*.ELF;*.GB;*.SGB;*.CGB;*.GBC;*.ZIP;*.Z;*.GZ_Gameboy Advance_*.BIN;*.AGB;*.GBA_Gameboy_*.GB;*.SGB;*.CGB;*.GBC__"
|
||||
IDS_FILTER_BIOS "Gameboy Advance_*.BIN;*.AGB;*.GBA;*.BIOS;*.ZIP;*.Z;*.RAR;*.7Z;*.GZ__"
|
||||
IDS_FILTER_ROM "All Gameboy Advance_*.BIN;*.AGB;*.GBA;*.MB;*.ELF;*.GB;*.SGB;*.CGB;*.GBC;*.ZIP;*.7Z;*.RAR;*.Z;*.GZ_Gameboy Advance_*.BIN;*.AGB;*.GBA_Gameboy_*.GB;*.SGB;*.CGB;*.GBC__"
|
||||
IDS_FILTER_SGM "VisualBoyAdvance Save Game_*.SGM__"
|
||||
IDS_FILTER_CHEAT_LIST "VisualBoyAdvance Cheat List_*.CLT__"
|
||||
IDS_FILTER_PNG "PNG Image_*.PNG_BMP Image_*.BMP__"
|
||||
|
@ -2099,7 +2099,7 @@ BEGIN
|
|||
IDS_ADD_CBA_CODE "Add CodeBreakerAdvance code"
|
||||
IDS_FILTER_WAV "Wave file_*.WAV__"
|
||||
IDS_SELECT_WAV_NAME "Select wave file name"
|
||||
IDS_FILTER_GBROM "All Gameboy_*.GB;*.SGB;*.CGB;*.GBC;*.ZIP;*.Z;*.GZ_Gameboy_*.GB_Super Gameboy_*.SGB_Color Gameboy_*.CGB;*.GBC__"
|
||||
IDS_FILTER_GBROM "All Gameboy_*.GB;*.SGB;*.CGB;*.GBC;*.ZIP;*.7Z;*.RAR;*.Z;*.GZ_Gameboy_*.GB_Super Gameboy_*.SGB_Color Gameboy_*.CGB;*.GBC__"
|
||||
IDS_FILTER_PAL "Windows Palette (*.PAL)_*.PAL_PaintShop Palette (*.PAL)_*.PAL_Adobe Color Table (*.ACT)_*.ACT__"
|
||||
IDS_SELECT_PALETTE_NAME "Select palette name:"
|
||||
IDS_SEARCH_PRODUCED_NO_RESULTS "Search produced no results."
|
||||
|
|
Loading…
Reference in New Issue