commit 4806cc3ba68d9e4911249ef50c13f396dee6ecb3
parent 21a450e90b83ef8e892a57454ad27141b42cac0c
Author: dsp56300 <dsp56300@users.noreply.github.com>
Date: Sun, 4 Dec 2022 13:49:36 +0100
also find rom if it is next to binary even if the binary is part of the component folder
Diffstat:
2 files changed, 36 insertions(+), 10 deletions(-)
diff --git a/source/synthLib/os.cpp b/source/synthLib/os.cpp
@@ -32,7 +32,7 @@
namespace synthLib
{
- std::string getModulePath()
+ std::string getModulePath(bool _stripPluginComponentFolders/* = true*/)
{
std::string path;
#ifdef _WIN32
@@ -61,7 +61,6 @@ namespace synthLib
}
else
{
- const auto end = path.find_last_of("/\\");
path = info.dli_fname;
}
#endif
@@ -70,6 +69,7 @@ namespace synthLib
{
const auto end = path.rfind(_key + _delim);
+ // strip folders such as "/foo.vst/" but do NOT strip "/.vst/"
if (end != std::string::npos && (path.find(_delim + _key) + 1) != end)
path = path.substr(0, end);
};
@@ -80,10 +80,13 @@ namespace synthLib
fixPathWithDelim(_key, '\\');
};
- fixPath(".vst");
- fixPath(".vst3");
- fixPath(".component");
- fixPath(".app");
+ if(_stripPluginComponentFolders)
+ {
+ fixPath(".vst");
+ fixPath(".vst3");
+ fixPath(".component");
+ fixPath(".app");
+ }
const auto end = path.find_last_of("/\\");
@@ -181,20 +184,25 @@ namespace synthLib
return {};
}
- std::string findROM(const size_t _minSize, const size_t _maxSize)
+ std::string findFile(const std::string& _extension, const size_t _minSize, const size_t _maxSize)
{
std::string path = getModulePath();
if(path.empty())
path = getCurrentDirectory();
+ return findFile(path, _extension, _minSize, _maxSize);
+ }
+
+ std::string findFile(const std::string& _rootPath, const std::string& _extension, const size_t _minSize, const size_t _maxSize)
+ {
std::vector<std::string> files;
- getDirectoryEntries(files, path);
+ getDirectoryEntries(files, _rootPath);
for (const auto& file : files)
{
- if(!hasExtension(file, ".bin"))
+ if(!hasExtension(file, _extension))
continue;
if (!_minSize && !_maxSize)
@@ -223,6 +231,22 @@ namespace synthLib
return {};
}
+ std::string findROM(const size_t _minSize, const size_t _maxSize)
+ {
+ std::string path = getModulePath();
+
+ if(path.empty())
+ path = getCurrentDirectory();
+
+ auto f = findFile(".bin", _minSize, _maxSize);
+ if(!f.empty())
+ return f;
+
+ path = getModulePath(false);
+
+ return findFile(".bin", _minSize, _maxSize);
+ }
+
std::string findROM(const size_t _expectedSize)
{
return findROM(_expectedSize, _expectedSize);
diff --git a/source/synthLib/os.h b/source/synthLib/os.h
@@ -4,7 +4,7 @@
namespace synthLib
{
- std::string getModulePath();
+ std::string getModulePath(bool _stripPluginComponentFolders = true);
std::string getCurrentDirectory();
bool createDirectory(const std::string& _dir);;
@@ -12,6 +12,8 @@ namespace synthLib
bool getDirectoryEntries(std::vector<std::string>& _files, const std::string& _folder);
+ std::string findFile(const std::string& _extension, size_t _minSize, size_t _maxSize);
+ std::string findFile(const std::string& _rootPath, const std::string& _extension, size_t _minSize, size_t _maxSize);
std::string findROM(size_t _minSize, size_t _maxSize);
std::string findROM(size_t _expectedSize = 524288);