From d2e0b4fefc7312c040d5a79f465688e3f28649ff Mon Sep 17 00:00:00 2001 From: Subin Siby Date: Thu, 8 Oct 2020 03:01:10 +0530 Subject: [PATCH 1/2] First order preference to user folder for searching VST --- varnam.c | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/varnam.c b/varnam.c index 0c8ce0c..f33a225 100644 --- a/varnam.c +++ b/varnam.c @@ -217,15 +217,43 @@ static const char* symbolsFileSearchPath[] = { const char* varnam_find_symbols_file_directory() { + char *tmp; + strbuf *user_path; int i; if (varnam_symbols_dir != NULL && is_directory(strbuf_to_s (varnam_symbols_dir))) { return strbuf_to_s(varnam_symbols_dir); } - for (i = 0; i < ARRAY_SIZE (symbolsFileSearchPath); i++) { - if (is_directory (symbolsFileSearchPath[i])) - return symbolsFileSearchPath[i]; +#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) + tmp = getenv ("APPDATA"); + if (tmp != NULL) { + strbuf_addf (user_path, "%s\\varnam\\vst\\", tmp); + if (!is_directory (strbuf_to_s (user_path))) { + strbuf_clear (user_path); + } + } +#else + tmp = getenv ("XDG_DATA_HOME"); + if (tmp == NULL) { + tmp = getenv ("HOME"); + if (tmp != NULL) { + strbuf_addf (user_path, "%s/.local/share/varnam/vst/", tmp); + } + } + else { + strbuf_addf (user_path, "%s/varnam/vst/", tmp); + } +#endif + + if (!strbuf_is_blank (user_path)) { + return strbuf_to_s(user_path); + } + else { + for (i = 0; i < ARRAY_SIZE (symbolsFileSearchPath); i++) { + if (is_directory (symbolsFileSearchPath[i])) + return symbolsFileSearchPath[i]; + } } return NULL; From 4cb9ba7cbdb72855dc8365040dfe064b80c4c416 Mon Sep 17 00:00:00 2001 From: Subin Siby Date: Thu, 8 Oct 2020 04:13:49 +0530 Subject: [PATCH 2/2] Init strbuf, compact & make it simpler --- varnam.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/varnam.c b/varnam.c index f33a225..1ac6b15 100644 --- a/varnam.c +++ b/varnam.c @@ -225,13 +225,12 @@ varnam_find_symbols_file_directory() return strbuf_to_s(varnam_symbols_dir); } + user_path = strbuf_init (20); + #if defined(WIN32) || defined(_WIN32) || defined(__WIN32) tmp = getenv ("APPDATA"); if (tmp != NULL) { strbuf_addf (user_path, "%s\\varnam\\vst\\", tmp); - if (!is_directory (strbuf_to_s (user_path))) { - strbuf_clear (user_path); - } } #else tmp = getenv ("XDG_DATA_HOME"); @@ -247,15 +246,18 @@ varnam_find_symbols_file_directory() #endif if (!strbuf_is_blank (user_path)) { - return strbuf_to_s(user_path); - } - else { - for (i = 0; i < ARRAY_SIZE (symbolsFileSearchPath); i++) { - if (is_directory (symbolsFileSearchPath[i])) - return symbolsFileSearchPath[i]; + if (is_path_exists (strbuf_to_s (user_path))) { + if (is_directory (strbuf_to_s (user_path))) { + return strbuf_to_s (user_path); + } } } + for (i = 0; i < ARRAY_SIZE (symbolsFileSearchPath); i++) { + if (is_directory (symbolsFileSearchPath[i])) + return symbolsFileSearchPath[i]; + } + return NULL; }