diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index b2dcc039a4..5ff1311a29 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -6,15 +6,17 @@ add_library(core STATIC core.h core_timing.cpp core_timing.h - file_sys/archive_backend.cpp - file_sys/archive_backend.h - file_sys/directory_backend.h + file_sys/directory.h file_sys/errors.h - file_sys/file_backend.h + file_sys/filesystem.cpp + file_sys/filesystem.h file_sys/path_parser.cpp file_sys/path_parser.h - file_sys/romfs_archive.cpp - file_sys/romfs_archive.h + file_sys/romfs_factory.cpp + file_sys/romfs_factory.h + file_sys/romfs_filesystem.cpp + file_sys/romfs_filesystem.h + file_sys/storage.h frontend/emu_window.cpp frontend/emu_window.h frontend/framebuffer_layout.cpp diff --git a/src/core/file_sys/directory_backend.h b/src/core/file_sys/directory.h similarity index 98% rename from src/core/file_sys/directory_backend.h rename to src/core/file_sys/directory.h index 0c93f20746..5a40bf472d 100644 --- a/src/core/file_sys/directory_backend.h +++ b/src/core/file_sys/directory.h @@ -1,4 +1,4 @@ -// Copyright 2014 Citra Emulator Project +// Copyright 2018 yuzu emulator team // Licensed under GPLv2 or any later version // Refer to the license.txt file included. diff --git a/src/core/file_sys/archive_backend.cpp b/src/core/file_sys/filesystem.cpp similarity index 97% rename from src/core/file_sys/archive_backend.cpp rename to src/core/file_sys/filesystem.cpp index fc472b44f3..82fdb3c464 100644 --- a/src/core/file_sys/archive_backend.cpp +++ b/src/core/file_sys/filesystem.cpp @@ -1,4 +1,4 @@ -// Copyright 2015 Citra Emulator Project +// Copyright 2018 yuzu emulator team // Licensed under GPLv2 or any later version // Refer to the license.txt file included. @@ -7,7 +7,7 @@ #include #include "common/logging/log.h" #include "common/string_util.h" -#include "core/file_sys/archive_backend.h" +#include "core/file_sys/filesystem.h" #include "core/memory.h" namespace FileSys { diff --git a/src/core/file_sys/archive_backend.h b/src/core/file_sys/filesystem.h similarity index 92% rename from src/core/file_sys/archive_backend.h rename to src/core/file_sys/filesystem.h index 2255bee42d..eb3d9c4d66 100644 --- a/src/core/file_sys/archive_backend.h +++ b/src/core/file_sys/filesystem.h @@ -1,4 +1,4 @@ -// Copyright 2014 Citra Emulator Project +// Copyright 2018 yuzu emulator team // Licensed under GPLv2 or any later version // Refer to the license.txt file included. @@ -15,7 +15,7 @@ namespace FileSys { -class FileBackend; +class StorageBackend; class DirectoryBackend; // Path string type @@ -71,9 +71,9 @@ struct ArchiveFormatInfo { }; static_assert(std::is_pod::value, "ArchiveFormatInfo is not POD"); -class ArchiveBackend : NonCopyable { +class FileSystemBackend : NonCopyable { public: - virtual ~ArchiveBackend() {} + virtual ~FileSystemBackend() {} /** * Get a descriptive name for the archive (e.g. "RomFS", "SaveData", etc.) @@ -138,8 +138,8 @@ public: * @param mode Mode to open the file with * @return Opened file, or error code */ - virtual ResultVal> OpenFile(const Path& path, - const Mode& mode) const = 0; + virtual ResultVal> OpenFile(const Path& path, + const Mode& mode) const = 0; /** * Open a directory specified by its path @@ -155,9 +155,9 @@ public: virtual u64 GetFreeSpaceSize() const = 0; }; -class ArchiveFactory : NonCopyable { +class FileSystemFactory : NonCopyable { public: - virtual ~ArchiveFactory() {} + virtual ~FileSystemFactory() {} /** * Get a descriptive name for the archive (e.g. "RomFS", "SaveData", etc.) @@ -169,7 +169,7 @@ public: * @param path Path to the archive * @return An ArchiveBackend corresponding operating specified archive path. */ - virtual ResultVal> Open(const Path& path) = 0; + virtual ResultVal> Open(const Path& path) = 0; /** * Deletes the archive contents and then re-creates the base folder diff --git a/src/core/file_sys/path_parser.h b/src/core/file_sys/path_parser.h index b9f52f65da..184f59d553 100644 --- a/src/core/file_sys/path_parser.h +++ b/src/core/file_sys/path_parser.h @@ -6,7 +6,7 @@ #include #include -#include "core/file_sys/archive_backend.h" +#include "core/file_sys/filesystem.h" namespace FileSys { diff --git a/src/core/file_sys/romfs_factory.cpp b/src/core/file_sys/romfs_factory.cpp new file mode 100644 index 0000000000..590c2acb30 --- /dev/null +++ b/src/core/file_sys/romfs_factory.cpp @@ -0,0 +1,39 @@ +// Copyright 2018 yuzu emulator team +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include +#include +#include "common/common_types.h" +#include "common/logging/log.h" +#include "core/file_sys/romfs_factory.h" +#include "core/file_sys/romfs_filesystem.h" + +namespace FileSys { + +RomFS_Factory::RomFS_Factory(Loader::AppLoader& app_loader) { + // Load the RomFS from the app + if (Loader::ResultStatus::Success != app_loader.ReadRomFS(romfs_file, data_offset, data_size)) { + LOG_ERROR(Service_FS, "Unable to read RomFS!"); + } +} + +ResultVal> RomFS_Factory::Open(const Path& path) { + auto archive = std::make_unique(romfs_file, data_offset, data_size); + return MakeResult>(std::move(archive)); +} + +ResultCode RomFS_Factory::Format(const Path& path, + const FileSys::ArchiveFormatInfo& format_info) { + LOG_ERROR(Service_FS, "Unimplemented Format archive %s", GetName().c_str()); + // TODO(bunnei): Find the right error code for this + return ResultCode(-1); +} + +ResultVal RomFS_Factory::GetFormatInfo(const Path& path) const { + LOG_ERROR(Service_FS, "Unimplemented GetFormatInfo archive %s", GetName().c_str()); + // TODO(bunnei): Find the right error code for this + return ResultCode(-1); +} + +} // namespace FileSys diff --git a/src/core/file_sys/romfs_factory.h b/src/core/file_sys/romfs_factory.h new file mode 100644 index 0000000000..10ea139667 --- /dev/null +++ b/src/core/file_sys/romfs_factory.h @@ -0,0 +1,35 @@ +// Copyright 2018 yuzu emulator team +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include +#include +#include +#include "common/common_types.h" +#include "core/file_sys/filesystem.h" +#include "core/hle/result.h" +#include "core/loader/loader.h" + +namespace FileSys { + +/// File system interface to the RomFS archive +class RomFS_Factory final : public FileSystemFactory { +public: + explicit RomFS_Factory(Loader::AppLoader& app_loader); + + std::string GetName() const override { + return "ArchiveFactory_RomFS"; + } + ResultVal> Open(const Path& path) override; + ResultCode Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info) override; + ResultVal GetFormatInfo(const Path& path) const override; + +private: + std::shared_ptr romfs_file; + u64 data_offset; + u64 data_size; +}; + +} // namespace FileSys diff --git a/src/core/file_sys/romfs_archive.cpp b/src/core/file_sys/romfs_filesystem.cpp similarity index 62% rename from src/core/file_sys/romfs_archive.cpp rename to src/core/file_sys/romfs_filesystem.cpp index 0d93fccd47..5b5c5a73e4 100644 --- a/src/core/file_sys/romfs_archive.cpp +++ b/src/core/file_sys/romfs_filesystem.cpp @@ -6,79 +6,79 @@ #include #include "common/common_types.h" #include "common/logging/log.h" -#include "core/file_sys/romfs_archive.h" +#include "core/file_sys/romfs_filesystem.h" namespace FileSys { -std::string ROMFSArchive::GetName() const { +std::string RomFS_FileSystem::GetName() const { return "RomFS"; } -ResultVal> ROMFSArchive::OpenFile(const Path& path, - const Mode& mode) const { - return MakeResult>( - std::make_unique(romfs_file, data_offset, data_size)); +ResultVal> RomFS_FileSystem::OpenFile(const Path& path, + const Mode& mode) const { + return MakeResult>( + std::make_unique(romfs_file, data_offset, data_size)); } -ResultCode ROMFSArchive::DeleteFile(const Path& path) const { +ResultCode RomFS_FileSystem::DeleteFile(const Path& path) const { LOG_CRITICAL(Service_FS, "Attempted to delete a file from an ROMFS archive (%s).", GetName().c_str()); // TODO(bunnei): Use correct error code return ResultCode(-1); } -ResultCode ROMFSArchive::RenameFile(const Path& src_path, const Path& dest_path) const { +ResultCode RomFS_FileSystem::RenameFile(const Path& src_path, const Path& dest_path) const { LOG_CRITICAL(Service_FS, "Attempted to rename a file within an ROMFS archive (%s).", GetName().c_str()); // TODO(wwylele): Use correct error code return ResultCode(-1); } -ResultCode ROMFSArchive::DeleteDirectory(const Path& path) const { +ResultCode RomFS_FileSystem::DeleteDirectory(const Path& path) const { LOG_CRITICAL(Service_FS, "Attempted to delete a directory from an ROMFS archive (%s).", GetName().c_str()); // TODO(wwylele): Use correct error code return ResultCode(-1); } -ResultCode ROMFSArchive::DeleteDirectoryRecursively(const Path& path) const { +ResultCode RomFS_FileSystem::DeleteDirectoryRecursively(const Path& path) const { LOG_CRITICAL(Service_FS, "Attempted to delete a directory from an ROMFS archive (%s).", GetName().c_str()); // TODO(wwylele): Use correct error code return ResultCode(-1); } -ResultCode ROMFSArchive::CreateFile(const Path& path, u64 size) const { +ResultCode RomFS_FileSystem::CreateFile(const Path& path, u64 size) const { LOG_CRITICAL(Service_FS, "Attempted to create a file in an ROMFS archive (%s).", GetName().c_str()); // TODO(bunnei): Use correct error code return ResultCode(-1); } -ResultCode ROMFSArchive::CreateDirectory(const Path& path) const { +ResultCode RomFS_FileSystem::CreateDirectory(const Path& path) const { LOG_CRITICAL(Service_FS, "Attempted to create a directory in an ROMFS archive (%s).", GetName().c_str()); // TODO(wwylele): Use correct error code return ResultCode(-1); } -ResultCode ROMFSArchive::RenameDirectory(const Path& src_path, const Path& dest_path) const { +ResultCode RomFS_FileSystem::RenameDirectory(const Path& src_path, const Path& dest_path) const { LOG_CRITICAL(Service_FS, "Attempted to rename a file within an ROMFS archive (%s).", GetName().c_str()); // TODO(wwylele): Use correct error code return ResultCode(-1); } -ResultVal> ROMFSArchive::OpenDirectory(const Path& path) const { +ResultVal> RomFS_FileSystem::OpenDirectory(const Path& path) const { return MakeResult>(std::make_unique()); } -u64 ROMFSArchive::GetFreeSpaceSize() const { +u64 RomFS_FileSystem::GetFreeSpaceSize() const { LOG_WARNING(Service_FS, "Attempted to get the free space in an ROMFS archive"); return 0; } -ResultVal ROMFSFile::Read(const u64 offset, const size_t length, u8* buffer) const { +ResultVal RomFS_Storage::Read(const u64 offset, const size_t length, u8* buffer) const { LOG_TRACE(Service_FS, "called offset=%llu, length=%zu", offset, length); romfs_file->Seek(data_offset + offset, SEEK_SET); size_t read_length = (size_t)std::min((u64)length, data_size - offset); @@ -86,18 +86,18 @@ ResultVal ROMFSFile::Read(const u64 offset, const size_t length, u8* buf return MakeResult(romfs_file->ReadBytes(buffer, read_length)); } -ResultVal ROMFSFile::Write(const u64 offset, const size_t length, const bool flush, - const u8* buffer) const { +ResultVal RomFS_Storage::Write(const u64 offset, const size_t length, const bool flush, + const u8* buffer) const { LOG_ERROR(Service_FS, "Attempted to write to ROMFS file"); // TODO(Subv): Find error code return MakeResult(0); } -u64 ROMFSFile::GetSize() const { +u64 RomFS_Storage::GetSize() const { return data_size; } -bool ROMFSFile::SetSize(const u64 size) const { +bool RomFS_Storage::SetSize(const u64 size) const { LOG_ERROR(Service_FS, "Attempted to set the size of an ROMFS file"); return false; } diff --git a/src/core/file_sys/romfs_archive.h b/src/core/file_sys/romfs_filesystem.h similarity index 80% rename from src/core/file_sys/romfs_archive.h rename to src/core/file_sys/romfs_filesystem.h index 2b6c573bad..900ea567a0 100644 --- a/src/core/file_sys/romfs_archive.h +++ b/src/core/file_sys/romfs_filesystem.h @@ -10,9 +10,9 @@ #include #include "common/common_types.h" #include "common/file_util.h" -#include "core/file_sys/archive_backend.h" -#include "core/file_sys/directory_backend.h" -#include "core/file_sys/file_backend.h" +#include "core/file_sys/directory.h" +#include "core/file_sys/filesystem.h" +#include "core/file_sys/storage.h" #include "core/hle/result.h" namespace FileSys { @@ -22,15 +22,15 @@ namespace FileSys { * archives This should be subclassed by concrete archive types, which will provide the input data * (load the raw ROMFS archive) and override any required methods */ -class ROMFSArchive : public ArchiveBackend { +class RomFS_FileSystem : public FileSystemBackend { public: - ROMFSArchive(std::shared_ptr file, u64 offset, u64 size) + RomFS_FileSystem(std::shared_ptr file, u64 offset, u64 size) : romfs_file(file), data_offset(offset), data_size(size) {} std::string GetName() const override; - ResultVal> OpenFile(const Path& path, - const Mode& mode) const override; + ResultVal> OpenFile(const Path& path, + const Mode& mode) const override; ResultCode DeleteFile(const Path& path) const override; ResultCode RenameFile(const Path& src_path, const Path& dest_path) const override; ResultCode DeleteDirectory(const Path& path) const override; @@ -47,9 +47,9 @@ protected: u64 data_size; }; -class ROMFSFile : public FileBackend { +class RomFS_Storage : public StorageBackend { public: - ROMFSFile(std::shared_ptr file, u64 offset, u64 size) + RomFS_Storage(std::shared_ptr file, u64 offset, u64 size) : romfs_file(file), data_offset(offset), data_size(size) {} ResultVal Read(u64 offset, size_t length, u8* buffer) const override; diff --git a/src/core/file_sys/file_backend.h b/src/core/file_sys/storage.h similarity index 86% rename from src/core/file_sys/file_backend.h rename to src/core/file_sys/storage.h index 5e7c2bab48..2a68118310 100644 --- a/src/core/file_sys/file_backend.h +++ b/src/core/file_sys/storage.h @@ -1,4 +1,4 @@ -// Copyright 2014 Citra Emulator Project +// Copyright 2018 yuzu emulator team // Licensed under GPLv2 or any later version // Refer to the license.txt file included. @@ -8,15 +8,12 @@ #include "common/common_types.h" #include "core/hle/result.h" -//////////////////////////////////////////////////////////////////////////////////////////////////// -// FileSys namespace - namespace FileSys { -class FileBackend : NonCopyable { +class StorageBackend : NonCopyable { public: - FileBackend() {} - virtual ~FileBackend() {} + StorageBackend() {} + virtual ~StorageBackend() {} /** * Read data from the file @@ -39,10 +36,9 @@ public: const u8* buffer) const = 0; /** - * Get the size of the file in bytes - * @return Size of the file in bytes + * Flushes the file */ - virtual u64 GetSize() const = 0; + virtual void Flush() const = 0; /** * Set the size of the file in bytes @@ -51,16 +47,17 @@ public: */ virtual bool SetSize(u64 size) const = 0; + /** + * Get the size of the file in bytes + * @return Size of the file in bytes + */ + virtual u64 GetSize() const = 0; + /** * Close the file * @return true if the file closed correctly */ virtual bool Close() const = 0; - - /** - * Flushes the file - */ - virtual void Flush() const = 0; }; } // namespace FileSys