More robust way to handle previous fix. Put the string manipulations into generic functions in common.cpp

This commit is contained in:
adelikat 2010-05-15 02:38:32 +00:00
parent e8bed97821
commit 2cd959fd84
3 changed files with 39 additions and 2 deletions

View File

@ -60,3 +60,34 @@ std::string GetPath(std::string filename)
{
return filename.substr(0,filename.find_last_of("/\\") + 1);
}
bool IsRelativePath(char* name)
{
if (name[0] == '.')
if (name[1] == '\\') return true;
else if (name[1] == '.' && name[2] == '\\') return true;
return false;
}
bool IsRelativePath(const char* name)
{
if (name[0] == '.')
if (name[1] == '\\') return true;
else if (name[1] == '.' && name[2] == '\\') return true;
return false;
}
bool IsRelativePath(std::string name)
{
if (name[0] == '.')
if (name[1] == '\\') return true;
else if (name[1] == '.' && name[2] == '\\') return true;
return false;
}
//Precondition: IsRelativePath() == true
std::string ConvertRelativePath(std::string name)
{
extern std::string BaseDirectory;
return BaseDirectory + '\\' + name.substr(2, name.length());
}

View File

@ -55,4 +55,8 @@ void WindowBoundsCheckNoResize(int &windowPosX, int &windowPosY, long windowRigh
void AddExtensionIfMissing(char * name,unsigned int maxsize,const char * extension);
void AddExtensionIfMissing(std::string &name,const char * extension);
std::string GetPath(std::string filename);
bool IsRelativePath(char* name);
bool IsRelativePath(const char* name);
bool IsRelativePath(std::string name);
std::string ConvertRelativePath(std::string name);
#endif

View File

@ -37,6 +37,7 @@
#ifdef WIN32
#include <windows.h>
#include "./drivers/win/common.h"
extern void AddRecentMovieFile(const char *filename);
#endif
@ -919,10 +920,11 @@ bool FCEUI_LoadMovie(const char *fname, bool _read_only, bool tasedit, int _paus
#ifdef WIN32
//Fix relative path if necessary and then add to the recent movie menu
extern std::string BaseDirectory;
string name = fname;
if (name[0] == '.' && name[1] == '\\')
if (IsRelativePath(fname))
{
name = BaseDirectory + '\\' + name.substr(2, name.length());
name = ConvertRelativePath(name);
}
AddRecentMovieFile(name.c_str());
#endif