Prechádzať zdrojové kódy

core: add Filesystem::rename()

Daniele Bartolini 1 rok pred
rodič
commit
069d2e8172

+ 3 - 0
src/core/filesystem/filesystem.h

@@ -64,6 +64,9 @@ struct Filesystem
 	/// Deletes the file at the given @a path.
 	/// Deletes the file at the given @a path.
 	virtual DeleteResult delete_file(const char *path) = 0;
 	virtual DeleteResult delete_file(const char *path) = 0;
 
 
+	/// Renames the file at @a old_path to @a new_path.
+	virtual RenameResult rename(const char *old_path, const char *new_path) = 0;
+
 	/// Returns the relative file names in the given @a path.
 	/// Returns the relative file names in the given @a path.
 	virtual void list_files(const char *path, Vector<DynamicString> &files) = 0;
 	virtual void list_files(const char *path, Vector<DynamicString> &files) = 0;
 
 

+ 9 - 0
src/core/filesystem/filesystem_apk.cpp

@@ -192,6 +192,15 @@ DeleteResult FilesystemApk::delete_file(const char *path)
 	return dr;
 	return dr;
 }
 }
 
 
+RenameResult FilesystemApk::rename(const char *old_path, const char *new_path)
+{
+	CE_UNUSED_2(old_path, new_path);
+	CE_FATAL("Cannot rename file in Android assets folder");
+	RenameResult rr;
+	rr.error = RenameResult::UNKNOWN;
+	return rr;
+}
+
 void FilesystemApk::list_files(const char *path, Vector<DynamicString> &files)
 void FilesystemApk::list_files(const char *path, Vector<DynamicString> &files)
 {
 {
 	CE_ENSURE(NULL != path);
 	CE_ENSURE(NULL != path);

+ 3 - 0
src/core/filesystem/filesystem_apk.h

@@ -55,6 +55,9 @@ struct FilesystemApk : public Filesystem
 	/// @copydoc Filesystem::delete_file()
 	/// @copydoc Filesystem::delete_file()
 	DeleteResult delete_file(const char *path) override;
 	DeleteResult delete_file(const char *path) override;
 
 
+	/// @copydoc Filesystem::rename()
+	RenameResult rename(const char *old_path, const char *new_path) override;
+
 	/// @copydoc Filesystem::list_files()
 	/// @copydoc Filesystem::list_files()
 	void list_files(const char *path, Vector<DynamicString> &files) override;
 	void list_files(const char *path, Vector<DynamicString> &files) override;
 
 

+ 13 - 0
src/core/filesystem/filesystem_disk.cpp

@@ -336,6 +336,19 @@ DeleteResult FilesystemDisk::delete_file(const char *path)
 	return os::delete_file(abs_path.c_str());
 	return os::delete_file(abs_path.c_str());
 }
 }
 
 
+RenameResult FilesystemDisk::rename(const char *old_path, const char *new_path)
+{
+	CE_ENSURE(old_path != NULL);
+	CE_ENSURE(new_path != NULL);
+
+	DynamicString old_abs_path(default_allocator());
+	DynamicString new_abs_path(default_allocator());
+	absolute_path(old_abs_path, old_path);
+	absolute_path(new_abs_path, new_path);
+
+	return os::rename(old_abs_path.c_str(), new_abs_path.c_str());
+}
+
 void FilesystemDisk::list_files(const char *path, Vector<DynamicString> &files)
 void FilesystemDisk::list_files(const char *path, Vector<DynamicString> &files)
 {
 {
 	CE_ENSURE(NULL != path);
 	CE_ENSURE(NULL != path);

+ 3 - 0
src/core/filesystem/filesystem_disk.h

@@ -65,6 +65,9 @@ struct FilesystemDisk : public Filesystem
 	/// @copydoc Filesystem::delete_file()
 	/// @copydoc Filesystem::delete_file()
 	DeleteResult delete_file(const char *path) override;
 	DeleteResult delete_file(const char *path) override;
 
 
+	/// @copydoc Filesystem::rename()
+	RenameResult rename(const char *old_path, const char *new_path);
+
 	/// @copydoc Filesystem::list_files()
 	/// @copydoc Filesystem::list_files()
 	void list_files(const char *path, Vector<DynamicString> &files) override;
 	void list_files(const char *path, Vector<DynamicString> &files) override;