diff --git a/projects/mtg/include/utils.h b/projects/mtg/include/utils.h index 36aac96ea..c255cc7cc 100644 --- a/projects/mtg/include/utils.h +++ b/projects/mtg/include/utils.h @@ -119,3 +119,4 @@ u32 ramAvailable(void); #endif +bool FileExists(const string& strFilename); \ No newline at end of file diff --git a/projects/mtg/src/utils.cpp b/projects/mtg/src/utils.cpp index 93ef23b02..680331a08 100644 --- a/projects/mtg/src/utils.cpp +++ b/projects/mtg/src/utils.cpp @@ -5,6 +5,7 @@ #include "Subtypes.h" #include "WResourceManager.h" #include "WFont.h" +#include namespace wagic { @@ -297,3 +298,28 @@ std::string wordWrap(const std::string& sentence, float width, int fontId) return retVal; } + +bool FileExists(const string& strFilename) { + struct stat stFileInfo; + bool blnReturn; + int intStat; + + // Attempt to get the file attributes + intStat = stat(strFilename.c_str(),&stFileInfo); + if(intStat == 0) { + // We were able to get the file attributes + // so the file obviously exists. + blnReturn = true; + } else { + // We were not able to get the file attributes. + // This may mean that we don't have permission to + // access the folder which contains this file. If you + // need to do that level of checking, lookup the + // return values of stat which will give you + // more details on why stat failed. + blnReturn = false; + } + + return(blnReturn); +} +