citra-emu
/
citra
Archived
1
0
Fork 0

Merge pull request #303 from linkmauve/fs-cleanup

FileSys cleanup
This commit is contained in:
Tony Wasserka 2014-12-29 12:14:59 +01:00
commit 13699f05e7
9 changed files with 99 additions and 171 deletions

View File

@ -40,19 +40,13 @@ union Mode {
class Path { class Path {
public: public:
Path(): Path() : type(Invalid) {
type(Invalid)
{
} }
Path(const char* path): Path(const char* path) : type(Char), string(path) {
type(Char), string(path)
{
} }
Path(LowPathType type, u32 size, u32 pointer): Path(LowPathType type, u32 size, u32 pointer) : type(type) {
type(type)
{
switch (type) { switch (type) {
case Binary: case Binary:
{ {
@ -60,18 +54,21 @@ public:
binary = std::vector<u8>(data, data + size); binary = std::vector<u8>(data, data + size);
break; break;
} }
case Char: case Char:
{ {
const char* data = reinterpret_cast<const char*>(Memory::GetPointer(pointer)); const char* data = reinterpret_cast<const char*>(Memory::GetPointer(pointer));
string = std::string(data, size - 1); // Data is always null-terminated. string = std::string(data, size - 1); // Data is always null-terminated.
break; break;
} }
case Wchar: case Wchar:
{ {
const char16_t* data = reinterpret_cast<const char16_t*>(Memory::GetPointer(pointer)); const char16_t* data = reinterpret_cast<const char16_t*>(Memory::GetPointer(pointer));
u16str = std::u16string(data, size/2 - 1); // Data is always null-terminated. u16str = std::u16string(data, size/2 - 1); // Data is always null-terminated.
break; break;
} }
default: default:
break; break;
} }
@ -104,10 +101,6 @@ public:
return "[Char: " + AsString() + ']'; return "[Char: " + AsString() + ']';
case Wchar: case Wchar:
return "[Wchar: " + AsString() + ']'; return "[Wchar: " + AsString() + ']';
default:
// TODO(yuriks): Add assert
LOG_ERROR(Service_FS, "LowPathType cannot be converted to string!");
return {};
} }
} }
@ -119,7 +112,8 @@ public:
return Common::UTF16ToUTF8(u16str); return Common::UTF16ToUTF8(u16str);
case Empty: case Empty:
return {}; return {};
default: case Invalid:
case Binary:
// TODO(yuriks): Add assert // TODO(yuriks): Add assert
LOG_ERROR(Service_FS, "LowPathType cannot be converted to string!"); LOG_ERROR(Service_FS, "LowPathType cannot be converted to string!");
return {}; return {};
@ -134,7 +128,8 @@ public:
return u16str; return u16str;
case Empty: case Empty:
return {}; return {};
default: case Invalid:
case Binary:
// TODO(yuriks): Add assert // TODO(yuriks): Add assert
LOG_ERROR(Service_FS, "LowPathType cannot be converted to u16string!"); LOG_ERROR(Service_FS, "LowPathType cannot be converted to u16string!");
return {}; return {};
@ -160,7 +155,7 @@ public:
} }
case Empty: case Empty:
return {}; return {};
default: case Invalid:
// TODO(yuriks): Add assert // TODO(yuriks): Add assert
LOG_ERROR(Service_FS, "LowPathType cannot be converted to binary!"); LOG_ERROR(Service_FS, "LowPathType cannot be converted to binary!");
return {}; return {};
@ -176,7 +171,8 @@ private:
class ArchiveBackend : NonCopyable { class ArchiveBackend : NonCopyable {
public: public:
virtual ~ArchiveBackend() { } virtual ~ArchiveBackend() {
}
/** /**
* Get a descriptive name for the archive (e.g. "RomFS", "SaveData", etc.) * Get a descriptive name for the archive (e.g. "RomFS", "SaveData", etc.)
@ -196,7 +192,7 @@ public:
* @param path Path relative to the archive * @param path Path relative to the archive
* @return Whether the file could be deleted * @return Whether the file could be deleted
*/ */
virtual bool DeleteFile(const FileSys::Path& path) const = 0; virtual bool DeleteFile(const Path& path) const = 0;
/** /**
* Rename a File specified by its path * Rename a File specified by its path
@ -204,14 +200,14 @@ public:
* @param dest_path Destination path relative to the archive * @param dest_path Destination path relative to the archive
* @return Whether rename succeeded * @return Whether rename succeeded
*/ */
virtual bool RenameFile(const FileSys::Path& src_path, const FileSys::Path& dest_path) const = 0; virtual bool RenameFile(const Path& src_path, const Path& dest_path) const = 0;
/** /**
* Delete a directory specified by its path * Delete a directory specified by its path
* @param path Path relative to the archive * @param path Path relative to the archive
* @return Whether the directory could be deleted * @return Whether the directory could be deleted
*/ */
virtual bool DeleteDirectory(const FileSys::Path& path) const = 0; virtual bool DeleteDirectory(const Path& path) const = 0;
/** /**
* Create a file specified by its path * Create a file specified by its path
@ -234,7 +230,7 @@ public:
* @param dest_path Destination path relative to the archive * @param dest_path Destination path relative to the archive
* @return Whether rename succeeded * @return Whether rename succeeded
*/ */
virtual bool RenameDirectory(const FileSys::Path& src_path, const FileSys::Path& dest_path) const = 0; virtual bool RenameDirectory(const Path& src_path, const Path& dest_path) const = 0;
/** /**
* Open a directory specified by its path * Open a directory specified by its path

View File

@ -23,37 +23,21 @@ Archive_RomFS::Archive_RomFS(const Loader::AppLoader& app_loader) {
} }
} }
/**
* Open a file specified by its path, using the specified mode
* @param path Path relative to the archive
* @param mode Mode to open the file with
* @return Opened file, or nullptr
*/
std::unique_ptr<FileBackend> Archive_RomFS::OpenFile(const Path& path, const Mode mode) const { std::unique_ptr<FileBackend> Archive_RomFS::OpenFile(const Path& path, const Mode mode) const {
return Common::make_unique<File_RomFS>(this); return Common::make_unique<File_RomFS>(this);
} }
/** bool Archive_RomFS::DeleteFile(const Path& path) const {
* Delete a file specified by its path
* @param path Path relative to the archive
* @return Whether the file could be deleted
*/
bool Archive_RomFS::DeleteFile(const FileSys::Path& path) const {
LOG_WARNING(Service_FS, "Attempted to delete a file from ROMFS."); LOG_WARNING(Service_FS, "Attempted to delete a file from ROMFS.");
return false; return false;
} }
bool Archive_RomFS::RenameFile(const FileSys::Path& src_path, const FileSys::Path& dest_path) const { bool Archive_RomFS::RenameFile(const Path& src_path, const Path& dest_path) const {
LOG_WARNING(Service_FS, "Attempted to rename a file within ROMFS."); LOG_WARNING(Service_FS, "Attempted to rename a file within ROMFS.");
return false; return false;
} }
/** bool Archive_RomFS::DeleteDirectory(const Path& path) const {
* Delete a directory specified by its path
* @param path Path relative to the archive
* @return Whether the directory could be deleted
*/
bool Archive_RomFS::DeleteDirectory(const FileSys::Path& path) const {
LOG_WARNING(Service_FS, "Attempted to delete a directory from ROMFS."); LOG_WARNING(Service_FS, "Attempted to delete a directory from ROMFS.");
return false; return false;
} }
@ -64,26 +48,16 @@ ResultCode Archive_RomFS::CreateFile(const Path& path, u32 size) const {
return ResultCode(ErrorDescription::NotAuthorized, ErrorModule::FS, ErrorSummary::NotSupported, ErrorLevel::Permanent); return ResultCode(ErrorDescription::NotAuthorized, ErrorModule::FS, ErrorSummary::NotSupported, ErrorLevel::Permanent);
} }
/**
* Create a directory specified by its path
* @param path Path relative to the archive
* @return Whether the directory could be created
*/
bool Archive_RomFS::CreateDirectory(const Path& path) const { bool Archive_RomFS::CreateDirectory(const Path& path) const {
LOG_WARNING(Service_FS, "Attempted to create a directory in ROMFS."); LOG_WARNING(Service_FS, "Attempted to create a directory in ROMFS.");
return false; return false;
} }
bool Archive_RomFS::RenameDirectory(const FileSys::Path& src_path, const FileSys::Path& dest_path) const { bool Archive_RomFS::RenameDirectory(const Path& src_path, const Path& dest_path) const {
LOG_WARNING(Service_FS, "Attempted to rename a file within ROMFS."); LOG_WARNING(Service_FS, "Attempted to rename a file within ROMFS.");
return false; return false;
} }
/**
* Open a directory specified by its path
* @param path Path relative to the archive
* @return Opened directory, or nullptr
*/
std::unique_ptr<DirectoryBackend> Archive_RomFS::OpenDirectory(const Path& path) const { std::unique_ptr<DirectoryBackend> Archive_RomFS::OpenDirectory(const Path& path) const {
return Common::make_unique<Directory_RomFS>(); return Common::make_unique<Directory_RomFS>();
} }

