diff --git a/plugins/common/plugin/NativeHelpers.cpp b/plugins/common/plugin/NativeHelpers.cpp index 8f7f0ae..29206eb 100644 --- a/plugins/common/plugin/NativeHelpers.cpp +++ b/plugins/common/plugin/NativeHelpers.cpp @@ -12,6 +12,28 @@ #include #include + +#if defined(_WIN32) +const fs::path toPlatformAgnosticPath(std::string& filePath) +{ + return fs::u8path(filePath.replace(filePath.begin(), filePath.end(), '\\', '/')); +} +const fs::path fromPlatformAgnosticPath(const char *filePath) +{ + std::string p{filePath}; + return fs::u8path(p.replace(p.begin(), p.end(), '/', '\\')); +} +#else +const fs::path toPlatformAgnosticPath(std::string& filePath) +{ + return fs::u8path(filePath); +} +const fs::path fromPlatformAgnosticPath(const char *filePath) +{ + return fs::u8path(filePath); +} +#endif + #if defined(_WIN32) #include #include diff --git a/plugins/common/plugin/NativeHelpers.h b/plugins/common/plugin/NativeHelpers.h index 0b534a1..d031dcb 100644 --- a/plugins/common/plugin/NativeHelpers.h +++ b/plugins/common/plugin/NativeHelpers.h @@ -13,6 +13,9 @@ const fs::path& getUserDocumentsDirectory(); +const fs::path toPlatformAgnosticPath(std::string& filePath); +const fs::path fromPlatformAgnosticPath(const char *filePath); + #if !defined(_WIN32) && !defined(__APPLE__) const fs::path& getUserHomeDirectory(); const fs::path& getXdgConfigHome(); diff --git a/plugins/vst/SfizzVstProcessor.cpp b/plugins/vst/SfizzVstProcessor.cpp index dc7ab60..9d54262 100644 --- a/plugins/vst/SfizzVstProcessor.cpp +++ b/plugins/vst/SfizzVstProcessor.cpp @@ -12,6 +12,7 @@ #include "sfizz/import/sfizz_import.h" #include "plugin/SfizzFileScan.h" #include "plugin/InstrumentDescription.h" +#include "plugin/NativeHelpers.h" #include "base/source/fstreamer.h" #include "base/source/updatehandler.h" #include "pluginterfaces/vst/ivstevents.h" @@ -178,7 +179,8 @@ tresult PLUGIN_API SfizzVstProcessor::setState(IBStream* stream) if (statePath->empty()) continue; - fs::path pathOrig = fs::u8path(*statePath); + // save file path in platform-agnostic way. See sfizz-ui issue #95 + fs::path pathOrig = toPlatformAgnosticPath(*statePath); std::error_code ec; if (fs::is_regular_file(pathOrig, ec)) continue; diff --git a/plugins/vst/SfizzVstState.cpp b/plugins/vst/SfizzVstState.cpp index 0919959..f11e1fd 100644 --- a/plugins/vst/SfizzVstState.cpp +++ b/plugins/vst/SfizzVstState.cpp @@ -5,6 +5,7 @@ // If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz #include "SfizzVstState.h" +#include "plugin/NativeHelpers.h" #include #include #include @@ -21,7 +22,7 @@ tresult SfizzVstState::load(IBStream* state) return kResultFalse; if (const char* str = s.readStr8()) - sfzFile = str; + sfzFile = fromPlatformAgnosticPath(str); else return kResultFalse; @@ -41,7 +42,7 @@ tresult SfizzVstState::load(IBStream* state) if (version >= 1) { if (const char* str = s.readStr8()) - scalaFile = str; + scalaFile = fromPlatformAgnosticPath(str); else return kResultFalse;