romfs_factory.cpp 2.5 KB

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