mingw build fixes (tested with i686-w64-mingw32 on linux-x86_64)
[ardour.git] / libs / ardour / vst_search_path.cc
1 /*
2     Copyright (C) 2008 John Emmas
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18
19 #include <glib.h>
20 #include <glibmm.h>
21 #include <string.h>
22
23 #include "ardour/vst_search_path.h"
24
25 #ifdef PLATFORM_WINDOWS
26
27 #include <windows.h>
28 #include <shlobj.h> // CSIDL_*
29 #include "pbd/windows_special_dirs.h"
30
31 namespace ARDOUR {
32
33 const char*
34 vst_search_path ()
35 {
36         DWORD dwType = REG_SZ;  
37         HKEY hKey;
38         DWORD dwSize = PATH_MAX;  
39         char* p = 0;
40         char* user_home = 0;
41         char tmp[PATH_MAX+1];
42
43         if (ERROR_SUCCESS == RegOpenKeyExA (HKEY_CURRENT_USER, "Software\\VST", 0, KEY_READ, &hKey)) {
44                 // Look for the user's VST Registry entry
45                 if (ERROR_SUCCESS == RegQueryValueExA (hKey, "VSTPluginsPath", 0, &dwType, (LPBYTE)tmp, &dwSize)) {
46                         p = g_build_filename (Glib::locale_to_utf8(tmp).c_str(), 0);
47                 }
48                 RegCloseKey (hKey);
49                 
50                 if (p == 0) {
51                         if (ERROR_SUCCESS == RegOpenKeyExA (HKEY_LOCAL_MACHINE, "Software\\VST", 0, KEY_READ, &hKey)) {
52                                 // Look for a global VST Registry entry
53                                 if (ERROR_SUCCESS == RegQueryValueExA (hKey, "VSTPluginsPath", 0, &dwType, (LPBYTE)tmp, &dwSize))
54                                         p = g_build_filename (Glib::locale_to_utf8(tmp).c_str(), 0);
55                                 
56                                 RegCloseKey (hKey);
57                         }
58                         
59                         if (p == 0) {
60                                 char *pVSTx86 = 0;
61                                 char *pProgFilesX86 = PBD::get_win_special_folder (CSIDL_PROGRAM_FILESX86);
62                                 
63                                 if (pProgFilesX86) {
64                                         // Look for a VST folder under C:\Program Files (x86)
65                                         if (pVSTx86 = g_build_filename (pProgFilesX86, "Steinberg", "VSTPlugins", 0)) {
66                                                 if (Glib::file_test (pVSTx86, Glib::FILE_TEST_EXISTS))
67                                                         if (Glib::file_test (pVSTx86, Glib::FILE_TEST_IS_DIR))
68                                                                 p = g_build_filename (pVSTx86, 0);
69                                                 
70                                                 g_free (pVSTx86);
71                                         }
72                                         
73                                         g_free (pProgFilesX86);
74                                 }
75                         }
76
77                         if (p == 0) {
78                                 // Look for a VST folder under C:\Program Files
79                                 char *pVST = 0;
80                                 char *pProgFiles = PBD::get_win_special_folder (CSIDL_PROGRAM_FILES);
81                                 
82                                 if (pProgFiles) {
83                                         if (pVST = g_build_filename (pProgFiles, "Steinberg", "VSTPlugins", 0)) {
84                                                 if (Glib::file_test (pVST, Glib::FILE_TEST_EXISTS))
85                                                         if (Glib::file_test (pVST, Glib::FILE_TEST_IS_DIR))
86                                                                 p = g_build_filename (pVST, 0);
87                                                 g_free (pVST);
88                                         }
89                                         
90                                         g_free (pProgFiles);
91                                 }
92                         }
93                 }
94                 
95                 if (p == 0) {
96                         // If all else failed, assume the plugins are under "My Documents"
97                         user_home = (char*) g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS);
98                         if (user_home) {
99                                 p = g_build_filename (user_home, "Plugins", "VST", 0);
100                         } else {
101                                 user_home = g_build_filename(g_get_home_dir(), "My Documents", 0);
102                                 if (user_home)
103                                         p = g_build_filename (user_home, "Plugins", "VST", 0);
104                         }
105                 } else {
106                         // Concatenate the registry path with the user's personal path
107
108                         user_home = (char*) g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS);
109                         
110                         if (user_home) {
111                                 p = g_build_path (";", p, g_build_filename(user_home, "Plugins", "VST", 0), 0);
112                         } else {
113                                 user_home = g_build_filename(g_get_home_dir(), "My Documents", 0);
114                                 if (user_home) {
115                                         p = g_build_path (";", p, g_build_filename (user_home, "Plugins", "VST", 0), 0);
116                                 }
117                         }
118                 }
119         }
120
121         return p;
122 }
123
124 }  // namespace ARDOUR
125
126 #else 
127
128 /* Unix-like. Probably require some OS X specific breakdown if we ever add VST
129  * support on that platform.
130  */
131
132 namespace ARDOUR {
133
134 const char *
135 vst_search_path ()
136 {
137         return "/usr/local/lib/vst:/usr/lib/vst";
138 }
139
140 } // namespace ARDOUR
141
142 #endif /* PLATFORM_WINDOWS */
143