mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2024-11-05 19:51:45 +00:00
fs.mitm: use new namespace types for saves
This commit is contained in:
parent
9bb5af9823
commit
0af2758fde
4 changed files with 29 additions and 29 deletions
|
@ -176,7 +176,7 @@ namespace ams::mitm::fs {
|
||||||
return ResultSuccess();
|
return ResultSuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
Result FsMitmService::OpenSaveDataFileSystem(sf::Out<std::shared_ptr<IFileSystemInterface>> out, u8 _space_id, const FsSaveDataAttribute &attribute) {
|
Result FsMitmService::OpenSaveDataFileSystem(sf::Out<std::shared_ptr<IFileSystemInterface>> out, u8 _space_id, const fs::SaveDataAttribute &attribute) {
|
||||||
/* We only want to intercept saves for games, right now. */
|
/* We only want to intercept saves for games, right now. */
|
||||||
const bool is_game_or_hbl = this->client_info.override_status.IsHbl() || ncm::IsApplicationId(this->client_info.program_id);
|
const bool is_game_or_hbl = this->client_info.override_status.IsHbl() || ncm::IsApplicationId(this->client_info.program_id);
|
||||||
R_UNLESS(is_game_or_hbl, sm::mitm::ResultShouldForwardToSession());
|
R_UNLESS(is_game_or_hbl, sm::mitm::ResultShouldForwardToSession());
|
||||||
|
@ -188,14 +188,15 @@ namespace ams::mitm::fs {
|
||||||
R_UNLESS(cfg::HasContentSpecificFlag(this->client_info.program_id, "redirect_save"), sm::mitm::ResultShouldForwardToSession());
|
R_UNLESS(cfg::HasContentSpecificFlag(this->client_info.program_id, "redirect_save"), sm::mitm::ResultShouldForwardToSession());
|
||||||
|
|
||||||
/* Only redirect account savedata. */
|
/* Only redirect account savedata. */
|
||||||
R_UNLESS(attribute.save_data_type == FsSaveDataType_Account, sm::mitm::ResultShouldForwardToSession());
|
R_UNLESS(attribute.type == fs::SaveDataType::Account, sm::mitm::ResultShouldForwardToSession());
|
||||||
|
|
||||||
/* Get enum type for space id. */
|
/* Get enum type for space id. */
|
||||||
auto space_id = static_cast<FsSaveDataSpaceId>(_space_id);
|
auto space_id = static_cast<FsSaveDataSpaceId>(_space_id);
|
||||||
|
|
||||||
/* Verify we can open the save. */
|
/* Verify we can open the save. */
|
||||||
|
static_assert(sizeof(fs::SaveDataAttribute) == sizeof(::FsSaveDataAttribute));
|
||||||
FsFileSystem save_fs;
|
FsFileSystem save_fs;
|
||||||
R_UNLESS(R_SUCCEEDED(fsOpenSaveDataFileSystemFwd(this->forward_service.get(), &save_fs, space_id, &attribute)), sm::mitm::ResultShouldForwardToSession());
|
R_UNLESS(R_SUCCEEDED(fsOpenSaveDataFileSystemFwd(this->forward_service.get(), &save_fs, space_id, reinterpret_cast<const FsSaveDataAttribute *>(&attribute))), sm::mitm::ResultShouldForwardToSession());
|
||||||
std::unique_ptr<fs::fsa::IFileSystem> save_ifs = std::make_unique<fs::RemoteFileSystem>(save_fs);
|
std::unique_ptr<fs::fsa::IFileSystem> save_ifs = std::make_unique<fs::RemoteFileSystem>(save_fs);
|
||||||
|
|
||||||
/* Mount the SD card using fs.mitm's session. */
|
/* Mount the SD card using fs.mitm's session. */
|
||||||
|
@ -205,7 +206,7 @@ namespace ams::mitm::fs {
|
||||||
std::shared_ptr<fs::fsa::IFileSystem> sd_ifs = std::make_shared<fs::RemoteFileSystem>(sd_fs);
|
std::shared_ptr<fs::fsa::IFileSystem> sd_ifs = std::make_shared<fs::RemoteFileSystem>(sd_fs);
|
||||||
|
|
||||||
/* Verify that we can open the save directory, and that it exists. */
|
/* Verify that we can open the save directory, and that it exists. */
|
||||||
const ncm::ProgramId application_id = attribute.application_id == 0 ? this->client_info.program_id : ncm::ProgramId{attribute.application_id};
|
const ncm::ProgramId application_id = attribute.program_id == ncm::InvalidProgramId ? this->client_info.program_id : attribute.program_id;
|
||||||
char save_dir_path[fs::EntryNameLengthMax + 1];
|
char save_dir_path[fs::EntryNameLengthMax + 1];
|
||||||
R_TRY(mitm::fs::SaveUtil::GetDirectorySaveDataPath(save_dir_path, sizeof(save_dir_path), application_id, space_id, attribute));
|
R_TRY(mitm::fs::SaveUtil::GetDirectorySaveDataPath(save_dir_path, sizeof(save_dir_path), application_id, space_id, attribute));
|
||||||
|
|
||||||
|
|
|
@ -82,7 +82,7 @@ namespace ams::mitm::fs {
|
||||||
Result OpenFileSystemWithPatch(sf::Out<std::shared_ptr<IFileSystemInterface>> out, ncm::ProgramId program_id, u32 _filesystem_type);
|
Result OpenFileSystemWithPatch(sf::Out<std::shared_ptr<IFileSystemInterface>> out, ncm::ProgramId program_id, u32 _filesystem_type);
|
||||||
Result OpenFileSystemWithId(sf::Out<std::shared_ptr<IFileSystemInterface>> out, const fssrv::sf::Path &path, ncm::ProgramId program_id, u32 _filesystem_type);
|
Result OpenFileSystemWithId(sf::Out<std::shared_ptr<IFileSystemInterface>> out, const fssrv::sf::Path &path, ncm::ProgramId program_id, u32 _filesystem_type);
|
||||||
Result OpenSdCardFileSystem(sf::Out<std::shared_ptr<IFileSystemInterface>> out);
|
Result OpenSdCardFileSystem(sf::Out<std::shared_ptr<IFileSystemInterface>> out);
|
||||||
Result OpenSaveDataFileSystem(sf::Out<std::shared_ptr<IFileSystemInterface>> out, u8 space_id, const FsSaveDataAttribute &attribute);
|
Result OpenSaveDataFileSystem(sf::Out<std::shared_ptr<IFileSystemInterface>> out, u8 space_id, const ams::fs::SaveDataAttribute &attribute);
|
||||||
Result OpenBisStorage(sf::Out<std::shared_ptr<IStorageInterface>> out, u32 bis_partition_id);
|
Result OpenBisStorage(sf::Out<std::shared_ptr<IStorageInterface>> out, u32 bis_partition_id);
|
||||||
Result OpenDataStorageByCurrentProcess(sf::Out<std::shared_ptr<IStorageInterface>> out);
|
Result OpenDataStorageByCurrentProcess(sf::Out<std::shared_ptr<IStorageInterface>> out);
|
||||||
Result OpenDataStorageByDataId(sf::Out<std::shared_ptr<IStorageInterface>> out, ncm::DataId data_id, u8 storage_id);
|
Result OpenDataStorageByDataId(sf::Out<std::shared_ptr<IStorageInterface>> out, ncm::DataId data_id, u8 storage_id);
|
||||||
|
|
|
@ -22,24 +22,24 @@ namespace ams::mitm::fs {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
Result GetSaveDataSpaceIdString(const char **out_str, u8 space_id) {
|
Result GetSaveDataSpaceIdString(const char **out_str, u8 space_id) {
|
||||||
switch (space_id) {
|
switch (static_cast<SaveDataSpaceId>(space_id)) {
|
||||||
case FsSaveDataSpaceId_System:
|
case SaveDataSpaceId::System:
|
||||||
case FsSaveDataSpaceId_ProperSystem:
|
case SaveDataSpaceId::ProperSystem:
|
||||||
*out_str = "sys";
|
*out_str = "sys";
|
||||||
break;
|
break;
|
||||||
case FsSaveDataSpaceId_User:
|
case SaveDataSpaceId::User:
|
||||||
*out_str = "user";
|
*out_str = "user";
|
||||||
break;
|
break;
|
||||||
case FsSaveDataSpaceId_SdSystem:
|
case SaveDataSpaceId::SdSystem:
|
||||||
*out_str = "sd_sys";
|
*out_str = "sd_sys";
|
||||||
break;
|
break;
|
||||||
case FsSaveDataSpaceId_Temporary:
|
case SaveDataSpaceId::Temporary:
|
||||||
*out_str = "temp";
|
*out_str = "temp";
|
||||||
break;
|
break;
|
||||||
case FsSaveDataSpaceId_SdUser:
|
case SaveDataSpaceId::SdUser:
|
||||||
*out_str = "sd_user";
|
*out_str = "sd_user";
|
||||||
break;
|
break;
|
||||||
case FsSaveDataSpaceId_SafeMode:
|
case SaveDataSpaceId::SafeMode:
|
||||||
*out_str = "safe";
|
*out_str = "safe";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -49,27 +49,27 @@ namespace ams::mitm::fs {
|
||||||
return ResultSuccess();
|
return ResultSuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
Result GetSaveDataTypeString(const char **out_str, u8 save_data_type) {
|
Result GetSaveDataTypeString(const char **out_str, SaveDataType save_data_type) {
|
||||||
switch (save_data_type) {
|
switch (save_data_type) {
|
||||||
case FsSaveDataType_System:
|
case SaveDataType::System:
|
||||||
*out_str = "system";
|
*out_str = "system";
|
||||||
break;
|
break;
|
||||||
case FsSaveDataType_Account:
|
case SaveDataType::Account:
|
||||||
*out_str = "account";
|
*out_str = "account";
|
||||||
break;
|
break;
|
||||||
case FsSaveDataType_Bcat:
|
case SaveDataType::Bcat:
|
||||||
*out_str = "bcat";
|
*out_str = "bcat";
|
||||||
break;
|
break;
|
||||||
case FsSaveDataType_Device:
|
case SaveDataType::Device:
|
||||||
*out_str = "device";
|
*out_str = "device";
|
||||||
break;
|
break;
|
||||||
case FsSaveDataType_Temporary:
|
case SaveDataType::Temporary:
|
||||||
*out_str = "temp";
|
*out_str = "temp";
|
||||||
break;
|
break;
|
||||||
case FsSaveDataType_Cache:
|
case SaveDataType::Cache:
|
||||||
*out_str = "cache";
|
*out_str = "cache";
|
||||||
break;
|
break;
|
||||||
case FsSaveDataType_SystemBcat:
|
case SaveDataType::SystemBcat:
|
||||||
*out_str = "system_bcat";
|
*out_str = "system_bcat";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -80,30 +80,29 @@ namespace ams::mitm::fs {
|
||||||
return ResultSuccess();
|
return ResultSuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr inline bool IsEmptyAccountId(const AccountUid &uid) {
|
constexpr inline bool IsEmptyAccountId(const UserId &uid) {
|
||||||
constexpr AccountUid empty_uid = {};
|
return uid == InvalidUserId;
|
||||||
return std::memcmp(&uid, &empty_uid, sizeof(uid)) == 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Result SaveUtil::GetDirectorySaveDataPath(char *dst, size_t dst_size, ncm::ProgramId program_id, u8 space_id, const FsSaveDataAttribute &attribute) {
|
Result SaveUtil::GetDirectorySaveDataPath(char *dst, size_t dst_size, ncm::ProgramId program_id, u8 space_id, const fs::SaveDataAttribute &attribute) {
|
||||||
/* Saves should be separate for emunand vs sysnand. */
|
/* Saves should be separate for emunand vs sysnand. */
|
||||||
const char *emummc_str = emummc::IsActive() ? "emummc" : "sysmmc";
|
const char *emummc_str = emummc::IsActive() ? "emummc" : "sysmmc";
|
||||||
|
|
||||||
/* Get space_id, save_data_type strings. */
|
/* Get space_id, save_data_type strings. */
|
||||||
const char *space_id_str, *save_type_str;
|
const char *space_id_str, *save_type_str;
|
||||||
R_TRY(GetSaveDataSpaceIdString(&space_id_str, space_id));
|
R_TRY(GetSaveDataSpaceIdString(&space_id_str, space_id));
|
||||||
R_TRY(GetSaveDataTypeString(&save_type_str, attribute.save_data_type));
|
R_TRY(GetSaveDataTypeString(&save_type_str, attribute.type));
|
||||||
|
|
||||||
/* Initialize the path. */
|
/* Initialize the path. */
|
||||||
const bool is_system = attribute.system_save_data_id != 0 && IsEmptyAccountId(attribute.uid);
|
const bool is_system = attribute.system_save_data_id != InvalidSystemSaveDataId && IsEmptyAccountId(attribute.user_id);
|
||||||
size_t out_path_len;
|
size_t out_path_len;
|
||||||
if (is_system) {
|
if (is_system) {
|
||||||
out_path_len = static_cast<size_t>(std::snprintf(dst, dst_size, "/atmosphere/saves/%s/%s/%s/%016lx", emummc_str, space_id_str, save_type_str, attribute.system_save_data_id));
|
out_path_len = static_cast<size_t>(std::snprintf(dst, dst_size, "/atmosphere/saves/%s/%s/%s/%016lx", emummc_str, space_id_str, save_type_str, attribute.system_save_data_id));
|
||||||
} else {
|
} else {
|
||||||
out_path_len = static_cast<size_t>(std::snprintf(dst, dst_size, "/atmosphere/saves/%s/%s/%s/%016lx/%016lx%016lx", emummc_str, space_id_str, save_type_str, static_cast<u64>(program_id), attribute.uid.uid[1], attribute.uid.uid[0]));
|
out_path_len = static_cast<size_t>(std::snprintf(dst, dst_size, "/atmosphere/saves/%s/%s/%s/%016lx/%016lx%016lx", emummc_str, space_id_str, save_type_str, static_cast<u64>(program_id), attribute.user_id.data[1], attribute.user_id.data[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
R_UNLESS(out_path_len < dst_size, fs::ResultTooLongPath());
|
R_UNLESS(out_path_len < dst_size, fs::ResultTooLongPath());
|
||||||
|
|
|
@ -20,7 +20,7 @@ namespace ams::mitm::fs {
|
||||||
|
|
||||||
class SaveUtil {
|
class SaveUtil {
|
||||||
public:
|
public:
|
||||||
static Result GetDirectorySaveDataPath(char *dst, size_t dst_size, ncm::ProgramId program_id, u8 space_id, const FsSaveDataAttribute &attribute);
|
static Result GetDirectorySaveDataPath(char *dst, size_t dst_size, ncm::ProgramId program_id, u8 space_id, const ams::fs::SaveDataAttribute &attribute);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue