romfs_factory.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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/core.h"
  9. #include "core/file_sys/romfs_factory.h"
  10. #include "core/hle/kernel/process.h"
  11. namespace FileSys {
  12. RomFSFactory::RomFSFactory(Loader::AppLoader& app_loader) {
  13. // Load the RomFS from the app
  14. if (Loader::ResultStatus::Success != app_loader.ReadRomFS(file)) {
  15. LOG_ERROR(Service_FS, "Unable to read RomFS!");
  16. }
  17. }
  18. ResultVal<VirtualFile> RomFSFactory::OpenCurrentProcess() {
  19. return MakeResult<VirtualFile>(file);
  20. }
  21. ResultVal<VirtualFile> RomFSFactory::Open(u64 title_id, StorageId storage, ContentRecordType type) {
  22. switch (storage) {
  23. case StorageId::NandSystem: {
  24. const auto res = Service::FileSystem::GetSystemNANDContents()->GetEntry(title_id, type);
  25. if (res == nullptr) {
  26. // TODO(DarkLordZach): Find the right error code to use here
  27. return ResultCode(-1);
  28. }
  29. const auto romfs = res->GetRomFS();
  30. if (romfs == nullptr) {
  31. // TODO(DarkLordZach): Find the right error code to use here
  32. return ResultCode(-1);
  33. }
  34. return MakeResult<VirtualFile>(romfs);
  35. }
  36. case StorageId::NandUser: {
  37. const auto res = Service::FileSystem::GetUserNANDContents()->GetEntry(title_id, type);
  38. if (res == nullptr) {
  39. // TODO(DarkLordZach): Find the right error code to use here
  40. return ResultCode(-1);
  41. }
  42. const auto romfs = res->GetRomFS();
  43. if (romfs == nullptr) {
  44. // TODO(DarkLordZach): Find the right error code to use here
  45. return ResultCode(-1);
  46. }
  47. return MakeResult<VirtualFile>(romfs);
  48. }
  49. default:
  50. UNIMPLEMENTED_MSG("Unimplemented storage_id={:02X}", static_cast<u8>(storage));
  51. }
  52. }
  53. } // namespace FileSys