From edd7363eddc9f6ef6a7f798a092500b328d5a7f3 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 18 Sep 2013 18:43:03 +0200 Subject: [PATCH] Proper folder / file distinction in plugin loading. --- source/OSSupport/File.cpp | 14 ++++++++++++++ source/OSSupport/File.h | 3 +++ source/PluginManager.cpp | 6 +++--- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/source/OSSupport/File.cpp b/source/OSSupport/File.cpp index cc091671..871d9fb9 100644 --- a/source/OSSupport/File.cpp +++ b/source/OSSupport/File.cpp @@ -287,6 +287,20 @@ bool cFile::Rename(const AString & a_OrigFileName, const AString & a_NewFileName +bool cFile::IsFolder(const AString & a_Path) +{ + #ifdef _WIN32 + return ((GetFileAttributes(a_Path.c_str()) & FILE_ATTRIBUTE_DIRECTORY) != 0); + #else + struct stat st; + return ((stat(a_Path.c_str(), &st) == 0) && S_ISDIR(st.st_mode)); + #endif +} + + + + + int cFile::Printf(const char * a_Fmt, ...) { AString buf; diff --git a/source/OSSupport/File.h b/source/OSSupport/File.h index 8a057afa..d4ea0d3a 100644 --- a/source/OSSupport/File.h +++ b/source/OSSupport/File.h @@ -99,6 +99,9 @@ public: /// Renames a file, returns true if successful. May fail if dest already exists (libc-dependant)! static bool Rename(const AString & a_OrigFileName, const AString & a_NewFileName); + /// Returns true if the specified path is a folder + static bool IsFolder(const AString & a_Path); + int Printf(const char * a_Fmt, ...); private: diff --git a/source/PluginManager.cpp b/source/PluginManager.cpp index 93ee7192..e7cac457 100644 --- a/source/PluginManager.cpp +++ b/source/PluginManager.cpp @@ -75,14 +75,14 @@ void cPluginManager::FindPlugins(void) AStringList Files = GetDirectoryContents(PluginsPath.c_str()); for (AStringList::const_iterator itr = Files.begin(); itr != Files.end(); ++itr) { - if (itr->rfind(".") != AString::npos) + if (!cFile::IsFolder(*itr)) { - // Ignore files, we only want directories + // We only want folders continue; } // Add plugin name/directory to the list - if (m_Plugins.find( *itr ) == m_Plugins.end()) + if (m_Plugins.find(*itr) == m_Plugins.end()) { m_Plugins[ *itr ] = NULL; }