]> git.sesse.net Git - vlc/blob - bin/cachegen.c
demux: ts: rewrite/split IOD parsing
[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 #ifdef HAVE_GETOPT_H
30 # include <getopt.h>
31 #endif
32 #ifdef WIN32
33 # include <windows.h>
34 #endif
35
36 static void version (void)
37 {
38     puts ("LibVLC plugins cache generation version "VERSION);
39 }
40
41 static void usage (const char *path)
42 {
43     printf (
44 "Usage: %s [-f] <path>\n"
45 "Generate the LibVLC plugins cache for the specified plugins directory.\n"
46 " -f, --force  forcefully reset the plugin cache (if it exists)\n",
47             path);
48 }
49
50 int main (int argc, char *argv[])
51 {
52 #ifdef WIN32
53     SetErrorMode(SEM_FAILCRITICALERRORS);
54 #endif
55     static const struct option opts[] =
56     {
57         { "force",      no_argument,       NULL, 'f' },
58         { "help",       no_argument,       NULL, 'h' },
59         { "version",    no_argument,       NULL, 'V' },
60         { NULL,         no_argument,       NULL, '\0'}
61     };
62
63     int c;
64     bool force = false;
65
66     while ((c = getopt_long (argc, argv, "fhV", opts, NULL)) != -1)
67         switch (c)
68         {
69             case 'f':
70                 force = true;
71                 break;
72             case 'h':
73                 usage (argv[0]);
74                 return 0;
75             case 'V':
76                 version ();
77                 return 0;
78             default:
79                 usage (argv[0]);
80                 return 1;
81         }
82
83     for (int i = optind; i < argc; i++)
84     {
85         const char *path = argv[i];
86
87         if (setenv ("VLC_PLUGIN_PATH", path, 1))
88             abort ();
89
90         const char *vlc_argv[4];
91         int vlc_argc = 0;
92
93         vlc_argv[vlc_argc++] = "--quiet";
94         if (force)
95             vlc_argv[vlc_argc++] = "--reset-plugins-cache";
96         vlc_argv[vlc_argc++] = "--"; /* end of options */
97         vlc_argv[vlc_argc] = NULL;
98
99         libvlc_instance_t *vlc = libvlc_new (vlc_argc, vlc_argv);
100         if (vlc != NULL)
101             libvlc_release (vlc);
102         if (vlc == NULL)
103             fprintf (stderr, "No plugins in %s\n", path);
104         if (vlc == NULL)
105             return 1;
106     }
107
108     return 0;
109 }