romfs_factory.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. void RomFSFactory::SetPackedUpdate(VirtualFile update_raw) {
  28. this->update_raw = std::move(update_raw);
  29. }
  30. ResultVal<VirtualFile> RomFSFactory::OpenCurrentProcess() {
  31. if (!updatable)
  32. return MakeResult<VirtualFile>(file);
  33. const PatchManager patch_manager(Core::CurrentProcess()->GetTitleID());
  34. return MakeResult<VirtualFile>(
  35. patch_manager.PatchRomFS(file, ivfc_offset, ContentRecordType::Program, update_raw));
  36. }
  37. ResultVal<VirtualFile> RomFSFactory::Open(u64 title_id, StorageId storage, ContentRecordType type) {
  38. std::shared_ptr<NCA> res;
  39. switch (storage) {
  40. case StorageId::None:
  41. res = Service::FileSystem::GetUnionContents()->GetEntry(title_id, type);
  42. break;
  43. case StorageId::NandSystem:
  44. res = Service::FileSystem::GetSystemNANDContents()->GetEntry(title_id, type);
  45. break;
  46. case StorageId::NandUser:
  47. res = Service::FileSystem::GetUserNANDContents()->GetEntry(title_id, type);
  48. break;
  49. case StorageId::SdCard:
  50. res = Service::FileSystem::GetSDMCContents()->GetEntry(title_id, type);
  51. break;
  52. default:
  53. UNIMPLEMENTED_MSG("Unimplemented storage_id={:02X}", static_cast<u8>(storage));
  54. }
  55. if (res == nullptr) {
  56. // TODO(DarkLordZach): Find the right error code to use here
  57. return ResultCode(-1);
  58. }
  59. const auto romfs = res->GetRomFS();
  60. if (romfs == nullptr) {
  61. // TODO(DarkLordZach): Find the right error code to use here
  62. return ResultCode(-1);
  63. }
  64. return MakeResult<VirtualFile>(romfs);
  65. }
  66. } // namespace FileSys