fsp-srv: use program registry for SetCurrentProcess
parent
82b58668ed
commit
aae9eea532
@ -0,0 +1,37 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "core/hle/service/filesystem/romfs_controller.h"
|
||||
|
||||
namespace Service::FileSystem {
|
||||
|
||||
RomFsController::RomFsController(std::shared_ptr<FileSys::RomFSFactory> factory_, u64 program_id_)
|
||||
: factory{std::move(factory_)}, program_id{program_id_} {}
|
||||
RomFsController::~RomFsController() = default;
|
||||
|
||||
FileSys::VirtualFile RomFsController::OpenRomFSCurrentProcess() {
|
||||
return factory->OpenCurrentProcess(program_id);
|
||||
}
|
||||
|
||||
FileSys::VirtualFile RomFsController::OpenPatchedRomFS(u64 title_id,
|
||||
FileSys::ContentRecordType type) {
|
||||
return factory->OpenPatchedRomFS(title_id, type);
|
||||
}
|
||||
|
||||
FileSys::VirtualFile RomFsController::OpenPatchedRomFSWithProgramIndex(
|
||||
u64 title_id, u8 program_index, FileSys::ContentRecordType type) {
|
||||
return factory->OpenPatchedRomFSWithProgramIndex(title_id, program_index, type);
|
||||
}
|
||||
|
||||
FileSys::VirtualFile RomFsController::OpenRomFS(u64 title_id, FileSys::StorageId storage_id,
|
||||
FileSys::ContentRecordType type) {
|
||||
return factory->Open(title_id, storage_id, type);
|
||||
}
|
||||
|
||||
std::shared_ptr<FileSys::NCA> RomFsController::OpenBaseNca(u64 title_id,
|
||||
FileSys::StorageId storage_id,
|
||||
FileSys::ContentRecordType type) {
|
||||
return factory->GetEntry(title_id, storage_id, type);
|
||||
}
|
||||
|
||||
} // namespace Service::FileSystem
|
@ -0,0 +1,31 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "core/file_sys/nca_metadata.h"
|
||||
#include "core/file_sys/romfs_factory.h"
|
||||
#include "core/file_sys/vfs_types.h"
|
||||
|
||||
namespace Service::FileSystem {
|
||||
|
||||
class RomFsController {
|
||||
public:
|
||||
explicit RomFsController(std::shared_ptr<FileSys::RomFSFactory> factory_, u64 program_id_);
|
||||
~RomFsController();
|
||||
|
||||
FileSys::VirtualFile OpenRomFSCurrentProcess();
|
||||
FileSys::VirtualFile OpenPatchedRomFS(u64 title_id, FileSys::ContentRecordType type);
|
||||
FileSys::VirtualFile OpenPatchedRomFSWithProgramIndex(u64 title_id, u8 program_index,
|
||||
FileSys::ContentRecordType type);
|
||||
FileSys::VirtualFile OpenRomFS(u64 title_id, FileSys::StorageId storage_id,
|
||||
FileSys::ContentRecordType type);
|
||||
std::shared_ptr<FileSys::NCA> OpenBaseNca(u64 title_id, FileSys::StorageId storage_id,
|
||||
FileSys::ContentRecordType type);
|
||||
|
||||
private:
|
||||
const std::shared_ptr<FileSys::RomFSFactory> factory;
|
||||
const u64 program_id;
|
||||
};
|
||||
|
||||
} // namespace Service::FileSystem
|
@ -0,0 +1,99 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "core/core.h"
|
||||
#include "core/file_sys/control_metadata.h"
|
||||
#include "core/file_sys/errors.h"
|
||||
#include "core/file_sys/patch_manager.h"
|
||||
#include "core/hle/service/filesystem/save_data_controller.h"
|
||||
#include "core/loader/loader.h"
|
||||
|
||||
namespace Service::FileSystem {
|
||||
|
||||
namespace {
|
||||
|
||||
// A default size for normal/journal save data size if application control metadata cannot be found.
|
||||
// This should be large enough to satisfy even the most extreme requirements (~4.2GB)
|
||||
constexpr u64 SufficientSaveDataSize = 0xF0000000;
|
||||
|
||||
FileSys::SaveDataSize GetDefaultSaveDataSize(Core::System& system, u64 program_id) {
|
||||
const FileSys::PatchManager pm{program_id, system.GetFileSystemController(),
|
||||
system.GetContentProvider()};
|
||||
const auto metadata = pm.GetControlMetadata();
|
||||
const auto& nacp = metadata.first;
|
||||
|
||||
if (nacp != nullptr) {
|
||||
return {nacp->GetDefaultNormalSaveSize(), nacp->GetDefaultJournalSaveSize()};
|
||||
}
|
||||
|
||||
return {SufficientSaveDataSize, SufficientSaveDataSize};
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
SaveDataController::SaveDataController(Core::System& system_,
|
||||
std::shared_ptr<FileSys::SaveDataFactory> factory_)
|
||||
: system{system_}, factory{std::move(factory_)} {}
|
||||
SaveDataController::~SaveDataController() = default;
|
||||
|
||||
Result SaveDataController::CreateSaveData(FileSys::VirtualDir* out_save_data,
|
||||
FileSys::SaveDataSpaceId space,
|
||||
const FileSys::SaveDataAttribute& attribute) {
|
||||
LOG_TRACE(Service_FS, "Creating Save Data for space_id={:01X}, save_struct={}", space,
|
||||
attribute.DebugInfo());
|
||||
|
||||
auto save_data = factory->Create(space, attribute);
|
||||
if (save_data == nullptr) {
|
||||
return FileSys::ERROR_ENTITY_NOT_FOUND;
|
||||
}
|
||||
|
||||
*out_save_data = save_data;
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result SaveDataController::OpenSaveData(FileSys::VirtualDir* out_save_data,
|
||||
FileSys::SaveDataSpaceId space,
|
||||
const FileSys::SaveDataAttribute& attribute) {
|
||||
auto save_data = factory->Open(space, attribute);
|
||||
if (save_data == nullptr) {
|
||||
return FileSys::ERROR_ENTITY_NOT_FOUND;
|
||||
}
|
||||
|
||||
*out_save_data = save_data;
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result SaveDataController::OpenSaveDataSpace(FileSys::VirtualDir* out_save_data_space,
|
||||
FileSys::SaveDataSpaceId space) {
|
||||
auto save_data_space = factory->GetSaveDataSpaceDirectory(space);
|
||||
if (save_data_space == nullptr) {
|
||||
return FileSys::ERROR_ENTITY_NOT_FOUND;
|
||||
}
|
||||
|
||||
*out_save_data_space = save_data_space;
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
FileSys::SaveDataSize SaveDataController::ReadSaveDataSize(FileSys::SaveDataType type, u64 title_id,
|
||||
u128 user_id) {
|
||||
const auto value = factory->ReadSaveDataSize(type, title_id, user_id);
|
||||
|
||||
if (value.normal == 0 && value.journal == 0) {
|
||||
const auto size = GetDefaultSaveDataSize(system, title_id);
|
||||
factory->WriteSaveDataSize(type, title_id, user_id, size);
|
||||
return size;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
void SaveDataController::WriteSaveDataSize(FileSys::SaveDataType type, u64 title_id, u128 user_id,
|
||||
FileSys::SaveDataSize new_value) {
|
||||
factory->WriteSaveDataSize(type, title_id, user_id, new_value);
|
||||
}
|
||||
|
||||
void SaveDataController::SetAutoCreate(bool state) {
|
||||
factory->SetAutoCreate(state);
|
||||
}
|
||||
|
||||
} // namespace Service::FileSystem
|
@ -0,0 +1,35 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "core/file_sys/nca_metadata.h"
|
||||
#include "core/file_sys/savedata_factory.h"
|
||||
#include "core/file_sys/vfs_types.h"
|
||||
|
||||
namespace Service::FileSystem {
|
||||
|
||||
class SaveDataController {
|
||||
public:
|
||||
explicit SaveDataController(Core::System& system,
|
||||
std::shared_ptr<FileSys::SaveDataFactory> factory_);
|
||||
~SaveDataController();
|
||||
|
||||
Result CreateSaveData(FileSys::VirtualDir* out_save_data, FileSys::SaveDataSpaceId space,
|
||||
const FileSys::SaveDataAttribute& attribute);
|
||||
Result OpenSaveData(FileSys::VirtualDir* out_save_data, FileSys::SaveDataSpaceId space,
|
||||
const FileSys::SaveDataAttribute& attribute);
|
||||
Result OpenSaveDataSpace(FileSys::VirtualDir* out_save_data_space,
|
||||
FileSys::SaveDataSpaceId space);
|
||||
|
||||
FileSys::SaveDataSize ReadSaveDataSize(FileSys::SaveDataType type, u64 title_id, u128 user_id);
|
||||
void WriteSaveDataSize(FileSys::SaveDataType type, u64 title_id, u128 user_id,
|
||||
FileSys::SaveDataSize new_value);
|
||||
void SetAutoCreate(bool state);
|
||||
|
||||
private:
|
||||
Core::System& system;
|
||||
const std::shared_ptr<FileSys::SaveDataFactory> factory;
|
||||
};
|
||||
|
||||
} // namespace Service::FileSystem
|
Loading…
Reference in New Issue