Root directory != default path
This commit is contained in:
parent
5dfeb7d6dc
commit
1eaa2a5c5f
4 changed files with 9 additions and 5 deletions
|
|
@ -43,11 +43,11 @@ void removeCommentOnLine(absl::string_view& line)
|
||||||
|
|
||||||
bool sfz::Parser::loadSfzFile(const fs::path& file)
|
bool sfz::Parser::loadSfzFile(const fs::path& file)
|
||||||
{
|
{
|
||||||
const auto sfzFile = file.is_absolute() ? file : defaultPath / file;
|
const auto sfzFile = file.is_absolute() ? file : originalDirectory / file;
|
||||||
if (!fs::exists(sfzFile))
|
if (!fs::exists(sfzFile))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
defaultPath = file.parent_path();
|
originalDirectory = file.parent_path();
|
||||||
std::vector<std::string> lines;
|
std::vector<std::string> lines;
|
||||||
readSfzFile(file, 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)) {
|
if (std::regex_search(tmpView.begin(), tmpView.end(), includeMatch, sfz::Regexes::includes)) {
|
||||||
auto includePath = includeMatch.str(1);
|
auto includePath = includeMatch.str(1);
|
||||||
std::replace(includePath.begin(), includePath.end(), '\\', '/');
|
std::replace(includePath.begin(), includePath.end(), '\\', '/');
|
||||||
const auto newFile = defaultPath / includePath;
|
const auto newFile = originalDirectory / includePath;
|
||||||
auto alreadyIncluded = std::find(includedFiles.begin(), includedFiles.end(), newFile);
|
auto alreadyIncluded = std::find(includedFiles.begin(), includedFiles.end(), newFile);
|
||||||
if (fs::exists(newFile)) {
|
if (fs::exists(newFile)) {
|
||||||
if (alreadyIncluded == includedFiles.end()) {
|
if (alreadyIncluded == includedFiles.end()) {
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ public:
|
||||||
void enableRecursiveIncludeGuard() { recursiveIncludeGuard = true; }
|
void enableRecursiveIncludeGuard() { recursiveIncludeGuard = true; }
|
||||||
protected:
|
protected:
|
||||||
virtual void callback(absl::string_view header, const std::vector<Opcode>& members) = 0;
|
virtual void callback(absl::string_view header, const std::vector<Opcode>& members) = 0;
|
||||||
fs::path defaultPath { fs::current_path() };
|
fs::path originalDirectory { fs::current_path() };
|
||||||
private:
|
private:
|
||||||
bool recursiveIncludeGuard { false };
|
bool recursiveIncludeGuard { false };
|
||||||
std::map<std::string, std::string> defines;
|
std::map<std::string, std::string> defines;
|
||||||
|
|
|
||||||
|
|
@ -189,7 +189,7 @@ void sfz::Synth::handleControlOpcodes(const std::vector<Opcode>& members)
|
||||||
[[fallthrough]];
|
[[fallthrough]];
|
||||||
case hash("default_path"): {
|
case hash("default_path"): {
|
||||||
const auto stringPath = absl::StrReplaceAll(trim(member.value), { { "\\", "/" } });
|
const auto stringPath = absl::StrReplaceAll(trim(member.value), { { "\\", "/" } });
|
||||||
const auto newPath = defaultPath / fs::path(stringPath);
|
const auto newPath = originalDirectory / fs::path(stringPath);
|
||||||
if (fs::exists(newPath)) {
|
if (fs::exists(newPath)) {
|
||||||
DBG("Changing default sample path to " << stringPath);
|
DBG("Changing default sample path to " << stringPath);
|
||||||
defaultPath = newPath;
|
defaultPath = newPath;
|
||||||
|
|
@ -229,6 +229,7 @@ bool sfz::Synth::loadSfzFile(const fs::path& filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
clear();
|
clear();
|
||||||
|
defaultPath = filename.parent_path();
|
||||||
auto parserReturned = sfz::Parser::loadSfzFile(filename);
|
auto parserReturned = sfz::Parser::loadSfzFile(filename);
|
||||||
if (!parserReturned)
|
if (!parserReturned)
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
|
|
@ -446,6 +446,9 @@ private:
|
||||||
Resources resources;
|
Resources resources;
|
||||||
MidiState midiState;
|
MidiState midiState;
|
||||||
|
|
||||||
|
// default_path
|
||||||
|
fs::path defaultPath { };
|
||||||
|
|
||||||
LEAK_DETECTOR(Synth);
|
LEAK_DETECTOR(Synth);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue