savedata_factory.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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/core.h"
  10. #include "core/file_sys/disk_filesystem.h"
  11. #include "core/file_sys/savedata_factory.h"
  12. #include "core/hle/kernel/process.h"
  13. namespace FileSys {
  14. SaveData_Factory::SaveData_Factory(std::string nand_directory)
  15. : nand_directory(std::move(nand_directory)) {}
  16. ResultVal<std::unique_ptr<FileSystemBackend>> SaveData_Factory::Open(const Path& path) {
  17. std::string save_directory = GetFullPath();
  18. // Return an error if the save data doesn't actually exist.
  19. if (!FileUtil::IsDirectory(save_directory)) {
  20. // TODO(Subv): Find out correct error code.
  21. return ResultCode(-1);
  22. }
  23. auto archive = std::make_unique<Disk_FileSystem>(save_directory);
  24. return MakeResult<std::unique_ptr<FileSystemBackend>>(std::move(archive));
  25. }
  26. ResultCode SaveData_Factory::Format(const Path& path) {
  27. LOG_WARNING(Service_FS, "Format archive %s", GetName().c_str());
  28. // Create the save data directory.
  29. if (!FileUtil::CreateFullPath(GetFullPath())) {
  30. // TODO(Subv): Find the correct error code.
  31. return ResultCode(-1);
  32. }
  33. return RESULT_SUCCESS;
  34. }
  35. ResultVal<ArchiveFormatInfo> SaveData_Factory::GetFormatInfo(const Path& path) const {
  36. LOG_ERROR(Service_FS, "Unimplemented GetFormatInfo archive %s", GetName().c_str());
  37. // TODO(bunnei): Find the right error code for this
  38. return ResultCode(-1);
  39. }
  40. std::string SaveData_Factory::GetFullPath() const {
  41. u64 title_id = Core::CurrentProcess()->program_id;
  42. // TODO(Subv): Somehow obtain this value.
  43. u32 user = 0;
  44. return Common::StringFromFormat("%ssave/%016" PRIX64 "/%08X/", nand_directory.c_str(), title_id,
  45. user);
  46. }
  47. } // namespace FileSys