archive_savedatacheck.cpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright 2014 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include <algorithm>
  5. #include <vector>
  6. #include "common/common_types.h"
  7. #include "common/file_util.h"
  8. #include "common/logging/log.h"
  9. #include "common/make_unique.h"
  10. #include "common/string_util.h"
  11. #include "core/file_sys/archive_savedatacheck.h"
  12. #include "core/file_sys/ivfc_archive.h"
  13. #include "core/hle/service/fs/archive.h"
  14. ////////////////////////////////////////////////////////////////////////////////////////////////////
  15. // FileSys namespace
  16. namespace FileSys {
  17. static std::string GetSaveDataCheckContainerPath(const std::string& nand_directory) {
  18. return Common::StringFromFormat("%s%s/title/", nand_directory.c_str(), SYSTEM_ID.c_str());
  19. }
  20. static std::string GetSaveDataCheckPath(const std::string& mount_point, u32 high, u32 low) {
  21. return Common::StringFromFormat("%s%08x/%08x/content/00000000.app.romfs",
  22. mount_point.c_str(), high, low);
  23. }
  24. ArchiveFactory_SaveDataCheck::ArchiveFactory_SaveDataCheck(const std::string& nand_directory) :
  25. mount_point(GetSaveDataCheckContainerPath(nand_directory)) {
  26. }
  27. ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_SaveDataCheck::Open(const Path& path) {
  28. auto vec = path.AsBinary();
  29. const u32* data = reinterpret_cast<u32*>(vec.data());
  30. std::string file_path = GetSaveDataCheckPath(mount_point, data[1], data[0]);
  31. FileUtil::IOFile file(file_path, "rb");
  32. if (!file.IsOpen()) {
  33. return ResultCode(-1); // TODO(Subv): Find the right error code
  34. }
  35. auto size = file.GetSize();
  36. auto raw_data = std::make_shared<std::vector<u8>>(size);
  37. file.ReadBytes(raw_data->data(), size);
  38. file.Close();
  39. auto archive = Common::make_unique<IVFCArchive>(std::move(raw_data));
  40. return MakeResult<std::unique_ptr<ArchiveBackend>>(std::move(archive));
  41. }
  42. ResultCode ArchiveFactory_SaveDataCheck::Format(const Path& path) {
  43. LOG_ERROR(Service_FS, "Attempted to format a SaveDataCheck archive.");
  44. // TODO: Verify error code
  45. return ResultCode(ErrorDescription::NotAuthorized, ErrorModule::FS,
  46. ErrorSummary::NotSupported, ErrorLevel::Permanent);
  47. }
  48. } // namespace FileSys