You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

118 lines
4.0 KiB

  1. From e0065b8343bc963a89556449e00f1d20086cc1f1 Mon Sep 17 00:00:00 2001
  2. From: Daniel Kamil Kozar <dkk089@gmail.com>
  3. Date: Sat, 15 Dec 2018 16:26:37 +0100
  4. Subject: [PATCH] Wrap container definitions into a structure
  5. ---
  6. containers.c | 25 +++++++++++++++++++++++++
  7. containers.h | 8 ++++++++
  8. scanner.c | 33 ++++++---------------------------
  9. 3 files changed, 39 insertions(+), 27 deletions(-)
  10. --- a/containers.c
  11. +++ b/containers.c
  12. @@ -23,6 +23,31 @@
  13. #include "containers.h"
  14. #include "log.h"
  15. +const struct container_s containers[] = {
  16. + { "0","-1", "root" },
  17. + { MUSIC_ID, "0", "Music" },
  18. + { MUSIC_ALL_ID, MUSIC_ID, "All Music" },
  19. + { MUSIC_GENRE_ID, MUSIC_ID, "Genre" },
  20. + { MUSIC_ARTIST_ID, MUSIC_ID, "Artist" },
  21. + { MUSIC_ALBUM_ID, MUSIC_ID, "Album" },
  22. + { MUSIC_DIR_ID, MUSIC_ID, "Folders" },
  23. + { MUSIC_PLIST_ID, MUSIC_ID, "Playlists" },
  24. +
  25. + { VIDEO_ID, "0", "Video" },
  26. + { VIDEO_ALL_ID, VIDEO_ID, "All Video" },
  27. + { VIDEO_DIR_ID, VIDEO_ID, "Folders" },
  28. +
  29. + { IMAGE_ID, "0", "Pictures" },
  30. + { IMAGE_ALL_ID, IMAGE_ID, "All Pictures" },
  31. + { IMAGE_DATE_ID, IMAGE_ID, "Date Taken" },
  32. + { IMAGE_CAMERA_ID, IMAGE_ID, "Camera" },
  33. + { IMAGE_DIR_ID, IMAGE_ID, "Folders" },
  34. +
  35. + { BROWSEDIR_ID, "0", "Browse Folders" },
  36. +
  37. + { 0, 0, 0 }
  38. +};
  39. +
  40. #define NINETY_DAYS "7776000"
  41. const char *music_id = MUSIC_ID;
  42. --- a/containers.h
  43. +++ b/containers.h
  44. @@ -16,6 +16,14 @@
  45. * along with MiniDLNA. If not, see <http://www.gnu.org/licenses/>.
  46. */
  47. +struct container_s {
  48. + const char *object_id;
  49. + const char *parent_id;
  50. + const char *name;
  51. +};
  52. +
  53. +extern const struct container_s containers[];
  54. +
  55. struct magic_container_s {
  56. const char *name;
  57. const char *objectid_match;
  58. --- a/scanner.c
  59. +++ b/scanner.c
  60. @@ -529,30 +529,7 @@ insert_file(const char *name, const char
  61. int
  62. CreateDatabase(void)
  63. {
  64. - int ret, i;
  65. - const char *containers[] = { "0","-1", "root",
  66. - MUSIC_ID, "0", _("Music"),
  67. - MUSIC_ALL_ID, MUSIC_ID, _("All Music"),
  68. - MUSIC_GENRE_ID, MUSIC_ID, _("Genre"),
  69. - MUSIC_ARTIST_ID, MUSIC_ID, _("Artist"),
  70. - MUSIC_ALBUM_ID, MUSIC_ID, _("Album"),
  71. - MUSIC_DIR_ID, MUSIC_ID, _("Folders"),
  72. - MUSIC_PLIST_ID, MUSIC_ID, _("Playlists"),
  73. -
  74. - VIDEO_ID, "0", _("Video"),
  75. - VIDEO_ALL_ID, VIDEO_ID, _("All Video"),
  76. - VIDEO_DIR_ID, VIDEO_ID, _("Folders"),
  77. -
  78. - IMAGE_ID, "0", _("Pictures"),
  79. - IMAGE_ALL_ID, IMAGE_ID, _("All Pictures"),
  80. - IMAGE_DATE_ID, IMAGE_ID, _("Date Taken"),
  81. - IMAGE_CAMERA_ID, IMAGE_ID, _("Camera"),
  82. - IMAGE_DIR_ID, IMAGE_ID, _("Folders"),
  83. -
  84. - BROWSEDIR_ID, "0", _("Browse Folders"),
  85. - 0 };
  86. -
  87. - ret = sql_exec(db, create_objectTable_sqlite);
  88. + int ret = sql_exec(db, create_objectTable_sqlite);
  89. if( ret != SQLITE_OK )
  90. goto sql_failed;
  91. ret = sql_exec(db, create_detailTable_sqlite);
  92. @@ -576,16 +553,18 @@ CreateDatabase(void)
  93. ret = sql_exec(db, "INSERT into SETTINGS values ('UPDATE_ID', '0')");
  94. if( ret != SQLITE_OK )
  95. goto sql_failed;
  96. - for( i=0; containers[i]; i=i+3 )
  97. + for( int i=0; containers[i].name; ++i )
  98. {
  99. + const struct container_s *c = &containers[i];
  100. + const char *name = _(c->name);
  101. ret = sql_exec(db, "INSERT into OBJECTS (OBJECT_ID, PARENT_ID, DETAIL_ID, CLASS, NAME)"
  102. " values "
  103. "('%s', '%s', %lld, 'container.storageFolder', '%q')",
  104. - containers[i], containers[i+1], GetFolderMetadata(containers[i+2], NULL, NULL, NULL, 0), containers[i+2]);
  105. + c->object_id, c->parent_id, GetFolderMetadata(name, NULL, NULL, NULL, 0), name);
  106. if( ret != SQLITE_OK )
  107. goto sql_failed;
  108. }
  109. - for( i=0; magic_containers[i].objectid_match; i++ )
  110. + for( int i=0; magic_containers[i].objectid_match; i++ )
  111. {
  112. struct magic_container_s *magic = &magic_containers[i];
  113. if (!magic->name)