Daniele Bartolini 10 лет назад
Родитель
Сommit
28b8ef101d

+ 2 - 23
src/core/filesystem/apk_file.cpp

@@ -54,24 +54,18 @@ void ApkFile::skip(uint32_t bytes)
 	CE_UNUSED(seek_result);
 }
 
-uint32_t ApkFile::read(void* buffer, uint32_t size)
+uint32_t ApkFile::read(void* data, uint32_t size)
 {
 	CE_ASSERT_NOT_NULL(buffer);
 	return (uint32_t)AAsset_read(_asset, buffer, size);
 }
 
-uint32_t ApkFile::write(const void* /*buffer*/, uint32_t /*size*/)
+uint32_t ApkFile::write(const void* /*data*/, uint32_t /*size*/)
 {
 	CE_ASSERT(false, "Apk files are read only!");
 	return 0;
 }
 
-bool ApkFile::copy_to(File& /*file*/, uint32_t /*size = 0*/)
-{
-	CE_ASSERT(false, "Not implemented");
-	return false;
-}
-
 void ApkFile::flush()
 {
 	// Not needed
@@ -97,21 +91,6 @@ uint32_t ApkFile::position()
 	return (uint32_t)(AAsset_getLength(_asset) - AAsset_getRemainingLength(_asset));
 }
 
-bool ApkFile::can_read() const
-{
-	return true;
-}
-
-bool ApkFile::can_write() const
-{
-	return false;
-}
-
-bool ApkFile::can_seek() const
-{
-	return true;
-}
-
 } // namespace crown
 
 #endif // CROWN_PLATFORM_ANDROID

+ 2 - 14
src/core/filesystem/apk_file.h

@@ -30,13 +30,10 @@ public:
 	void skip(uint32_t bytes);
 
 	/// @copydoc File::read()
-	uint32_t read(void* buffer, uint32_t size);
+	uint32_t read(void* data, uint32_t size);
 
 	/// @copydoc File::write()
-	uint32_t write(const void* buffer, uint32_t size);
-
-	/// @copydoc File::copy_to()
-	bool copy_to(File& file, uint32_t size = 0);
+	uint32_t write(const void* data, uint32_t size);
 
 	/// @copydoc File::flush()
 	void flush();
@@ -53,15 +50,6 @@ public:
 	/// @copydoc File::position()
 	uint32_t position();
 
-	/// @copydoc File::can_read()
-	bool can_read() const;
-
-	/// @copydoc File::can_write()
-	bool can_write() const;
-
-	/// @copydoc File::can_seek()
-	bool can_seek() const;
-
 private:
 
 	AAsset* _asset;

+ 4 - 82
src/core/filesystem/disk_file.cpp

@@ -13,7 +13,6 @@ namespace crown
 
 DiskFile::DiskFile(FileOpenMode mode, const char* path)
 	: File(mode)
-	, _last_was_read(true)
 {
 	_file.open(path, mode);
 }
@@ -26,86 +25,31 @@ DiskFile::~DiskFile()
 void DiskFile::seek(uint32_t position)
 {
 	check_valid();
-
 	_file.seek(position);
 }
 
 void DiskFile::seek_to_end()
 {
 	check_valid();
-
 	_file.seek_to_end();
 }
 
 void DiskFile::skip(uint32_t bytes)
 {
 	check_valid();
-
 	_file.skip(bytes);
 }
 
-uint32_t DiskFile::read(void* buffer, uint32_t size)
+uint32_t DiskFile::read(void* data, uint32_t size)
 {
 	check_valid();
-
-	if (!_last_was_read)
-	{
-		_last_was_read = true;
-		_file.seek(0);
-	}
-
-	return _file.read(buffer, size);
+	return _file.read(data, size);
 }
 
-uint32_t DiskFile::write(const void* buffer, uint32_t size)
+uint32_t DiskFile::write(const void* data, uint32_t size)
 {
 	check_valid();
-
-	if (_last_was_read)
-	{
-		_last_was_read = false;
-		_file.seek(0);
-	}
-
-	return _file.write(buffer, size);
-}
-
-bool DiskFile::copy_to(File& file, uint32_t size)
-{
-	check_valid();
-
-	const uint32_t chunksize = 1024*1024;
-
-	char* buff = (char*) default_allocator().allocate(chunksize * sizeof(char));
-
-	uint32_t tot_read_bytes = 0;
-
-	while (tot_read_bytes < size)
-	{
-		uint32_t expected_read_bytes = std::min(size - tot_read_bytes, chunksize);
-		uint32_t read_bytes = _file.read(buff, expected_read_bytes);
-
-		if (read_bytes < expected_read_bytes)
-		{
-			if (_file.eof())
-			{
-				if (read_bytes != 0)
-				{
-					file.write(buff, read_bytes);
-				}
-			}
-
-			default_allocator().deallocate(buff);
-			//Either the file gave an error, or ended before size bytes could be copied
-			return false;
-		}
-
-		file.write(buff, read_bytes);
-		tot_read_bytes += read_bytes;
-	}
-
-	default_allocator().deallocate(buff);
-	return true;
+	return _file.write(data, size);
 }
 
 bool DiskFile::end_of_file()
