Feature request: Create folders with IFileSystem

Discuss about anything related to the Irrlicht Engine, or read announcements about any significant features or usage changes.
Post Reply
Sylence
Posts: 725
Joined: Sat Mar 03, 2007 9:01 pm
Location: Germany
Contact:

Feature request: Create folders with IFileSystem

Post by Sylence »

I just noticed that IFileSystem offers no functionality to create new folders and I thought that would be a nice thing to have so here is the patch:

Code: Select all

Index: include/IFileSystem.h
===================================================================
--- include/IFileSystem.h	(Revision 2143)
+++ include/IFileSystem.h	(Arbeitskopie)
@@ -212,6 +212,11 @@
 	If you no longer need the object, you should call IAttributes::drop().
 	See IReferenceCounted::drop() for more information. */
 	virtual IAttributes* createEmptyAttributes(video::IVideoDriver* driver=0) = 0;
+	
+	//! Creates a new directory in the current working dir
+	/** \param dirname: Name of the directory that should be created
+	\return Returns true if the directory was created, and false if an error occured */
+	virtual bool createDir( const c8* dirname ) const = 0;
 };
 
 } // end namespace io
Index: source/Irrlicht/CFileSystem.cpp
===================================================================
--- source/Irrlicht/CFileSystem.cpp	(Revision 2143)
+++ source/Irrlicht/CFileSystem.cpp	(Arbeitskopie)
@@ -404,7 +404,23 @@
 	return new CAttributes(driver);
 }
 
+//! Creates a new directory in the current working dir
+bool CFileSystem::createDir( const c8* dirname ) const
+{
+#ifdef _IRR_WINDOWS_API_
+	if( _mkdir( dirname ) != 0)
+#else
+	if( mkdir( dirname, 777 ) != 0 )
+#endif
+	{
+		_IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
+		return false;
+	}
+	
+	return true;
+}
 
+
 } // end namespace irr
 } // end namespace io
 
Index: source/Irrlicht/CFileSystem.h
===================================================================
--- source/Irrlicht/CFileSystem.h	(Revision 2143)
+++ source/Irrlicht/CFileSystem.h	(Arbeitskopie)
@@ -103,6 +103,9 @@
 
 	//! Creates a new empty collection of attributes, usable for serialization and more.
 	virtual IAttributes* createEmptyAttributes(video::IVideoDriver* driver);
+	
+	//! Creates a new directory in the current working dir
+	virtual bool createDir( const c8* dirname ) const;
 
 private:
 

Tracker URL: https://sourceforge.net/tracker/index.p ... tid=540679
Software documentation is like sex. If it's good you want more. If it's bad it's better than nothing.
Nox
Posts: 304
Joined: Wed Jan 14, 2009 6:23 pm

Post by Nox »

Hell its about time
Nice one! May be you have an idea to integrate this in the filemethods so that non existing folders would be created automaticly if a bool is set (or something like this :)).
By the way, 777...is not it a bit to loose?
Sylence
Posts: 725
Joined: Sat Mar 03, 2007 9:01 pm
Location: Germany
Contact:

Post by Sylence »

Well yes, but I can't image a scenario where 777 would be bad since this is not for hardcore security but just a quick way to create a folder. However changing to 644 shouldn't make any problems.
Software documentation is like sex. If it's good you want more. If it's bad it's better than nothing.
Dorth
Posts: 931
Joined: Sat May 26, 2007 11:03 pm

Post by Dorth »

It should actually do the default behavior of most OS. Copy the security of the folder containing it.
Post Reply