Просмотр исходного кода

Add is_file and is_directory, also fix a bug in get_absolute_path

Daniele Bartolini 12 лет назад
Родитель
Сommit
6b575c85bd

+ 25 - 1
engine/core/filesystem/DiskFilesystem.cpp

@@ -67,6 +67,30 @@ void DiskFilesystem::close(File* file)
 	CE_DELETE(default_allocator(), file);
 }
 
+//-----------------------------------------------------------------------------
+bool DiskFilesystem::is_directory(const char* path)
+{
+	CE_ASSERT_NOT_NULL(path);
+
+	TempAllocator256 alloc;
+	DynamicString abs_path(alloc);
+	get_absolute_path(path, abs_path);
+
+	return os::is_directory(abs_path.c_str());
+}
+
+//-----------------------------------------------------------------------------
+bool DiskFilesystem::is_file(const char* path)
+{
+	CE_ASSERT_NOT_NULL(path);
+
+	TempAllocator256 alloc;
+	DynamicString abs_path(alloc);
+	get_absolute_path(path, abs_path);
+
+	return os::is_file(abs_path.c_str());
+}
+
 //-----------------------------------------------------------------------------
 void DiskFilesystem::create_directory(const char* path)
 {
@@ -124,7 +148,7 @@ void DiskFilesystem::list_files(const char* path, Vector<DynamicString>& files)
 	DynamicString abs_path(alloc);
 	get_absolute_path(path, abs_path);
 
-	os::list_files(path, files);
+	os::list_files(abs_path.c_str(), files);
 }
 
 //-----------------------------------------------------------------------------

+ 6 - 0
engine/core/filesystem/DiskFilesystem.h

@@ -57,6 +57,12 @@ public:
 	/// Closes the given @a file.
 	void close(File* file);
 
+	/// Returns true if @a path is a directory.
+	bool is_directory(const char* path);
+
+	/// Returns true if @a path is a regular file.
+	bool is_file(const char* path);
+
 	/// Creates the directory at the given @a path.
 	void create_directory(const char* path);
 

+ 6 - 0
engine/core/filesystem/Filesystem.h

@@ -91,6 +91,12 @@ public:
 	/// Closes the given @a file.
 	virtual void		close(File* file) = 0;
 
+	/// Returns true if @a path is a directory.
+	virtual bool		is_directory(const char* path) = 0;
+
+	/// Returns true if @a path is a regular file.
+	virtual bool		is_file(const char* path) = 0;
+
 	/// Creates the directory at the given @a path.
 	virtual void		create_directory(const char* path) = 0;