archive.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. // Copyright 2014 Citra Emulator Project
  2. // Licensed under GPLv2
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include "common/common_types.h"
  6. #include "core/file_sys/archive_backend.h"
  7. #include "core/hle/kernel/kernel.h"
  8. #include "core/hle/result.h"
  9. namespace Service {
  10. namespace FS {
  11. /// Supported archive types
  12. enum class ArchiveIdCode : u32 {
  13. RomFS = 0x00000003,
  14. SaveData = 0x00000004,
  15. ExtSaveData = 0x00000006,
  16. SharedExtSaveData = 0x00000007,
  17. SystemSaveData = 0x00000008,
  18. SDMC = 0x00000009,
  19. SDMCWriteOnly = 0x0000000A,
  20. };
  21. typedef u64 ArchiveHandle;
  22. /**
  23. * Opens an archive
  24. * @param id_code IdCode of the archive to open
  25. * @return Handle to the opened archive
  26. */
  27. ResultVal<ArchiveHandle> OpenArchive(ArchiveIdCode id_code);
  28. /**
  29. * Closes an archive
  30. * @param id_code IdCode of the archive to open
  31. */
  32. ResultCode CloseArchive(ArchiveHandle handle);
  33. /**
  34. * Creates an Archive
  35. * @param backend File system backend interface to the archive
  36. * @param id_code Id code used to access this type of archive
  37. */
  38. ResultCode CreateArchive(std::unique_ptr<FileSys::ArchiveBackend>&& backend, ArchiveIdCode id_code);
  39. /**
  40. * Open a File from an Archive
  41. * @param archive_handle Handle to an open Archive object
  42. * @param path Path to the File inside of the Archive
  43. * @param mode Mode under which to open the File
  44. * @return Handle to the opened File object
  45. */
  46. ResultVal<Handle> OpenFileFromArchive(ArchiveHandle archive_handle, const FileSys::Path& path, const FileSys::Mode mode);
  47. /**
  48. * Delete a File from an Archive
  49. * @param archive_handle Handle to an open Archive object
  50. * @param path Path to the File inside of the Archive
  51. * @return Whether deletion succeeded
  52. */
  53. ResultCode DeleteFileFromArchive(ArchiveHandle archive_handle, const FileSys::Path& path);
  54. /**
  55. * Rename a File between two Archives
  56. * @param src_archive_handle Handle to the source Archive object
  57. * @param src_path Path to the File inside of the source Archive
  58. * @param dest_archive_handle Handle to the destination Archive object
  59. * @param dest_path Path to the File inside of the destination Archive
  60. * @return Whether rename succeeded
  61. */
  62. ResultCode RenameFileBetweenArchives(ArchiveHandle src_archive_handle, const FileSys::Path& src_path,
  63. ArchiveHandle dest_archive_handle, const FileSys::Path& dest_path);
  64. /**
  65. * Delete a Directory from an Archive
  66. * @param archive_handle Handle to an open Archive object
  67. * @param path Path to the Directory inside of the Archive
  68. * @return Whether deletion succeeded
  69. */
  70. ResultCode DeleteDirectoryFromArchive(ArchiveHandle archive_handle, const FileSys::Path& path);
  71. /**
  72. * Create a Directory from an Archive
  73. * @param archive_handle Handle to an open Archive object
  74. * @param path Path to the Directory inside of the Archive
  75. * @return Whether creation of directory succeeded
  76. */
  77. ResultCode CreateDirectoryFromArchive(ArchiveHandle archive_handle, const FileSys::Path& path);
  78. /**
  79. * Rename a Directory between two Archives
  80. * @param src_archive_handle Handle to the source Archive object
  81. * @param src_path Path to the Directory inside of the source Archive
  82. * @param dest_archive_handle Handle to the destination Archive object
  83. * @param dest_path Path to the Directory inside of the destination Archive
  84. * @return Whether rename succeeded
  85. */
  86. ResultCode RenameDirectoryBetweenArchives(ArchiveHandle src_archive_handle, const FileSys::Path& src_path,
  87. ArchiveHandle dest_archive_handle, const FileSys::Path& dest_path);
  88. /**
  89. * Open a Directory from an Archive
  90. * @param archive_handle Handle to an open Archive object
  91. * @param path Path to the Directory inside of the Archive
  92. * @return Handle to the opened File object
  93. */
  94. ResultVal<Handle> OpenDirectoryFromArchive(ArchiveHandle archive_handle, const FileSys::Path& path);
  95. /**
  96. * Creates a blank SaveData archive.
  97. * @return ResultCode 0 on success or the corresponding code on error
  98. */
  99. ResultCode FormatSaveData();
  100. /// Initialize archives
  101. void ArchiveInit();
  102. /// Shutdown archives
  103. void ArchiveShutdown();
  104. } // namespace FS
  105. } // namespace Service