From 1a4b7aab1ad36ba51062a39fbfc7bf542f9cf554 Mon Sep 17 00:00:00 2001 From: falkTX Date: Mon, 25 Aug 2014 23:18:31 +0100 Subject: [PATCH] Fix LV2 state map/make path features --- source/backend/plugin/Lv2Plugin.cpp | 22 +++++++++++++++++++--- source/bridges-ui/CarlaBridgeUI-LV2.cpp | 22 +++++++++++++++++++--- 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/source/backend/plugin/Lv2Plugin.cpp b/source/backend/plugin/Lv2Plugin.cpp index 37e9478d7..5b525502a 100644 --- a/source/backend/plugin/Lv2Plugin.cpp +++ b/source/backend/plugin/Lv2Plugin.cpp @@ -5463,8 +5463,16 @@ private: CARLA_SAFE_ASSERT_RETURN(path != nullptr && path[0] != '\0', nullptr); carla_debug("carla_lv2_state_make_path(%p, \"%s\")", handle, path); - File(path).createDirectory(); - return strdup(path); + File file; + + if (File::isAbsolutePath(path)) + file = File(path); + else + file = File::getCurrentWorkingDirectory().getChildFile(path); + + file.getParentDirectory().createDirectory(); + + return strdup(file.getFullPathName().toRawUTF8()); } static char* carla_lv2_state_map_abstract_path(LV2_State_Map_Path_Handle handle, const char* absolute_path) @@ -5473,6 +5481,10 @@ private: 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()); } @@ -5482,7 +5494,11 @@ private: 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); - return strdup(File(abstract_path).getFullPathName().toRawUTF8()); + // may already be an absolute path + if (File::isAbsolutePath(abstract_path)) + return strdup(abstract_path); + + return strdup(File::getCurrentWorkingDirectory().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) diff --git a/source/bridges-ui/CarlaBridgeUI-LV2.cpp b/source/bridges-ui/CarlaBridgeUI-LV2.cpp index f6bca01dd..4da7d9afc 100644 --- a/source/bridges-ui/CarlaBridgeUI-LV2.cpp +++ b/source/bridges-ui/CarlaBridgeUI-LV2.cpp @@ -855,8 +855,16 @@ private: CARLA_SAFE_ASSERT_RETURN(path != nullptr && path[0] != '\0', nullptr); carla_debug("carla_lv2_state_make_path(%p, \"%s\")", handle, path); - File(path).createDirectory(); - return strdup(path); + File file; + + if (File::isAbsolutePath(path)) + file = File(path); + else + file = File::getCurrentWorkingDirectory().getChildFile(path); + + file.getParentDirectory().createDirectory(); + + return strdup(file.getFullPathName().toRawUTF8()); } static char* carla_lv2_state_map_abstract_path(LV2_State_Map_Path_Handle handle, const char* absolute_path) @@ -865,6 +873,10 @@ private: 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()); } @@ -874,7 +886,11 @@ private: 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); - return strdup(File(abstract_path).getFullPathName().toRawUTF8()); + // may already be an absolute path + if (File::isAbsolutePath(abstract_path)) + return strdup(abstract_path); + + return strdup(File::getCurrentWorkingDirectory().getChildFile(abstract_path).getFullPathName().toRawUTF8()); } // -------------------------------------------------------------------