Explorar o código

Delete MountPoint & Co.

Daniele Bartolini %!s(int64=12) %!d(string=hai) anos
pai
achega
f5f428a153

+ 0 - 203
engine/core/filesystem/DiskMountPoint.cpp

@@ -1,203 +0,0 @@
-/*
-Copyright (c) 2013 Daniele Bartolini, Michele Rossi
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#include "DiskMountPoint.h"
-#include "Assert.h"
-#include "DiskFile.h"
-#include "StringUtils.h"
-#include "Allocator.h"
-
-namespace crown
-{
-
-//-----------------------------------------------------------------------------
-DiskMountPoint::DiskMountPoint() : MountPoint(DISK_TYPE)
-{
-}
-
-//-----------------------------------------------------------------------------
-File* DiskMountPoint::open(const char* relative_path, FileOpenMode mode)
-{
-	CE_ASSERT(exists(relative_path), "File does not exist: %s", relative_path);
-	CE_ASSERT(is_file(relative_path), "File is not a regular file: %s", relative_path);
-
-	return CE_NEW(default_allocator(), DiskFile)(mode, os_path(relative_path));
-}
-
-//-----------------------------------------------------------------------------
-void DiskMountPoint::close(File* file)
-{
-	CE_DELETE(default_allocator(), file);
-}
-
-//-----------------------------------------------------------------------------
-void DiskMountPoint::set_root_path(const char* root_path)
-{
-	CE_ASSERT(root_path != NULL, "Root path must be != NULL");
-	CE_ASSERT(os::is_absolute_path(root_path), "Root path must be absolute");
-
-	string::strncpy(m_root_path, root_path, MAX_PATH_LENGTH);
-}
-
-//-----------------------------------------------------------------------------
-const char*	DiskMountPoint::root_path() const
-{
-	return m_root_path;
-}
-
-//-----------------------------------------------------------------------------
-bool DiskMountPoint::exists(const char* relative_path)
-{
-	MountPointEntry info;
-
-	return get_info(relative_path, info);	
-}
-//-----------------------------------------------------------------------------
-bool DiskMountPoint::get_info(const char* relative_path, MountPointEntry& info)
-{
-	// Entering OS-DEPENDENT-PATH-MODE
-	// (i.e. os_path is of the form: C:\foo\relative_path or /foo/relative_path)
-
-	const char* os_path = build_os_path(m_root_path, relative_path);
-
-	string::strncpy(info.os_path, os_path, MAX_PATH_LENGTH);
-	string::strncpy(info.relative_path, relative_path, MAX_PATH_LENGTH);
-
-	if (os::is_file(os_path))
-	{
-		info.type = MountPointEntry::FILE;
-		return true;
-	}
-	else if (os::is_directory(os_path))
-	{
-		info.type = MountPointEntry::DIRECTORY;
-		return true;
-	}
-	
-	info.type = MountPointEntry::UNKNOWN;
-
-	return false;
-}
-
-//-----------------------------------------------------------------------------
-bool DiskMountPoint::is_file(const char* relative_path)
-{
-	MountPointEntry info;
-
-	if (get_info(relative_path, info))
-	{
-		return info.type == MountPointEntry::FILE;
-	}
-
-	return false;
-}
-
-//-----------------------------------------------------------------------------
-bool DiskMountPoint::is_dir(const char* relative_path)
-{
-	MountPointEntry info;
-
-	if (get_info(relative_path, info))
-	{
-		return info.type == MountPointEntry::DIRECTORY;
-	}
-
-	return false;
-}
-
-//-----------------------------------------------------------------------------
-bool DiskMountPoint::create_file(const char* relative_path)
-{
-	const char* os_path = build_os_path(m_root_path, relative_path);
-
-	return os::create_file(os_path);
-}
-
-//-----------------------------------------------------------------------------
-bool DiskMountPoint::create_dir(const char* relative_path)
-{
-	const char* os_path = build_os_path(m_root_path, relative_path);
-
-	return os::create_directory(os_path);
-}
-
-//-----------------------------------------------------------------------------
-bool DiskMountPoint::delete_file(const char* relative_path)
-{
-	const char* os_path = build_os_path(m_root_path, relative_path);
-
-	return os::delete_file(os_path);
-}
-
-//-----------------------------------------------------------------------------
-bool DiskMountPoint::delete_dir(const char* relative_path)
-{
-	const char* os_path = build_os_path(m_root_path, relative_path);
-
-	return os::delete_directory(os_path);
-}
-
-//-----------------------------------------------------------------------------
-const char* DiskMountPoint::os_path(const char* relative_path)
-{
-	static char os_path[MAX_PATH_LENGTH];
-
-	MountPointEntry entry;
-
-	get_info(relative_path, entry);
-
-	string::strncpy(os_path, entry.os_path, MAX_PATH_LENGTH);
-
-	return os_path;
-}
-
-//-----------------------------------------------------------------------------
-const char* DiskMountPoint::build_os_path(const char* base_path, const char* relative_path)
-{
-	static char os_path[MAX_PATH_LENGTH];
-
-	string::strncpy(os_path, base_path, MAX_PATH_LENGTH);
-
-	size_t base_path_len = string::strlen(base_path);
-
-	os_path[base_path_len] = PATH_SEPARATOR;
-	os_path[base_path_len + 1] = '\0';
-
-	string::strcat(os_path, relative_path);
-
-	// FIXME FIXME FIXME Replace Crown-specific path separator with OS-specific one
-	for (size_t j = 0; j < string::strlen(os_path); j++)
-	{
-		if (os_path[j] == '/')
-		{
-			os_path[j] = PATH_SEPARATOR;
-		}
-	}
-
-	return os_path;
-}
-
-} // namespace crown

+ 0 - 92
engine/core/filesystem/DiskMountPoint.h

@@ -1,92 +0,0 @@
-/*
-Copyright (c) 2013 Daniele Bartolini, Michele Rossi
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#pragma once
-
-#include "MountPoint.h"
-
-namespace crown
-{
-
-class DiskMountPoint : public MountPoint
-{
-public:
-						DiskMountPoint();
-
-	/// Opens file @a relative_path in specified @a mode
-	File*				open(const char* relative_path, FileOpenMode mode);
-
-	/// Closes @a file
-	void				close(File* file);
-
-	/// Sets @a root_path
-	void				set_root_path(const char* root_path);
-
-	/// Returns the root path of the mount point
-	const char*			root_path() const;
-
-	/// Returns true if file @a relative_path exists
-	bool				exists(const char* relative_path);
-
-	/// Returns whether the @a relative_path exists and fills @a info with
-	/// with informations about the given @a relative_path path
-	bool				get_info(const char* relative_path, MountPointEntry& info);
-	
-	/// Returns whether @a relative_path is a regular file
-	bool				is_file(const char* relative_path);
-
-	/// Returns whether @a relative_path is a directory
-	bool				is_dir(const char* relative_path);
-
-	/// Creates a regular file called @a relative_path
-	bool				create_file(const char* relative_path);
-
-	/// Creates a directory called @a relative_path
-	bool 				create_dir(const char* relative_path);
-
-	/// Deletes a regular file called @a relative_path
-	bool				delete_file(const char* relative_path);
-
-	/// Deletes a directory called @a relative_path
-	bool 				delete_dir(const char* relative_path);
-
-	/// Returns the os-specific path which @a relative_path refers to.
-	/// @note
-	/// In general, you typically do not want to use it for normal
-	/// file interactions. Prefer using the other methods whenever possible.
-	const char*			os_path(const char* relative_path);
-
-protected:
-
-	// Builds the OS-dependent path from base_path and relative_path
-	const char*			build_os_path(const char* base_path, const char* relative_path);
-
-protected:
-
-	char				m_root_path[MAX_PATH_LENGTH];
-};
-
-} // namespace crown

+ 0 - 110
engine/core/filesystem/MountPoint.h

@@ -1,110 +0,0 @@
-/*
-Copyright (c) 2013 Daniele Bartolini, Michele Rossi
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#pragma once
-
-#include "OS.h"
-#include "File.h"
-
-
-namespace crown
-{
-
-/// Hashed values for supported MountPoint types
-const char* const DISK_MOUNT_POINT			= "disk";
-const char* const ANDROID_MOUNT_POINT		= "asset";
-
-const uint32_t DISK_TYPE 					= 0x7BCBC5EE;
-const uint32_t ANDROID_TYPE					= 0xAAD5F176;
-
-/// Represent single entity in MountPoint
-struct MountPointEntry
-{
-	enum Type
-	{
-		DIRECTORY = 0,		/// The entry is a directory
-		FILE,				/// The entry is a file
-		MEMORY,				/// The entry is a memory file (i.e. does not exist on the disk)
-		UNKNOWN				/// The entry type is unknown
-	};
-
-	MountPointEntry() : type(UNKNOWN) {}
-
-	Type			type;								/// Type of the entry
-	char			os_path[MAX_PATH_LENGTH];			/// OS-specific path (use only for debug)
-	char			relative_path[MAX_PATH_LENGTH];		/// Relative path of the entry
-};
-
-
-/// Interface which provides a platform-independent way to access files and directories.
-/// Each MountPoint are managed by FileSystem.
-/// There may be several types of MountPoint:
-///
-/// - DiskMountPoint 	- provides interaction with HDD, DVD, BlueRay...
-/// - ZipMountPoint  	- provides interaction with compressed archives
-/// - NetworkMountPoint	- provides interaction with network
-///
-/// Accessing files:
-/// Every file and every directory must be accessed through the Filesystem's MountPoints.
-/// Not a single C/C++ std file io call or other similar facilities
-/// should be used in any other part of the engine in order to maintain
-/// absolute platform independence.
-///
-/// MountPoint maintains a root path which acts as base directory for every
-/// file operation; access to files outside the root path is not allowed. If
-/// you really need it, instantiate another filesystem whith the appropriate
-/// root path (e.g.)
-///
-/// The MountPoint will take care of the necessary path conversions.
-/// The root path must be an absolute path for the underlying operating system.
-class MountPoint
-{
-public:
-	inline						MountPoint(uint32_t type) : m_type(type) {}
-
-	/// Opens a file and returns a specific instance
-	virtual File*				open(const char* path, FileOpenMode mode) = 0;
-
-	/// Close file
-	virtual void				close(File* file) = 0;
-
-	/// Returns whether the @a relative_path exists
-	virtual bool				exists(const char* relative_path) = 0;
-
-	virtual const char*			os_path(const char* relative_path) = 0;
-
-	uint32_t					type() const { return m_type; }
-
-protected:
-
-	MountPoint*			m_next;
-
-	uint32_t			m_type;
-
-	friend class Filesystem;
-};
-
-} // namespace crown