diff --git a/src/CLatch.cpp b/src/CLatch.cpp
index bb6165230..2e141bac8 100644
--- a/src/CLatch.cpp
+++ b/src/CLatch.cpp
@@ -14,7 +14,7 @@
#include "keen.h"
#include "keenext.h"
#include "StringUtils.h"
-
+#include "FindFile.h"
#include "CLogFile.h"
//#include "vorticon/CEGAGraphics.h"
@@ -77,7 +77,7 @@ char CLatch::loadHeader(int episode, const char *path)
delete EGAGraphics;*/
- headfile = fopen(fname.c_str(), "rb");
+ headfile = OpenGameFile(fname.c_str(), "rb");
if (!headfile)
{
g_pLogFile->ftextOut("latch_loadheader(): unable to open '%s'.
", fname.c_str());
@@ -217,7 +217,7 @@ unsigned long RawDataSize;
g_pLogFile->ftextOut("latch_loadlatch(): Opening file '%s'.
", fname.c_str());
- latchfile = fopen(fname.c_str(), "rb");
+ latchfile = OpenGameFile(fname.c_str(), "rb");
if (!latchfile)
{
g_pLogFile->ftextOut("latch_loadlatch(): Unable to open '%s'!
", fname.c_str());
@@ -426,7 +426,7 @@ CPlanes *Planes;
g_pLogFile->ftextOut("latch_loadsprites(): Opening file '%s'.
", fname.c_str());
- spritfile = fopen(fname.c_str(), "rb");
+ spritfile = OpenGameFile(fname.c_str(), "rb");
if (!spritfile)
{
g_pLogFile->ftextOut("latch_loadsprites(): Unable to open '%s'!
", fname.c_str());
diff --git a/src/CLogFile.cpp b/src/CLogFile.cpp
index 1c79b8910..93fcde916 100644
--- a/src/CLogFile.cpp
+++ b/src/CLogFile.cpp
@@ -10,6 +10,7 @@
#include
#include "CLogFile.h"
#include
+#include "FindFile.h"
CLogFile::CLogFile() {}
@@ -22,7 +23,7 @@ CLogFile::~CLogFile() {
void CLogFile::CreateLogfile(const char *LogName)
{
// Open and empty the log file
- m_Logfile = fopen(LogName, "wt");
+ m_Logfile = OpenGameFile(LogName, "wt");
// Write the head
textOut("LogFile");
@@ -50,7 +51,7 @@ void CLogFile::CreateLogfile(const char *LogName)
textOut("Send E-Mail to me
");
fclose(m_Logfile);
- m_Logfile = fopen(LogName, "at");
+ m_Logfile = OpenGameFile(LogName, "at");
}
// Function for writing the topic
diff --git a/src/ConfigHandler.cpp b/src/ConfigHandler.cpp
index b6d237f35..218c89100 100644
--- a/src/ConfigHandler.cpp
+++ b/src/ConfigHandler.cpp
@@ -204,7 +204,7 @@ static bool GetString(const std::string& filename, const std::string& section, c
return false;
if(abs_fn) {
- config = fopen(filename.c_str(), "rt");
+ config = OpenGameFile(filename.c_str(), "rt");
} else
config = OpenGameFile(filename,"rt");
if(!config)
diff --git a/src/fileio.cpp b/src/fileio.cpp
index 0b7311c8a..36b26c4ee 100644
--- a/src/fileio.cpp
+++ b/src/fileio.cpp
@@ -19,6 +19,7 @@
#include
#include "StringUtils.h"
#include "Debug.h"
+#include "FindFile.h"
extern CPlayer *Player;
@@ -147,7 +148,7 @@ short checkConsistencyofGameData(stGameData *p_GameData)
buf += "/";
buf += p_GameData->FileList[c];
- if((fp = fopen(buf.c_str(),"r")) != NULL)
+ if((fp = OpenGameFile(buf.c_str(),"r")) != NULL)
{
fclose(fp);
}
@@ -538,7 +539,7 @@ int resetcnt, resetpt;
std::string buffer = formatPathString(path);
std::string fname = buffer + filename;
- fp = fopen(fname.c_str(), "rb");
+ fp = OpenGameFile(fname.c_str(), "rb");
if (!fp)
{
// only record this error message on build platforms that log errors
@@ -632,7 +633,7 @@ int resetcnt, resetpt;
// HQ Sounds. Load Music for a level if you have HQP
g_pMusicPlayer->stop();
- if((fp=fopen("data/hqp/music/table.cfg","rt")) != NULL)
+ if((fp=OpenGameFile("data/hqp/music/table.cfg","rt")) != NULL)
{
static const int MAX_STRING_LENGTH = 256;
char buf1[MAX_STRING_LENGTH];
@@ -770,7 +771,7 @@ char highlight;
#define STSTATE_READATTR 3
g_pLogFile->ftextOut("loadstrings(): Opening string file '%s'.
", fname.c_str());
- fp = fopen(fname.c_str(), "rb");
+ fp = OpenGameFile(fname.c_str(), "rb");
if (!fp)
{
g_pLogFile->ftextOut("loadstrings(): String file unable to open.
");
diff --git a/src/fileio/CParser.cpp b/src/fileio/CParser.cpp
index 5938fc6a4..4eb28d901 100644
--- a/src/fileio/CParser.cpp
+++ b/src/fileio/CParser.cpp
@@ -9,6 +9,7 @@
#include "../CLogFile.h"
#include "../StringUtils.h"
#include "../sdl/CSettings.h"
+#include "../FindFile.h"
#include
#include
@@ -41,7 +42,7 @@ bool CParser::loadParseFile() // Open, read the list and close the file
{
FILE *fp;
- if((fp=fopen(m_configfile.c_str(),"rt")))
+ if((fp=OpenGameFile(m_configfile.c_str(),"rt")))
{
while(!feof(fp))
{
@@ -62,7 +63,7 @@ bool CParser::saveParseFile() // open, write on the file and close
{
FILE *fp;
- if((fp=fopen(m_configfile.c_str(),"wt")))
+ if((fp=OpenGameFile(m_configfile.c_str(),"wt")))
{
for(std::list::iterator i=m_filebuffer.begin() ; i != m_filebuffer.end() ; ++i )
fprintf(fp,"%s\n",i->c_str());
diff --git a/src/fileio/CTileLoader.cpp b/src/fileio/CTileLoader.cpp
index 63657f317..393d0e2df 100644
--- a/src/fileio/CTileLoader.cpp
+++ b/src/fileio/CTileLoader.cpp
@@ -7,10 +7,10 @@
#include "CTileLoader.h"
#include "../CLogFile.h"
-
+#include "../StringUtils.h"
+#include "../FindFile.h"
#include
#include
-#include "../StringUtils.h"
extern stTile tiles[MAX_TILES+1];
@@ -153,7 +153,7 @@ bool CTileLoader::load()
fname = "ep" + itoa(m_episode) + "attr.dat";
FILE *fp;
- fp = fopen(fname.c_str(), "rb");
+ fp = OpenGameFile(fname.c_str(), "rb");
if (!fp)
{
g_pLogFile->textOut(RED,"TileLoader: Cannot open tile attribute file!
");
diff --git a/src/fileio/story.cpp b/src/fileio/story.cpp
index 84e33f50b..54234cbd4 100644
--- a/src/fileio/story.cpp
+++ b/src/fileio/story.cpp
@@ -13,6 +13,8 @@
#include "../fileio/CExeFile.h"
#include "../CLogFile.h"
#include "../StringUtils.h"
+#include "../FindFile.h"
+
int readStoryText(char **ptext, int episode, const std::string& path)
{
@@ -20,11 +22,11 @@ int readStoryText(char **ptext, int episode, const std::string& path)
std::string buf = buf2 + "storytxt.ck" + itoa(episode);
FILE *fp;
- if((fp=fopen(buf.c_str(),"rt"))==NULL)
+ if((fp=OpenGameFile(buf.c_str(),"rt"))==NULL)
{
buf = buf2 + "keen" + itoa(episode) + ".exe";
- if((fp=fopen(buf.c_str(),"rb"))!=NULL)
+ if((fp=OpenGameFile(buf.c_str(),"rb"))!=NULL)
{
unsigned char *filebuf;
int startflag=0, endflag=0; // where story begins and ends!
@@ -84,5 +86,7 @@ int readStoryText(char **ptext, int episode, const std::string& path)
return filesize;
}
+
+ return -1;
}
diff --git a/src/finale.cpp b/src/finale.cpp
index b470884ad..1aa7f441b 100644
--- a/src/finale.cpp
+++ b/src/finale.cpp
@@ -7,6 +7,7 @@
#include "keen.h"
#include "include/fileio.h"
#include "CGraphics.h"
+#include "FindFile.h"
int finale_x;
int finale_y;
@@ -84,7 +85,7 @@ int i;
map_unregister_all_animtiles();
std::string fname = buffer + filename;
- fp = fopen(fname.c_str(), "rb");
+ fp = OpenGameFile(fname.c_str(), "rb");
if (!fp)
{
crashflag = 1;
diff --git a/src/hqp/CHQBitmap.cpp b/src/hqp/CHQBitmap.cpp
index bb86085b0..24f07613a 100644
--- a/src/hqp/CHQBitmap.cpp
+++ b/src/hqp/CHQBitmap.cpp
@@ -7,7 +7,8 @@
#include "CHQBitmap.h"
#include "../CLogFile.h"
-#include
+#include "../FindFile.h"
+#include
CHQBitmap::CHQBitmap(SDL_Rect screenrect) {
m_scrimg = NULL;
@@ -24,10 +25,14 @@ CHQBitmap::~CHQBitmap() {
bool CHQBitmap::loadImage(const std::string& pFilename, int wsize, int hsize)
{
- SDL_Surface *BitmapSurface = SDL_LoadBMP(pFilename.c_str());
-
m_active = false;
+ std::string fullfname = GetFullFileName(pFilename);
+ if(fullfname.size() == 0)
+ return false;
+
+ SDL_Surface *BitmapSurface = SDL_LoadBMP(Utf8ToSystemNative(fullfname).c_str());
+
if(BitmapSurface)
{
if((m_scrimg = SDL_DisplayFormat(BitmapSurface)))
diff --git a/src/hqp/CMusic.cpp b/src/hqp/CMusic.cpp
index 638883b05..08e7d98a1 100644
--- a/src/hqp/CMusic.cpp
+++ b/src/hqp/CMusic.cpp
@@ -9,6 +9,7 @@
#include "../hqp/hq_sound.h"
#include "../CLogFile.h"
#include "../include/vorbis/oggsupport.h"
+#include "../FindFile.h"
CMusic::CMusic() {
playmode = PLAY_MODE_STOP;
@@ -37,7 +38,7 @@ int CMusic::load(SDL_AudioSpec AudioSpec, char *musicfile)
pOggAudio.sound_pos=0;
FILE *fp;
- if((fp = fopen(musicfile,"rb")) == NULL)
+ if((fp = OpenGameFile(musicfile,"rb")) == NULL)
{
g_pLogFile->textOut(PURPLE,"Music Driver(): \"%s\". File does not exist!
", musicfile);
return -1;
diff --git a/src/hqp/hq_sound.cpp b/src/hqp/hq_sound.cpp
index e08e57248..687621b21 100644
--- a/src/hqp/hq_sound.cpp
+++ b/src/hqp/hq_sound.cpp
@@ -10,6 +10,7 @@
#include "../sdl/CVideoDriver.h"
#include "../include/vorbis/oggsupport.h"
#include "../CLogFile.h"
+#include "../FindFile.h"
short HQSndDrv_Load(SDL_AudioSpec *AudioSpec, stHQSound *psound, const std::string& soundfile)
{
@@ -21,7 +22,7 @@ short HQSndDrv_Load(SDL_AudioSpec *AudioSpec, stHQSound *psound, const std::stri
FILE *fp;
buf = "data/hqp/snd/" + soundfile + ".OGG"; // Start with OGG
- if((fp = fopen(buf.c_str(),"rb")) != NULL)
+ if((fp = OpenGameFile(buf.c_str(),"rb")) != NULL)
{
#ifdef BUILD_WITH_OGG
if(openOGGSound(fp, &AudioFileSpec, AudioSpec->format, psound) != 0)
@@ -52,8 +53,12 @@ short HQSndDrv_Load(SDL_AudioSpec *AudioSpec, stHQSound *psound, const std::stri
{
buf = "data/hqp/snd/" + soundfile + ".WAV";
- // Check, if it is a wav file or go back to classic sounds
- if (SDL_LoadWAV (buf.c_str(), &AudioFileSpec, &(psound->sound_buffer), &(psound->sound_len)) == NULL)
+ std::string fullfname = GetFullFileName(buf);
+ if(fullfname.size() == 0)
+ return 1;
+
+ // Check, if it is a wav file or go back to classic sounds
+ if (SDL_LoadWAV (Utf8ToSystemNative(fullfname).c_str(), &AudioFileSpec, &(psound->sound_buffer), &(psound->sound_len)) == NULL)
{
g_pLogFile->textOut(PURPLE,"Wave file could not be opened: \"%s\". Trying to load the classical sounds
", buf.c_str());
return 1;
diff --git a/src/main.cpp b/src/main.cpp
index 93f63f3b1..c4d43279e 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -510,7 +510,7 @@ char SaveOptions[NUM_OPTIONS];
// open the demo file
sprintf(filename, "ep%ddemo%d.dat", p_levelcontrol->episode, demonum);
- demofile = fopen(filename, "rb");
+ demofile = OpenGameFile(filename, "rb");
if (!demofile)
{
return DEMO_RESULT_FILE_BAD;
diff --git a/src/misc.cpp b/src/misc.cpp
index 60bbde906..f864ece04 100644
--- a/src/misc.cpp
+++ b/src/misc.cpp
@@ -25,6 +25,8 @@
#include "CLogFile.h"
#include "CGraphics.h"
#include "StringUtils.h"
+#include "FindFile.h"
+
void banner(void)
{
@@ -625,7 +627,7 @@ void showinventory(int p, stCloneKeenPlus *pCKP)
FILE *fp;
int x,y;
- fp = fopen(visiblefile, "wb");
+ fp = OpenGameFile(visiblefile, "wb");
if (!fp) return;<
for(y=0;y<200;y++)
@@ -634,7 +636,7 @@ int x,y;
fclose(fp);
- fp = fopen(scrollfile, "wb");
+ fp = OpenGameFile(scrollfile, "wb");
if (!fp) return;
for(y=0;y<512;y++)
@@ -733,7 +735,7 @@ void game_save(char *fname, stCloneKeenPlus *pCKP)
unsigned int i;
FILE *fp;
- fp = fopen(fname, "wb");
+ fp = OpenGameFile(fname, "wb");
// save the header/version check
fputc('S', fp);
@@ -766,7 +768,7 @@ int savegameiswm(char *fname)
FILE *fp;
int i;
- fp = fopen(fname, "rb");
+ fp = OpenGameFile(fname, "rb");
if (!fp) return 0; // file didn't exist, don't try to go further
fgetc(fp); fgetc(fp);
@@ -785,7 +787,7 @@ long i;
unsigned long scrx;
int scry;
- fp = fopen(fname, "rb");
+ fp = OpenGameFile(fname, "rb");
if (!fp) return 1;
// do the header and version check
@@ -828,7 +830,7 @@ unsigned int scry;
stLevelControl *p_levelcontrol;
p_levelcontrol = &(pCKP->Control.levelcontrol);
- fp = fopen(fname, "rb");
+ fp = OpenGameFile(fname, "rb");
if (!fp) return 1;
// do the header and version check
@@ -936,7 +938,7 @@ top: ;
fname += saveslot+'0';
fname += ".dat";
slotexists = 0;
- fp = fopen(fname.c_str(), "rb");
+ fp = OpenGameFile(fname.c_str(), "rb");
if (fp)
{
fclose(fp);
diff --git a/src/sdl/CInput.cpp b/src/sdl/CInput.cpp
index 5e77a09e2..651ae00e0 100644
--- a/src/sdl/CInput.cpp
+++ b/src/sdl/CInput.cpp
@@ -9,9 +9,10 @@
#include
#include "CInput.h"
-#include "../CLogFile.h"
#include "CVideoDriver.h"
#include "CTimer.h"
+#include "../CLogFile.h"
+#include "../FindFile.h"
#ifdef WIZ
#include "gp2x.h"
@@ -89,7 +90,7 @@ void CInput::resetControls() {
short CInput::loadControlconfig(void)
{
FILE *fp;
- if((fp=fopen("controls.dat","rb")) != NULL)
+ if((fp=OpenGameFile("controls.dat","rb")) != NULL)
{
if(fread(InputCommand, sizeof(stInputCommand),NUMBER_OF_COMMANDS*NUM_INPUTS, fp) == 0 )
{
@@ -105,7 +106,7 @@ short CInput::loadControlconfig(void)
short CInput::saveControlconfig(void)
{
FILE *fp;
- if((fp=fopen("controls.dat","wb")) != NULL)
+ if((fp=OpenGameFile("controls.dat","wb")) != NULL)
{
fwrite(InputCommand, sizeof(stInputCommand),NUMBER_OF_COMMANDS*NUM_INPUTS, fp);
fclose(fp);
diff --git a/src/sdl/sound/CSound.cpp b/src/sdl/sound/CSound.cpp
index 2aad47373..be8cd5e13 100644
--- a/src/sdl/sound/CSound.cpp
+++ b/src/sdl/sound/CSound.cpp
@@ -13,6 +13,7 @@
#include "../../vorticon/sounds.h"
#include "../../fileio/CExeFile.h"
#include "../../StringUtils.h"
+#include "../../FindFile.h"
#define SAFE_DELETE_ARRAY(x) if(x) delete[] x; x=NULL
@@ -323,7 +324,7 @@ bool CSound::loadSoundData(unsigned short Episode, const std::string& DataDirect
FILE *p_file;
- if( ( p_file = fopen(soundfile.c_str(),"rb") ) == NULL )
+ if( ( p_file = OpenGameFile(soundfile.c_str(),"rb") ) == NULL )
{
buf = "keen" + itoa(Episode) + ".exe";
@@ -444,7 +445,7 @@ char CSound::extractOfExeFile(const std::string& inputpath, int episode)
if( *(buffer.end()) != '/') buffer += "/";
buffer += outputfname;
- if(!(fout = fopen(buffer.c_str(),"wb"))) ret = 1;
+ if(!(fout = OpenGameFile(buffer.c_str(),"wb"))) ret = 1;
else
{
fwrite( ExeFile->getData()+sounds_start, 1, (sounds_end-sounds_start), fout);
diff --git a/src/sdl/sound/CSoundSlot.cpp b/src/sdl/sound/CSoundSlot.cpp
index 527025bd8..1886a64b4 100644
--- a/src/sdl/sound/CSoundSlot.cpp
+++ b/src/sdl/sound/CSoundSlot.cpp
@@ -16,6 +16,7 @@
#include "CSoundSlot.h"
#include "../../CLogFile.h"
#include "../../fileio.h"
+#include "../../FindFile.h"
CSoundSlot::CSoundSlot() {
m_priority = 0;
@@ -57,7 +58,7 @@ bool CSoundSlot::loadSound(const std::string& fname, const std::string& searchna
for(i=0;i<12;i++)
name[i] = 0;
- fp = fopen(fname.c_str(), "rb");
+ fp = OpenGameFile(fname.c_str(), "rb");
if (!fp)
{
g_pLogFile->ftextOut("loadSound : Sounds file '%s' unopenable attempting load of '%s'
", fname.c_str(), searchname.c_str());
diff --git a/src/vorticon/CEGALatch.cpp b/src/vorticon/CEGALatch.cpp
index 1ea63f2d5..c004bb6f1 100644
--- a/src/vorticon/CEGALatch.cpp
+++ b/src/vorticon/CEGALatch.cpp
@@ -11,6 +11,7 @@
#include "../funcdefs.h"
#include "../keen.h"
#include "../keenext.h"
+#include "../FindFile.h"
#include
#include
@@ -69,7 +70,7 @@ bool CEGALatch::loadData(const std::string& filename, bool compresseddata)
{
char *RawData;
- FILE* latchfile = fopen(filename.c_str(),"rb");
+ FILE* latchfile = OpenGameFile(filename.c_str(),"rb");
if(!latchfile)
return false;
diff --git a/src/vorticon/CEGASprit.cpp b/src/vorticon/CEGASprit.cpp
index cb4b96dde..ef164eca0 100644
--- a/src/vorticon/CEGASprit.cpp
+++ b/src/vorticon/CEGASprit.cpp
@@ -12,6 +12,7 @@
#include "CEGASprit.h"
#include "CPlanes.h"
#include "../keen.h"
+#include "../FindFile.h"
#include
#include
@@ -75,7 +76,7 @@ bool CEGASprit::loadData(const std::string& filename, bool compresseddata)
{
char *RawData;
- FILE* latchfile = fopen(filename.c_str(),"rb");
+ FILE* latchfile = OpenGameFile(filename.c_str(),"rb");
if(!latchfile)
return false;