savedata_factory.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Copyright 2018 yuzu emulator team
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include <cinttypes>
  5. #include <memory>
  6. #include "common/common_types.h"
  7. #include "common/logging/log.h"
  8. #include "common/string_util.h"
  9. #include "core/file_sys/disk_filesystem.h"
  10. #include "core/file_sys/savedata_factory.h"
  11. #include "core/hle/kernel/process.h"
  12. namespace FileSys {
  13. SaveData_Factory::SaveData_Factory(std::string nand_directory)
  14. : nand_directory(std::move(nand_directory)) {}
  15. ResultVal<std::unique_ptr<FileSystemBackend>> SaveData_Factory::Open(const Path& path) {
  16. std::string save_directory = GetFullPath();
  17. // Return an error if the save data doesn't actually exist.
  18. if (!FileUtil::IsDirectory(save_directory)) {
  19. // TODO(Subv): Find out correct error code.
  20. return ResultCode(-1);
  21. }
  22. auto archive = std::make_unique<Disk_FileSystem>(save_directory);
  23. return MakeResult<std::unique_ptr<FileSystemBackend>>(std::move(archive));
  24. }
  25. ResultCode SaveData_Factory::Format(const Path& path) {
  26. LOG_WARNING(Service_FS, "Format archive %s", GetName().c_str());
  27. // Create the save data directory.
  28. if (!FileUtil::CreateFullPath(GetFullPath())) {
  29. // TODO(Subv): Find the correct error code.
  30. return ResultCode(-1);
  31. }
  32. return RESULT_SUCCESS;
  33. }
  34. ResultVal<ArchiveFormatInfo> SaveData_Factory::GetFormatInfo(const Path& path) const {
  35. LOG_ERROR(Service_FS, "Unimplemented GetFormatInfo archive %s", GetName().c_str());
  36. // TODO(bunnei): Find the right error code for this
  37. return ResultCode(-1);
  38. }
  39. std::string SaveData_Factory::GetFullPath() const {
  40. u64 title_id = Kernel::g_current_process->program_id;
  41. // TODO(Subv): Somehow obtain this value.
  42. u32 user = 0;
  43. return Common::StringFromFormat("%ssave/%016" PRIX64 "/%08X/", nand_directory.c_str(), title_id,
  44. user);
  45. }
  46. } // namespace FileSys