Procházet zdrojové kódy

Add Filesystem::last_modified_time()

Daniele Bartolini před 10 roky
rodič
revize
820384642c

+ 5 - 0
src/core/filesystem/apk_filesystem.cpp

@@ -47,6 +47,11 @@ bool ApkFilesystem::is_file(const char* path)
 	return true;
 }
 
+uint64_t ApkFilesystem::last_modified_time(const char* path)
+{
+	return 0;
+}
+
 void ApkFilesystem::create_directory(const char* /*path*/)
 {
 	CE_ASSERT(false, "Attempt to create directory in Android assets folder");

+ 12 - 14
src/core/filesystem/apk_filesystem.h

@@ -25,41 +25,39 @@ public:
 	ApkFilesystem(AAssetManager* asset_manager);
 
 	/// @copydoc Filesystem::open()
-	/// @note
-	/// @a mode can only be FOM_READ
 	File* open(const char* path, FileOpenMode::Enum mode);
 
 	/// @copydoc Filesystem::close()
 	void close(File& file);
 
-	/// Returns always false under Android.
+	/// @copydoc Filesystem::exists()
 	bool exists(const char* path);
 
-	/// Returns always false under Android.
+	/// @copydoc Filesystem::is_directory()
 	bool is_directory(const char* path);
 
-	/// Returns always false under Android.
+	/// @copydoc Filesystem::is_file()
 	bool is_file(const char* path);
 
-	/// Stub method, assets folder is read-only.
+	/// @copydoc Filesystem::last_modified_time()
+	uint64_t last_modified_time(const char* path);
+
+	/// @copydoc Filesystem::create_directory()
 	void create_directory(const char* path);
 
-	/// Stub method, assets folder is read-only.
+	/// @copydoc Filesystem::delete_directory()
 	void delete_directory(const char* path);
 
-	/// Stub method, assets folder is read-only.
+	/// @copydoc Filesystem::create_file()
 	void create_file(const char* path);
 
-	/// Stub method, assets folder is read-only.
+	/// @copydoc Filesystem::delete_file()
 	void delete_file(const char* path);
 
-	/// @copydoc Filesystem::list_files().
+	/// @copydoc Filesystem::list_files()
 	void list_files(const char* path, Vector<DynamicString>& files);
 
-	/// Returns the absolute path of the given @a path.
-	/// @note
-	/// Assets folder has no concept of "absolute path", all paths are
-	/// relative to the assets folder itself, so, all paths are returned unchanged.
+	/// @copydoc Filesystem::get_absolute_path()
 	void get_absolute_path(const char* path, DynamicString& os_path);
 
 private:

+ 11 - 0
src/core/filesystem/disk_filesystem.cpp

@@ -76,6 +76,17 @@ bool DiskFilesystem::is_file(const char* path)
 	return os::is_file(abs_path.c_str());
 }
 
+uint64_t DiskFilesystem::last_modified_time(const char* path)
+{
+	CE_ASSERT_NOT_NULL(path);
+
+	TempAllocator256 alloc;
+	DynamicString abs_path(alloc);
+	get_absolute_path(path, abs_path);
+
+	return os::mtime(abs_path.c_str());
+}
+
 void DiskFilesystem::create_directory(const char* path)
 {
 	CE_ASSERT_NOT_NULL(path);

+ 14 - 13
src/core/filesystem/disk_filesystem.h

@@ -31,39 +31,40 @@ public:
 	/// The @a prefix must be absolute.
 	DiskFilesystem(const char* prefix);
 
-	/// Opens the file at the given @a path with the given @a mode.
+	/// @copydoc Filesystem::open()
 	File* open(const char* path, FileOpenMode::Enum mode);
 
-	/// Closes the given @a file.
+	/// @copydoc Filesystem::close()
 	void close(File& file);
 
-	/// Returns whether @a path exists.
+	/// @copydoc Filesystem::exists()
 	bool exists(const char* path);
 
-	/// Returns true if @a path is a directory.
+	/// @copydoc Filesystem::is_directory()
 	bool is_directory(const char* path);
 
-	/// Returns true if @a path is a regular file.
+	/// @copydoc Filesystem::is_file()
 	bool is_file(const char* path);
 
-	/// Creates the directory at the given @a path.
+	/// @copydoc Filesystem::last_modified_time()
+	uint64_t last_modified_time(const char* path);
+
+	/// @copydoc Filesystem::create_directory()
 	void create_directory(const char* path);
 
-	/// Deletes the directory at the given @a path.
+	/// @copydoc Filesystem::delete_directory()
 	void delete_directory(const char* path);
 
-	/// Creates the file at the given @a path.
+	/// @copydoc Filesystem::create_file()
 	void create_file(const char* path);
 
-	/// Deletes the file at the given @a path.
+	/// @copydoc Filesystem::delete_file()
 	void delete_file(const char* path);
 
-	/// Returns the relative file names in the given @a path.
+	/// @copydoc Filesystem::list_files()
 	void list_files(const char* path, Vector<DynamicString>& files);
 
-	/// Returns the absolute path of the given @a path based on
-	/// the root path of the file source. If @a path is absolute,
-	/// the given path is returned.
+	/// @copydoc Filesystem::get_absolute_path()
 	void get_absolute_path(const char* path, DynamicString& os_path);
 
 private:

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

@@ -40,6 +40,9 @@ public:
 	/// Returns true if @a path is a regular file.
 	virtual bool is_file(const char* path) = 0;
 
+	/// Returns the time of last modify operaton to @a path.
+	virtual uint64_t last_modified_time(const char* path) = 0;
+
 	/// Creates the directory at the given @a path.
 	virtual void create_directory(const char* path) = 0;