mirror of
https://github.com/Lime3DS/Lime3DS.git
synced 2024-11-24 02:29:20 +01:00
Service.FS: Do archive registration using IdCode instead of name
This commit is contained in:
parent
ca67bb7945
commit
f6153679b0
@ -162,25 +162,12 @@ private:
|
||||
|
||||
class Archive : NonCopyable {
|
||||
public:
|
||||
/// Supported archive types
|
||||
enum class IdCode : u32 {
|
||||
RomFS = 0x00000003,
|
||||
SaveData = 0x00000004,
|
||||
ExtSaveData = 0x00000006,
|
||||
SharedExtSaveData = 0x00000007,
|
||||
SystemSaveData = 0x00000008,
|
||||
SDMC = 0x00000009,
|
||||
SDMCWriteOnly = 0x0000000A,
|
||||
};
|
||||
|
||||
Archive() { }
|
||||
virtual ~Archive() { }
|
||||
|
||||
/**
|
||||
* Get the IdCode of the archive (e.g. RomFS, SaveData, etc.)
|
||||
* @return IdCode of the archive
|
||||
* Get a descriptive name for the archive (e.g. "RomFS", "SaveData", etc.)
|
||||
*/
|
||||
virtual IdCode GetIdCode() const = 0;
|
||||
virtual std::string GetName() const = 0;
|
||||
|
||||
/**
|
||||
* Open a file specified by its path, using the specified mode
|
||||
|
@ -22,11 +22,7 @@ public:
|
||||
Archive_RomFS(const Loader::AppLoader& app_loader);
|
||||
~Archive_RomFS() override;
|
||||
|
||||
/**
|
||||
* Get the IdCode of the archive (e.g. RomFS, SaveData, etc.)
|
||||
* @return IdCode of the archive
|
||||
*/
|
||||
IdCode GetIdCode() const override { return IdCode::RomFS; }
|
||||
std::string GetName() const override { return "RomFS"; }
|
||||
|
||||
/**
|
||||
* Open a file specified by its path, using the specified mode
|
||||
|
@ -26,11 +26,7 @@ public:
|
||||
*/
|
||||
bool Initialize();
|
||||
|
||||
/**
|
||||
* Get the IdCode of the archive (e.g. RomFS, SaveData, etc.)
|
||||
* @return IdCode of the archive
|
||||
*/
|
||||
IdCode GetIdCode() const override { return IdCode::SDMC; }
|
||||
std::string GetName() const override { return "SDMC"; }
|
||||
|
||||
/**
|
||||
* Open a file specified by its path, using the specified mode
|
||||
|
@ -43,9 +43,9 @@ enum class DirectoryCommand : u32 {
|
||||
|
||||
class Archive : public Kernel::Session {
|
||||
public:
|
||||
std::string GetName() const override { return "Archive: " + name; }
|
||||
std::string GetName() const override { return "Archive: " + backend->GetName(); }
|
||||
|
||||
std::string name; ///< Name of archive (optional)
|
||||
ArchiveIdCode id_code; ///< Id code of the archive
|
||||
FileSys::Archive* backend; ///< Archive backend interface
|
||||
|
||||
ResultVal<bool> SyncRequest() override {
|
||||
@ -91,7 +91,7 @@ public:
|
||||
case FileCommand::Close:
|
||||
{
|
||||
LOG_TRACE(Service_FS, "Close %s %s", GetTypeName().c_str(), GetName().c_str());
|
||||
CloseArchive(backend->GetIdCode());
|
||||
CloseArchive(id_code);
|
||||
break;
|
||||
}
|
||||
// Unknown command...
|
||||
@ -228,9 +228,9 @@ public:
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::map<FileSys::Archive::IdCode, Handle> g_archive_map; ///< Map of file archives by IdCode
|
||||
std::map<ArchiveIdCode, Handle> g_archive_map; ///< Map of file archives by IdCode
|
||||
|
||||
ResultVal<Handle> OpenArchive(FileSys::Archive::IdCode id_code) {
|
||||
ResultVal<Handle> OpenArchive(ArchiveIdCode id_code) {
|
||||
auto itr = g_archive_map.find(id_code);
|
||||
if (itr == g_archive_map.end()) {
|
||||
return ResultCode(ErrorDescription::NotFound, ErrorModule::FS,
|
||||
@ -240,7 +240,7 @@ ResultVal<Handle> OpenArchive(FileSys::Archive::IdCode id_code) {
|
||||
return MakeResult<Handle>(itr->second);
|
||||
}
|
||||
|
||||
ResultCode CloseArchive(FileSys::Archive::IdCode id_code) {
|
||||
ResultCode CloseArchive(ArchiveIdCode id_code) {
|
||||
auto itr = g_archive_map.find(id_code);
|
||||
if (itr == g_archive_map.end()) {
|
||||
LOG_ERROR(Service_FS, "Cannot close archive %d, does not exist!", (int)id_code);
|
||||
@ -256,7 +256,7 @@ ResultCode CloseArchive(FileSys::Archive::IdCode id_code) {
|
||||
* @param archive Pointer to the archive to mount
|
||||
*/
|
||||
ResultCode MountArchive(Archive* archive) {
|
||||
FileSys::Archive::IdCode id_code = archive->backend->GetIdCode();
|
||||
ArchiveIdCode id_code = archive->id_code;
|
||||
ResultVal<Handle> archive_handle = OpenArchive(id_code);
|
||||
if (archive_handle.Succeeded()) {
|
||||
LOG_ERROR(Service_FS, "Cannot mount two archives with the same ID code! (%d)", (int) id_code);
|
||||
@ -267,10 +267,10 @@ ResultCode MountArchive(Archive* archive) {
|
||||
return RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
ResultCode CreateArchive(FileSys::Archive* backend, const std::string& name) {
|
||||
ResultCode CreateArchive(FileSys::Archive* backend, ArchiveIdCode id_code) {
|
||||
Archive* archive = new Archive;
|
||||
Handle handle = Kernel::g_object_pool.Create(archive);
|
||||
archive->name = name;
|
||||
archive->id_code = id_code;
|
||||
archive->backend = backend;
|
||||
|
||||
ResultCode result = MountArchive(archive);
|
||||
@ -411,7 +411,7 @@ void ArchiveInit() {
|
||||
std::string sdmc_directory = FileUtil::GetUserPath(D_SDMC_IDX);
|
||||
auto archive = new FileSys::Archive_SDMC(sdmc_directory);
|
||||
if (archive->Initialize())
|
||||
CreateArchive(archive, "SDMC");
|
||||
CreateArchive(archive, ArchiveIdCode::SDMC);
|
||||
else
|
||||
LOG_ERROR(Service_FS, "Can't instantiate SDMC archive with path %s", sdmc_directory.c_str());
|
||||
}
|
||||
|
@ -13,25 +13,36 @@
|
||||
namespace Service {
|
||||
namespace FS {
|
||||
|
||||
/// Supported archive types
|
||||
enum class ArchiveIdCode : u32 {
|
||||
RomFS = 0x00000003,
|
||||
SaveData = 0x00000004,
|
||||
ExtSaveData = 0x00000006,
|
||||
SharedExtSaveData = 0x00000007,
|
||||
SystemSaveData = 0x00000008,
|
||||
SDMC = 0x00000009,
|
||||
SDMCWriteOnly = 0x0000000A,
|
||||
};
|
||||
|
||||
/**
|
||||
* Opens an archive
|
||||
* @param id_code IdCode of the archive to open
|
||||
* @return Handle to the opened archive
|
||||
*/
|
||||
ResultVal<Handle> OpenArchive(FileSys::Archive::IdCode id_code);
|
||||
ResultVal<Handle> OpenArchive(ArchiveIdCode id_code);
|
||||
|
||||
/**
|
||||
* Closes an archive
|
||||
* @param id_code IdCode of the archive to open
|
||||
*/
|
||||
ResultCode CloseArchive(FileSys::Archive::IdCode id_code);
|
||||
ResultCode CloseArchive(ArchiveIdCode id_code);
|
||||
|
||||
/**
|
||||
* Creates an Archive
|
||||
* @param backend File system backend interface to the archive
|
||||
* @param name Name of Archive
|
||||
* @param id_code Id code used to access this type of archive
|
||||
*/
|
||||
ResultCode CreateArchive(FileSys::Archive* backend, const std::string& name);
|
||||
ResultCode CreateArchive(FileSys::Archive* backend, ArchiveIdCode id_code);
|
||||
|
||||
/**
|
||||
* Open a File from an Archive
|
||||
|
@ -88,7 +88,7 @@ static void OpenFile(Service::Interface* self) {
|
||||
static void OpenFileDirectly(Service::Interface* self) {
|
||||
u32* cmd_buff = Kernel::GetCommandBuffer();
|
||||
|
||||
auto archive_id = static_cast<FileSys::Archive::IdCode>(cmd_buff[2]);
|
||||
auto archive_id = static_cast<FS::ArchiveIdCode>(cmd_buff[2]);
|
||||
auto archivename_type = static_cast<FileSys::LowPathType>(cmd_buff[3]);
|
||||
u32 archivename_size = cmd_buff[4];
|
||||
auto filename_type = static_cast<FileSys::LowPathType>(cmd_buff[5]);
|
||||
@ -334,7 +334,7 @@ static void OpenDirectory(Service::Interface* self) {
|
||||
static void OpenArchive(Service::Interface* self) {
|
||||
u32* cmd_buff = Kernel::GetCommandBuffer();
|
||||
|
||||
auto archive_id = static_cast<FileSys::Archive::IdCode>(cmd_buff[1]);
|
||||
auto archive_id = static_cast<FS::ArchiveIdCode>(cmd_buff[1]);
|
||||
auto archivename_type = static_cast<FileSys::LowPathType>(cmd_buff[2]);
|
||||
u32 archivename_size = cmd_buff[3];
|
||||
u32 archivename_ptr = cmd_buff[5];
|
||||
|
@ -74,7 +74,7 @@ ResultStatus LoadFile(const std::string& filename) {
|
||||
|
||||
// Load application and RomFS
|
||||
if (ResultStatus::Success == app_loader.Load()) {
|
||||
Service::FS::CreateArchive(new FileSys::Archive_RomFS(app_loader), "RomFS");
|
||||
Service::FS::CreateArchive(new FileSys::Archive_RomFS(app_loader), Service::FS::ArchiveIdCode::RomFS);
|
||||
return ResultStatus::Success;
|
||||
}
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user