X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=bin%2Fcachegen.c;h=8e72bf40b27d9638ee9284b49506e2e81788ce21;hb=e801e17989806362fff307836cf441db9cdab7d3;hp=17f01a3a1a212733041dfe9690fba5004e240f3a;hpb=54a847e61499d93ba027fa73ec5715aadd96d2f0;p=vlc diff --git a/bin/cachegen.c b/bin/cachegen.c index 17f01a3a1a..8e72bf40b2 100644 --- a/bin/cachegen.c +++ b/bin/cachegen.c @@ -25,14 +25,13 @@ #include #include #include - -#ifdef HAVE_SETLOCALE -# include -#endif - +#include #ifdef HAVE_GETOPT_H # include #endif +#ifdef WIN32 +# include +#endif static void version (void) { @@ -41,32 +40,35 @@ static void version (void) static void usage (const char *path) { - printf ("Usage: %s \n" - "Generate the LibVLC plugins cache " - "for the specified plugins directory.\n", path); + printf ( +"Usage: %s [-f] \n" +"Generate the LibVLC plugins cache for the specified plugins directory.\n" +" -f, --force forcefully reset the plugin cache (if it exists)\n", + path); } -/* Explicit HACK */ -extern void LocaleFree (const char *); -extern char *FromLocale (const char *); - int main (int argc, char *argv[]) { +#ifdef WIN32 + SetErrorMode(SEM_FAILCRITICALERRORS); +#endif static const struct option opts[] = { + { "force", no_argument, NULL, 'f' }, { "help", no_argument, NULL, 'h' }, { "version", no_argument, NULL, 'V' }, { NULL, no_argument, NULL, '\0'} }; -#ifdef HAVE_SETLOCALE - setlocale (LC_CTYPE, ""); /* needed by FromLocale() */ -#endif - int c; - while ((c = getopt_long (argc, argv, "hV", opts, NULL)) != -1) + bool force = false; + + while ((c = getopt_long (argc, argv, "fhV", opts, NULL)) != -1) switch (c) { + case 'f': + force = true; + break; case 'h': usage (argv[0]); return 0; @@ -80,30 +82,25 @@ int main (int argc, char *argv[]) for (int i = optind; i < argc; i++) { - /* Note that FromLocale() can be used before libvlc is initialized */ - const char *path = FromLocale (argv[i]); - char *arg; + const char *path = argv[i]; - if (asprintf (&arg, "--plugin-path=%s", path) == -1) + if (setenv ("VLC_PLUGIN_PATH", path, 1)) abort (); - const char *const vlc_argv[] = { - "--ignore-config", - "--quiet", - arg, - NULL, - }; + const char *vlc_argv[4]; + int vlc_argc = 0; - libvlc_exception_t ex; - libvlc_exception_init (&ex); + vlc_argv[vlc_argc++] = "--quiet"; + if (force) + vlc_argv[vlc_argc++] = "--reset-plugins-cache"; + vlc_argv[vlc_argc++] = "--"; /* end of options */ + vlc_argv[vlc_argc] = NULL; - libvlc_instance_t *vlc = libvlc_new (3, vlc_argv, &ex); + libvlc_instance_t *vlc = libvlc_new (vlc_argc, vlc_argv); if (vlc != NULL) libvlc_release (vlc); - free (arg); if (vlc == NULL) fprintf (stderr, "No plugins in %s\n", path); - LocaleFree (path); if (vlc == NULL) return 1; }