ncm.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. #pragma once
  2. #include <stdint.h>
  3. #include <stdbool.h>
  4. #include <switch.h>
  5. typedef struct
  6. {
  7. NcmContentMetaKey key;
  8. uint8_t storage_id;
  9. uint8_t padding[0x7];
  10. } NcmContentStorageRecord;
  11. typedef struct
  12. {
  13. char major[0x3];
  14. char minor[0x3];
  15. char macro[0x3];
  16. char bug_fix[0x4];
  17. } NcmVersionString_t;
  18. typedef struct
  19. {
  20. NcmContentStorage storage; //
  21. NcmPlaceHolderId placeholder_id; // placeholder_id where the nca is written to.
  22. NcmContentId content_id;
  23. } NcmInstall_t;
  24. /*
  25. * standard ncm memes.
  26. */
  27. //
  28. bool ncm_init(void);
  29. //
  30. void ncm_exit(void);
  31. // open storage frome the given storage ID (nand / sd card).
  32. bool ncm_open_storage(NcmContentStorage *cs, NcmStorageId fs_storage_ID);
  33. // close storage.
  34. void ncm_close_storage(NcmContentStorage *cs);
  35. // check if the placeholder_id exists, should be used to check if needed to attempt to delete said placeholder_id.
  36. bool ncm_check_if_placeholder_id_exists(NcmContentStorage *cs, const NcmPlaceHolderId *placeholder_id);
  37. // create a placeholder_id.
  38. bool ncm_generate_placeholder_id(NcmContentStorage *cs, NcmPlaceHolderId *placeholder_out);
  39. // create a placeholder_id.
  40. bool ncm_create_placeholder_id(NcmContentStorage *cs, const NcmContentId *content_id, const NcmPlaceHolderId *placeholder_id, int64_t size);
  41. // get the path of the placeholder_id.
  42. bool ncm_get_placeholder_path_id(NcmContentStorage *cs, const NcmPlaceHolderId *placeholder_id, char *out, size_t size);
  43. // write data to a placeholder_id, for installing nca's.
  44. bool ncm_write_placeholder_id(NcmContentStorage *cs, const NcmPlaceHolderId *placeholder_id, uint64_t offset, const void *data, size_t data_size);
  45. // delete placeholder_id, should be used if register fails.
  46. bool ncm_delete_placeholder_id(NcmContentStorage *cs, const NcmPlaceHolderId *placeholder_id);
  47. // delete all placeholders, should be added either as an option or run on app startup.
  48. void ncm_delete_all_placeholders_id(void);
  49. // register a placeholder_id (remember to clean up after).
  50. bool ncm_register_placeholder_id(NcmContentStorage *cs, const NcmContentId *content_id, const NcmPlaceHolderId *placeholder_id);
  51. // check if the nca exists.
  52. bool ncm_check_if_content_id_exists(NcmContentStorage *cs, const NcmContentId *content_id);
  53. // delete registered nca.
  54. bool ncm_delete_content_id(NcmContentStorage *cs, const NcmContentId *content_id);
  55. // get the storage path of an installed nca from the nca_id.
  56. bool ncm_get_content_id_path(NcmContentStorage *cs, char *path_out, size_t size, const NcmContentId *content_id);
  57. // get size of placeholder_id.
  58. int64_t ncm_get_placeholder_id_size(NcmContentStorage *cs, const NcmPlaceHolderId *placeholder_id);
  59. // get the size of installed nca from the given nca_id.
  60. int64_t ncm_get_content_id_size(NcmContentStorage *cs, const NcmContentId *content_id);
  61. // read data from the nca into void *out.
  62. bool ncm_read_content_id(NcmContentStorage *cs, void *data, size_t data_size, uint64_t offset, const NcmContentId *content_id);
  63. /*
  64. * ncm_database
  65. */
  66. // open database.
  67. bool ncm_open_database(NcmContentMetaDatabase *db, NcmStorageId storage_id);
  68. // set the data in the database.
  69. bool ncm_set_database(NcmContentMetaDatabase *db, const NcmContentMetaKey *key, const void *data, size_t data_size);
  70. // commit changes made to the database.
  71. bool ncm_commit_database(NcmContentMetaDatabase *db);
  72. // close the database.
  73. void ncm_close_database(NcmContentMetaDatabase *db);
  74. /*
  75. * misc
  76. */
  77. // get the free size of the selected storage device (sd card / nand).
  78. int64_t ncm_get_storage_free_space(NcmStorageId storage_id);
  79. // get the total size of the selected storage device (sd card / nand).
  80. int64_t ncm_get_storage_total_size(NcmStorageId storage_id);
  81. //
  82. int32_t ncm_get_application_meta_total(NcmContentMetaDatabase *db, NcmContentMetaType type);
  83. //
  84. int32_t ncm_get_meta_total(NcmContentMetaDatabase *db, NcmContentMetaType type);
  85. //
  86. bool ncm_get_latest_key(NcmContentMetaDatabase *db, NcmContentMetaKey *key_out, uint64_t id);
  87. //
  88. bool ncm_get_latest_key2(NcmContentMetaKey *out_key, uint64_t id); // temp name
  89. //
  90. bool ncm_is_key_newer(const NcmContentMetaKey *key);
  91. /*
  92. * Ncm Utils
  93. */
  94. //
  95. uint64_t ncm_get_app_id_from_title_id(uint64_t title_id, NcmContentMetaType type);
  96. void ncm_get_version_string(uint32_t version, NcmVersionString_t *out);
  97. //
  98. size_t ncm_calculate_content_info_size(const NcmContentInfo *info);
  99. size_t ncm_calculate_content_infos_size(const NcmContentInfo *infos, uint16_t count);
  100. bool ncm_get_content_type_from_infos(NcmContentInfo *infos, uint16_t count, NcmContentInfo *found, NcmContentType wanted_type);
  101. //
  102. const char *ncm_get_storage_id_string(NcmStorageId storage_id);
  103. const char *ncm_get_meta_type_string(NcmContentMetaType type);
  104. const char *ncm_get_content_type_string(NcmContentType type);
  105. const char *ncm_get_attribute_string(NcmContentMetaAttribute attribute);
  106. const char *ncm_get_install_type_string(NcmContentInstallType type);
  107. /*
  108. * Debug
  109. */
  110. void ncm_print_key(const NcmContentMetaKey *key);
  111. void ncm_print_keys(const NcmContentMetaKey *key, uint16_t count);
  112. void ncm_print_application_record(const NcmContentStorageRecord *record);
  113. void ncm_print_application_records(const NcmContentStorageRecord *records, uint32_t count);