romfs_factory.cpp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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/card_image.h"
  10. #include "core/file_sys/content_archive.h"
  11. #include "core/file_sys/nca_metadata.h"
  12. #include "core/file_sys/patch_manager.h"
  13. #include "core/file_sys/registered_cache.h"
  14. #include "core/file_sys/romfs_factory.h"
  15. #include "core/hle/kernel/process.h"
  16. #include "core/hle/service/filesystem/filesystem.h"
  17. #include "core/loader/loader.h"
  18. namespace FileSys {
  19. RomFSFactory::RomFSFactory(Loader::AppLoader& app_loader) {
  20. // Load the RomFS from the app
  21. if (app_loader.ReadRomFS(file) != Loader::ResultStatus::Success) {
  22. LOG_ERROR(Service_FS, "Unable to read RomFS!");
  23. }
  24. updatable = app_loader.IsRomFSUpdatable();
  25. ivfc_offset = app_loader.ReadRomFSIVFCOffset();
  26. }
  27. RomFSFactory::~RomFSFactory() = default;
  28. void RomFSFactory::SetPackedUpdate(VirtualFile update_raw) {
  29. this->update_raw = std::move(update_raw);
  30. }
  31. ResultVal<VirtualFile> RomFSFactory::OpenCurrentProcess() {
  32. if (!updatable)
  33. return MakeResult<VirtualFile>(file);
  34. const PatchManager patch_manager(Core::CurrentProcess()->GetTitleID());
  35. return MakeResult<VirtualFile>(
  36. patch_manager.PatchRomFS(file, ivfc_offset, ContentRecordType::Program, update_raw));
  37. }
  38. ResultVal<VirtualFile> RomFSFactory::Open(u64 title_id, StorageId storage, ContentRecordType type) {
  39. std::shared_ptr<NCA> res;
  40. switch (storage) {
  41. case StorageId::None:
  42. res = Core::System::GetInstance().GetContentProvider().GetEntry(title_id, type);
  43. break;
  44. case StorageId::NandSystem:
  45. res =
  46. Core::System::GetInstance().GetFileSystemController().GetSystemNANDContents()->GetEntry(
  47. title_id, type);
  48. break;
  49. case StorageId::NandUser:
  50. res = Core::System::GetInstance().GetFileSystemController().GetUserNANDContents()->GetEntry(
  51. title_id, type);
  52. break;
  53. case StorageId::SdCard:
  54. res = Core::System::GetInstance().GetFileSystemController().GetSDMCContents()->GetEntry(
  55. title_id, type);
  56. break;
  57. default:
  58. UNIMPLEMENTED_MSG("Unimplemented storage_id={:02X}", static_cast<u8>(storage));
  59. }
  60. if (res == nullptr) {
  61. // TODO(DarkLordZach): Find the right error code to use here
  62. return ResultCode(-1);
  63. }
  64. const auto romfs = res->GetRomFS();
  65. if (romfs == nullptr) {
  66. // TODO(DarkLordZach): Find the right error code to use here
  67. return ResultCode(-1);
  68. }
  69. return MakeResult<VirtualFile>(romfs);
  70. }
  71. } // namespace FileSys