archive_savedatacheck.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Copyright 2014 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include "common/file_util.h"
  5. #include "core/file_sys/archive_savedatacheck.h"
  6. #include "core/hle/service/fs/archive.h"
  7. ////////////////////////////////////////////////////////////////////////////////////////////////////
  8. // FileSys namespace
  9. namespace FileSys {
  10. static std::string GetSaveDataCheckContainerPath(const std::string& mount_point) {
  11. return Common::StringFromFormat("%s%s/title", mount_point.c_str(), SYSTEM_ID.c_str());
  12. }
  13. static std::string GetSaveDataCheckPath(const std::string& mount_point, u32 high, u32 low) {
  14. return Common::StringFromFormat("%s%08x/%08x/content/00000000.app.romfs",
  15. mount_point.c_str(), high, low);
  16. }
  17. Archive_SaveDataCheck::Archive_SaveDataCheck(const std::string& mount_loc) :
  18. mount_point(GetSaveDataCheckContainerPath(mount_loc)) {
  19. }
  20. ResultCode Archive_SaveDataCheck::Open(const Path& path) {
  21. // TODO(Subv): We should not be overwriting raw_data everytime this function is called,
  22. // but until we use factory classes to create the archives at runtime instead of creating them beforehand
  23. // and allow multiple archives of the same type to be open at the same time without clobbering each other,
  24. // we won't be able to maintain the state of each archive, hence we overwrite it every time it's needed.
  25. // There are a number of problems with this, for example opening a file in this archive, then opening
  26. // this archive again with a different path, will corrupt the previously open file.
  27. auto vec = path.AsBinary();
  28. const u32* data = reinterpret_cast<u32*>(vec.data());
  29. std::string file_path = GetSaveDataCheckPath(mount_point, data[1], data[0]);
  30. FileUtil::IOFile file(file_path, "rb");
  31. std::fill(raw_data.begin(), raw_data.end(), 0);
  32. if (!file.IsOpen()) {
  33. return ResultCode(-1); // TODO(Subv): Find the right error code
  34. }
  35. auto size = file.GetSize();
  36. raw_data.resize(size);
  37. file.ReadBytes(raw_data.data(), size);
  38. file.Close();
  39. return RESULT_SUCCESS;
  40. }
  41. } // namespace FileSys