@@ -121,41 +65,19 @@ bool DiskFile::is_valid()
 void DiskFile::flush()
 {
 	check_valid();
-
 	// FIXME implement flush in File
 }
 
 uint32_t DiskFile::position()
 {
 	check_valid();
-
 	return _file.position();
 }
 
 uint32_t DiskFile::size()
 {
 	check_valid();
-
 	return _file.size();
 }
 
-bool DiskFile::can_read() const
-{
-	check_valid();
-
-	return true;
-}
-
-bool DiskFile::can_write() const
-{
-	check_valid();
-
-	return true;
-}
-
-bool DiskFile::can_seek() const
-{
-	return true;
-}
-
 } // namespace crown

+ 2 - 15
src/core/filesystem/disk_file.h

@@ -33,13 +33,10 @@ public:
 	void skip(uint32_t bytes);
 
 	/// @copydoc File::read()
-	uint32_t read(void* buffer, uint32_t size);
+	uint32_t read(void* data, uint32_t size);
 
 	/// @copydoc File::write()
-	uint32_t write(const void* buffer, uint32_t size);
-
-	/// @copydoc File::copy_to()
-	bool copy_to(File& file, uint32_t size = 0);
+	uint32_t write(const void* data, uint32_t size);
 
 	/// @copydoc File::flush()
 	void flush();
@@ -56,19 +53,9 @@ public:
 	/// @copydoc File::position()
 	uint32_t position();
 
-	/// @copydoc File::can_read()
-	bool can_read() const;
-
-	/// @copydoc File::can_write()
-	bool can_write() const;
-
-	/// @copydoc File::can_seek()
-	bool can_seek() const;
-
 protected:
 
 	OsFile _file;
-	bool _last_was_read;
 
 protected:
 

+ 2 - 27
src/core/filesystem/file.h

@@ -16,16 +16,8 @@ enum FileOpenMode
 	FOM_WRITE		= 2
 };
 
-class Compressor;
-
 /// An abstraction to access data files.
 ///
-/// It represents a flow of data attached to a 'file' which can be an archived file,
-/// a regular file, a location in memory or anything that can be read or wrote.
-/// A File is an abstraction to interact with these in an uniform way; every file
-/// comes with a convenient set of methods to facilitate reading from it, writing to
-/// it and so on.
-///
 /// @ingroup Filesystem
 class File
 {
@@ -45,20 +37,12 @@ public:
 	virtual void skip(uint32_t bytes) = 0;
 
 	/// Reads a block of data from the file.
-	virtual uint32_t read(void* buffer, uint32_t size) = 0;
+	virtual uint32_t read(void* data, uint32_t size) = 0;
 
 	/// Writes a block of data to the file.
-	virtual uint32_t write(const void* buffer, uint32_t size) = 0;
-
-	/// Copies a chunk of 'size' bytes of data from this to another file.
-	virtual bool copy_to(File& file, uint32_t size = 0) = 0;
+	virtual uint32_t write(const void* data, uint32_t size) = 0;
 
 	/// Forces the previouses write operations to complete.
-	/// Generally, when a File is attached to a file,
-	/// write operations are not performed instantly, the output data
-	/// may be stored to a temporary buffer before making its way to
-	/// the file. This method forces all the pending output operations
-	/// to be written to the file.
 	virtual void flush() = 0;
 
 	/// Returns whether the file is valid.
@@ -78,15 +62,6 @@ public:
 	/// from the beginning of the file.
 	virtual uint32_t position() = 0;
 
-	/// Returns whether the file can be read.
-	virtual bool can_read() const = 0;
-
-	/// Returns whether the file can be wrote.
-	virtual bool can_write() const = 0;
-
-	/// Returns whether the file can be sought.
-	virtual bool can_seek() const = 0;
-
 protected:
 
 	FileOpenMode _open_mode;