romfs_factory.cpp 2.1 KB

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