1
0
mirror of https://github.com/blupi-games/planetblupi synced 2024-12-30 10:15:36 +01:00

Fix path on unix-like OS

This commit is contained in:
Mathieu Schroeter 2017-02-11 19:31:30 +01:00
parent f7fa611593
commit 36a1822d59
6 changed files with 78 additions and 80 deletions

View File

@ -68,7 +68,7 @@ bool ReadConfig(int argc, char *argv[])
char* pText;
size_t nb;
file = fopen("data\\config.ini", "rb");
file = fopen("data/config.ini", "rb");
if ( file == nullptr ) return false;
nb = fread(buffer, sizeof(char), 200-1, file);
buffer[nb] = 0;
@ -313,7 +313,7 @@ void WindowProc2 (const SDL_Event &event)
totalDim.y = 66;
iconDim.x = 64;
iconDim.y = 66 / 2;
g_pPixmap->Cache (CHHILI, "image\\hili.blp", totalDim, iconDim);
g_pPixmap->Cache (CHHILI, "image/hili.blp", totalDim, iconDim);
}
SDL_SetWindowTitle (g_window, "Blupi");
if (g_pSound != nullptr) g_pSound->RestartMusic ();
@ -462,9 +462,9 @@ static bool DoInit(int argc, char *argv[])
iconDim.x = 0;
iconDim.y = 0;
#if _INTRO
if ( !g_pPixmap->Cache(CHBACK, "image\\intro1.blp", totalDim, iconDim) )
if ( !g_pPixmap->Cache(CHBACK, "image/intro1.blp", totalDim, iconDim) )
#else
if ( !g_pPixmap->Cache(CHBACK, "image\\init.blp", totalDim, iconDim) )
if ( !g_pPixmap->Cache(CHBACK, "image/init.blp", totalDim, iconDim) )
#endif
return false;
@ -473,7 +473,7 @@ static bool DoInit(int argc, char *argv[])
totalDim.y = LYIMAGE;
iconDim.x = 0;
iconDim.y = 0;
if ( !g_pPixmap->Cache(CHGROUND, "image\\init.blp", totalDim, iconDim) )
if ( !g_pPixmap->Cache(CHGROUND, "image/init.blp", totalDim, iconDim) )
return false;
rcRect.left = 0;
@ -487,80 +487,80 @@ static bool DoInit(int argc, char *argv[])
totalDim.y = DIMCELY*2*6;
iconDim.x = DIMCELX*2;
iconDim.y = DIMCELY*2;
if ( !g_pPixmap->Cache(CHFLOOR, "image\\floor000.blp", totalDim, iconDim) )
if ( !g_pPixmap->Cache(CHFLOOR, "image/floor000.blp", totalDim, iconDim) )
return InitFail("Cache floor000.blp", true);
totalDim.x = DIMOBJX*16;
totalDim.y = DIMOBJY*8;
iconDim.x = DIMOBJX;
iconDim.y = DIMOBJY;
if ( !g_pPixmap->Cache(CHOBJECT, "image\\obj000.blp", totalDim, iconDim) )
if ( !g_pPixmap->Cache(CHOBJECT, "image/obj000.blp", totalDim, iconDim) )
return InitFail("Cache obj000.blp", true);
if ( !g_pPixmap->Cache(CHOBJECTo, "image\\obj-o000.blp", totalDim, iconDim) )
if ( !g_pPixmap->Cache(CHOBJECTo, "image/obj-o000.blp", totalDim, iconDim) )
return InitFail("Cache obj-o000.blp", true);
totalDim.x = DIMBLUPIX*16;
totalDim.y = DIMBLUPIY*23;
iconDim.x = DIMBLUPIX;
iconDim.y = DIMBLUPIY;
if ( !g_pPixmap->Cache(CHBLUPI, "image\\blupi.blp", totalDim, iconDim) )
if ( !g_pPixmap->Cache(CHBLUPI, "image/blupi.blp", totalDim, iconDim) )
return InitFail("Cache blupi.blp", true);
totalDim.x = 64;
totalDim.y = 66;
iconDim.x = 64;
iconDim.y = 66/2;
if ( !g_pPixmap->Cache(CHHILI, "image\\hili.blp", totalDim, iconDim) )
if ( !g_pPixmap->Cache(CHHILI, "image/hili.blp", totalDim, iconDim) )
return InitFail("Cache hili.blp", true);
totalDim.x = DIMCELX*2*3;
totalDim.y = DIMCELY*2*5;
iconDim.x = DIMCELX*2;
iconDim.y = DIMCELY*2;
if ( !g_pPixmap->Cache(CHFOG, "image\\fog.blp", totalDim, iconDim) )
if ( !g_pPixmap->Cache(CHFOG, "image/fog.blp", totalDim, iconDim) )
return InitFail("Cache fog.blp", true);
totalDim.x = DIMCELX*2*16;
totalDim.y = DIMCELY*2*1;
iconDim.x = DIMCELX*2;
iconDim.y = DIMCELY*2;
if ( !g_pPixmap->Cache(CHMASK1, "image\\mask1.blp", totalDim, iconDim) )
if ( !g_pPixmap->Cache(CHMASK1, "image/mask1.blp", totalDim, iconDim) )
return InitFail("Cache mask1.blp", true);
totalDim.x = DIMBUTTONX*6;
totalDim.y = DIMBUTTONY*21;
iconDim.x = DIMBUTTONX;
iconDim.y = DIMBUTTONY;
if ( !g_pPixmap->Cache(CHBUTTON, "image\\button00.blp", totalDim, iconDim) )
if ( !g_pPixmap->Cache(CHBUTTON, "image/button00.blp", totalDim, iconDim) )
return InitFail("Cache button00.blp", true);
totalDim.x = DIMJAUGEX*1;
totalDim.y = DIMJAUGEY*4;
iconDim.x = DIMJAUGEX;
iconDim.y = DIMJAUGEY;
if ( !g_pPixmap->Cache(CHJAUGE, "image\\jauge.blp", totalDim, iconDim) )
if ( !g_pPixmap->Cache(CHJAUGE, "image/jauge.blp", totalDim, iconDim) )
return InitFail("Cache jauge.blp", true);
totalDim.x = DIMTEXTX*16;
totalDim.y = DIMTEXTY*8*3;
iconDim.x = DIMTEXTX;
iconDim.y = DIMTEXTY;
if ( !g_pPixmap->Cache(CHTEXT, "image\\text.blp", totalDim, iconDim) )
if ( !g_pPixmap->Cache(CHTEXT, "image/text.blp", totalDim, iconDim) )
return InitFail("Cache text.blp", true);
totalDim.x = DIMLITTLEX*16;
totalDim.y = DIMLITTLEY*8;
iconDim.x = DIMLITTLEX;
iconDim.y = DIMLITTLEY;
if ( !g_pPixmap->Cache(CHLITTLE, "image\\little.blp", totalDim, iconDim) )
if ( !g_pPixmap->Cache(CHLITTLE, "image/little.blp", totalDim, iconDim) )
return InitFail("Cache little.blp", true);
totalDim.x = 426;
totalDim.y = 52;
iconDim.x = 426;
iconDim.y = 52;
if ( !g_pPixmap->Cache(CHBIGNUM, "image\\bignum.blp", totalDim, iconDim) )
if ( !g_pPixmap->Cache(CHBIGNUM, "image/bignum.blp", totalDim, iconDim) )
return InitFail("Cache bignum.blp", true);
// Load all cursors

