Refactor the name for the root directory to act more as a default path

This commit is contained in:
Paul Ferrand 2019-12-15 16:18:36 +01:00
parent a6e9666f92
commit 5dfeb7d6dc
3 changed files with 7 additions and 7 deletions

View file

@ -43,11 +43,11 @@ void removeCommentOnLine(absl::string_view& line)
bool sfz::Parser::loadSfzFile(const fs::path& file)
{
const auto sfzFile = file.is_absolute() ? file : rootDirectory / file;
const auto sfzFile = file.is_absolute() ? file : defaultPath / file;
if (!fs::exists(sfzFile))
return false;
rootDirectory = file.parent_path();
defaultPath = file.parent_path();
std::vector<std::string> lines;
readSfzFile(file, lines);
@ -105,7 +105,7 @@ void sfz::Parser::readSfzFile(const fs::path& fileName, std::vector<std::string>
if (std::regex_search(tmpView.begin(), tmpView.end(), includeMatch, sfz::Regexes::includes)) {
auto includePath = includeMatch.str(1);
std::replace(includePath.begin(), includePath.end(), '\\', '/');
const auto newFile = rootDirectory / includePath;
const auto newFile = defaultPath / includePath;
auto alreadyIncluded = std::find(includedFiles.begin(), includedFiles.end(), newFile);
if (fs::exists(newFile)) {
if (alreadyIncluded == includedFiles.end()) {

View file

@ -40,7 +40,7 @@ public:
void enableRecursiveIncludeGuard() { recursiveIncludeGuard = true; }
protected:
virtual void callback(absl::string_view header, const std::vector<Opcode>& members) = 0;
fs::path rootDirectory { fs::current_path() };
fs::path defaultPath { fs::current_path() };
private:
bool recursiveIncludeGuard { false };
std::map<std::string, std::string> defines;

View file

@ -189,10 +189,10 @@ void sfz::Synth::handleControlOpcodes(const std::vector<Opcode>& members)
[[fallthrough]];
case hash("default_path"): {
const auto stringPath = absl::StrReplaceAll(trim(member.value), { { "\\", "/" } });
const auto newPath = rootDirectory / fs::path(stringPath);
const auto newPath = defaultPath / fs::path(stringPath);
if (fs::exists(newPath)) {
DBG("Changing default sample path to " << stringPath);
rootDirectory = newPath;
defaultPath = newPath;
}
break;
}
@ -236,7 +236,7 @@ bool sfz::Synth::loadSfzFile(const fs::path& filename)
if (regions.empty())
return false;
resources.filePool.setRootDirectory(this->rootDirectory);
resources.filePool.setRootDirectory(this->defaultPath);
auto lastRegion = regions.end() - 1;
auto currentRegion = regions.begin();