View File

@ -36,7 +36,7 @@ public:
* @param path Path relative to the archive * @param path Path relative to the archive
* @return Whether the file could be deleted * @return Whether the file could be deleted
*/ */
bool DeleteFile(const FileSys::Path& path) const override; bool DeleteFile(const Path& path) const override;
/** /**
* Rename a File specified by its path * Rename a File specified by its path
@ -44,14 +44,14 @@ public:
* @param dest_path Destination path relative to the archive * @param dest_path Destination path relative to the archive
* @return Whether rename succeeded * @return Whether rename succeeded
*/ */
bool RenameFile(const FileSys::Path& src_path, const FileSys::Path& dest_path) const override; bool RenameFile(const Path& src_path, const Path& dest_path) const override;
/** /**
* Delete a directory specified by its path * Delete a directory specified by its path
* @param path Path relative to the archive * @param path Path relative to the archive
* @return Whether the directory could be deleted * @return Whether the directory could be deleted
*/ */
bool DeleteDirectory(const FileSys::Path& path) const override; bool DeleteDirectory(const Path& path) const override;
/** /**
* Create a file specified by its path * Create a file specified by its path
@ -74,7 +74,7 @@ public:
* @param dest_path Destination path relative to the archive * @param dest_path Destination path relative to the archive
* @return Whether rename succeeded * @return Whether rename succeeded
*/ */
bool RenameDirectory(const FileSys::Path& src_path, const FileSys::Path& dest_path) const override; bool RenameDirectory(const Path& src_path, const Path& dest_path) const override;
/** /**
* Open a directory specified by its path * Open a directory specified by its path

View File

@ -21,20 +21,10 @@ bool Directory_RomFS::Open() {
return false; return false;
} }
/**
* List files contained in the directory
* @param count Number of entries to return at once in entries
* @param entries Buffer to read data into
* @return Number of entries listed
*/
u32 Directory_RomFS::Read(const u32 count, Entry* entries) { u32 Directory_RomFS::Read(const u32 count, Entry* entries) {
return 0; return 0;
} }
/**
* Close the directory
* @return true if the directory closed correctly
*/
bool Directory_RomFS::Close() const { bool Directory_RomFS::Close() const {
return false; return false;
} }

