archive_sdmc.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. // Copyright 2014 Citra Emulator Project
  2. // Licensed under GPLv2
  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_sdmc.h"
  8. #include "core/file_sys/directory_sdmc.h"
  9. #include "core/file_sys/file_sdmc.h"
  10. #include "core/settings.h"
  11. ////////////////////////////////////////////////////////////////////////////////////////////////////
  12. // FileSys namespace
  13. namespace FileSys {
  14. Archive_SDMC::Archive_SDMC(const std::string& mount_point) {
  15. this->mount_point = mount_point;
  16. DEBUG_LOG(FILESYS, "Directory %s set as SDMC.", mount_point.c_str());
  17. }
  18. Archive_SDMC::~Archive_SDMC() {
  19. }
  20. /**
  21. * Initialize the archive.
  22. * @return true if it initialized successfully
  23. */
  24. bool Archive_SDMC::Initialize() {
  25. if (!Settings::values.use_virtual_sd) {
  26. WARN_LOG(FILESYS, "SDMC disabled by config.");
  27. return false;
  28. }
  29. if (!FileUtil::CreateFullPath(mount_point)) {
  30. WARN_LOG(FILESYS, "Unable to create SDMC path.");
  31. return false;
  32. }
  33. return true;
  34. }
  35. /**
  36. * Open a file specified by its path, using the specified mode
  37. * @param path Path relative to the archive
  38. * @param mode Mode to open the file with
  39. * @return Opened file, or nullptr
  40. */
  41. std::unique_ptr<File> Archive_SDMC::OpenFile(const Path& path, const Mode mode) const {
  42. DEBUG_LOG(FILESYS, "called path=%s mode=%d", path.DebugStr().c_str(), mode);
  43. File_SDMC* file = new File_SDMC(this, path, mode);
  44. if (!file->Open())
  45. return nullptr;
  46. return std::unique_ptr<File>(file);
  47. }
  48. /**
  49. * Create a directory specified by its path
  50. * @param path Path relative to the archive
  51. * @return Whether the directory could be created
  52. */
  53. bool Archive_SDMC::CreateDirectory(const Path& path) const {
  54. return FileUtil::CreateDir(GetMountPoint() + path.AsString());
  55. }
  56. /**
  57. * Open a directory specified by its path
  58. * @param path Path relative to the archive
  59. * @return Opened directory, or nullptr
  60. */
  61. std::unique_ptr<Directory> Archive_SDMC::OpenDirectory(const Path& path) const {
  62. DEBUG_LOG(FILESYS, "called path=%s", path.DebugStr().c_str());
  63. Directory_SDMC* directory = new Directory_SDMC(this, path);
  64. return std::unique_ptr<Directory>(directory);
  65. }
  66. /**
  67. * Read data from the archive
  68. * @param offset Offset in bytes to start reading archive from
  69. * @param length Length in bytes to read data from archive
  70. * @param buffer Buffer to read data into
  71. * @return Number of bytes read
  72. */
  73. size_t Archive_SDMC::Read(const u64 offset, const u32 length, u8* buffer) const {
  74. ERROR_LOG(FILESYS, "(UNIMPLEMENTED)");
  75. return -1;
  76. }
  77. /**
  78. * Write data to the archive
  79. * @param offset Offset in bytes to start writing data to
  80. * @param length Length in bytes of data to write to archive
  81. * @param buffer Buffer to write data from
  82. * @param flush The flush parameters (0 == do not flush)
  83. * @return Number of bytes written
  84. */
  85. size_t Archive_SDMC::Write(const u64 offset, const u32 length, const u32 flush, u8* buffer) {
  86. ERROR_LOG(FILESYS, "(UNIMPLEMENTED)");
  87. return -1;
  88. }
  89. /**
  90. * Get the size of the archive in bytes
  91. * @return Size of the archive in bytes
  92. */
  93. size_t Archive_SDMC::GetSize() const {
  94. ERROR_LOG(FILESYS, "(UNIMPLEMENTED)");
  95. return 0;
  96. }
  97. /**
  98. * Set the size of the archive in bytes
  99. */
  100. void Archive_SDMC::SetSize(const u64 size) {
  101. ERROR_LOG(FILESYS, "(UNIMPLEMENTED)");
  102. }
  103. /**
  104. * Getter for the path used for this Archive
  105. * @return Mount point of that passthrough archive
  106. */
  107. std::string Archive_SDMC::GetMountPoint() const {
  108. return mount_point;
  109. }
  110. } // namespace FileSys