From 638e3689fc81812ebf8778b6bc57016680b2b954 Mon Sep 17 00:00:00 2001 From: Paul Walker Date: Thu, 9 Sep 2021 18:06:00 -0400 Subject: [PATCH] Use fs::poath in SrugeStorage Closes #4823 --- src/common/FxPresetAndClipboardManager.cpp | 5 +- src/common/ModulatorPresetManager.cpp | 6 +- src/common/PatchDB.cpp | 3 +- src/common/SurgeStorage.cpp | 81 ++++++++----------- src/common/SurgeStorage.h | 28 +++---- src/common/SurgeSynthesizerIO.cpp | 2 +- src/common/UserDefaults.cpp | 4 +- src/common/UserDefaults.h | 11 +++ src/common/WAVFileSupport.cpp | 17 ++-- src/gui/SkinSupport.cpp | 9 +-- src/gui/SurgeGUIEditor.cpp | 53 ++++++------ src/gui/SurgeGUIUtils.h | 1 + src/gui/overlays/AboutScreen.cpp | 8 +- src/gui/widgets/OscillatorWaveformDisplay.cpp | 13 ++- src/gui/widgets/PatchSelector.cpp | 27 +++---- 15 files changed, 126 insertions(+), 142 deletions(-) diff --git a/src/common/FxPresetAndClipboardManager.cpp b/src/common/FxPresetAndClipboardManager.cpp index 74709864d54..8477bb40826 100644 --- a/src/common/FxPresetAndClipboardManager.cpp +++ b/src/common/FxPresetAndClipboardManager.cpp @@ -38,7 +38,7 @@ void FxUserPreset::doPresetRescan(SurgeStorage *storage, bool forceRescan) haveScannedPresets = true; auto ud = storage->userFXPath; - auto fd = string_to_path(storage->datapath) / "fx_presets"; + auto fd = storage->datapath / "fx_presets"; std::vector> sfxfiles; @@ -115,8 +115,7 @@ void FxUserPreset::doPresetRescan(SurgeStorage *storage, bool forceRescan) if (f.second) rpath = f.first.lexically_relative(fd).parent_path(); else - rpath = - f.first.lexically_relative(string_to_path(storage->userFXPath)).parent_path(); + rpath = f.first.lexically_relative(storage->userFXPath).parent_path(); auto startCatPath = rpath.begin(); if (*(startCatPath) == fx_type_names[t]) diff --git a/src/common/ModulatorPresetManager.cpp b/src/common/ModulatorPresetManager.cpp index 6c8524906c7..d8df8a4451d 100644 --- a/src/common/ModulatorPresetManager.cpp +++ b/src/common/ModulatorPresetManager.cpp @@ -35,7 +35,7 @@ void ModulatorPreset::savePresetToUser(const fs::path &location, SurgeStorage *s auto lfo = &(s->getPatch().scene[scene].lfo[lfoid]); int lfotype = lfo->shape.val.i; - auto containingPath = fs::path{string_to_path(s->userDataPath) / fs::path{PresetDir}}; + auto containingPath = s->userDataPath / fs::path{PresetDir}; if (lfotype == lt_mseg) containingPath = containingPath / fs::path{"MSEG"}; @@ -233,8 +233,8 @@ std::vector ModulatorPreset::getPresets(SurgeStorage // Do a dual directory traversal of factory and user data with the fs::directory_iterator stuff // looking for .lfopreset - auto factoryPath = fs::path({string_to_path(s->datapath) / fs::path{"modulator_presets"}}); - auto userPath = fs::path({string_to_path(s->userDataPath) / fs::path{PresetDir}}); + auto factoryPath = s->datapath / fs::path{"modulator_presets"}; + auto userPath = s->userDataPath / fs::path{PresetDir}; std::map resMap; // handy it is sorted! diff --git a/src/common/PatchDB.cpp b/src/common/PatchDB.cpp index c063fa018d3..ae38c5f0ff1 100644 --- a/src/common/PatchDB.cpp +++ b/src/common/PatchDB.cpp @@ -288,7 +288,8 @@ CREATE TABLE Category ( explicit workerS(SurgeStorage *storage) : storage(storage) { - auto dbname = storage->userDataPath + "/SurgePatches.db"; + auto dbpath = storage->userDataPath / fs::path{"SurgePatches.db"}; + auto dbname = path_to_string(dbpath); auto flag = SQLITE_OPEN_FULLMUTEX; // basically lock flag |= SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE; diff --git a/src/common/SurgeStorage.cpp b/src/common/SurgeStorage.cpp index 1db276c5c20..cce9d23c893 100644 --- a/src/common/SurgeStorage.cpp +++ b/src/common/SurgeStorage.cpp @@ -293,25 +293,27 @@ SurgeStorage::SurgeStorage(std::string suppliedDataPath) : otherscene_clients(0) ** If local directory doesn't exists - we probably came here through an installer - ** check for /usr/share/surge and use /usr/share/Surge as our last guess */ - if (!fs::is_directory(string_to_path(datapath))) + if (!fs::is_directory(datapath)) { - if (fs::is_directory(string_to_path(std::string(Surge::Build::CMAKE_INSTALL_PREFIX) + - "/share/surge-xt"))) + if (fs::is_directory(string_to_path(std::string(Surge::Build::CMAKE_INSTALL_PREFIX)) / + "share" / "surge-xt")) { - datapath = std::string() + Surge::Build::CMAKE_INSTALL_PREFIX + "/share/surge-xt"; + datapath = + string_to_path(Surge::Build::CMAKE_INSTALL_PREFIX) / "share" / "surge-xt"; } - else if (fs::is_directory(string_to_path( - std::string(Surge::Build::CMAKE_INSTALL_PREFIX) + "/share/Surge XT"))) + else if (fs::is_directory(string_to_path(Surge::Build::CMAKE_INSTALL_PREFIX) / "share" / + "Surge XT")) { - datapath = std::string() + Surge::Build::CMAKE_INSTALL_PREFIX + "/share/Surge XT"; + datapath = + string_to_path(Surge::Build::CMAKE_INSTALL_PREFIX) / "share" / "Surge XT"; } else { std::string systemDataPath = "/usr/share/surge-xt/"; if (fs::is_directory(string_to_path(systemDataPath))) - datapath = systemDataPath; + datapath = string_to_path(systemDataPath); else - datapath = "/usr/share/Surge XT/"; + datapath = string_to_path("/usr/share/Surge XT/"); } } @@ -397,7 +399,7 @@ SurgeStorage::SurgeStorage(std::string suppliedDataPath) : otherscene_clients(0) path /= L"SurgeXTData"; if (fs::is_directory(path)) { - datapath = path_to_string(path); + datapath = path; } } bailOnPortable: @@ -455,14 +457,13 @@ SurgeStorage::SurgeStorage(std::string suppliedDataPath) : otherscene_clients(0) } // append separator if not present - datapath = Surge::Storage::appendDirectory(datapath, std::string()); - userPatchesPath = Surge::Storage::appendDirectory(userDataPath, "Patches"); - userWavetablesPath = Surge::Storage::appendDirectory(userDataPath, "Wavetables"); - userWavetablesExportPath = Surge::Storage::appendDirectory(userWavetablesPath, "Exported"); - userFXPath = Surge::Storage::appendDirectory(userDataPath, "FX Presets"); - userMidiMappingsPath = Surge::Storage::appendDirectory(userDataPath, "MIDI Mappings"); - userModulatorSettingsPath = Surge::Storage::appendDirectory(userDataPath, "Modulator Presets"); - userSkinsPath = Surge::Storage::appendDirectory(userDataPath, "Skins"); + userPatchesPath = userDataPath / "Patches"; + userWavetablesPath = userDataPath / "Wavetables"; + userWavetablesExportPath = userWavetablesPath / "Exported"; + userFXPath = userDataPath / "FX Presets"; + userMidiMappingsPath = userDataPath / "MIDI Mappings"; + userModulatorSettingsPath = userDataPath / "Modulator Presets"; + userSkinsPath = userDataPath / "Skins"; createUserDirectory(); /* @@ -482,9 +483,8 @@ SurgeStorage::SurgeStorage(std::string suppliedDataPath) : otherscene_clients(0) "\n"; if (!snapshotloader.Parse(cxmlData.c_str())) { - reportError("Cannot parse 'configuration.xml' in path '" + datapath + - "'. Please reinstall Surge!", - "Surge Incorrectly Installed"); + reportError("Cannot parse 'configuration.xml' from memory. Internal Software Error.", + "Surge Incorrectly Built"); } load_midi_controllers(); @@ -655,7 +655,7 @@ SurgeStorage::SurgeStorage(std::string suppliedDataPath) : otherscene_clients(0) void SurgeStorage::createUserDirectory() { - auto p = string_to_path(userDataPath); + auto p = userDataPath; auto needToBuild = false; if (!fs::is_directory(p)) { @@ -669,13 +669,12 @@ void SurgeStorage::createUserDirectory() for (auto &s : {userDataPath, userDefaultFilePath, userPatchesPath, userWavetablesPath, userModulatorSettingsPath, userFXPath, userWavetablesExportPath, userSkinsPath, userMidiMappingsPath}) - fs::create_directories(string_to_path(s)); + fs::create_directories(s); auto rd = std::string(SurgeSharedBinary::README_UserArea_txt, SurgeSharedBinary::README_UserArea_txtSize) + "\n"; - auto of = - std::ofstream(string_to_path(userDataPath) / "README.txt", std::ofstream::out); + auto of = std::ofstream(userDataPath / "README.txt", std::ofstream::out); if (of.is_open()) of << rd << std::endl; of.close(); @@ -809,9 +808,9 @@ void SurgeStorage::refreshPatchOrWTListAddDir(bool userDir, string subdir, try { - fs::path patchpath = string_to_path(userDir ? userDataPath : datapath); + fs::path patchpath = userDir ? userDataPath : datapath; if (!subdir.empty()) - patchpath /= string_to_path(subdir); + patchpath /= subdir; if (!fs::is_directory(patchpath)) { @@ -1624,9 +1623,8 @@ void SurgeStorage::write_midi_controllers_to_user_default() try { - auto dir = string_to_path(userDataPath); - fs::create_directories(dir); - auto f = string_to_path(userDataPath) / "SurgeMIDIDefaults.xml"; + fs::create_directories(userDataPath); + auto f = userDataPath / "SurgeMIDIDefaults.xml"; doc.SaveFile(f); } catch (const fs::filesystem_error &e) @@ -1659,7 +1657,7 @@ void SurgeStorage::setSamplerate(float sr) void SurgeStorage::load_midi_controllers() { - auto mcp = string_to_path(userDataPath) / "SurgeMIDIDefaults.xml"; + auto mcp = userDataPath / "SurgeMIDIDefaults.xml"; TiXmlDocument mcd; TiXmlElement *midiRoot = nullptr; if (mcd.LoadFile(mcp)) @@ -2000,7 +1998,7 @@ void SurgeStorage::rescanUserMidiMappings() const auto extension{fs::path{".srgmid"}.native()}; try { - for (const fs::path &d : fs::directory_iterator{string_to_path(userMidiMappingsPath), ec}) + for (const fs::path &d : fs::directory_iterator{userMidiMappingsPath, ec}) { if (d.extension().native() == extension) { @@ -2125,10 +2123,10 @@ void SurgeStorage::storeMidiMappingToName(std::string name) doc.InsertEndChild(sm); - fs::create_directories(string_to_path(userMidiMappingsPath)); - std::string fn = Surge::Storage::appendDirectory(userMidiMappingsPath, name + ".srgmid"); + fs::create_directories(userMidiMappingsPath); + auto fn = userMidiMappingsPath / (name + ".srgmid"); - if (!doc.SaveFile(string_to_path(fn))) + if (!doc.SaveFile(path_to_string(fn))) { std::ostringstream oss; oss << "Unable to save MIDI settings to '" << fn << "'!"; @@ -2340,18 +2338,5 @@ string findReplaceSubstring(string &source, const string &from, const string &to return newString; } -std::string appendDirectory(const std::string &root, const std::string &path1) -{ - if (root[root.size() - 1] == PATH_SEPARATOR) - return root + path1; - else - return root + PATH_SEPARATOR + path1; -} -std::string appendDirectory(const std::string &root, const std::string &path1, - const std::string &path2) -{ - return appendDirectory(appendDirectory(root, path1), path2); -} - } // namespace Storage } // namespace Surge diff --git a/src/common/SurgeStorage.h b/src/common/SurgeStorage.h index 705314a02ed..712cbcaf2f7 100644 --- a/src/common/SurgeStorage.h +++ b/src/common/SurgeStorage.h @@ -1023,19 +1023,18 @@ class alignas(16) SurgeStorage std::unique_ptr fxUserPreset; std::unique_ptr modulatorPreset; - std::string wtpath; - std::string datapath; - std::string userDefaultFilePath; - std::string userDataPath; - std::string userPatchesPath; - std::string userWavetablesPath; - std::string userModulatorSettingsPath; - std::string userFXPath; - std::string userWavetablesExportPath; - std::string userSkinsPath; - std::string userMidiMappingsPath; - - std::string installedPath; + fs::path datapath; + fs::path userDefaultFilePath; + fs::path userDataPath; + fs::path userPatchesPath; + fs::path userWavetablesPath; + fs::path userModulatorSettingsPath; + fs::path userFXPath; + fs::path userWavetablesExportPath; + fs::path userSkinsPath; + fs::path userMidiMappingsPath; + + fs::path installedPath; std::map userMidiMappingsXMLByName; void rescanUserMidiMappings(); @@ -1365,9 +1364,6 @@ bool isValidUTF8(const std::string &testThis); std::string findReplaceSubstring(std::string &source, const std::string &from, const std::string &to); -std::string appendDirectory(const std::string &root, const std::string &path1); -std::string appendDirectory(const std::string &root, const std::string &path1, - const std::string &path2); } // namespace Storage } // namespace Surge diff --git a/src/common/SurgeSynthesizerIO.cpp b/src/common/SurgeSynthesizerIO.cpp index 9da47c7ac2a..0f05ec78036 100644 --- a/src/common/SurgeSynthesizerIO.cpp +++ b/src/common/SurgeSynthesizerIO.cpp @@ -488,7 +488,7 @@ void SurgeSynthesizer::savePatch() if (storage.getPatch().category.empty()) storage.getPatch().category = "Default"; - fs::path savepath = string_to_path(storage.userPatchesPath); + fs::path savepath = storage.userPatchesPath; try { diff --git a/src/common/UserDefaults.cpp b/src/common/UserDefaults.cpp index 2db16de6bac..19ab0760244 100644 --- a/src/common/UserDefaults.cpp +++ b/src/common/UserDefaults.cpp @@ -163,7 +163,7 @@ bool haveReadDefaultsFile = false; std::string defaultsFileName(SurgeStorage *storage) { - std::string fn = storage->userDefaultFilePath + PATH_SEPARATOR + "SurgeXTUserDefaults.xml"; + std::string fn = path_to_string(storage->userDefaultFilePath / "SurgeXTUserDefaults.xml"); return fn; } @@ -230,7 +230,7 @@ bool storeUserDefaultValue(SurgeStorage *storage, const DefaultKey &key, const s ** See SurgeSytnehsizer::savePatch for instance ** and so we have to do the same here */ - fs::create_directories(string_to_path(storage->userDefaultFilePath)); + fs::create_directories(storage->userDefaultFilePath); UserDefaultValue v; v.key = key; diff --git a/src/common/UserDefaults.h b/src/common/UserDefaults.h index cc0379cfcc0..fa03cdf2b33 100644 --- a/src/common/UserDefaults.h +++ b/src/common/UserDefaults.h @@ -2,6 +2,7 @@ #include #include +#include /* ** Surge has a variety of settings which users can update and save across @@ -72,6 +73,11 @@ enum DefaultKey // streamed as strings so feel free to change the order to whate std::string getUserDefaultValue(SurgeStorage *storage, const DefaultKey &key, const std::string &valueIfMissing); int getUserDefaultValue(SurgeStorage *storage, const DefaultKey &key, int valueIfMissing); +inline fs::path getUserDefaultPath(SurgeStorage *storage, const DefaultKey &key, + const fs::path &valueIfMissing) +{ + return string_to_path(getUserDefaultValue(storage, key, path_to_string(valueIfMissing))); +} /** * updateUserDefaultValue @@ -80,6 +86,11 @@ int getUserDefaultValue(SurgeStorage *storage, const DefaultKey &key, int valueI */ bool updateUserDefaultValue(SurgeStorage *storage, const DefaultKey &key, const std::string &value); bool updateUserDefaultValue(SurgeStorage *storage, const DefaultKey &key, const int value); +inline bool updateUserDefaultPath(SurgeStorage *storage, const DefaultKey &key, + const fs::path &path) +{ + return updateUserDefaultValue(storage, key, path_to_string(path)); +} } // namespace Storage } // namespace Surge diff --git a/src/common/WAVFileSupport.cpp b/src/common/WAVFileSupport.cpp index ee92e340704..1e4da44f000 100644 --- a/src/common/WAVFileSupport.cpp +++ b/src/common/WAVFileSupport.cpp @@ -468,16 +468,15 @@ bool SurgeStorage::load_wt_wav_portable(std::string fn, Wavetable *wt) std::string SurgeStorage::export_wt_wav_portable(std::string fbase, Wavetable *wt) { - std::string path; - path = Surge::Storage::appendDirectory(userDataPath, "Wavetables", "Exported"); - fs::create_directories(string_to_path(path)); + auto path = userDataPath / "Wavetables" / "Exported"; + fs::create_directories(path); auto fnamePre = fbase + ".wav"; - auto fname = Surge::Storage::appendDirectory(path, fbase + ".wav"); + auto fname = path / (fbase + ".wav"); int fnum = 1; - while (fs::exists(fs::path(fname))) + while (fs::exists(fname)) { - fname = Surge::Storage::appendDirectory(path, fbase + "_" + std::to_string(fnum) + ".wav"); + fname = path / (fbase + "_" + std::to_string(fnum) + ".wav"); fnamePre = fbase + "_" + std::to_string(fnum) + ".wav"; fnum++; } @@ -486,9 +485,9 @@ std::string SurgeStorage::export_wt_wav_portable(std::string fbase, Wavetable *w { std::filebuf wfp; - if (!wfp.open(string_to_path(fname), std::ios::binary | std::ios::out)) + if (!wfp.open(fname, std::ios::binary | std::ios::out)) { - errorMessage = "Unable to open file " + fname + "!"; + errorMessage = "Unable to open file " + fname.u8string() + "!"; errorMessage += std::strerror(errno); reportError(errorMessage, "Wavetable Export"); @@ -574,5 +573,5 @@ std::string SurgeStorage::export_wt_wav_portable(std::string fbase, Wavetable *w refresh_wtlist(); - return fname; + return path_to_string(fname); } diff --git a/src/gui/SkinSupport.cpp b/src/gui/SkinSupport.cpp index 5cf7e4a7f3a..6b28e132b9c 100644 --- a/src/gui/SkinSupport.cpp +++ b/src/gui/SkinSupport.cpp @@ -96,15 +96,14 @@ void SkinDB::rescanForSkins(SurgeStorage *storage) #endif availableSkins.clear(); - std::array paths = {string_to_path(storage->datapath), - string_to_path(storage->userSkinsPath)}; + std::array paths = {storage->datapath, storage->userSkinsPath}; for (auto &source : paths) { Entry::RootType rt = UNKNOWN; - if (path_to_string(source) == path_to_string(paths[0])) + if (source == paths[0]) rt = FACTORY; - if (path_to_string(source) == path_to_string(paths[1])) + if (source == paths[1]) rt = USER; std::vector alldirs; @@ -1338,7 +1337,7 @@ Maybe SkinDB::installSkinFromPathToUserDirectory(SurgeStorage *s, { auto parentP = p.parent_path(); auto nmP = p.lexically_relative(parentP); - auto tgPath = string_to_path(s->userSkinsPath) / nmP; + auto tgPath = s->userSkinsPath / nmP; try { diff --git a/src/gui/SurgeGUIEditor.cpp b/src/gui/SurgeGUIEditor.cpp index 6fcfd7855d8..52d208b0160 100644 --- a/src/gui/SurgeGUIEditor.cpp +++ b/src/gui/SurgeGUIEditor.cpp @@ -2325,14 +2325,13 @@ juce::PopupMenu SurgeGUIEditor::makeTuningMenu(const juce::Point &where, bo } }; - auto scl_path = - Surge::Storage::appendDirectory(this->synth->storage.datapath, "tuning_library", "SCL"); + auto scl_path = this->synth->storage.datapath / "tuning_library" / "SCL"; - scl_path = Surge::Storage::getUserDefaultValue(&(this->synth->storage), - Surge::Storage::LastSCLPath, scl_path); + scl_path = Surge::Storage::getUserDefaultPath(&(this->synth->storage), + Surge::Storage::LastSCLPath, scl_path); - fileChooser = - std::make_unique("Select SCL Scale", juce::File(scl_path), "*.scl"); + fileChooser = std::make_unique( + "Select SCL Scale", juce::File(path_to_string(scl_path)), "*.scl"); fileChooser->launchAsync( juce::FileBrowserComponent::openMode | juce::FileBrowserComponent::canSelectFiles, @@ -2342,12 +2341,12 @@ juce::PopupMenu SurgeGUIEditor::makeTuningMenu(const juce::Point &where, bo return; auto res = ress.getFirst(); auto rString = res.getFullPathName().toStdString(); - auto dir = res.getParentDirectory().getFullPathName().toStdString(); + auto dir = string_to_path(res.getParentDirectory().getFullPathName().toStdString()); cb(rString); if (dir != scl_path) { - Surge::Storage::updateUserDefaultValue(&(this->synth->storage), - Surge::Storage::LastSCLPath, dir); + Surge::Storage::updateUserDefaultPath(&(this->synth->storage), + Surge::Storage::LastSCLPath, dir); } }); }); @@ -2383,13 +2382,12 @@ juce::PopupMenu SurgeGUIEditor::makeTuningMenu(const juce::Point &where, bo } }; - auto kbm_path = Surge::Storage::appendDirectory(this->synth->storage.datapath, - "tuning_library", "KBM Concert Pitch"); + auto kbm_path = this->synth->storage.datapath / "tuning_library" / "KBM Concert Pitch"; - kbm_path = Surge::Storage::getUserDefaultValue(&(this->synth->storage), - Surge::Storage::LastKBMPath, kbm_path); - fileChooser = std::make_unique("Select KBM Mapping", - juce::File(kbm_path), "*.kbm"); + kbm_path = Surge::Storage::getUserDefaultPath(&(this->synth->storage), + Surge::Storage::LastKBMPath, kbm_path); + fileChooser = std::make_unique( + "Select KBM Mapping", juce::File(path_to_string(kbm_path)), "*.kbm"); fileChooser->launchAsync( juce::FileBrowserComponent::openMode | juce::FileBrowserComponent::canSelectFiles, @@ -2402,12 +2400,12 @@ juce::PopupMenu SurgeGUIEditor::makeTuningMenu(const juce::Point &where, bo auto res = c.getResult(); auto rString = res.getFullPathName().toStdString(); - auto dir = res.getParentDirectory().getFullPathName().toStdString(); + auto dir = string_to_path(res.getParentDirectory().getFullPathName().toStdString()); cb(rString); if (dir != kbm_path) { - Surge::Storage::updateUserDefaultValue(&(this->synth->storage), - Surge::Storage::LastKBMPath, dir); + Surge::Storage::updateUserDefaultPath(&(this->synth->storage), + Surge::Storage::LastKBMPath, dir); } }); }); @@ -2523,9 +2521,7 @@ juce::PopupMenu SurgeGUIEditor::makeTuningMenu(const juce::Point &where, bo [this]() { showHTML(this->tuningToHtml()); }); tuningSubMenu.addItem(Surge::GUI::toOSCaseForMenu("Factory Tuning Library..."), [this]() { - auto path = - Surge::Storage::appendDirectory(this->synth->storage.datapath, "tuning_library"); - + auto path = this->synth->storage.datapath / "tuning_library"; Surge::GUI::openFileOrFolder(path); }); @@ -2981,11 +2977,12 @@ juce::PopupMenu SurgeGUIEditor::makeSkinMenu(const juce::Point &where) if (useDevMenu) { dname += " ("; - if (entry.root.find(synth->storage.datapath) != std::string::npos) + + if (entry.rootType == Surge::GUI::FACTORY) { dname += "factory"; } - else if (entry.root.find(synth->storage.userDataPath) != std::string::npos) + else if (entry.rootType == Surge::GUI::USER) { dname += "user"; } @@ -3085,8 +3082,8 @@ juce::PopupMenu SurgeGUIEditor::makeSkinMenu(const juce::Point &where) if (useDevMenu) { skinSubMenu.addItem(Surge::GUI::toOSCaseForMenu("Open Current Skin Folder..."), [this]() { - Surge::GUI::openFileOrFolder( - Surge::Storage::appendDirectory(this->currentSkin->root, this->currentSkin->name)); + Surge::GUI::openFileOrFolder(string_to_path(this->currentSkin->root) / + this->currentSkin->name); }); } else @@ -3117,13 +3114,13 @@ juce::PopupMenu SurgeGUIEditor::makeDataMenu(const juce::Point &where) dataSubMenu.addItem(Surge::GUI::toOSCaseForMenu("Open User Data Folder..."), [this]() { // make it if it isn't there - fs::create_directories(string_to_path(this->synth->storage.userDataPath)); + fs::create_directories(this->synth->storage.userDataPath); Surge::GUI::openFileOrFolder(this->synth->storage.userDataPath); }); dataSubMenu.addItem(Surge::GUI::toOSCaseForMenu("Set Custom User Data Folder..."), [this]() { - fileChooser = std::make_unique("Set Custom User Data Folder", - juce::File(synth->storage.userDataPath)); + fileChooser = std::make_unique( + "Set Custom User Data Folder", juce::File(path_to_string(synth->storage.userDataPath))); fileChooser->launchAsync( juce::FileBrowserComponent::openMode | juce::FileBrowserComponent::canSelectDirectories, [this](const juce::FileChooser &f) { diff --git a/src/gui/SurgeGUIUtils.h b/src/gui/SurgeGUIUtils.h index 49f59229296..6d9799f7c0d 100644 --- a/src/gui/SurgeGUIUtils.h +++ b/src/gui/SurgeGUIUtils.h @@ -16,5 +16,6 @@ bool get_line_intersection(float p0_x, float p0_y, float p1_x, float p1_y, float float p3_x, float p3_y, float *i_x, float *i_y); void openFileOrFolder(const std::string &f); +inline void openFileOrFolder(const fs::path &f) { openFileOrFolder(path_to_string(f)); } } // namespace GUI } // namespace Surge diff --git a/src/gui/overlays/AboutScreen.cpp b/src/gui/overlays/AboutScreen.cpp index 07ca38135f5..059100b7def 100644 --- a/src/gui/overlays/AboutScreen.cpp +++ b/src/gui/overlays/AboutScreen.cpp @@ -109,9 +109,11 @@ void AboutScreen::populateData() if (host != "Unknown") lowerLeft.emplace_back("Host", host, ""); lowerLeft.emplace_back("", "", ""); - lowerLeft.emplace_back("Factory Data", storage->datapath, storage->datapath); - lowerLeft.emplace_back("User Data", storage->userDataPath, storage->userDataPath); - lowerLeft.emplace_back("Plugin", storage->installedPath, ""); + lowerLeft.emplace_back("Factory Data", storage->datapath.u8string(), + storage->datapath.u8string()); + lowerLeft.emplace_back("User Data", storage->userDataPath.u8string(), + storage->userDataPath.u8string()); + lowerLeft.emplace_back("Plugin", storage->installedPath.u8string(), ""); lowerLeft.emplace_back("Current Skin", skin->displayName, skin->root + skin->name); lowerLeft.emplace_back("Skin Author", skin->author, skin->authorURL); diff --git a/src/gui/widgets/OscillatorWaveformDisplay.cpp b/src/gui/widgets/OscillatorWaveformDisplay.cpp index 19ec51b5e4c..ec8ef6cbc4b 100644 --- a/src/gui/widgets/OscillatorWaveformDisplay.cpp +++ b/src/gui/widgets/OscillatorWaveformDisplay.cpp @@ -439,13 +439,12 @@ void OscillatorWaveformDisplay::loadWavetable(int id) void OscillatorWaveformDisplay::loadWavetableFromFile() { auto wtPath = storage->userWavetablesPath; - wtPath = - Surge::Storage::getUserDefaultValue(storage, Surge::Storage::LastWavetablePath, wtPath); + wtPath = Surge::Storage::getUserDefaultPath(storage, Surge::Storage::LastWavetablePath, wtPath); if (!sge) return; - sge->fileChooser = - std::make_unique("Select Wavetable to Load", juce::File(wtPath)); + sge->fileChooser = std::make_unique("Select Wavetable to Load", + juce::File(path_to_string(wtPath))); sge->fileChooser->launchAsync( juce::FileBrowserComponent::openMode | juce::FileBrowserComponent::canSelectFiles, [this, wtPath](const juce::FileChooser &c) { @@ -456,11 +455,11 @@ void OscillatorWaveformDisplay::loadWavetableFromFile() auto res = c.getResult(); auto rString = res.getFullPathName().toStdString(); strncpy(this->oscdata->wt.queue_filename, rString.c_str(), 255); - auto dir = res.getParentDirectory().getFullPathName().toStdString(); + auto dir = string_to_path(res.getParentDirectory().getFullPathName().toStdString()); if (dir != wtPath) { - Surge::Storage::updateUserDefaultValue(storage, Surge::Storage::LastWavetablePath, - dir); + Surge::Storage::updateUserDefaultPath(storage, Surge::Storage::LastWavetablePath, + dir); } }); } diff --git a/src/gui/widgets/PatchSelector.cpp b/src/gui/widgets/PatchSelector.cpp index 2f9e0e78a31..9a984d34766 100644 --- a/src/gui/widgets/PatchSelector.cpp +++ b/src/gui/widgets/PatchSelector.cpp @@ -242,12 +242,12 @@ void PatchSelector::showClassicMenu(bool single_category) contextMenu.addItem(Surge::GUI::toOSCaseForMenu("Load Patch From File..."), [this]() { auto patchPath = storage->userPatchesPath; patchPath = - Surge::Storage::getUserDefaultValue(storage, Surge::Storage::LastPatchPath, patchPath); + Surge::Storage::getUserDefaultPath(storage, Surge::Storage::LastPatchPath, patchPath); auto sge = firstListenerOfType(); if (!sge) return; - sge->fileChooser = std::make_unique("Select Patch to Load", - juce::File(patchPath), "*.fxp"); + sge->fileChooser = std::make_unique( + "Select Patch to Load", juce::File(path_to_string(patchPath)), "*.fxp"); sge->fileChooser->launchAsync( juce::FileBrowserComponent::openMode | juce::FileBrowserComponent::canSelectFiles, [this, patchPath](const juce::FileChooser &c) { @@ -263,32 +263,27 @@ void PatchSelector::showClassicMenu(bool single_category) { sge->queuePatchFileLoad(rString); } - auto dir = res.getParentDirectory().getFullPathName().toStdString(); + auto dir = string_to_path(res.getParentDirectory().getFullPathName().toStdString()); if (dir != patchPath) { - Surge::Storage::updateUserDefaultValue(storage, Surge::Storage::LastPatchPath, - dir); + Surge::Storage::updateUserDefaultPath(storage, Surge::Storage::LastPatchPath, + dir); } }); }); contextMenu.addSeparator(); - contextMenu.addItem(Surge::GUI::toOSCaseForMenu("Open User Patches Folder..."), [this]() { - Surge::GUI::openFileOrFolder( - Surge::Storage::appendDirectory(this->storage->userDataPath, "Patches")); - }); + contextMenu.addItem(Surge::GUI::toOSCaseForMenu("Open User Patches Folder..."), + [this]() { Surge::GUI::openFileOrFolder(this->storage->userPatchesPath); }); contextMenu.addItem(Surge::GUI::toOSCaseForMenu("Open Factory Patches Folder..."), [this]() { - Surge::GUI::openFileOrFolder( - Surge::Storage::appendDirectory(this->storage->datapath, "patches_factory")); + Surge::GUI::openFileOrFolder(this->storage->datapath / "patches_factory"); }); contextMenu.addItem( - Surge::GUI::toOSCaseForMenu("Open Third Party Patches Folder..."), [this]() { - Surge::GUI::openFileOrFolder( - Surge::Storage::appendDirectory(this->storage->datapath, "patches_3rdparty")); - }); + Surge::GUI::toOSCaseForMenu("Open Third Party Patches Folder..."), + [this]() { Surge::GUI::openFileOrFolder(this->storage->datapath / "patches_3rdparty"); }); contextMenu.addSeparator();