Updated file extraction code in Util.cpp

Modded fex due to MS compiler idiocy when it comes to fex_type_rar
Updated OpenAL renderering setting to now save initial setting in the INI


git-svn-id: https://svn.code.sf.net/p/vbam/code/trunk@168 a31d4220-a93d-0410-bf67-fe4944624d44
This commit is contained in:
mudlord 2007-12-06 09:50:41 +00:00
parent faf058870c
commit 82c163e159
3 changed files with 261 additions and 617 deletions

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8,00"
Version="8.00"
Name="VisualBoyAdvance"
ProjectGUID="{6D4C5EC8-933F-4C05-A1BF-498E658576DF}"
RootNamespace="VBA"
@ -129,115 +129,6 @@
ExcludedFromBuild="true"
/>
</Configuration>
<Configuration
Name="Debug|x64"
OutputDirectory="$(ProjectDir)$(PlatformName)\$(ConfigurationName)"
IntermediateDirectory="$(ProjectDir)$(PlatformName)\$(ConfigurationName)_temp"
ConfigurationType="1"
UseOfMFC="1"
CharacterSet="2"
BuildLogFile="$(IntDir)\$(ProjectName)_BuildLog.htm"
>
<Tool
Name="VCPreBuildEventTool"
ExcludedFromBuild="true"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="MASM"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
PreprocessorDefinitions="_DEBUG"
MkTypLibCompatible="false"
TargetEnvironment="3"
/>
<Tool
Name="VCCLCompilerTool"
AdditionalOptions="/MP"
Optimization="0"
AdditionalIncludeDirectories="..\dependencies\zlib;..\dependencies\libpng;&quot;..\dependencies\File_Extractor-0.4.2\fex&quot;;..\dependencies\cximage;..\dependencies\msvc"
PreprocessorDefinitions="WIN32;_WINDOWS;_DEBUG;DEV_VERSION;BKPT_SUPPORT;CRT_SECURE_NO_WARNINGS;HAS_FILE_EXTRACTOR;C_CORE"
StringPooling="false"
MinimalRebuild="true"
BasicRuntimeChecks="3"
SmallerTypeCheck="false"
RuntimeLibrary="1"
StructMemberAlignment="0"
BufferSecurityCheck="false"
EnableFunctionLevelLinking="false"
EnableEnhancedInstructionSet="0"
TreatWChar_tAsBuiltInType="false"
UsePrecompiledHeader="0"
ProgramDataBaseFileName="$(IntDir)\$(ProjectName).pdb"
WarningLevel="3"
Detect64BitPortabilityProblems="false"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="_DEBUG"
Culture="1033"
AdditionalIncludeDirectories=""
/>
<Tool
Name="VCPreLinkEventTool"
ExcludedFromBuild="true"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="nafxcwd.lib LIBCMTD.lib Vfw32.Lib OpenGL32.Lib dinput8.lib dxguid.lib ddraw.lib winmm.lib Dsound.lib"
OutputFile="$(OutDir)\VisualBoyAdvance.exe"
Version=""
LinkIncremental="2"
AdditionalLibraryDirectories=""
GenerateManifest="true"
AdditionalManifestDependencies="type=&apos;win32&apos; name=&apos;Microsoft.Windows.Common-Controls&apos; version=&apos;6.0.0.0&apos; processorArchitecture=&apos;amd64&apos; publicKeyToken=&apos;6595b64144ccf1df&apos; language=&apos;*&apos;"
IgnoreDefaultLibraryNames="nafxcwd.lib;LIBCMTD.lib"
GenerateDebugInformation="true"
SubSystem="2"
OptimizeReferences="1"
EnableCOMDATFolding="1"
OptimizeForWindows98="1"
TargetMachine="17"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
ExcludedFromBuild="true"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(ProjectDir)$(PlatformName)\$(ConfigurationName)"
@ -360,6 +251,115 @@
ExcludedFromBuild="true"
/>
</Configuration>
<Configuration
Name="Debug|x64"
OutputDirectory="$(ProjectDir)$(PlatformName)\$(ConfigurationName)"
IntermediateDirectory="$(ProjectDir)$(PlatformName)\$(ConfigurationName)_temp"
ConfigurationType="1"
UseOfMFC="1"
CharacterSet="2"
BuildLogFile="$(IntDir)\$(ProjectName)_BuildLog.htm"
>
<Tool
Name="VCPreBuildEventTool"
ExcludedFromBuild="true"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="MASM"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
PreprocessorDefinitions="_DEBUG"
MkTypLibCompatible="false"
TargetEnvironment="3"
/>
<Tool
Name="VCCLCompilerTool"
AdditionalOptions="/MP"
Optimization="0"
AdditionalIncludeDirectories="..\dependencies\zlib;..\dependencies\libpng;&quot;..\dependencies\File_Extractor-0.4.2\fex&quot;;..\dependencies\cximage;..\dependencies\msvc"
PreprocessorDefinitions="WIN32;_WINDOWS;_DEBUG;DEV_VERSION;BKPT_SUPPORT;CRT_SECURE_NO_WARNINGS;HAS_FILE_EXTRACTOR;C_CORE"
StringPooling="false"
MinimalRebuild="true"
BasicRuntimeChecks="3"
SmallerTypeCheck="false"
RuntimeLibrary="1"
StructMemberAlignment="0"
BufferSecurityCheck="false"
EnableFunctionLevelLinking="false"
EnableEnhancedInstructionSet="0"
TreatWChar_tAsBuiltInType="false"
UsePrecompiledHeader="0"
ProgramDataBaseFileName="$(IntDir)\$(ProjectName).pdb"
WarningLevel="3"
Detect64BitPortabilityProblems="false"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="_DEBUG"
Culture="1033"
AdditionalIncludeDirectories=""
/>
<Tool
Name="VCPreLinkEventTool"
ExcludedFromBuild="true"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="nafxcwd.lib LIBCMTD.lib Vfw32.Lib OpenGL32.Lib dinput8.lib dxguid.lib ddraw.lib winmm.lib Dsound.lib"
OutputFile="$(OutDir)\VisualBoyAdvance.exe"
Version=""
LinkIncremental="2"
AdditionalLibraryDirectories=""
GenerateManifest="true"
AdditionalManifestDependencies="type=&apos;win32&apos; name=&apos;Microsoft.Windows.Common-Controls&apos; version=&apos;6.0.0.0&apos; processorArchitecture=&apos;amd64&apos; publicKeyToken=&apos;6595b64144ccf1df&apos; language=&apos;*&apos;"
IgnoreDefaultLibraryNames="nafxcwd.lib;LIBCMTD.lib"
GenerateDebugInformation="true"
SubSystem="2"
OptimizeReferences="1"
EnableCOMDATFolding="1"
OptimizeForWindows98="1"
TargetMachine="17"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
ExcludedFromBuild="true"
/>
</Configuration>
<Configuration
Name="Release|x64"
OutputDirectory="$(ProjectDir)$(PlatformName)\$(ConfigurationName)"
@ -528,16 +528,6 @@
Outputs="&quot;$(IntDir)\$(InputName).obj&quot;"
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|x64"
>
<Tool
Name="VCCustomBuildTool"
Description="Assembling $(InputFileName)..."
CommandLine="nasm -D__DJGPP__ -f win64 -o &quot;$(IntDir)\$(InputName).obj&quot; &quot;$(InputPath)&quot;&#x0D;&#x0A;"
Outputs="&quot;$(IntDir)\$(InputName).obj&quot;"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
@ -548,6 +538,16 @@
Outputs="&quot;$(IntDir)\$(InputName).obj&quot;"
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|x64"
>
<Tool
Name="VCCustomBuildTool"
Description="Assembling $(InputFileName)..."
CommandLine="nasm -D__DJGPP__ -f win64 -o &quot;$(IntDir)\$(InputName).obj&quot; &quot;$(InputPath)&quot;&#x0D;&#x0A;"
Outputs="&quot;$(IntDir)\$(InputName).obj&quot;"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|x64"
>
@ -623,16 +623,6 @@
Outputs="&quot;$(IntDir)\$(InputName).obj&quot;"
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|x64"
>
<Tool
Name="VCCustomBuildTool"
Description="Assembling $(InputFileName)..."
CommandLine="nasm -D__DJGPP__ -O1 -Isrc/ -f win64 -o &quot;$(IntDir)\$(InputName).obj&quot; &quot;$(InputPath)&quot;&#x0D;&#x0A;"
Outputs="&quot;$(IntDir)\$(InputName).obj&quot;"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
@ -643,6 +633,16 @@
Outputs="&quot;$(IntDir)\$(InputName).obj&quot;"
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|x64"
>
<Tool
Name="VCCustomBuildTool"
Description="Assembling $(InputFileName)..."
CommandLine="nasm -D__DJGPP__ -O1 -Isrc/ -f win64 -o &quot;$(IntDir)\$(InputName).obj&quot; &quot;$(InputPath)&quot;&#x0D;&#x0A;"
Outputs="&quot;$(IntDir)\$(InputName).obj&quot;"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|x64"
>
@ -667,16 +667,6 @@
Outputs="&quot;$(IntDir)\$(InputName).obj&quot;"
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|x64"
>
<Tool
Name="VCCustomBuildTool"
Description="Assembling $(InputFileName)..."
CommandLine="nasm -D__DJGPP__ -O1 -Isrc/ -f win64 -o &quot;$(IntDir)\$(InputName).obj&quot; &quot;$(InputPath)&quot;&#x0D;&#x0A;"
Outputs="&quot;$(IntDir)\$(InputName).obj&quot;"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
@ -687,6 +677,16 @@
Outputs="&quot;$(IntDir)\$(InputName).obj&quot;"
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|x64"
>
<Tool
Name="VCCustomBuildTool"
Description="Assembling $(InputFileName)..."
CommandLine="nasm -D__DJGPP__ -O1 -Isrc/ -f win64 -o &quot;$(IntDir)\$(InputName).obj&quot; &quot;$(InputPath)&quot;&#x0D;&#x0A;"
Outputs="&quot;$(IntDir)\$(InputName).obj&quot;"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|x64"
>
@ -711,16 +711,6 @@
Outputs="&quot;$(IntDir)\$(InputName).obj&quot;"
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|x64"
>
<Tool
Name="VCCustomBuildTool"
Description="Assembling $(InputFileName)..."
CommandLine="nasm -D__DJGPP__ -O1 -Isrc/ -f win64 -o &quot;$(IntDir)\$(InputName).obj&quot; &quot;$(InputPath)&quot;&#x0D;&#x0A;"
Outputs="&quot;$(IntDir)\$(InputName).obj&quot;"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
@ -731,6 +721,16 @@
Outputs="&quot;$(IntDir)\$(InputName).obj&quot;"
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|x64"
>
<Tool
Name="VCCustomBuildTool"
Description="Assembling $(InputFileName)..."
CommandLine="nasm -D__DJGPP__ -O1 -Isrc/ -f win64 -o &quot;$(IntDir)\$(InputName).obj&quot; &quot;$(InputPath)&quot;&#x0D;&#x0A;"
Outputs="&quot;$(IntDir)\$(InputName).obj&quot;"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|x64"
>
@ -755,16 +755,6 @@
Outputs="&quot;$(IntDir)\$(InputName).obj&quot;"
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|x64"
>
<Tool
Name="VCCustomBuildTool"
Description="Assembling $(InputFileName)..."
CommandLine="nasm -D__DJGPP__ -O1 -Isrc/ -f win64 -o &quot;$(IntDir)\$(InputName).obj&quot; &quot;$(InputPath)&quot;&#x0D;&#x0A;"
Outputs="&quot;$(IntDir)\$(InputName).obj&quot;"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
@ -775,6 +765,16 @@
Outputs="&quot;$(IntDir)\$(InputName).obj&quot;"
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|x64"
>
<Tool
Name="VCCustomBuildTool"
Description="Assembling $(InputFileName)..."
CommandLine="nasm -D__DJGPP__ -O1 -Isrc/ -f win64 -o &quot;$(IntDir)\$(InputName).obj&quot; &quot;$(InputPath)&quot;&#x0D;&#x0A;"
Outputs="&quot;$(IntDir)\$(InputName).obj&quot;"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|x64"
>
@ -1379,7 +1379,7 @@
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|x64"
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
@ -1387,7 +1387,7 @@
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
Name="Debug|x64"
>
<Tool
Name="VCCLCompilerTool"

