archive_savedata.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright 2014 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include <sys/stat.h>
  5. #include "common/common_types.h"
  6. #include "common/file_util.h"
  7. #include "core/file_sys/archive_savedata.h"
  8. #include "core/file_sys/disk_archive.h"
  9. #include "core/settings.h"
  10. ////////////////////////////////////////////////////////////////////////////////////////////////////
  11. // FileSys namespace
  12. namespace FileSys {
  13. Archive_SaveData::Archive_SaveData(const std::string& mount_point)
  14. : DiskArchive(mount_point) {
  15. LOG_INFO(Service_FS, "Directory %s set as SaveData.", this->mount_point.c_str());
  16. }
  17. ResultCode Archive_SaveData::Open(const Path& path) {
  18. if (concrete_mount_point.empty())
  19. concrete_mount_point = Common::StringFromFormat("%s%016X", mount_point.c_str(), Kernel::g_program_id) + DIR_SEP;
  20. if (!FileUtil::Exists(concrete_mount_point)) {
  21. // When a SaveData archive is created for the first time, it is not yet formatted
  22. // and the save file/directory structure expected by the game has not yet been initialized.
  23. // Returning the NotFormatted error code will signal the game to provision the SaveData archive
  24. // with the files and folders that it expects.
  25. return ResultCode(ErrorDescription::FS_NotFormatted, ErrorModule::FS,
  26. ErrorSummary::InvalidState, ErrorLevel::Status);
  27. }
  28. return RESULT_SUCCESS;
  29. }
  30. ResultCode Archive_SaveData::Format(const Path& path) const {
  31. FileUtil::DeleteDirRecursively(concrete_mount_point);
  32. FileUtil::CreateFullPath(concrete_mount_point);
  33. return RESULT_SUCCESS;
  34. }
  35. } // namespace FileSys