From 458d4dc6de6e26c8cf45d197f1db29c19767e6db Mon Sep 17 00:00:00 2001 From: John Emmas Date: Tue, 27 May 2014 14:48:44 +0100 Subject: [PATCH] (Windows) Add support for finding the bundled version of Jack which comes with Mixbus A few things need to be tested / completed:- 1) The code is currently guarded by #ifdef COMPILER_MSVC. This is just precautionary. If it builds okay with MinGW ,the guard can be removed. 2) Windows Playback and Capture devices almost always have different names. This needs to get accommodated in our Backend dialog (as in Mixbus) 3) Windows Playback and Capture devices will almost always contain spaces. We need to accommodate this when writing to .jackdrc (surround them in quote marks) --- libs/backends/jack/jack_utils.cc | 59 ++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/libs/backends/jack/jack_utils.cc b/libs/backends/jack/jack_utils.cc index 1e74a5315f..fcb0d7a169 100644 --- a/libs/backends/jack/jack_utils.cc +++ b/libs/backends/jack/jack_utils.cc @@ -29,6 +29,11 @@ #include #endif +#ifdef PLATFORM_WINDOWS +#include // Needed for +#include // 'IShellLink' +#endif + #ifdef HAVE_PORTAUDIO #include #endif @@ -584,6 +589,60 @@ ARDOUR::get_jack_server_dir_paths (vector& server_dir_paths) Searchpath sp(string(g_getenv("PATH"))); #ifdef PLATFORM_WINDOWS +// N.B. The #define (immediately below) can be safely removed once we know that this code builds okay with mingw +#ifdef COMPILER_MSVC + IShellLinkA *pISL = NULL; + IPersistFile *ppf = NULL; + + // Mixbus creates a Windows shortcut giving the location of its + // own (bundled) version of Jack. Let's see if that shortcut exists + if (SUCCEEDED (CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void**)&pISL))) + { + if (SUCCEEDED (pISL->QueryInterface(IID_IPersistFile, (LPVOID*)&ppf))) + { + char target_path[MAX_PATH]; + char shortcut_pathA[MAX_PATH]; + WCHAR shortcut_pathW[MAX_PATH]; + + // Our Windows installer should have created a shortcut to the Jack + // server so let's start by finding out what drive it got installed on + if (char *env_path = getenv ("windir")) + { + strcpy (shortcut_pathA, env_path); + shortcut_pathA[2] = '\0'; // Gives us just the drive letter and colon + } + else // Assume 'C:' + strcpy (shortcut_pathA, "C:"); + + strcat (shortcut_pathA, "\\Program Files (x86)\\Jack\\Start Jack.lnk"); + + MultiByteToWideChar (CP_ACP, MB_PRECOMPOSED, shortcut_pathA, -1, shortcut_pathW, MAX_PATH); + + // If it did, load the shortcut into our persistent file + if (SUCCEEDED (ppf->Load(shortcut_pathW, 0))) + { + // Read the target information from the shortcut object + if (S_OK == (pISL->GetPath (target_path, MAX_PATH, NULL, SLGP_UNCPRIORITY))) + { + char *p = strrchr (target_path, '\\'); + + if (p) + { + *p = NULL; + sp.push_back (target_path); + } + } + } + } + } + + if (ppf) + ppf->Release(); + + if (pISL) + pISL->Release(); +#endif + gchar *install_dir = g_win32_get_package_installation_directory_of_module (NULL); if (install_dir) { sp.push_back (install_dir);