View File

@ -103,12 +103,12 @@ bool CDecor::Write(int rank, bool bUser, int world, int time, int total)
if ( bUser )
{
sprintf(filename, "data\\user%.3d.blp", rank);
sprintf(filename, "data/user%.3d.blp", rank);
AddUserPath(filename);
}
else
{
sprintf(filename, "data\\world%.3d.blp", rank);
sprintf(filename, "data/world%.3d.blp", rank);
}
file = fopen(filename, "wb");
@ -186,12 +186,12 @@ bool CDecor::Read(int rank, bool bUser, int &world, int &time, int &total)
if ( bUser )
{
sprintf(filename, "data\\user%.3d.blp", rank);
sprintf(filename, "data/user%.3d.blp", rank);
AddUserPath(filename);
}
else
{
sprintf(filename, "data\\world%.3d.blp", rank);
sprintf(filename, "data/world%.3d.blp", rank);
}
file = fopen(filename, "rb");
@ -323,12 +323,12 @@ bool CDecor::FileExist(int rank, bool bUser, int &world, int &time, int &total)
if ( bUser )
{
sprintf(filename, "data\\user%.3d.blp", rank);
sprintf(filename, "data/user%.3d.blp", rank);
AddUserPath(filename);
}
else
{
sprintf(filename, "data\\world%.3d.blp", rank);
sprintf(filename, "data/world%.3d.blp", rank);
}
file = fopen(filename, "rb");