View File

@ -25,11 +25,6 @@ extern "C" {
#include <png.h>
}
#ifdef HAS_FILE_EXTRACTOR
#include <Zip_Extractor.h>
#include <Zip7_Extractor.h>
#endif
#include "System.h"
#include "NLS.h"
#include "Util.h"
@ -39,6 +34,10 @@ extern "C" {
#include "RTC.h"
#include "Port.h"
#ifdef HAS_FILE_EXTRACTOR
#include <fex.h>
#endif
extern "C" {
#include "memgzio.h"
@ -542,24 +541,6 @@ bool utilIsZipFile(const char *file)
return false;
}
#ifdef HAS_FILE_EXTRACTOR
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)
{
if(strlen(file) > 3) {
@ -578,7 +559,8 @@ bool utilIsGzipFile(const char *file)
void utilGetBaseName(const char *file, char *buffer)
{
strcpy(buffer, file);
if(buffer != file) // allows conversion in place
strcpy(buffer, file);
if(utilIsGzipFile(file)) {
char *p = strrchr(buffer, '.');
@ -588,143 +570,67 @@ void utilGetBaseName(const char *file, char *buffer)
}
}
// Opens and scans archive using accept(). Returns File_Extractor if found.
// If error or not found, displays message and returns NULL.
static File_Extractor* scan_arc(const char *file, bool (*accept)(const char *),
char (&buffer) [2048] )
{
File_Extractor* fe;
fex_err_t err = fex_open( file, &fe );
if(!fe)
{
systemMessage(MSG_CANNOT_OPEN_FILE, N_("Cannot open file %s: %s"), file, err);
return NULL;
}
// Scan filenames
bool found=false;
while(!fex_done(fe)) {
strncpy(buffer,fex_name(fe),sizeof buffer);
buffer [sizeof buffer-1] = '\0';
utilGetBaseName(buffer, buffer); // strip .gz or .z off end
if(accept(buffer)) {
found = true;
break;
}
fex_err_t err = fex_next(fe);
if(err) {
systemMessage(MSG_BAD_ZIP_FILE, N_("Cannot read archive %s: %s"), file, err);
fex_close(fe);
return NULL;
}
}
if(!found) {
systemMessage(MSG_NO_IMAGE_ON_ZIP,
N_("No image found in file %s"), file);
fex_close(fe);
return NULL;
}
return fe;
}
static bool utilIsImage(const char *file)
{
return utilIsGBAImage(file) || utilIsGBImage(file);
}
IMAGE_TYPE utilFindType(const char *file)
{
char buffer[2048];
#ifdef HAS_FILE_EXTRACTOR
int type = -1;
if (utilIsZipFile(file)) type = 0;
else if (utilIs7ZipFile(file)) type = 1;
char buffer [2048];
if ( !utilIsImage( file ) ) // TODO: utilIsArchive() instead?
{
File_Extractor* fe = scan_arc(file,utilIsImage,buffer);
if(!fe)
return IMAGE_UNKNOWN;
fex_close(fe);
file = buffer;
}
if(type >= 0) {
Std_File_Reader in;
File_Extractor * ex = 0;
switch (type) {
case 0: ex = new Zip_Extractor; break;
case 1: 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);
if(unz == NULL) {
systemMessage(MSG_CANNOT_OPEN_FILE, N_("Cannot open file %s"), file);
return IMAGE_UNKNOWN;
}
int r = unzGoToFirstFile(unz);
if(r != UNZ_OK) {
unzClose(unz);
systemMessage(MSG_BAD_ZIP_FILE, N_("Bad ZIP file %s"), file);
return IMAGE_UNKNOWN;
}
IMAGE_TYPE found = IMAGE_UNKNOWN;
unz_file_info info;
while(true) {
r = unzGetCurrentFileInfo(unz,
&info,
buffer,
sizeof(buffer),
NULL,
0,
NULL,
0);
if(r != UNZ_OK) {
unzClose(unz);
systemMessage(MSG_BAD_ZIP_FILE, N_("Bad ZIP file %s"), file);
return IMAGE_UNKNOWN;
}
if(utilIsGBAImage(buffer)) {
found = IMAGE_GBA;
break;
}
if(utilIsGBImage(buffer)) {
found = IMAGE_GB;
break;
}
r = unzGoToNextFile(unz);
if(r != UNZ_OK)
break;
}
unzClose(unz);
if(found == IMAGE_UNKNOWN) {
systemMessage(MSG_NO_IMAGE_ON_ZIP,
N_("No image found on ZIP file %s"), file);
return found;
}
return found;
#endif
} else {
if(utilIsGzipFile(file))
utilGetBaseName(file, buffer);
else
strcpy(buffer, file);
if(utilIsGBAImage(buffer))
return IMAGE_GBA;
if(utilIsGBImage(buffer))
return IMAGE_GB;
}
return IMAGE_UNKNOWN;
return utilIsGBAImage(file) ? IMAGE_GBA : IMAGE_GB;
}
static int utilGetSize(int size)
@ -735,314 +641,50 @@ 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 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,
int &size)
{
char buffer[2048];
unzFile unz = unzOpen(file);
if(unz == NULL) {
systemMessage(MSG_CANNOT_OPEN_FILE, N_("Cannot open file %s"), file);
return NULL;
}
int r = unzGoToFirstFile(unz);
if(r != UNZ_OK) {
unzClose(unz);
systemMessage(MSG_BAD_ZIP_FILE, N_("Bad ZIP file %s"), file);
return NULL;
}
bool found = false;
unz_file_info info;
while(true) {
r = unzGetCurrentFileInfo(unz,
&info,
buffer,
sizeof(buffer),
NULL,
0,
NULL,
0);
if(r != UNZ_OK) {
unzClose(unz);
systemMessage(MSG_BAD_ZIP_FILE, N_("Bad ZIP file %s"), file);
return NULL;
}
if(accept(buffer)) {
found = true;
break;
}
r = unzGoToNextFile(unz);
if(r != UNZ_OK)
break;
}
if(!found) {
unzClose(unz);
systemMessage(MSG_NO_IMAGE_ON_ZIP,
N_("No image found on ZIP file %s"), file);
return NULL;
}
int fileSize = info.uncompressed_size;
if(size == 0)
size = fileSize;
r = unzOpenCurrentFile(unz);
if(r != UNZ_OK) {
unzClose(unz);
systemMessage(MSG_ERROR_OPENING_IMAGE, N_("Error opening image %s"), buffer);
return NULL;
}
u8 *image = data;
if(image == NULL) {
image = (u8 *)malloc(utilGetSize(size));
if(image == NULL) {
unzCloseCurrentFile(unz);
unzClose(unz);
systemMessage(MSG_OUT_OF_MEMORY, N_("Failed to allocate memory for %s"),
"data");
return NULL;
}
size = fileSize;
}
int read = fileSize <= size ? fileSize : size;
r = unzReadCurrentFile(unz,
image,
read);
unzCloseCurrentFile(unz);
unzClose(unz);
if(r != (int)read) {
systemMessage(MSG_ERROR_READING_IMAGE,
N_("Error reading image %s"), buffer);
if(data == NULL)
free(image);
return NULL;
}
size = fileSize;
return image;
}
#endif
static u8 *utilLoadGzipFile(const char *file,
bool (*accept)(const char *),
u8 *data,
int &size)
{
FILE *f = fopen(file, "rb");
if(f == NULL) {
systemMessage(MSG_ERROR_OPENING_IMAGE, N_("Error opening image %s"), file);
return NULL;
}
fseek(f, -4, SEEK_END);
int fileSize = fgetc(f) | (fgetc(f) << 8) | (fgetc(f) << 16) | (fgetc(f) << 24);
fclose(f);
if(size == 0)
size = fileSize;
gzFile gz = gzopen(file, "rb");
if(gz == NULL) {
// should not happen, but who knows?
systemMessage(MSG_ERROR_OPENING_IMAGE, N_("Error opening image %s"), file);
return NULL;
}
u8 *image = data;
if(image == NULL) {
image = (u8 *)malloc(utilGetSize(size));
if(image == NULL) {
systemMessage(MSG_OUT_OF_MEMORY, N_("Failed to allocate memory for %s"),
"data");
fclose(f);
return NULL;
}
size = fileSize;
}
int read = fileSize <= size ? fileSize : size;
int r = gzread(gz, image, read);
gzclose(gz);
if(r != (int)read) {
systemMessage(MSG_ERROR_READING_IMAGE,
N_("Error reading image %s"), file);
if(data == NULL)
free(image);
return NULL;
}
size = fileSize;
return image;
}
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 (utilIs7ZipFile(file)) type = 1;
// find image file
char buffer [2048];
File_Extractor* fe = scan_arc(file,accept,buffer);
if(!fe)
return NULL;
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);
}
// Allocate space for image
int fileSize = fex_size(fe);
if(size == 0)
size = fileSize;
u8 *image = data;
u8 *image = data;
FILE *f = fopen(file, "rb");
if(image == NULL) {
image = (u8 *)malloc(utilGetSize(size));
if(image == NULL) {
fex_close(fe);
systemMessage(MSG_OUT_OF_MEMORY, N_("Failed to allocate memory for %s"),
"data");
return NULL;
}
size = fileSize;
}
if(!f) {
systemMessage(MSG_ERROR_OPENING_IMAGE, N_("Error opening image %s"), file);
return NULL;
}
// Read image
int read = fileSize <= size ? fileSize : size;
fex_err_t err = fex_read(fe, image, read); // TODO: change to fex_read_once
fex_close(fe);
if(err) {
systemMessage(MSG_ERROR_READING_IMAGE,
N_("Error reading image from %s: %s"), buffer, err);
if(data == NULL)
free(image);
return NULL;
}
fseek(f,0,SEEK_END);
int fileSize = ftell(f);
fseek(f,0,SEEK_SET);
if(size == 0)
size = fileSize;
size = fileSize;
if(image == NULL) {
image = (u8 *)malloc(utilGetSize(size));
if(image == NULL) {
systemMessage(MSG_OUT_OF_MEMORY, N_("Failed to allocate memory for %s"),
"data");
fclose(f);
return NULL;
}
size = fileSize;
}
size_t read = fileSize <= size ? fileSize : size;
size_t r = fread(image, 1, read, f);
fclose(f);
if(r != read) {
systemMessage(MSG_ERROR_READING_IMAGE,
N_("Error reading image %s"), file);
if(data == NULL)
free(image);
return NULL;
}
size = fileSize;
return image;
return image;
}
void utilWriteInt(gzFile gzFile, int i)

View File

@ -2484,6 +2484,8 @@ void VBA::saveSettings()
regSetDwordValue("autoFrameSkip", autoFrameSkip);
regSetDwordValue( "OpenALAudiomixing", OpenALAudiomixing);
regSetDwordValue("vsync", vsync);
regSetDwordValue("synchronize", synchronize);
regSetDwordValue("stretch", fullScreenStretch);