prepare fix for copying plugin state
[ardour.git] / libs / ardour / search_paths.cc
index 09227f6347a84e90e70c6714177bd4a9d5da4d11..789c9b6b4878fc76cca954df9b0cc232d94cc7cf 100644 (file)
@@ -1,6 +1,6 @@
 /*
-    Copyright (C) 2011 Tim Mayberry 
-    Copyright (C) 2013 Paul Davis 
+    Copyright (C) 2011 Tim Mayberry
+    Copyright (C) 2013 Paul Davis
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -64,7 +64,7 @@ control_protocol_search_path ()
        Searchpath spath(user_config_directory ());
        spath += ardour_dll_directory ();
        spath.add_subdirectory_to_paths (surfaces_dir_name);
-       
+
        spath += Searchpath(Glib::getenv(surfaces_env_variable_name));
        return spath;
 }
@@ -147,14 +147,39 @@ panner_search_path ()
        return spath;
 }
 
+Searchpath
+template_search_path ()
+{
+       Searchpath spath (ardour_data_search_path());
+       spath.add_subdirectory_to_paths(templates_dir_name);
+       return spath;
+}
+
+Searchpath
+route_template_search_path ()
+{
+       Searchpath spath (ardour_data_search_path());
+       spath.add_subdirectory_to_paths(route_templates_dir_name);
+       return spath;
+}
+
+Searchpath
+lua_search_path ()
+{
+       Searchpath spath (ardour_data_search_path());
+       spath.add_subdirectory_to_paths(lua_dir_name);
+
+       return spath;
+}
+
 #ifdef PLATFORM_WINDOWS
 
 const char*
 vst_search_path ()
 {
-       DWORD dwType = REG_SZ;  
+       DWORD dwType = REG_SZ;
        HKEY hKey;
-       DWORD dwSize = PATH_MAX;  
+       DWORD dwSize = PATH_MAX;
        char* p = 0;
        char* user_home = 0;
        char tmp[PATH_MAX+1];
@@ -162,7 +187,7 @@ vst_search_path ()
        if (ERROR_SUCCESS == RegOpenKeyExA (HKEY_CURRENT_USER, "Software\\VST", 0, KEY_READ, &hKey)) {
                // Look for the user's VST Registry entry
                if (ERROR_SUCCESS == RegQueryValueExA (hKey, "VSTPluginsPath", 0, &dwType, (LPBYTE)tmp, &dwSize))
-                       p = g_build_filename (Glib::locale_to_utf8(tmp).c_str(), 0);
+                       p = g_build_filename (Glib::locale_to_utf8(tmp).c_str(), NULL);
 
                RegCloseKey (hKey);
        }
@@ -172,7 +197,7 @@ vst_search_path ()
                {
                        // Look for a global VST Registry entry
                        if (ERROR_SUCCESS == RegQueryValueExA (hKey, "VSTPluginsPath", 0, &dwType, (LPBYTE)tmp, &dwSize))
-                               p = g_build_filename (Glib::locale_to_utf8(tmp).c_str(), 0);
+                               p = g_build_filename (Glib::locale_to_utf8(tmp).c_str(), NULL);
 
                        RegCloseKey (hKey);
                }
@@ -180,37 +205,33 @@ vst_search_path ()
 
        if (p == 0) {
                char *pVSTx86 = 0;
-               char *pProgFilesX86 = PBD::get_win_special_folder (CSIDL_PROGRAM_FILESX86);
+               std::string pProgFilesX86 = PBD::get_win_special_folder_path (CSIDL_PROGRAM_FILESX86);
 
-               if (pProgFilesX86) {
+               if (!pProgFilesX86.empty()) {
                        // Look for a VST folder under C:\Program Files (x86)
-                       if (pVSTx86 = g_build_filename (pProgFilesX86, "Steinberg", "VSTPlugins", 0))
+                       if ((pVSTx86 = g_build_filename (pProgFilesX86.c_str(), "Steinberg", "VSTPlugins", NULL)))
                        {
                                if (Glib::file_test (pVSTx86, Glib::FILE_TEST_EXISTS))
                                        if (Glib::file_test (pVSTx86, Glib::FILE_TEST_IS_DIR))
-                                               p = g_build_filename (pVSTx86, 0);
+                                               p = g_build_filename (pVSTx86, NULL);
 
                                g_free (pVSTx86);
                        }
-
-                       g_free (pProgFilesX86);
                }
 
                if (p == 0) {
                        // Look for a VST folder under C:\Program Files
                        char *pVST = 0;
-                       char *pProgFiles = PBD::get_win_special_folder (CSIDL_PROGRAM_FILES);
+                       std::string pProgFiles = PBD::get_win_special_folder_path (CSIDL_PROGRAM_FILES);
 
-                       if (pProgFiles) {
-                               if (pVST = g_build_filename (pProgFiles, "Steinberg", "VSTPlugins", 0)) {
+                       if (!pProgFiles.empty()) {
+                               if ((pVST = g_build_filename (pProgFiles.c_str(), "Steinberg", "VSTPlugins", NULL))) {
                                        if (Glib::file_test (pVST, Glib::FILE_TEST_EXISTS))
                                                if (Glib::file_test (pVST, Glib::FILE_TEST_IS_DIR))
-                                                       p = g_build_filename (pVST, 0);
+                                                       p = g_build_filename (pVST, NULL);
 
                                        g_free (pVST);
                                }
-
-                               g_free (pProgFiles);
                        }
                }
        }
@@ -219,23 +240,23 @@ vst_search_path ()
                // If all else failed, assume the plugins are under "My Documents"
                user_home = (char*) g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS);
                if (user_home) {
-                       p = g_build_filename (user_home, "Plugins", "VST", 0);
+                       p = g_build_filename (user_home, "Plugins", "VST", NULL);
                } else {
-                       user_home = g_build_filename(g_get_home_dir(), "My Documents", 0);
+                       user_home = g_build_filename(g_get_home_dir(), "My Documents", NULL);
                        if (user_home)
-                               p = g_build_filename (user_home, "Plugins", "VST", 0);
+                               p = g_build_filename (user_home, "Plugins", "VST", NULL);
                }
        } else {
                // Concatenate the registry path with the user's personal path
                user_home = (char*) g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS);
 
                if (user_home) {
-                       p = g_build_path (";", p, g_build_filename(user_home, "Plugins", "VST", 0), 0);
+                       p = g_build_path (";", p, g_build_filename(user_home, "Plugins", "VST", NULL), NULL);
                } else {
-                       user_home = g_build_filename(g_get_home_dir(), "My Documents", 0);
+                       user_home = g_build_filename(g_get_home_dir(), "My Documents", NULL);
 
                        if (user_home) {
-                               p = g_build_path (";", p, g_build_filename (user_home, "Plugins", "VST", 0), 0);
+                               p = g_build_path (";", p, g_build_filename (user_home, "Plugins", "VST", NULL), NULL);
                        }
                }
        }
@@ -243,7 +264,7 @@ vst_search_path ()
        return p;
 }
 
-#else 
+#else
 
 /* Unix-like. Probably require some OS X specific breakdown if we ever add VST
  * support on that platform.