Fix #95: replace \ with / on Windows when saving file paths.
... and do vice versa on restore.
This commit is contained in:
parent
bfad6519a1
commit
5afabd4429
4 changed files with 31 additions and 3 deletions
|
|
@ -12,6 +12,28 @@
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
|
|
||||||
|
#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)
|
#if defined(_WIN32)
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <shlobj.h>
|
#include <shlobj.h>
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,9 @@
|
||||||
|
|
||||||
const fs::path& getUserDocumentsDirectory();
|
const fs::path& getUserDocumentsDirectory();
|
||||||
|
|
||||||
|
const fs::path toPlatformAgnosticPath(std::string& filePath);
|
||||||
|
const fs::path fromPlatformAgnosticPath(const char *filePath);
|
||||||
|
|
||||||
#if !defined(_WIN32) && !defined(__APPLE__)
|
#if !defined(_WIN32) && !defined(__APPLE__)
|
||||||
const fs::path& getUserHomeDirectory();
|
const fs::path& getUserHomeDirectory();
|
||||||
const fs::path& getXdgConfigHome();
|
const fs::path& getXdgConfigHome();
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@
|
||||||
#include "sfizz/import/sfizz_import.h"
|
#include "sfizz/import/sfizz_import.h"
|
||||||
#include "plugin/SfizzFileScan.h"
|
#include "plugin/SfizzFileScan.h"
|
||||||
#include "plugin/InstrumentDescription.h"
|
#include "plugin/InstrumentDescription.h"
|
||||||
|
#include "plugin/NativeHelpers.h"
|
||||||
#include "base/source/fstreamer.h"
|
#include "base/source/fstreamer.h"
|
||||||
#include "base/source/updatehandler.h"
|
#include "base/source/updatehandler.h"
|
||||||
#include "pluginterfaces/vst/ivstevents.h"
|
#include "pluginterfaces/vst/ivstevents.h"
|
||||||
|
|
@ -178,7 +179,8 @@ tresult PLUGIN_API SfizzVstProcessor::setState(IBStream* stream)
|
||||||
if (statePath->empty())
|
if (statePath->empty())
|
||||||
continue;
|
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;
|
std::error_code ec;
|
||||||
if (fs::is_regular_file(pathOrig, ec))
|
if (fs::is_regular_file(pathOrig, ec))
|
||||||
continue;
|
continue;
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
// If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz
|
// If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz
|
||||||
|
|
||||||
#include "SfizzVstState.h"
|
#include "SfizzVstState.h"
|
||||||
|
#include "plugin/NativeHelpers.h"
|
||||||
#include <sfizz.h>
|
#include <sfizz.h>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
@ -21,7 +22,7 @@ tresult SfizzVstState::load(IBStream* state)
|
||||||
return kResultFalse;
|
return kResultFalse;
|
||||||
|
|
||||||
if (const char* str = s.readStr8())
|
if (const char* str = s.readStr8())
|
||||||
sfzFile = str;
|
sfzFile = fromPlatformAgnosticPath(str);
|
||||||
else
|
else
|
||||||
return kResultFalse;
|
return kResultFalse;
|
||||||
|
|
||||||
|
|
@ -41,7 +42,7 @@ tresult SfizzVstState::load(IBStream* state)
|
||||||
|
|
||||||
if (version >= 1) {
|
if (version >= 1) {
|
||||||
if (const char* str = s.readStr8())
|
if (const char* str = s.readStr8())
|
||||||
scalaFile = str;
|
scalaFile = fromPlatformAgnosticPath(str);
|
||||||
else
|
else
|
||||||
return kResultFalse;
|
return kResultFalse;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue