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

From e0065b8343bc963a89556449e00f1d20086cc1f1 Mon Sep 17 00:00:00 2001
From: Daniel Kamil Kozar <dkk089@gmail.com>
Date: Sat, 15 Dec 2018 16:26:37 +0100
Subject: [PATCH] Wrap container definitions into a structure
---
containers.c | 25 +++++++++++++++++++++++++
containers.h | 8 ++++++++
scanner.c | 33 ++++++---------------------------
3 files changed, 39 insertions(+), 27 deletions(-)
diff --git a/containers.c b/containers.c
index f5cece1..19a0bb1 100644
--- a/containers.c
+++ b/containers.c
@@ -23,6 +23,31 @@
#include "containers.h"
#include "log.h"
+const struct container_s containers[] = {
+ { "0","-1", "root" },
+ { MUSIC_ID, "0", "Music" },
+ { MUSIC_ALL_ID, MUSIC_ID, "All Music" },
+ { MUSIC_GENRE_ID, MUSIC_ID, "Genre" },
+ { MUSIC_ARTIST_ID, MUSIC_ID, "Artist" },
+ { MUSIC_ALBUM_ID, MUSIC_ID, "Album" },
+ { MUSIC_DIR_ID, MUSIC_ID, "Folders" },
+ { MUSIC_PLIST_ID, MUSIC_ID, "Playlists" },
+
+ { VIDEO_ID, "0", "Video" },
+ { VIDEO_ALL_ID, VIDEO_ID, "All Video" },
+ { VIDEO_DIR_ID, VIDEO_ID, "Folders" },
+
+ { IMAGE_ID, "0", "Pictures" },
+ { IMAGE_ALL_ID, IMAGE_ID, "All Pictures" },
+ { IMAGE_DATE_ID, IMAGE_ID, "Date Taken" },
+ { IMAGE_CAMERA_ID, IMAGE_ID, "Camera" },
+ { IMAGE_DIR_ID, IMAGE_ID, "Folders" },
+
+ { BROWSEDIR_ID, "0", "Browse Folders" },
+
+ { 0, 0, 0 }
+};
+
#define NINETY_DAYS "7776000"
const char *music_id = MUSIC_ID;
diff --git a/containers.h b/containers.h
index aef77c5..1fcf7cd 100644
--- a/containers.h
+++ b/containers.h
@@ -16,6 +16,14 @@
* along with MiniDLNA. If not, see <http://www.gnu.org/licenses/>.
*/
+struct container_s {
+ const char *object_id;
+ const char *parent_id;
+ const char *name;
+};
+
+extern const struct container_s containers[];
+
struct magic_container_s {
const char *name;
const char *objectid_match;
diff --git a/scanner.c b/scanner.c
index a730567..eb26c9e 100644
--- a/scanner.c
+++ b/scanner.c
@@ -529,30 +529,7 @@ insert_file(const char *name, const char *path, const char *parentID, int object
int
CreateDatabase(void)
{
- int ret, i;
- const char *containers[] = { "0","-1", "root",
- MUSIC_ID, "0", _("Music"),
- MUSIC_ALL_ID, MUSIC_ID, _("All Music"),
- MUSIC_GENRE_ID, MUSIC_ID, _("Genre"),
- MUSIC_ARTIST_ID, MUSIC_ID, _("Artist"),
- MUSIC_ALBUM_ID, MUSIC_ID, _("Album"),
- MUSIC_DIR_ID, MUSIC_ID, _("Folders"),
- MUSIC_PLIST_ID, MUSIC_ID, _("Playlists"),
-
- VIDEO_ID, "0", _("Video"),
- VIDEO_ALL_ID, VIDEO_ID, _("All Video"),
- VIDEO_DIR_ID, VIDEO_ID, _("Folders"),
-
- IMAGE_ID, "0", _("Pictures"),
- IMAGE_ALL_ID, IMAGE_ID, _("All Pictures"),
- IMAGE_DATE_ID, IMAGE_ID, _("Date Taken"),
- IMAGE_CAMERA_ID, IMAGE_ID, _("Camera"),
- IMAGE_DIR_ID, IMAGE_ID, _("Folders"),
-
- BROWSEDIR_ID, "0", _("Browse Folders"),
- 0 };
-
- ret = sql_exec(db, create_objectTable_sqlite);
+ int ret = sql_exec(db, create_objectTable_sqlite);
if( ret != SQLITE_OK )
goto sql_failed;
ret = sql_exec(db, create_detailTable_sqlite);
@@ -576,16 +553,18 @@ CreateDatabase(void)
ret = sql_exec(db, "INSERT into SETTINGS values ('UPDATE_ID', '0')");
if( ret != SQLITE_OK )
goto sql_failed;
- for( i=0; containers[i]; i=i+3 )
+ for( int i=0; containers[i].name; ++i )
{
+ const struct container_s *c = &containers[i];
+ const char *name = _(c->name);
ret = sql_exec(db, "INSERT into OBJECTS (OBJECT_ID, PARENT_ID, DETAIL_ID, CLASS, NAME)"
" values "
"('%s', '%s', %lld, 'container.storageFolder', '%q')",
- containers[i], containers[i+1], GetFolderMetadata(containers[i+2], NULL, NULL, NULL, 0), containers[i+2]);
+ c->object_id, c->parent_id, GetFolderMetadata(name, NULL, NULL, NULL, 0), name);
if( ret != SQLITE_OK )
goto sql_failed;
}
- for( i=0; magic_containers[i].objectid_match; i++ )
+ for( int i=0; magic_containers[i].objectid_match; i++ )
{
struct magic_container_s *magic = &magic_containers[i];
if (!magic->name)