MCPcopy Create free account
hub / github.com/audacity/audacity / listFiles

Method listFiles

lib-src/libvamp/src/vamp-hostsdk/PluginLoader.cpp:592–669  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

590}
591
592vector<string>
593PluginLoader::Impl::listFiles(string dir, string extension)
594{
595 vector<string> files;
596
597#ifdef _WIN32
598 string expression = dir + "\\*." + extension;
599#ifdef UNICODE
600 int len = expression.length() + 1; // cannot be more wchars than length in bytes of utf8 string
601 wchar_t *buffer = new wchar_t[len];
602 int rv = MultiByteToWideChar(CP_UTF8, 0, expression.c_str(), len, buffer, len);
603 if (rv <= 0) {
604 cerr << "Vamp::HostExt::PluginLoader: Unable to convert wildcard path \""
605 << expression << "\" to wide characters" << endl;
606 delete[] buffer;
607 return files;
608 }
609 WIN32_FIND_DATA data;
610 HANDLE fh = FindFirstFile(buffer, &data);
611 if (fh == INVALID_HANDLE_VALUE) {
612 delete[] buffer;
613 return files;
614 }
615
616 bool ok = true;
617 while (ok) {
618 wchar_t *fn = data.cFileName;
619 int wlen = wcslen(fn) + 1;
620 int maxlen = wlen * 6;
621 char *conv = new char[maxlen];
622 int rv = WideCharToMultiByte(CP_UTF8, 0, fn, wlen, conv, maxlen, 0, 0);
623 if (rv > 0) {
624 files.push_back(conv);
625 }
626 delete[] conv;
627 ok = FindNextFile(fh, &data);
628 }
629
630 FindClose(fh);
631 delete[] buffer;
632#else
633 WIN32_FIND_DATA data;
634 HANDLE fh = FindFirstFile(expression.c_str(), &data);
635 if (fh == INVALID_HANDLE_VALUE) return files;
636
637 bool ok = true;
638 while (ok) {
639 files.push_back(data.cFileName);
640 ok = FindNextFile(fh, &data);
641 }
642
643 FindClose(fh);
644#endif
645#else
646
647 size_t extlen = extension.length();
648 DIR *d = opendir(dir.c_str());
649 if (!d) return files;

Callers

nothing calls this directly

Calls 6

opendirFunction · 0.85
readdirFunction · 0.85
closedirFunction · 0.85
lengthMethod · 0.45
c_strMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected