mirror of
https://github.com/blupi-games/planetblupi
synced 2024-12-30 10:15:36 +01:00
Improve how the base dir is retrieved
This commit is contained in:
parent
4134b1bfae
commit
6af7270020
34
src/misc.cpp
34
src/misc.cpp
@ -7,6 +7,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <direct.h>
|
#include <direct.h>
|
||||||
|
#include "misc.h"
|
||||||
#include "blupi.h"
|
#include "blupi.h"
|
||||||
#include "def.h"
|
#include "def.h"
|
||||||
|
|
||||||
@ -64,33 +65,24 @@ int Random(int min, int max)
|
|||||||
|
|
||||||
// Retourne le nom de dossier en cours.
|
// Retourne le nom de dossier en cours.
|
||||||
|
|
||||||
void GetCurrentDir(char *pName, size_t lg)
|
std::string GetBaseDir ()
|
||||||
{
|
{
|
||||||
char *basePath = SDL_GetBasePath ();
|
char *sdlBasePath = nullptr;
|
||||||
strncpy(pName, basePath, lg-1);
|
static std::string basePath;
|
||||||
pName[lg-1] = 0;
|
|
||||||
|
|
||||||
lg = strlen(pName);
|
if (!basePath.size ())
|
||||||
if (lg == 0)
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
while ( lg > 0 )
|
|
||||||
{
|
{
|
||||||
lg --;
|
sdlBasePath = SDL_GetBasePath ();
|
||||||
if ( pName[lg] == '\\' )
|
sdlBasePath[strlen (sdlBasePath) - 1] = '\0';
|
||||||
{
|
|
||||||
pName[lg+1] = 0;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( lg > 6 && strcmp(pName+lg-6, "\\Debug\\") == 0 )
|
std::string path = sdlBasePath;
|
||||||
{
|
path = path.substr (0, path.find_last_of ("\\/") + 1);
|
||||||
pName[lg-5] = 0; // ignore le dossier \debug !
|
|
||||||
}
|
|
||||||
|
|
||||||
out:
|
if (sdlBasePath)
|
||||||
SDL_free (basePath);
|
SDL_free (sdlBasePath);
|
||||||
|
|
||||||
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ajoute le chemin permettant de lire un fichier
|
// Ajoute le chemin permettant de lire un fichier
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
#include "blupi.h"
|
#include "blupi.h"
|
||||||
|
|
||||||
extern void OutputDebug(char *pMessage);
|
extern void OutputDebug(char *pMessage);
|
||||||
@ -12,5 +13,5 @@ extern POINT ConvLongToPos(LPARAM lParam);
|
|||||||
extern void InitRandom();
|
extern void InitRandom();
|
||||||
extern int Random(int min, int max);
|
extern int Random(int min, int max);
|
||||||
|
|
||||||
extern void GetCurrentDir(char *pName, size_t lg);
|
std::string GetBaseDir();
|
||||||
extern void AddUserPath(char *pFilename);
|
extern void AddUserPath(char *pFilename);
|
||||||
|
@ -79,24 +79,15 @@ void CMovie::fileCloseMovie()
|
|||||||
|
|
||||||
bool CMovie::fileOpenMovie(RECT rect, char *pFilename)
|
bool CMovie::fileOpenMovie(RECT rect, char *pFilename)
|
||||||
{
|
{
|
||||||
char string[MAX_PATH];
|
std::string path = GetBaseDir ();
|
||||||
|
path += pFilename;
|
||||||
if ( pFilename[1] == ':' ) // nom complet "D:\REP..." ?
|
|
||||||
{
|
|
||||||
strcpy(string, pFilename);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
GetCurrentDir(string, MAX_PATH-30);
|
|
||||||
strcat(string, pFilename);
|
|
||||||
}
|
|
||||||
|
|
||||||
// we got a filename, now close any old movie and open the new one. */
|
// we got a filename, now close any old movie and open the new one. */
|
||||||
if ( m_fMovieOpen ) fileCloseMovie();
|
if ( m_fMovieOpen ) fileCloseMovie();
|
||||||
|
|
||||||
// Open up the sourcefile.
|
// Open up the sourcefile.
|
||||||
// This can be a local file, network url, ...
|
// This can be a local file, network url, ...
|
||||||
m_movie = Kit_CreateSourceFromUrl (string);
|
m_movie = Kit_CreateSourceFromUrl (path.c_str ());
|
||||||
if (m_movie)
|
if (m_movie)
|
||||||
{
|
{
|
||||||
// Create the player
|
// Create the player
|
||||||
@ -204,20 +195,12 @@ bool CMovie::GetEnable()
|
|||||||
|
|
||||||
bool CMovie::IsExist(char *pFilename)
|
bool CMovie::IsExist(char *pFilename)
|
||||||
{
|
{
|
||||||
char string[MAX_PATH];
|
std::string path = GetBaseDir ();
|
||||||
FILE* file;
|
FILE* file;
|
||||||
|
|
||||||
if ( pFilename[1] == ':' ) // nom complet "D:\REP..." ?
|
path += pFilename;
|
||||||
{
|
|
||||||
strcpy(string, pFilename);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
GetCurrentDir(string, MAX_PATH-30);
|
|
||||||
strcat(string, pFilename);
|
|
||||||
}
|
|
||||||
|
|
||||||
file = fopen(string, "rb");
|
file = fopen(path.c_str (), "rb");
|
||||||
if ( file == nullptr ) return false;
|
if ( file == nullptr ) return false;
|
||||||
|
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
@ -267,7 +267,7 @@ bool CSound::PlayImage(int channel, POINT pos, int rank)
|
|||||||
|
|
||||||
bool CSound::PlayMusic(const char *lpszMIDIFilename)
|
bool CSound::PlayMusic(const char *lpszMIDIFilename)
|
||||||
{
|
{
|
||||||
char string[MAX_PATH];
|
std::string path = GetBaseDir ();
|
||||||
|
|
||||||
if ( !m_bEnable ) return true;
|
if ( !m_bEnable ) return true;
|
||||||
if ( m_midiVolume == 0 ) return true;
|
if ( m_midiVolume == 0 ) return true;
|
||||||
@ -275,17 +275,9 @@ bool CSound::PlayMusic(const char *lpszMIDIFilename)
|
|||||||
Mix_VolumeMusic (MIX_MAX_VOLUME * 100 * m_midiVolume / 20 / 100);
|
Mix_VolumeMusic (MIX_MAX_VOLUME * 100 * m_midiVolume / 20 / 100);
|
||||||
m_lastMidiVolume = m_midiVolume;
|
m_lastMidiVolume = m_midiVolume;
|
||||||
|
|
||||||
if ( lpszMIDIFilename[1] == ':' ) // nom complet "D:\REP..." ?
|
path += lpszMIDIFilename;
|
||||||
{
|
|
||||||
strcpy(string, lpszMIDIFilename);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
GetCurrentDir(string, MAX_PATH-30);
|
|
||||||
strcat(string, lpszMIDIFilename);
|
|
||||||
}
|
|
||||||
|
|
||||||
m_pMusic = Mix_LoadMUS (string);
|
m_pMusic = Mix_LoadMUS (path.c_str ());
|
||||||
if (!m_pMusic)
|
if (!m_pMusic)
|
||||||
{
|
{
|
||||||
printf ("%s\n", Mix_GetError ());
|
printf ("%s\n", Mix_GetError ());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user