romfs_factory.cpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // Copyright 2018 yuzu emulator team
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include <memory>
  5. #include "common/assert.h"
  6. #include "common/common_types.h"
  7. #include "common/logging/log.h"
  8. #include "core/core.h"
  9. #include "core/file_sys/content_archive.h"
  10. #include "core/file_sys/nca_metadata.h"
  11. #include "core/file_sys/patch_manager.h"
  12. #include "core/file_sys/registered_cache.h"
  13. #include "core/file_sys/romfs_factory.h"
  14. #include "core/hle/kernel/process.h"
  15. #include "core/hle/service/filesystem/filesystem.h"
  16. #include "core/loader/loader.h"
  17. namespace FileSys {
  18. RomFSFactory::RomFSFactory(Loader::AppLoader& app_loader) {
  19. // Load the RomFS from the app
  20. if (app_loader.ReadRomFS(file) != Loader::ResultStatus::Success) {
  21. LOG_ERROR(Service_FS, "Unable to read RomFS!");
  22. }
  23. updatable = app_loader.IsRomFSUpdatable();
  24. ivfc_offset = app_loader.ReadRomFSIVFCOffset();
  25. }
  26. RomFSFactory::~RomFSFactory() = default;
  27. ResultVal<VirtualFile> RomFSFactory::OpenCurrentProcess() {
  28. if (!updatable)
  29. return MakeResult<VirtualFile>(file);
  30. const PatchManager patch_manager(Core::CurrentProcess()->program_id);
  31. return MakeResult<VirtualFile>(patch_manager.PatchRomFS(file, ivfc_offset));
  32. }
  33. ResultVal<VirtualFile> RomFSFactory::Open(u64 title_id, StorageId storage, ContentRecordType type) {
  34. switch (storage) {
  35. case StorageId::NandSystem: {
  36. const auto res = Service::FileSystem::GetSystemNANDContents()->GetEntry(title_id, type);
  37. if (res == nullptr) {
  38. // TODO(DarkLordZach): Find the right error code to use here
  39. return ResultCode(-1);
  40. }
  41. const auto romfs = res->GetRomFS();
  42. if (romfs == nullptr) {
  43. // TODO(DarkLordZach): Find the right error code to use here
  44. return ResultCode(-1);
  45. }
  46. return MakeResult<VirtualFile>(romfs);
  47. }
  48. case StorageId::NandUser: {
  49. const auto res = Service::FileSystem::GetUserNANDContents()->GetEntry(title_id, type);
  50. if (res == nullptr) {
  51. // TODO(DarkLordZach): Find the right error code to use here
  52. return ResultCode(-1);
  53. }
  54. const auto romfs = res->GetRomFS();
  55. if (romfs == nullptr) {
  56. // TODO(DarkLordZach): Find the right error code to use here
  57. return ResultCode(-1);
  58. }
  59. return MakeResult<VirtualFile>(romfs);
  60. }
  61. default:
  62. UNIMPLEMENTED_MSG("Unimplemented storage_id={:02X}", static_cast<u8>(storage));
  63. }
  64. }
  65. } // namespace FileSys