archive_sdmcwriteonly.cpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Copyright 2016 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include <memory>
  5. #include "common/file_util.h"
  6. #include "core/file_sys/archive_sdmcwriteonly.h"
  7. #include "core/file_sys/directory_backend.h"
  8. #include "core/file_sys/errors.h"
  9. #include "core/file_sys/file_backend.h"
  10. #include "core/settings.h"
  11. ////////////////////////////////////////////////////////////////////////////////////////////////////
  12. // FileSys namespace
  13. namespace FileSys {
  14. ResultVal<std::unique_ptr<FileBackend>> SDMCWriteOnlyArchive::OpenFile(const Path& path,
  15. const Mode& mode) const {
  16. if (mode.read_flag) {
  17. LOG_ERROR(Service_FS, "Read flag is not supported");
  18. return ERROR_INVALID_READ_FLAG;
  19. }
  20. return SDMCArchive::OpenFileBase(path, mode);
  21. }
  22. ResultVal<std::unique_ptr<DirectoryBackend>> SDMCWriteOnlyArchive::OpenDirectory(
  23. const Path& path) const {
  24. LOG_ERROR(Service_FS, "Not supported");
  25. return ERROR_UNSUPPORTED_OPEN_FLAGS;
  26. }
  27. ArchiveFactory_SDMCWriteOnly::ArchiveFactory_SDMCWriteOnly(const std::string& mount_point)
  28. : sdmc_directory(mount_point) {
  29. LOG_DEBUG(Service_FS, "Directory %s set as SDMCWriteOnly.", sdmc_directory.c_str());
  30. }
  31. bool ArchiveFactory_SDMCWriteOnly::Initialize() {
  32. if (!Settings::values.use_virtual_sd) {
  33. LOG_WARNING(Service_FS, "SDMC disabled by config.");
  34. return false;
  35. }
  36. if (!FileUtil::CreateFullPath(sdmc_directory)) {
  37. LOG_ERROR(Service_FS, "Unable to create SDMC path.");
  38. return false;
  39. }
  40. return true;
  41. }
  42. ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_SDMCWriteOnly::Open(const Path& path) {
  43. auto archive = std::make_unique<SDMCWriteOnlyArchive>(sdmc_directory);
  44. return MakeResult<std::unique_ptr<ArchiveBackend>>(std::move(archive));
  45. }
  46. ResultCode ArchiveFactory_SDMCWriteOnly::Format(const Path& path,
  47. const FileSys::ArchiveFormatInfo& format_info) {
  48. // TODO(wwylele): hwtest this
  49. LOG_ERROR(Service_FS, "Attempted to format a SDMC write-only archive.");
  50. return ResultCode(-1);
  51. }
  52. ResultVal<ArchiveFormatInfo> ArchiveFactory_SDMCWriteOnly::GetFormatInfo(const Path& path) const {
  53. // TODO(Subv): Implement
  54. LOG_ERROR(Service_FS, "Unimplemented GetFormatInfo archive %s", GetName().c_str());
  55. return ResultCode(-1);
  56. }
  57. } // namespace FileSys