]> git.sesse.net Git - vlc/blob - bin/cachegen.c
Use var_InheritString for --decklink-video-connection.
[vlc] / bin / cachegen.c
1 /*****************************************************************************
2  * cachegen.c: LibVLC plugins cache generator
3  *****************************************************************************
4  * Copyright (C) 2010 RĂ©mi Denis-Courmont
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19  *****************************************************************************/
20
21 #ifdef HAVE_CONFIG_H
22 # include "config.h"
23 #endif
24
25 #include <vlc/vlc.h>
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <stdbool.h>
29
30 #ifdef HAVE_SETLOCALE
31 # include <locale.h>
32 #endif
33
34 #ifdef HAVE_GETOPT_H
35 # include <getopt.h>
36 #endif
37
38 static void version (void)
39 {
40     puts ("LibVLC plugins cache generation version "VERSION);
41 }
42
43 static void usage (const char *path)
44 {
45     printf (
46 "Usage: %s [-f] <path>\n"
47 "Generate the LibVLC plugins cache for the specified plugins directory.\n"
48 " -f, --force  forcefully reset the plugin cache (if it exists)\n",
49             path);
50 }
51
52 /* Explicit HACK */
53 extern void LocaleFree (const char *);
54 extern char *FromLocale (const char *);
55
56 int main (int argc, char *argv[])
57 {
58     static const struct option opts[] =
59     {
60         { "force",      no_argument,       NULL, 'f' },
61         { "help",       no_argument,       NULL, 'h' },
62         { "version",    no_argument,       NULL, 'V' },
63         { NULL,         no_argument,       NULL, '\0'}
64     };
65
66 #ifdef HAVE_SETLOCALE
67     setlocale (LC_CTYPE, ""); /* needed by FromLocale() */
68 #endif
69
70     int c;
71     bool force = false;
72
73     while ((c = getopt_long (argc, argv, "fhV", opts, NULL)) != -1)
74         switch (c)
75         {
76             case 'f':
77                 force = true;
78                 break;
79             case 'h':
80                 usage (argv[0]);
81                 return 0;
82             case 'V':
83                 version ();
84                 return 0;
85             default:
86                 usage (argv[0]);
87                 return 1;
88         }
89
90     for (int i = optind; i < argc; i++)
91     {
92         /* Note that FromLocale() can be used before libvlc is initialized */
93         const char *path = FromLocale (argv[i]);
94         char *arg;
95
96         if (asprintf (&arg, "--plugin-path=%s", path) == -1)
97             abort ();
98
99         const char *vlc_argv[7];
100         int vlc_argc = 0;
101
102         vlc_argv[vlc_argc++] = "--ignore-config";
103         vlc_argv[vlc_argc++] = "--quiet";
104         vlc_argv[vlc_argc++] = "--no-media-library";
105         if (force)
106             vlc_argv[vlc_argc++] = "--reset-plugins-cache";
107         vlc_argv[vlc_argc++] = arg;
108         vlc_argv[vlc_argc++] = "--"; /* end of options */
109         vlc_argv[vlc_argc] = NULL;
110
111         libvlc_instance_t *vlc = libvlc_new (vlc_argc, vlc_argv);
112         if (vlc != NULL)
113             libvlc_release (vlc);
114         free (arg);
115         if (vlc == NULL)
116             fprintf (stderr, "No plugins in %s\n", path);
117         LocaleFree (path);
118         if (vlc == NULL)
119             return 1;
120     }
121
122     return 0;
123 }