View File

@ -224,7 +224,7 @@ bool CDecor::LoadImages()
totalDim.y = DIMCELY*2*6;
iconDim.x = DIMCELX*2;
iconDim.y = DIMCELY*2;
sprintf(filename, "image\\floor%.3d.blp", m_region);
sprintf(filename, "image/floor%.3d.blp", m_region);
if ( !m_pPixmap->Cache(CHFLOOR, filename, totalDim, iconDim) )
return false;
@ -232,11 +232,11 @@ bool CDecor::LoadImages()
totalDim.y = DIMOBJY*8;
iconDim.x = DIMOBJX;
iconDim.y = DIMOBJY;
sprintf(filename, "image\\obj%.3d.blp", m_region);
sprintf(filename, "image/obj%.3d.blp", m_region);
if ( !m_pPixmap->Cache(CHOBJECT, filename, totalDim, iconDim) )
return false;
sprintf(filename, "image\\obj-o%.3d.blp", m_region);
sprintf(filename, "image/obj-o%.3d.blp", m_region);
if ( !m_pPixmap->Cache(CHOBJECTo, filename, totalDim, iconDim) )
return false;

View File

@ -73,7 +73,7 @@ static Phase table[] =
{
{
WM_PHASE_TESTCD,
"image\\init.blp",
"image/init.blp",
false,
{
{
@ -84,7 +84,7 @@ static Phase table[] =
{
WM_PHASE_INTRO1,
"image\\intro1.blp",
"image/intro1.blp",
false,
{
{
@ -95,7 +95,7 @@ static Phase table[] =
{
WM_PHASE_INTRO2,
"image\\intro2.blp",
"image/intro2.blp",
false,
{
{
@ -106,7 +106,7 @@ static Phase table[] =
{
WM_PHASE_INIT,
"image\\init.blp",
"image/init.blp",
false,
{
{
@ -147,7 +147,7 @@ static Phase table[] =
{
WM_PHASE_HISTORY0,
"image\\history0.blp",
"image/history0.blp",
true,
{
{
@ -170,7 +170,7 @@ static Phase table[] =
{
WM_PHASE_HISTORY1,
"image\\history1.blp",
"image/history1.blp",
true,
{
{
@ -193,7 +193,7 @@ static Phase table[] =
{
WM_PHASE_INFO,
"image\\info%.3d.blp",
"image/info%.3d.blp",
false,
{
{
@ -258,7 +258,7 @@ static Phase table[] =
{
WM_PHASE_PLAY,
"image\\play.blp",
"image/play.blp",
false,
{
{
@ -287,7 +287,7 @@ static Phase table[] =
{
WM_PHASE_STOP,
"image\\stop%.3d.blp",
"image/stop%.3d.blp",
false,
{
{
@ -334,7 +334,7 @@ static Phase table[] =
{
WM_PHASE_HELP,
"image\\help.blp",
"image/help.blp",
true,
{
{
@ -375,7 +375,7 @@ static Phase table[] =
{
WM_PHASE_SETUP,
"image\\setup.blp",
"image/setup.blp",
false,
{
{
@ -452,7 +452,7 @@ static Phase table[] =
{
WM_PHASE_SETUPp,
"image\\setup.blp",
"image/setup.blp",
false,
{
{
@ -529,7 +529,7 @@ static Phase table[] =
{
WM_PHASE_READ,
"image\\read.blp",
"image/read.blp",
false,
{
{
@ -606,7 +606,7 @@ static Phase table[] =
{
WM_PHASE_WRITE,
"image\\write.blp",
"image/write.blp",
false,
{
{
@ -683,7 +683,7 @@ static Phase table[] =
{
WM_PHASE_WRITEp,
"image\\write.blp",
"image/write.blp",
false,
{
{
@ -760,7 +760,7 @@ static Phase table[] =
{
WM_PHASE_LOST,
"image\\lost.blp",
"image/lost.blp",
true,
{
{
@ -777,7 +777,7 @@ static Phase table[] =
{
WM_PHASE_WIN,
"image\\win.blp",
"image/win.blp",
true,
{
{
@ -794,7 +794,7 @@ static Phase table[] =
{
WM_PHASE_LASTWIN,
"image\\last%.3d.blp",
"image/last%.3d.blp",
true,
{
{
@ -811,7 +811,7 @@ static Phase table[] =
{
WM_PHASE_BUILD,
"image\\build.blp",
"image/build.blp",
true,
{
{
@ -926,7 +926,7 @@ static Phase table[] =
{
WM_PHASE_BUTTON,
"image\\button.blp",
"image/button.blp",
true,
{
{
@ -1146,7 +1146,7 @@ static Phase table[] =
{
WM_PHASE_TERM,
"image\\term.blp",
"image/term.blp",
true,
{
{
@ -1235,7 +1235,7 @@ static Phase table[] =
{
WM_PHASE_MUSIC,
"image\\music.blp",
"image/music.blp",
true,
{
{
@ -1312,7 +1312,7 @@ static Phase table[] =
{
WM_PHASE_REGION,
"image\\region.blp",
"image/region.blp",
true,
{
{
@ -1353,7 +1353,7 @@ static Phase table[] =
{
WM_PHASE_PLAYMOVIE,
"image\\movie.blp",
"image/movie.blp",
false,
{
{
@ -1364,7 +1364,7 @@ static Phase table[] =
{
WM_PHASE_WINMOVIE,
"image\\movie.blp",
"image/movie.blp",
false,
{
{
@ -1375,7 +1375,7 @@ static Phase table[] =
{
WM_PHASE_H0MOVIE,
"image\\movie.blp",
"image/movie.blp",
false,
{
{
@ -1386,7 +1386,7 @@ static Phase table[] =
{
WM_PHASE_H1MOVIE,
"image\\movie.blp",
"image/movie.blp",
false,
{
{
@ -1397,7 +1397,7 @@ static Phase table[] =
{
WM_PHASE_H2MOVIE,
"image\\movie.blp",
"image/movie.blp",
false,
{
{
@ -1408,7 +1408,7 @@ static Phase table[] =
{
WM_PHASE_BYE,
"image\\bye.blp",
"image/bye.blp",
false,
{
{
@ -1419,7 +1419,7 @@ static Phase table[] =
{
WM_PHASE_INSERT,
"image\\insert.blp",
"image/insert.blp",
false,
{
{
@ -3099,7 +3099,7 @@ bool CEvent::ChangePhase(unsigned int phase)
music = m_pDecor->GetMusic();
if ( music > 0 )
{
sprintf(filename, "sound\\music%.3d.blp", music-1);
sprintf(filename, "sound/music%.3d.blp", music-1);
m_pSound->StopMusic ();
m_pSound->PlayMusic(filename);
}
@ -3108,31 +3108,31 @@ bool CEvent::ChangePhase(unsigned int phase)
if ( phase == WM_PHASE_H0MOVIE )
{
strcpy(m_movieToStart, "movie\\history0.mkv");
strcpy(m_movieToStart, "movie/history0.mkv");
m_phaseAfterMovie = WM_PHASE_HISTORY0;
}
if ( phase == WM_PHASE_H1MOVIE )
{
strcpy(m_movieToStart, "movie\\history1.mkv");
strcpy(m_movieToStart, "movie/history1.mkv");
m_phaseAfterMovie = WM_PHASE_HISTORY1;
}
if ( phase == WM_PHASE_H2MOVIE )
{
strcpy(m_movieToStart, "movie\\history2.mkv");
strcpy(m_movieToStart, "movie/history2.mkv");
m_phaseAfterMovie = WM_PHASE_INFO;
}
if ( phase == WM_PHASE_PLAYMOVIE )
{
sprintf(m_movieToStart, "movie\\play%.3d.mkv", GetPhysicalWorld());
sprintf(m_movieToStart, "movie/play%.3d.mkv", GetPhysicalWorld());
m_phaseAfterMovie = WM_PHASE_PLAY;
}
if ( phase == WM_PHASE_WINMOVIE )
{
sprintf(m_movieToStart, "movie\\win%.3d.mkv", GetPhysicalWorld());
sprintf(m_movieToStart, "movie/win%.3d.mkv", GetPhysicalWorld());
m_phaseAfterMovie = WM_PHASE_WIN;
if ( !m_bPrivate &&
@ -4166,7 +4166,7 @@ bool CEvent::ReadLibelle(int world, bool bSchool, bool bHelp)
if ( pBuffer == nullptr ) goto error;
memset(pBuffer, 0, sizeof(char)*50000);
file = fopen("data\\enigmes.blp", "rb");
file = fopen("data/enigmes.blp", "rb");
if ( file == nullptr ) goto error;
nb = fread(pBuffer, sizeof(char), 50000-1, file);
@ -4220,7 +4220,7 @@ bool CEvent::WriteInfo()
DescInfo info;
size_t nb;
strcpy(filename, "data\\info.blp");
strcpy(filename, "data/info.blp");
AddUserPath(filename);
file = fopen(filename, "wb");
@ -4262,7 +4262,7 @@ bool CEvent::ReadInfo()
DescInfo info;
size_t nb;
strcpy(filename, "data\\info.blp");
strcpy(filename, "data/info.blp");
AddUserPath(filename);
file = fopen(filename, "rb");
@ -4349,8 +4349,8 @@ void CEvent::DemoRecStop()
if ( m_pDemoBuffer != nullptr )
{
_unlink ("data\\demo.blp");
file = fopen("data\\demo.blp", "wb");
_unlink ("data/demo.blp");
file = fopen("data/demo.blp", "wb");
if ( file != nullptr )
{
memset(&header, 0, sizeof(DemoHeader));
@ -4387,7 +4387,7 @@ bool CEvent::DemoPlayStart()
if ( m_pDemoBuffer == nullptr ) return false;
memset(m_pDemoBuffer, 0, MAXDEMO*sizeof(DemoEvent));
sprintf(filename, "data\\demo%.3d.blp", m_demoNumber);
sprintf(filename, "data/demo%.3d.blp", m_demoNumber);
file = fopen(filename, "rb");
if ( file == nullptr )
{
@ -5319,7 +5319,7 @@ bool CEvent::TreatEventBase(const SDL_Event &event)
break;
case WM_MOVIE:
StartMovie("movie\\essai.avi");
StartMovie("movie/essai.avi");
ChangePhase(WM_PHASE_INIT);
break;
}

View File

@ -3,6 +3,7 @@
#include <SDL2/SDL_log.h>
#include <SDL2/SDL_mouse.h>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -67,22 +68,19 @@ int Random(int min, int max)
std::string GetBaseDir ()
{
char *sdlBasePath = nullptr;
static std::string basePath;
if (!basePath.size ())
{
sdlBasePath = SDL_GetBasePath ();
auto sdlBasePath = SDL_GetBasePath ();
sdlBasePath[strlen (sdlBasePath) - 1] = '\0';
basePath = sdlBasePath;
std::replace (basePath.begin (), basePath.end (), '\\', '/');
basePath = basePath.substr (0, basePath.find_last_of ("//") + 1);
SDL_free (sdlBasePath);
}
std::string path = sdlBasePath;
path = path.substr (0, path.find_last_of ("\\/") + 1);
if (sdlBasePath)
SDL_free (sdlBasePath);
return path;
return basePath;
}
// Ajoute le chemin permettant de lire un fichier
@ -97,7 +95,7 @@ void AddUserPath(char *pFilename)
temp = SDL_GetPrefPath ("Epsitec SA", "Planet Blupi");
pText = strstr(pFilename, "\\");
pText = strstr(pFilename, "/");
if ( pText != nullptr )
{
pos = strlen(temp)+(pText-pFilename)+1;

View File

@ -136,7 +136,7 @@ void CSound::CacheAll()
for ( i=0 ; i<MAXSOUND ; i++ )
{
sprintf(name, "sound\\sound%.3d.blp", i);
sprintf(name, "sound/sound%.3d.blp", i);
if ( !Cache(i, name) ) break;
}
}