Daniele Bartolini 9 лет назад
Родитель
Сommit
9f09c302bf

+ 18 - 18
src/core/filesystem/apk_filesystem.cpp → src/core/filesystem/filesystem_apk.cpp

@@ -7,29 +7,29 @@
 
 #if CROWN_PLATFORM_ANDROID
 
-#include "apk_filesystem.h"
 #include "dynamic_string.h"
 #include "file.h"
+#include "filesystem_apk.h"
 #include "os.h"
 #include "temp_allocator.h"
 #include "vector.h"
 
 namespace crown
 {
-class ApkFile : public File
+class FileApk : public File
 {
 	AAssetManager* _asset_manager;
 	AAsset* _asset;
 
 public:
 
-	ApkFile(AAssetManager* asset_manager)
+	FileApk(AAssetManager* asset_manager)
 		: _asset_manager(asset_manager)
 		, _asset(NULL)
 	{
 	}
 
-	virtual ~ApkFile()
+	virtual ~FileApk()
 	{
 		close();
 	}
@@ -103,67 +103,67 @@ public:
 	}
 };
 
-ApkFilesystem::ApkFilesystem(Allocator& a, AAssetManager* asset_manager)
+FilesystemApk::FilesystemApk(Allocator& a, AAssetManager* asset_manager)
 	: _allocator(&a)
 	, _asset_manager(asset_manager)
 {
 }
 
-File* ApkFilesystem::open(const char* path, FileOpenMode::Enum mode)
+File* FilesystemApk::open(const char* path, FileOpenMode::Enum mode)
 {
 	CE_ASSERT_NOT_NULL(path);
 	CE_ASSERT(mode == FileOpenMode::READ, "Cannot open for writing in Android assets folder");
-	ApkFile* file = CE_NEW(*_allocator, ApkFile)(_asset_manager);
+	FileApk* file = CE_NEW(*_allocator, FileApk)(_asset_manager);
 	file->open(path, mode);
 	return file;
 }
 
-void ApkFilesystem::close(File& file)
+void FilesystemApk::close(File& file)
 {
 	CE_DELETE(*_allocator, &file);
 }
 
-bool ApkFilesystem::exists(const char* path)
+bool FilesystemApk::exists(const char* path)
 {
 	return false;
 }
 
-bool ApkFilesystem::is_directory(const char* path)
+bool FilesystemApk::is_directory(const char* path)
 {
 	return true;
 }
 
-bool ApkFilesystem::is_file(const char* path)
+bool FilesystemApk::is_file(const char* path)
 {
 	return true;
 }
 
-u64 ApkFilesystem::last_modified_time(const char* path)
+u64 FilesystemApk::last_modified_time(const char* path)
 {
 	return 0;
 }
 
-void ApkFilesystem::create_directory(const char* /*path*/)
+void FilesystemApk::create_directory(const char* /*path*/)
 {
 	CE_ASSERT(false, "Cannot create directory in Android assets folder");
 }
 
-void ApkFilesystem::delete_directory(const char* /*path*/)
+void FilesystemApk::delete_directory(const char* /*path*/)
 {
 	CE_ASSERT(false, "Cannot delete directory in Android assets folder");
 }
 
-void ApkFilesystem::create_file(const char* /*path*/)
+void FilesystemApk::create_file(const char* /*path*/)
 {
 	CE_ASSERT(false, "Cannot create file in Android assets folder");
 }
 
-void ApkFilesystem::delete_file(const char* /*path*/)
+void FilesystemApk::delete_file(const char* /*path*/)
 {
 	CE_ASSERT(false, "Cannot delete file in Android assets folder");
 }
 
-void ApkFilesystem::list_files(const char* path, Vector<DynamicString>& files)
+void FilesystemApk::list_files(const char* path, Vector<DynamicString>& files)
 {
 	CE_ASSERT_NOT_NULL(path);
 
@@ -182,7 +182,7 @@ void ApkFilesystem::list_files(const char* path, Vector<DynamicString>& files)
 	AAssetDir_close(root_dir);
 }
 
-void ApkFilesystem::get_absolute_path(const char* path, DynamicString& os_path)
+void FilesystemApk::get_absolute_path(const char* path, DynamicString& os_path)
 {
 	os_path = path;
 }

+ 2 - 2
src/core/filesystem/apk_filesystem.h → src/core/filesystem/filesystem_apk.h

