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.

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