From 2cd959fd84dc1180adebb3224e201b0ceaede7d8 Mon Sep 17 00:00:00 2001 From: adelikat Date: Sat, 15 May 2010 02:38:32 +0000 Subject: [PATCH] More robust way to handle previous fix. Put the string manipulations into generic functions in common.cpp --- src/drivers/win/common.cpp | 31 +++++++++++++++++++++++++++++++ src/drivers/win/common.h | 4 ++++ src/movie.cpp | 6 ++++-- 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/src/drivers/win/common.cpp b/src/drivers/win/common.cpp index 322db208..5d607ad2 100644 --- a/src/drivers/win/common.cpp +++ b/src/drivers/win/common.cpp @@ -59,4 +59,35 @@ void AddExtensionIfMissing(std::string &name,const char * extension) { 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()); } \ No newline at end of file diff --git a/src/drivers/win/common.h b/src/drivers/win/common.h index 08c0e984..f9adf878 100644 --- a/src/drivers/win/common.h +++ b/src/drivers/win/common.h @@ -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 diff --git a/src/movie.cpp b/src/movie.cpp index 372aefcb..fec21269 100644 --- a/src/movie.cpp +++ b/src/movie.cpp @@ -37,6 +37,7 @@ #ifdef WIN32 #include +#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