View File

@ -23,15 +23,15 @@ std::unique_ptr<FileBackend> DiskArchive::OpenFile(const Path& path, const Mode
return std::unique_ptr<FileBackend>(file); return std::unique_ptr<FileBackend>(file);
} }
bool DiskArchive::DeleteFile(const FileSys::Path& path) const { bool DiskArchive::DeleteFile(const Path& path) const {
return FileUtil::Delete(GetMountPoint() + path.AsString()); return FileUtil::Delete(GetMountPoint() + path.AsString());
} }
bool DiskArchive::RenameFile(const FileSys::Path& src_path, const FileSys::Path& dest_path) const { bool DiskArchive::RenameFile(const Path& src_path, const Path& dest_path) const {
return FileUtil::Rename(GetMountPoint() + src_path.AsString(), GetMountPoint() + dest_path.AsString()); return FileUtil::Rename(GetMountPoint() + src_path.AsString(), GetMountPoint() + dest_path.AsString());
} }
bool DiskArchive::DeleteDirectory(const FileSys::Path& path) const { bool DiskArchive::DeleteDirectory(const Path& path) const {
return FileUtil::DeleteDir(GetMountPoint() + path.AsString()); return FileUtil::DeleteDir(GetMountPoint() + path.AsString());
} }
@ -60,7 +60,7 @@ bool DiskArchive::CreateDirectory(const Path& path) const {
return FileUtil::CreateDir(GetMountPoint() + path.AsString()); return FileUtil::CreateDir(GetMountPoint() + path.AsString());
} }
bool DiskArchive::RenameDirectory(const FileSys::Path& src_path, const FileSys::Path& dest_path) const { bool DiskArchive::RenameDirectory(const Path& src_path, const Path& dest_path) const {
return FileUtil::Rename(GetMountPoint() + src_path.AsString(), GetMountPoint() + dest_path.AsString()); return FileUtil::Rename(GetMountPoint() + src_path.AsString(), GetMountPoint() + dest_path.AsString());
} }
@ -85,7 +85,7 @@ DiskFile::DiskFile(const DiskArchive* archive, const Path& path, const Mode mode
bool DiskFile::Open() { bool DiskFile::Open() {
if (!mode.create_flag && !FileUtil::Exists(path)) { if (!mode.create_flag && !FileUtil::Exists(path)) {
LOG_ERROR(Service_FS, "Non-existing file %s cant be open without mode create.", path.c_str()); LOG_ERROR(Service_FS, "Non-existing file %s can't be open without mode create.", path.c_str());
return false; return false;
} }

View File

@ -26,12 +26,12 @@ public:
virtual std::string GetName() const = 0; virtual std::string GetName() const = 0;
std::unique_ptr<FileBackend> OpenFile(const Path& path, const Mode mode) const override; std::unique_ptr<FileBackend> OpenFile(const Path& path, const Mode mode) const override;
bool DeleteFile(const FileSys::Path& path) const override; bool DeleteFile(const Path& path) const override;
bool RenameFile(const FileSys::Path& src_path, const FileSys::Path& dest_path) const override; bool RenameFile(const Path& src_path, const Path& dest_path) const override;
bool DeleteDirectory(const FileSys::Path& path) const override; bool DeleteDirectory(const Path& path) const override;
ResultCode CreateFile(const Path& path, u32 size) const override; ResultCode CreateFile(const Path& path, u32 size) const override;
bool CreateDirectory(const Path& path) const override; bool CreateDirectory(const Path& path) const override;
bool RenameDirectory(const FileSys::Path& src_path, const FileSys::Path& dest_path) const override; bool RenameDirectory(const Path& src_path, const Path& dest_path) const override;
std::unique_ptr<DirectoryBackend> OpenDirectory(const Path& path) const override; std::unique_ptr<DirectoryBackend> OpenDirectory(const Path& path) const override;
/** /**

View File

@ -12,62 +12,30 @@
namespace FileSys { namespace FileSys {
/**
* Open the file
* @return true if the file opened correctly
*/
bool File_RomFS::Open() { bool File_RomFS::Open() {
return true; return true;
} }
/**
* Read data from the file
* @param offset Offset in bytes to start reading data from
* @param length Length in bytes of data to read from file
* @param buffer Buffer to read data into
* @return Number of bytes read
*/
size_t File_RomFS::Read(const u64 offset, const u32 length, u8* buffer) const { size_t File_RomFS::Read(const u64 offset, const u32 length, u8* buffer) const {
LOG_TRACE(Service_FS, "called offset=%llu, length=%d", offset, length); LOG_TRACE(Service_FS, "called offset=%llu, length=%d", offset, length);
memcpy(buffer, &archive->raw_data[(u32)offset], length); memcpy(buffer, &archive->raw_data[(u32)offset], length);
return length; return length;
} }
/**
* Write data to the file
* @param offset Offset in bytes to start writing data to
* @param length Length in bytes of data to write to file
* @param flush The flush parameters (0 == do not flush)
* @param buffer Buffer to read data from
* @return Number of bytes written
*/
size_t File_RomFS::Write(const u64 offset, const u32 length, const u32 flush, const u8* buffer) const { size_t File_RomFS::Write(const u64 offset, const u32 length, const u32 flush, const u8* buffer) const {
LOG_WARNING(Service_FS, "Attempted to write to ROMFS."); LOG_WARNING(Service_FS, "Attempted to write to ROMFS.");
return 0; return 0;
} }
/**
* Get the size of the file in bytes
* @return Size of the file in bytes
*/
size_t File_RomFS::GetSize() const { size_t File_RomFS::GetSize() const {
return sizeof(u8) * archive->raw_data.size(); return sizeof(u8) * archive->raw_data.size();
} }
/**
* Set the size of the file in bytes
* @param size New size of the file
* @return true if successful
*/
bool File_RomFS::SetSize(const u64 size) const { bool File_RomFS::SetSize(const u64 size) const {
LOG_WARNING(Service_FS, "Attempted to set the size of ROMFS"); LOG_WARNING(Service_FS, "Attempted to set the size of ROMFS");
return false; return false;
} }
/**
* Close the file
* @return true if the file closed correctly
*/
bool File_RomFS::Close() const { bool File_RomFS::Close() const {
return false; return false;
} }