@@ -19,14 +19,14 @@ namespace crown
 /// The assets folder is read-only and all the paths are relative.
 ///
 /// @ingroup Filesystem
-class ApkFilesystem : public Filesystem
+class FilesystemApk : public Filesystem
 {
 	Allocator* _allocator;
 	AAssetManager* _asset_manager;
 
 public:
 
-	ApkFilesystem(Allocator& a, AAssetManager* asset_manager);
+	FilesystemApk(Allocator& a, AAssetManager* asset_manager);
 
 	/// @copydoc Filesystem::open()
 	File* open(const char* path, FileOpenMode::Enum mode);

+ 19 - 19
src/core/filesystem/disk_filesystem.cpp → src/core/filesystem/filesystem_disk.cpp

@@ -3,9 +3,9 @@
  * License: https://github.com/taylor001/crown/blob/master/LICENSE
  */
 
-#include "disk_filesystem.h"
 #include "dynamic_string.h"
 #include "file.h"
+#include "filesystem_disk.h"
 #include "os.h"
 #include "path.h"
 #include "temp_allocator.h"
@@ -21,7 +21,7 @@
 
 namespace crown
 {
-class DiskFile : public File
+class FileDisk : public File
 {
 #if CROWN_PLATFORM_POSIX
 	FILE* _file;
@@ -33,7 +33,7 @@ class DiskFile : public File
 public:
 
 	/// Opens the file located at @a path with the given @a mode.
-	DiskFile()
+	FileDisk()
 #if CROWN_PLATFORM_POSIX
 		: _file(NULL)
 #elif CROWN_PLATFORM_WINDOWS
@@ -43,7 +43,7 @@ public:
 	{
 	}
 
-	virtual ~DiskFile()
+	virtual ~FileDisk()
 	{
 		close();
 	}
@@ -231,18 +231,18 @@ public:
 	}
 };
 
-DiskFilesystem::DiskFilesystem(Allocator& a)
+FilesystemDisk::FilesystemDisk(Allocator& a)
 	: _allocator(&a)
 	, _prefix(a)
 {
 }
 
-void DiskFilesystem::set_prefix(const char* prefix)
+void FilesystemDisk::set_prefix(const char* prefix)
 {
 	_prefix.set(prefix, strlen32(prefix));
 }
 
-File* DiskFilesystem::open(const char* path, FileOpenMode::Enum mode)
+File* FilesystemDisk::open(const char* path, FileOpenMode::Enum mode)
 {
 	CE_ASSERT_NOT_NULL(path);
 
@@ -250,17 +250,17 @@ File* DiskFilesystem::open(const char* path, FileOpenMode::Enum mode)
 	DynamicString abs_path(ta);
 	get_absolute_path(path, abs_path);
 
-	DiskFile* file = CE_NEW(*_allocator, DiskFile)();
+	FileDisk* file = CE_NEW(*_allocator, FileDisk)();
 	file->open(abs_path.c_str(), mode);
 	return file;
 }
 
-void DiskFilesystem::close(File& file)
+void FilesystemDisk::close(File& file)
 {
 	CE_DELETE(*_allocator, &file);
 }
 
-bool DiskFilesystem::exists(const char* path)
+bool FilesystemDisk::exists(const char* path)
 {
 	CE_ASSERT_NOT_NULL(path);
 
@@ -271,7 +271,7 @@ bool DiskFilesystem::exists(const char* path)
 	return os::exists(abs_path.c_str());
 }
 
-bool DiskFilesystem::is_directory(const char* path)
+bool FilesystemDisk::is_directory(const char* path)
 {
 	CE_ASSERT_NOT_NULL(path);
 
@@ -282,7 +282,7 @@ bool DiskFilesystem::is_directory(const char* path)
 	return os::is_directory(abs_path.c_str());
 }
 
-bool DiskFilesystem::is_file(const char* path)
+bool FilesystemDisk::is_file(const char* path)
 {
 	CE_ASSERT_NOT_NULL(path);
 
@@ -293,7 +293,7 @@ bool DiskFilesystem::is_file(const char* path)
 	return os::is_file(abs_path.c_str());
 }
 
-u64 DiskFilesystem::last_modified_time(const char* path)
+u64 FilesystemDisk::last_modified_time(const char* path)
 {
 	CE_ASSERT_NOT_NULL(path);
 
@@ -304,7 +304,7 @@ u64 DiskFilesystem::last_modified_time(const char* path)
 	return os::mtime(abs_path.c_str());
 }
 
-void DiskFilesystem::create_directory(const char* path)
+void FilesystemDisk::create_directory(const char* path)
 {
 	CE_ASSERT_NOT_NULL(path);
 
@@ -316,7 +316,7 @@ void DiskFilesystem::create_directory(const char* path)
 		os::create_directory(abs_path.c_str());
 }
 
-void DiskFilesystem::delete_directory(const char* path)
+void FilesystemDisk::delete_directory(const char* path)
 {
 	CE_ASSERT_NOT_NULL(path);
 
@@ -327,7 +327,7 @@ void DiskFilesystem::delete_directory(const char* path)
 	os::delete_directory(abs_path.c_str());
 }
 
-void DiskFilesystem::create_file(const char* path)
+void FilesystemDisk::create_file(const char* path)
 {
 	CE_ASSERT_NOT_NULL(path);
 
@@ -338,7 +338,7 @@ void DiskFilesystem::create_file(const char* path)
 	os::create_file(abs_path.c_str());
 }
 
-void DiskFilesystem::delete_file(const char* path)
+void FilesystemDisk::delete_file(const char* path)
 {
 	CE_ASSERT_NOT_NULL(path);
 
@@ -349,7 +349,7 @@ void DiskFilesystem::delete_file(const char* path)
 	os::delete_file(abs_path.c_str());
 }
 
-void DiskFilesystem::list_files(const char* path, Vector<DynamicString>& files)
+void FilesystemDisk::list_files(const char* path, Vector<DynamicString>& files)
 {
 	CE_ASSERT_NOT_NULL(path);
 
@@ -360,7 +360,7 @@ void DiskFilesystem::list_files(const char* path, Vector<DynamicString>& files)
 	os::list_files(abs_path.c_str(), files);
 }
 
-void DiskFilesystem::get_absolute_path(const char* path, DynamicString& os_path)
+void FilesystemDisk::get_absolute_path(const char* path, DynamicString& os_path)
 {
 	if (path::is_absolute(path))
 	{

+ 2 - 2
src/core/filesystem/disk_filesystem.h → src/core/filesystem/filesystem_disk.h

@@ -18,14 +18,14 @@ namespace crown
 /// but platform-specific and thus generally not recommended.
 ///
 /// @ingroup Filesystem
-class DiskFilesystem : public Filesystem
+class FilesystemDisk : public Filesystem
 {
 	Allocator* _allocator;
 	DynamicString _prefix;
 
 public:
 
-	DiskFilesystem(Allocator& a);
+	FilesystemDisk(Allocator& a);
 
 	/// Sets the root path to the given @a prefix.
 	/// @note

+ 0 - 72
src/core/filesystem/null_file.h

@@ -1,72 +0,0 @@
-/*
- * Copyright (c) 2012-2016 Daniele Bartolini and individual contributors.
- * License: https://github.com/taylor001/crown/blob/master/LICENSE
- */
-
-#pragma once
-
-#include "file.h"
-
-namespace crown
-{
-/// Bit bucket file.
-/// Discards all data written to it and provides null data reading from it; plain and simple.
-///
-/// @ingroup Filesystem
-class NullFile: public File
-{
-public:
-
-	/// @copydoc File::open()
-	void open(const char* /*path*/, FileOpenMode::Enum /*mode*/) {}
-
-	/// @copydoc File::close()
-	void close() {}
-
-	/// @copydoc File::size()
-	/// @note
-	///	Returns always 0xFFFFFFFF
-	u32 size() { return ~0; }
-
-	/// @copydoc File::position()
-	/// @note
-	///	Returns always zero
-	u32 position() { return 0; }
-
-	/// @copydoc File::end_of_file()
-	/// @note
-	///	Returns always false
-	bool end_of_file() { return false; }
-
-	/// @copydoc File::seek()
-	void seek(u32 position) { (void)position; }
-
-	/// @copydoc File::seek_to_end()
-	void seek_to_end() {}
-
-	/// @copydoc File::skip()
-	void skip(u32 bytes) { (void)bytes; }
-
-	/// @copydoc File::read()
-	/// @note
-	///	Fills buffer with zeroes
-	u32 read(void* data, u32 size)
-	{
-		for (u32 i = 0; i < size; ++i)
-		{
-			((u8*)data)[i] = 0;
-		}
-		return size;
-	}
-
-	/// @copydoc File::write()
-	u32 write(const void* /*data*/, u32 size)
-	{
-		return size;
-	}
-
-	/// @copydoc File::flush()
-	void flush() {};
-};
-
-} // namespace crown

+ 5 - 5
src/device/device.cpp

@@ -3,7 +3,6 @@
  * License: https://github.com/taylor001/crown/blob/master/LICENSE
  */
 
-#include "apk_filesystem.h"
 #include "array.h"
 #include "audio.h"
 #include "bundle_compiler.h"
@@ -11,9 +10,10 @@
 #include "config_resource.h"
 #include "console_server.h"
 #include "device.h"
-#include "disk_filesystem.h"
 #include "file.h"
 #include "filesystem.h"
+#include "filesystem_apk.h"
+#include "filesystem_disk.h"
 #include "font_resource.h"
 #include "input_device.h"
 #include "input_manager.h"
@@ -415,7 +415,7 @@ void Device::run()
 	if (do_continue)
 	{
 #if CROWN_PLATFORM_ANDROID
-		_bundle_filesystem = CE_NEW(_allocator, ApkFilesystem)(default_allocator(), const_cast<AAssetManager*>((AAssetManager*)_device_options._asset_manager));
+		_bundle_filesystem = CE_NEW(_allocator, FilesystemApk)(default_allocator(), const_cast<AAssetManager*>((AAssetManager*)_device_options._asset_manager));
 #else
 		const char* bundle_dir = _device_options._bundle_dir;
 		if (!bundle_dir)
@@ -423,8 +423,8 @@ void Device::run()
 			char buf[1024];
 			bundle_dir = os::getcwd(buf, sizeof(buf));
 		}
-		_bundle_filesystem = CE_NEW(_allocator, DiskFilesystem)(default_allocator());
-		((DiskFilesystem*)_bundle_filesystem)->set_prefix(bundle_dir);
+		_bundle_filesystem = CE_NEW(_allocator, FilesystemDisk)(default_allocator());
+		((FilesystemDisk*)_bundle_filesystem)->set_prefix(bundle_dir);
 		if (!_bundle_filesystem->exists(bundle_dir))
 			_bundle_filesystem->create_directory(bundle_dir);
 

+ 3 - 3
src/resource/bundle_compiler.cpp

@@ -8,9 +8,9 @@
 #include "compile_options.h"
 #include "config.h"
 #include "console_server.h"
-#include "disk_filesystem.h"
 #include "dynamic_string.h"
 #include "file.h"
+#include "filesystem_disk.h"
 #include "log.h"
 #include "map.h"
 #include "os.h"
@@ -137,7 +137,7 @@ void BundleCompiler::scan(const char* source_dir)
 	scan_source_dir("");
 }
 
-bool BundleCompiler::compile(DiskFilesystem& bundle_fs, const char* type, const char* name, const char* platform)
+bool BundleCompiler::compile(FilesystemDisk& bundle_fs, const char* type, const char* name, const char* platform)
 {
 	StringId64 _type(type);
 	StringId64 _name(name);
@@ -193,7 +193,7 @@ bool BundleCompiler::compile(DiskFilesystem& bundle_fs, const char* type, const
 bool BundleCompiler::compile(const char* bundle_dir, const char* platform)
 {
 	// Create bundle dir if necessary
-	DiskFilesystem bundle_fs(default_allocator());
+	FilesystemDisk bundle_fs(default_allocator());
 	bundle_fs.set_prefix(bundle_dir);
 	bundle_fs.create_directory("");
 

+ 3 - 3
src/resource/bundle_compiler.h

@@ -7,7 +7,7 @@
 
 #include "compile_options.h"
 #include "container_types.h"
-#include "disk_filesystem.h"
+#include "filesystem_disk.h"
 
 namespace crown
 {
@@ -21,14 +21,14 @@ class BundleCompiler
 		CompileFunction compiler;
 	};
 
-	DiskFilesystem _source_fs;
+	FilesystemDisk _source_fs;
 	SortMap<StringId64, ResourceTypeData> _compilers;
 	Vector<DynamicString> _files;
 	Vector<DynamicString> _globs;
 
 	void compile(StringId64 type, const char* path, CompileOptions& opts);
 	void scan_source_dir(const char* path);
-	bool compile(DiskFilesystem& bundle_fs, const char* type, const char* name, const char* platform);
+	bool compile(FilesystemDisk& bundle_fs, const char* type, const char* name, const char* platform);
 
 public: