More robust way to handle previous fix. Put the string manipulations into generic functions in common.cpp
This commit is contained in:
parent
e8bed97821
commit
2cd959fd84
|
@ -59,4 +59,35 @@ void AddExtensionIfMissing(std::string &name,const char * extension) {
|
||||||
std::string GetPath(std::string filename)
|
std::string GetPath(std::string filename)
|
||||||
{
|
{
|
||||||
return filename.substr(0,filename.find_last_of("/\\") + 1);
|
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());
|
||||||
}
|
}
|
|
@ -55,4 +55,8 @@ void WindowBoundsCheckNoResize(int &windowPosX, int &windowPosY, long windowRigh
|
||||||
void AddExtensionIfMissing(char * name,unsigned int maxsize,const char * extension);
|
void AddExtensionIfMissing(char * name,unsigned int maxsize,const char * extension);
|
||||||
void AddExtensionIfMissing(std::string &name,const char * extension);
|
void AddExtensionIfMissing(std::string &name,const char * extension);
|
||||||
std::string GetPath(std::string filename);
|
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
|
#endif
|
||||||
|
|
|
@ -37,6 +37,7 @@
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
#include "./drivers/win/common.h"
|
||||||
extern void AddRecentMovieFile(const char *filename);
|
extern void AddRecentMovieFile(const char *filename);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -919,10 +920,11 @@ bool FCEUI_LoadMovie(const char *fname, bool _read_only, bool tasedit, int _paus
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
//Fix relative path if necessary and then add to the recent movie menu
|
//Fix relative path if necessary and then add to the recent movie menu
|
||||||
extern std::string BaseDirectory;
|
extern std::string BaseDirectory;
|
||||||
|
|
||||||
string name = fname;
|
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());
|
AddRecentMovieFile(name.c_str());
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue