]> git.sesse.net Git - vlc/blob - bin/cachegen.c
Add vlc-cache-gen to generate the plugins cache off-line
[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 <locale.h>
29
30 #ifdef HAVE_GETOPT_H
31 # include <getopt.h>
32 #endif
33
34 static void version (void)
35 {
36     puts ("LibVLC plugins cache generation version "VERSION);
37 }
38
39 static void usage (const char *path)
40 {
41     printf ("Usage: %s <path>\n"
42             "Generate the LibVLC plugins cache "
43             "for the specified plugins directory.\n", path);
44 }
45
46 /* Explicit HACK */
47 extern void LocaleFree (const char *);
48 extern char *FromLocale (const char *);
49
50 int main (int argc, char *argv[])
51 {
52     static const struct option opts[] =
53     {
54         { "help",       no_argument,       NULL, 'h' },
55         { "version",    no_argument,       NULL, 'V' },
56         { NULL,         no_argument,       NULL, '\0'}
57     };
58
59     setlocale (LC_CTYPE, ""); /* needed by FromLocale() */
60
61     int c;
62     while ((c = getopt_long (argc, argv, "hV", opts, NULL)) != -1)
63         switch (c)
64         {
65             case 'h':
66                 usage (argv[0]);
67                 return 0;
68             case 'V':
69                 version ();
70                 return 0;
71             default:
72                 usage (argv[0]);
73                 return 1;
74         }
75
76     for (int i = optind; i < argc; i++)
77     {
78         /* Note that FromLocale() can be used before libvlc is initialized */
79         const char *path = FromLocale (argv[i]);
80         char *arg;
81
82         if (asprintf (&arg, "--plugin-path=%s", path) == -1)
83             abort ();
84
85         const char *const vlc_argv[] = {
86             "--ignore-config",
87             "--quiet",
88             arg,
89             NULL,
90         };
91
92         libvlc_exception_t ex;
93         libvlc_exception_init (&ex);
94
95         libvlc_instance_t *vlc = libvlc_new (3, vlc_argv, &ex);
96         if (vlc != NULL)
97             libvlc_release (vlc);
98         free (arg);
99         if (vlc == NULL)
100             fprintf (stderr, "No plugins in %s\n", path);
101         LocaleFree (path);
102         if (vlc == NULL)
103             return 1;
104     }
105
106     return 0;
107 }