From 66f912aa9252a447422e2335b71569fc9bc62115 Mon Sep 17 00:00:00 2001 From: falkTX Date: Thu, 25 Jun 2020 19:04:02 +0100 Subject: [PATCH] Better handle lv2 map/make path, now based on project dir Signed-off-by: falkTX --- source/backend/plugin/CarlaPluginLV2.cpp | 47 ++++++++++++++++++------ 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/source/backend/plugin/CarlaPluginLV2.cpp b/source/backend/plugin/CarlaPluginLV2.cpp index ad452f867..c86bd8cb6 100644 --- a/source/backend/plugin/CarlaPluginLV2.cpp +++ b/source/backend/plugin/CarlaPluginLV2.cpp @@ -6798,43 +6798,66 @@ private: CARLA_SAFE_ASSERT_RETURN(path != nullptr && path[0] != '\0', nullptr); carla_debug("carla_lv2_state_make_path(%p, \"%s\")", handle, path); - File file; + File target; if (File::isAbsolutePath(path)) - file = File(path); + { + target = path; + } else - file = File::getCurrentWorkingDirectory().getChildFile(path); + { + if (const char* const projFolder = ((CarlaPluginLV2*)handle)->pData->engine->getCurrentProjectFolder()) + target = projFolder; + else + target = File::getCurrentWorkingDirectory(); - file.getParentDirectory().createDirectory(); + target = target.getChildFile(path); + } + + if (! target.exists()) + target.createDirectory(); - return strdup(file.getFullPathName().toRawUTF8()); + return strdup(target.getFullPathName().toRawUTF8()); } static char* carla_lv2_state_map_abstract_path(LV2_State_Map_Path_Handle handle, const char* absolute_path) { - CARLA_SAFE_ASSERT_RETURN(handle != nullptr, strdup("")); - CARLA_SAFE_ASSERT_RETURN(absolute_path != nullptr && absolute_path[0] != '\0', strdup("")); + CARLA_SAFE_ASSERT_RETURN(handle != nullptr, nullptr); + CARLA_SAFE_ASSERT_RETURN(absolute_path != nullptr && absolute_path[0] != '\0', nullptr); carla_debug("carla_lv2_state_map_abstract_path(%p, \"%s\")", handle, absolute_path); // may already be an abstract path if (! File::isAbsolutePath(absolute_path)) return strdup(absolute_path); - return strdup(File(absolute_path).getRelativePathFrom(File::getCurrentWorkingDirectory()).toRawUTF8()); + File target; + + if (const char* const projFolder = ((CarlaPluginLV2*)handle)->pData->engine->getCurrentProjectFolder()) + target = projFolder; + else + target = File::getCurrentWorkingDirectory(); + + return strdup(File(absolute_path).getRelativePathFrom(target).toRawUTF8()); } static char* carla_lv2_state_map_absolute_path(LV2_State_Map_Path_Handle handle, const char* abstract_path) { - const char* const cwd(File::getCurrentWorkingDirectory().getFullPathName().toRawUTF8()); - CARLA_SAFE_ASSERT_RETURN(handle != nullptr, strdup(cwd)); - CARLA_SAFE_ASSERT_RETURN(abstract_path != nullptr && abstract_path[0] != '\0', strdup(cwd)); + CARLA_SAFE_ASSERT_RETURN(handle != nullptr, nullptr); + CARLA_SAFE_ASSERT_RETURN(abstract_path != nullptr && abstract_path[0] != '\0', nullptr); carla_debug("carla_lv2_state_map_absolute_path(%p, \"%s\")", handle, abstract_path); // may already be an absolute path if (File::isAbsolutePath(abstract_path)) return strdup(abstract_path); - return strdup(File::getCurrentWorkingDirectory().getChildFile(abstract_path).getFullPathName().toRawUTF8()); + File base; + + if (const char* const projFolder = ((CarlaPluginLV2*)handle)->pData->engine->getCurrentProjectFolder()) + base = projFolder; + else + base = File::getCurrentWorkingDirectory(); + + return strdup(base.getChildFile(abstract_path).getFullPathName().toRawUTF8()); } static LV2_State_Status carla_lv2_state_store(LV2_State_Handle handle, uint32_t key, const void* value, size_t size, uint32_t type, uint32_t flags)