Skip to content

Commit

Permalink
Handle saved Windows paths on Unix
Browse files Browse the repository at this point in the history
  • Loading branch information
paulfd committed Sep 11, 2023
1 parent a6b38b8 commit b17a0c6
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion plugins/common/plugin/SfizzFileScan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
// If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz

#include "SfizzFileScan.h"
#include "utility/Debug.h"
#include "SfizzForeignPaths.h"
#include "SfizzSettings.h"
#include "NativeHelpers.h"
#include <absl/strings/ascii.h>
#include <absl/algorithm/container.h>
#include <memory>
#include <iostream>
#if defined(_WIN32)
#include <windows.h>
#endif
Expand All @@ -34,7 +36,18 @@ bool SfzFileScan::locateRealFile(const fs::path& pathOrig, fs::path& pathFound)
std::unique_lock<std::mutex> lock { mutex };
refreshScan();

auto it = file_index_.find(keyOf(pathOrig.filename()));
const auto key = [&] {
auto path = pathOrig.string();
if (path.size() > 3 && path[1] == ':' && path[2] == '\\') {
// Assume an absolute windows path and switch anti-slashes to slashes
std::replace(path.begin(), path.end(), '\\', '/');
return keyOf(fs::path(path).filename());
}

return keyOf(pathOrig.filename());
}();

auto it = file_index_.find(key);
if (it == file_index_.end())
return false;

Expand Down

0 comments on commit b17a0c6

Please sign in to comment.