|
@@ -56,10 +56,20 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
#include "types.h"
|
|
#include "types.h"
|
|
|
|
|
|
|
|
+#ifdef _WIN32
|
|
|
|
+# include <direct.h>
|
|
|
|
+# include <stdlib.h>
|
|
|
|
+# include <stdio.h>
|
|
|
|
+#else
|
|
|
|
+# include <sys/stat.h>
|
|
|
|
+# include <sys/types.h>
|
|
|
|
+#endif // _WIN32
|
|
|
|
+
|
|
#include <vector>
|
|
#include <vector>
|
|
|
|
|
|
namespace Assimp {
|
|
namespace Assimp {
|
|
-class IOStream;
|
|
|
|
|
|
+
|
|
|
|
+ class IOStream;
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------
|
|
/** @brief CPP-API: Interface to the file system.
|
|
/** @brief CPP-API: Interface to the file system.
|
|
@@ -198,20 +208,35 @@ public:
|
|
*/
|
|
*/
|
|
virtual bool PopDirectory();
|
|
virtual bool PopDirectory();
|
|
|
|
|
|
|
|
+ // -------------------------------------------------------------------
|
|
|
|
+ /** @brief CReates an new directory at the given path.
|
|
|
|
+ * @param path [in] The path to create.
|
|
|
|
+ * @return True, when a directory was created. False if the directory
|
|
|
|
+ * cannot be created.
|
|
|
|
+ */
|
|
|
|
+ virtual bool CreateDirectory( const std::string &path );
|
|
|
|
+
|
|
|
|
+ // -------------------------------------------------------------------
|
|
|
|
+ /** @brief Will change the current directory to the given path.
|
|
|
|
+ * @param path [in] The path to change to.
|
|
|
|
+ * @return True, when the directory has changed successfully.
|
|
|
|
+ */
|
|
|
|
+ virtual bool ChangeDirectory( const std::string &path );
|
|
|
|
+
|
|
private:
|
|
private:
|
|
std::vector<std::string> m_pathStack;
|
|
std::vector<std::string> m_pathStack;
|
|
};
|
|
};
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// ----------------------------------------------------------------------------
|
|
-AI_FORCE_INLINE IOSystem::IOSystem() :
|
|
|
|
- m_pathStack()
|
|
|
|
-{
|
|
|
|
|
|
+AI_FORCE_INLINE
|
|
|
|
+IOSystem::IOSystem()
|
|
|
|
+: m_pathStack() {
|
|
// empty
|
|
// empty
|
|
}
|
|
}
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// ----------------------------------------------------------------------------
|
|
-AI_FORCE_INLINE IOSystem::~IOSystem()
|
|
|
|
-{
|
|
|
|
|
|
+AI_FORCE_INLINE
|
|
|
|
+IOSystem::~IOSystem() {
|
|
// empty
|
|
// empty
|
|
}
|
|
}
|
|
|
|
|
|
@@ -222,9 +247,8 @@ AI_FORCE_INLINE IOSystem::~IOSystem()
|
|
// ----------------------------------------------------------------------------
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// ----------------------------------------------------------------------------
|
|
-AI_FORCE_INLINE IOStream* IOSystem::Open(const std::string& pFile,
|
|
|
|
- const std::string& pMode)
|
|
|
|
-{
|
|
|
|
|
|
+AI_FORCE_INLINE
|
|
|
|
+IOStream* IOSystem::Open(const std::string& pFile, const std::string& pMode) {
|
|
// NOTE:
|
|
// NOTE:
|
|
// For compatibility, interface was changed to const char* to
|
|
// For compatibility, interface was changed to const char* to
|
|
// avoid crashes between binary incompatible STL versions
|
|
// avoid crashes between binary incompatible STL versions
|
|
@@ -232,8 +256,8 @@ AI_FORCE_INLINE IOStream* IOSystem::Open(const std::string& pFile,
|
|
}
|
|
}
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// ----------------------------------------------------------------------------
|
|
-AI_FORCE_INLINE bool IOSystem::Exists( const std::string& pFile) const
|
|
|
|
-{
|
|
|
|
|
|
+AI_FORCE_INLINE
|
|
|
|
+bool IOSystem::Exists( const std::string& pFile) const {
|
|
// NOTE:
|
|
// NOTE:
|
|
// For compatibility, interface was changed to const char* to
|
|
// For compatibility, interface was changed to const char* to
|
|
// avoid crashes between binary incompatible STL versions
|
|
// avoid crashes between binary incompatible STL versions
|
|
@@ -241,9 +265,8 @@ AI_FORCE_INLINE bool IOSystem::Exists( const std::string& pFile) const
|
|
}
|
|
}
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// ----------------------------------------------------------------------------
|
|
-inline bool IOSystem::ComparePaths (const std::string& one,
|
|
|
|
- const std::string& second) const
|
|
|
|
-{
|
|
|
|
|
|
+AI_FORCE_INLINE
|
|
|
|
+bool IOSystem::ComparePaths (const std::string& one, const std::string& second) const {
|
|
// NOTE:
|
|
// NOTE:
|
|
// For compatibility, interface was changed to const char* to
|
|
// For compatibility, interface was changed to const char* to
|
|
// avoid crashes between binary incompatible STL versions
|
|
// avoid crashes between binary incompatible STL versions
|
|
@@ -251,7 +274,8 @@ inline bool IOSystem::ComparePaths (const std::string& one,
|
|
}
|
|
}
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// ----------------------------------------------------------------------------
|
|
-inline bool IOSystem::PushDirectory( const std::string &path ) {
|
|
|
|
|
|
+AI_FORCE_INLINE
|
|
|
|
+bool IOSystem::PushDirectory( const std::string &path ) {
|
|
if ( path.empty() ) {
|
|
if ( path.empty() ) {
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
@@ -262,7 +286,8 @@ inline bool IOSystem::PushDirectory( const std::string &path ) {
|
|
}
|
|
}
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// ----------------------------------------------------------------------------
|
|
-inline const std::string &IOSystem::CurrentDirectory() const {
|
|
|
|
|
|
+AI_FORCE_INLINE
|
|
|
|
+const std::string &IOSystem::CurrentDirectory() const {
|
|
if ( m_pathStack.empty() ) {
|
|
if ( m_pathStack.empty() ) {
|
|
static const std::string Dummy("");
|
|
static const std::string Dummy("");
|
|
return Dummy;
|
|
return Dummy;
|
|
@@ -271,12 +296,14 @@ inline const std::string &IOSystem::CurrentDirectory() const {
|
|
}
|
|
}
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// ----------------------------------------------------------------------------
|
|
-inline size_t IOSystem::StackSize() const {
|
|
|
|
|
|
+AI_FORCE_INLINE
|
|
|
|
+size_t IOSystem::StackSize() const {
|
|
return m_pathStack.size();
|
|
return m_pathStack.size();
|
|
}
|
|
}
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// ----------------------------------------------------------------------------
|
|
-inline bool IOSystem::PopDirectory() {
|
|
|
|
|
|
+AI_FORCE_INLINE
|
|
|
|
+bool IOSystem::PopDirectory() {
|
|
if ( m_pathStack.empty() ) {
|
|
if ( m_pathStack.empty() ) {
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
@@ -287,6 +314,32 @@ inline bool IOSystem::PopDirectory() {
|
|
}
|
|
}
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// ----------------------------------------------------------------------------
|
|
|
|
+AI_FORCE_INLINE
|
|
|
|
+bool IOSystem::CreateDirectory( const std::string &path ) {
|
|
|
|
+ if ( path.empty() ) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+#ifdef _WIN32
|
|
|
|
+ return 0 != ::_mkdir( path.c_str() );
|
|
|
|
+#else
|
|
|
|
+ return 0 != ::mkdir( path.c_str(), 0777 );
|
|
|
|
+#endif // _WIN32
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// ----------------------------------------------------------------------------
|
|
|
|
+AI_FORCE_INLINE
|
|
|
|
+bool IOSystem::ChangeDirectory( const std::string &path ) {
|
|
|
|
+ if ( path.empty() ) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+#ifdef _WIN32
|
|
|
|
+ return 0 != ::_chdir( path.c_str() );
|
|
|
|
+#else
|
|
|
|
+ return 0 != ::chdir( path.c_str() );
|
|
|
|
+#endif // _WIN32
|
|
|
|
+}
|
|
|
|
|
|
} //!ns Assimp
|
|
} //!ns Assimp
|
|
|
|
|