savedata_factory.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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/common_types.h"
  6. #include "common/logging/log.h"
  7. #include "core/core.h"
  8. #include "core/file_sys/disk_filesystem.h"
  9. #include "core/file_sys/savedata_factory.h"
  10. #include "core/hle/kernel/process.h"
  11. namespace FileSys {
  12. SaveData_Factory::SaveData_Factory(std::string nand_directory)
  13. : nand_directory(std::move(nand_directory)) {}
  14. ResultVal<std::unique_ptr<FileSystemBackend>> SaveData_Factory::Open(const Path& path) {
  15. std::string save_directory = GetFullPath();
  16. if (!FileUtil::Exists(save_directory)) {
  17. // TODO(bunnei): This is a work-around to always create a save data directory if it does not
  18. // already exist. This is a hack, as we do not understand yet how this works on hardware.
  19. // Without a save data directory, many games will assert on boot. This should not have any
  20. // bad side-effects.
  21. FileUtil::CreateFullPath(save_directory);
  22. }
  23. // Return an error if the save data doesn't actually exist.
  24. if (!FileUtil::IsDirectory(save_directory)) {
  25. // TODO(Subv): Find out correct error code.
  26. return ResultCode(-1);
  27. }
  28. auto archive = std::make_unique<Disk_FileSystem>(save_directory);
  29. return MakeResult<std::unique_ptr<FileSystemBackend>>(std::move(archive));
  30. }
  31. ResultCode SaveData_Factory::Format(const Path& path) {
  32. LOG_WARNING(Service_FS, "Format archive {}", GetName());
  33. // Create the save data directory.
  34. if (!FileUtil::CreateFullPath(GetFullPath())) {
  35. // TODO(Subv): Find the correct error code.
  36. return ResultCode(-1);
  37. }
  38. return RESULT_SUCCESS;
  39. }
  40. ResultVal<ArchiveFormatInfo> SaveData_Factory::GetFormatInfo(const Path& path) const {
  41. LOG_ERROR(Service_FS, "Unimplemented GetFormatInfo archive {}", GetName());
  42. // TODO(bunnei): Find the right error code for this
  43. return ResultCode(-1);
  44. }
  45. std::string SaveData_Factory::GetFullPath() const {
  46. u64 title_id = Core::CurrentProcess()->program_id;
  47. // TODO(Subv): Somehow obtain this value.
  48. u32 user = 0;
  49. return fmt::format("{}save/{:016X}/{:08X}/", nand_directory, title_id, user);
  50. }
  51. } // namespace FileSys