2020-09-10 08:43:05 -04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2020 Robin Gareus <robin@gareus.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <cstdio>
|
|
|
|
#include <getopt.h>
|
|
|
|
#include <iostream>
|
|
|
|
#include <string>
|
|
|
|
|
2021-07-11 22:00:43 -04:00
|
|
|
#ifdef PLATFORM_WINDOWS
|
|
|
|
#include <windows.h>
|
|
|
|
#else
|
|
|
|
#include <signal.h>
|
|
|
|
#endif
|
|
|
|
|
2020-09-10 08:43:05 -04:00
|
|
|
#ifdef COMPILER_MSVC
|
|
|
|
#include <sys/utime.h>
|
|
|
|
#else
|
|
|
|
#include <utime.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "pbd/error.h"
|
|
|
|
#include "pbd/transmitter.h"
|
|
|
|
#include "pbd/receiver.h"
|
|
|
|
#include "pbd/pbd.h"
|
2021-07-11 22:00:43 -04:00
|
|
|
#include "pbd/stacktrace.h"
|
2020-09-20 14:00:05 -04:00
|
|
|
#include "pbd/win_console.h"
|
2020-09-10 08:43:05 -04:00
|
|
|
#include "pbd/xml++.h"
|
|
|
|
|
|
|
|
#ifdef __MINGW64__
|
|
|
|
#define NO_OLDNAMES // no backwards compat _pid_t, conflict with w64 pthread/sched
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "../ardour/vst3_scan.cc"
|
|
|
|
#include "../ardour/vst3_host.cc"
|
|
|
|
#include "../ardour/vst3_module.cc"
|
|
|
|
|
2021-09-27 09:49:41 -04:00
|
|
|
#include "../ardour/filesystem_paths.cc"
|
|
|
|
|
2020-09-10 08:43:05 -04:00
|
|
|
using namespace PBD;
|
|
|
|
|
|
|
|
class LogReceiver : public Receiver
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
void receive (Transmitter::Channel chn, const char * str) {
|
|
|
|
const char *prefix = "";
|
|
|
|
switch (chn) {
|
2020-10-13 15:46:52 -04:00
|
|
|
case Transmitter::Debug:
|
|
|
|
/* ignore */
|
2020-09-10 08:43:05 -04:00
|
|
|
break;
|
|
|
|
case Transmitter::Info:
|
|
|
|
prefix = "[Info]: ";
|
|
|
|
break;
|
|
|
|
case Transmitter::Warning:
|
|
|
|
prefix = "[WARNING]: ";
|
|
|
|
break;
|
2020-10-13 15:46:52 -04:00
|
|
|
case Transmitter::Error:
|
|
|
|
prefix = "[ERROR]: ";
|
|
|
|
break;
|
2020-09-10 08:43:05 -04:00
|
|
|
case Transmitter::Fatal:
|
|
|
|
prefix = "[FATAL]: ";
|
|
|
|
break;
|
|
|
|
case Transmitter::Throw:
|
|
|
|
abort ();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::cout << prefix << str << std::endl;
|
|
|
|
|
|
|
|
if (chn == Transmitter::Fatal) {
|
2020-09-20 14:00:05 -04:00
|
|
|
console_madness_end ();
|
2020-09-10 08:43:05 -04:00
|
|
|
::exit (EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
LogReceiver log_receiver;
|
|
|
|
|
2021-06-25 14:28:45 -04:00
|
|
|
static void vst3_plugin (string const&, string const&, VST3Info const& i)
|
2020-09-10 08:43:05 -04:00
|
|
|
{
|
|
|
|
info << "Found Plugin: " << i.name << endmsg;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
2020-10-23 21:21:25 -04:00
|
|
|
scan_vst3 (std::string const& bundle_path, bool force, bool verbose)
|
2020-09-10 08:43:05 -04:00
|
|
|
{
|
|
|
|
info << "Scanning: " << bundle_path << endmsg;
|
|
|
|
string module_path = module_path_vst3 (bundle_path);
|
|
|
|
if (module_path.empty ()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-10-23 21:21:25 -04:00
|
|
|
if (!vst3_valid_cache_file (module_path, verbose).empty()) {
|
2020-09-10 08:43:05 -04:00
|
|
|
if (!force) {
|
|
|
|
info << "Skipping scan." << endmsg;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-01 19:57:03 -05:00
|
|
|
if (vst3_scan_and_cache (module_path, bundle_path, sigc::ptr_fun (&vst3_plugin), verbose)) {
|
2020-09-10 08:43:05 -04:00
|
|
|
info << string_compose (_("Saved VST3 plugin cache to %1"), vst3_cache_file (module_path)) << endmsg;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-07-11 22:00:43 -04:00
|
|
|
#ifdef PLATFORM_WINDOWS
|
|
|
|
static LONG WINAPI
|
2021-07-11 22:57:53 -04:00
|
|
|
crash_handler (EXCEPTION_POINTERS* exceptioninfo)
|
2021-07-11 22:00:43 -04:00
|
|
|
{
|
|
|
|
// TODO consider DrMingw if HAVE_DRMINGW
|
2021-07-12 17:33:03 -04:00
|
|
|
printf ("Error: %x\n ---8<---\n", exceptioninfo->ExceptionRecord->ExceptionCode);
|
|
|
|
PBD::stacktrace (std::cout, 15, 2);
|
|
|
|
printf (" --->8---\n");
|
2021-07-11 22:00:43 -04:00
|
|
|
return EXCEPTION_CONTINUE_SEARCH;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static void
|
|
|
|
sig_handler (int sig)
|
|
|
|
{
|
2021-07-12 17:33:03 -04:00
|
|
|
printf ("Error: signal %d\n ---8<---\n", sig);
|
|
|
|
PBD::stacktrace (std::cout, 15, 2);
|
|
|
|
printf (" --->8---\n");
|
2021-07-22 19:37:46 -04:00
|
|
|
fflush(stdout);
|
|
|
|
fflush(stderr);
|
|
|
|
_exit (EXIT_FAILURE);
|
2021-07-11 22:00:43 -04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-09-10 08:43:05 -04:00
|
|
|
static void
|
|
|
|
usage ()
|
|
|
|
{
|
|
|
|
// help2man compatible format (standard GNU help-text)
|
|
|
|
printf ("ardour-vst3-scanner - load and index VST3 plugins.\n\n");
|
|
|
|
printf ("Usage: ardour-vst3-scanner [ OPTIONS ] <VST3-bundle> [<VST3-bundle>]*\n\n");
|
|
|
|
printf ("Options:\n\
|
2021-01-23 17:43:01 -05:00
|
|
|
-f, --force Force update of cache file\n\
|
2020-09-10 08:43:05 -04:00
|
|
|
-h, --help Display this help and exit\n\
|
|
|
|
-q, --quiet Hide usual output, only print errors\n\
|
2020-10-23 21:21:25 -04:00
|
|
|
-v, --verbose Give verbose output (unless quiet)\n\
|
2020-09-10 08:43:05 -04:00
|
|
|
-V, --version Print version information and exit\n\
|
|
|
|
\n");
|
|
|
|
|
|
|
|
printf ("\n\
|
|
|
|
This tool ...\n\
|
|
|
|
\n");
|
|
|
|
|
2022-10-05 16:57:27 -04:00
|
|
|
printf ("Report bugs to <https://tracker.ardour.org/>\n"
|
|
|
|
"Website: <https://ardour.org/>\n");
|
2020-09-20 14:00:05 -04:00
|
|
|
|
|
|
|
console_madness_end ();
|
2020-09-10 08:43:05 -04:00
|
|
|
::exit (EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, char **argv)
|
|
|
|
{
|
|
|
|
bool print_log = true;
|
|
|
|
bool stop_on_error = false;
|
|
|
|
bool force = false;
|
2020-10-23 21:21:25 -04:00
|
|
|
bool verbose = false;
|
2020-09-10 08:43:05 -04:00
|
|
|
|
2020-10-23 21:21:25 -04:00
|
|
|
const char* optstring = "fhqvV";
|
2020-09-10 08:43:05 -04:00
|
|
|
|
|
|
|
/* clang-format off */
|
|
|
|
const struct option longopts[] = {
|
|
|
|
{ "force", no_argument, 0, 'f' },
|
|
|
|
{ "help", no_argument, 0, 'h' },
|
|
|
|
{ "quiet", no_argument, 0, 'q' },
|
2020-10-23 21:21:25 -04:00
|
|
|
{ "verbose", no_argument, 0, 'v' },
|
2020-09-10 08:43:05 -04:00
|
|
|
{ "version", no_argument, 0, 'V' },
|
|
|
|
};
|
|
|
|
/* clang-format on */
|
|
|
|
|
2020-09-20 14:00:05 -04:00
|
|
|
console_madness_begin ();
|
|
|
|
|
2020-09-10 08:43:05 -04:00
|
|
|
int c = 0;
|
|
|
|
while (EOF != (c = getopt_long (argc, argv, optstring, longopts, (int*)0))) {
|
|
|
|
switch (c) {
|
|
|
|
case 'V':
|
|
|
|
printf ("ardour-vst3-scanner version %s\n\n", VERSIONSTRING);
|
|
|
|
printf ("Copyright (C) GPL 2020 Robin Gareus <robin@gareus.org>\n");
|
2020-09-20 14:00:05 -04:00
|
|
|
console_madness_end ();
|
2020-09-10 08:43:05 -04:00
|
|
|
exit (EXIT_SUCCESS);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'f':
|
|
|
|
force = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'h':
|
|
|
|
usage ();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'q':
|
|
|
|
print_log = false;
|
|
|
|
break;
|
|
|
|
|
2020-10-23 21:21:25 -04:00
|
|
|
case 'v':
|
|
|
|
verbose = true;
|
|
|
|
break;
|
|
|
|
|
2020-09-10 08:43:05 -04:00
|
|
|
default:
|
|
|
|
std::cerr << "Error: unrecognized option. See --help for usage information.\n";
|
2020-09-20 14:00:05 -04:00
|
|
|
console_madness_end ();
|
2020-09-10 08:43:05 -04:00
|
|
|
::exit (EXIT_FAILURE);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (optind >= argc) {
|
|
|
|
std::cerr << "Error: Missing parameter. See --help for usage information.\n";
|
2020-09-20 14:00:05 -04:00
|
|
|
console_madness_end ();
|
2020-09-10 08:43:05 -04:00
|
|
|
::exit (EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PBD::init();
|
|
|
|
|
|
|
|
if (print_log) {
|
|
|
|
log_receiver.listen_to (info);
|
|
|
|
log_receiver.listen_to (warning);
|
2020-10-13 15:46:52 -04:00
|
|
|
log_receiver.listen_to (error);
|
|
|
|
log_receiver.listen_to (fatal);
|
2020-10-23 21:21:25 -04:00
|
|
|
} else {
|
|
|
|
verbose = false;
|
2020-09-10 08:43:05 -04:00
|
|
|
}
|
|
|
|
|
2021-07-11 22:00:43 -04:00
|
|
|
#ifdef PLATFORM_WINDOWS
|
|
|
|
::SetUnhandledExceptionFilter (crash_handler);
|
|
|
|
#else
|
|
|
|
signal (SIGSEGV, sig_handler);
|
|
|
|
signal (SIGBUS, sig_handler);
|
|
|
|
signal (SIGILL, sig_handler);
|
2021-07-22 19:37:46 -04:00
|
|
|
signal (SIGABRT, sig_handler);
|
2021-07-11 22:00:43 -04:00
|
|
|
#endif
|
|
|
|
|
2020-09-10 08:43:05 -04:00
|
|
|
bool err = false;
|
|
|
|
|
|
|
|
while (optind < argc) {
|
2020-10-23 21:21:25 -04:00
|
|
|
if (!scan_vst3 (argv[optind++], force, verbose)) {
|
2020-09-10 08:43:05 -04:00
|
|
|
err = true;
|
|
|
|
}
|
|
|
|
if (stop_on_error) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PBD::cleanup();
|
|
|
|
|
2020-09-20 14:00:05 -04:00
|
|
|
console_madness_end ();
|
|
|
|
|
2020-09-10 08:43:05 -04:00
|
|
|
if (err) {
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
} else {
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|