diff --git a/src/vst2_main.cpp b/src/vst2_main.cpp index 8565b6ab..208cc5f9 100644 --- a/src/vst2_main.cpp +++ b/src/vst2_main.cpp @@ -42,6 +42,9 @@ #include #include #include +#ifdef HAVE_UNIX +#include +#endif #include "../dep/yac/yac.h" #include "../dep/yac/yac_host.cpp" @@ -523,15 +526,26 @@ public: char oldCWD[1024]; char dllnameraw[1024]; + +#ifdef HAVE_WINDOWS ::GetCurrentDirectory(1024, (LPSTR) oldCWD); // ::GetModuleFileNameA(NULL, dllnameraw, 1024); // returns executable name (not the dll pathname) GetModuleFileNameA((HINSTANCE)&__ImageBase, dllnameraw, 1024); +#elif defined(HAVE_UNIX) + getcwd(oldCWD, 1024); + readlink("/proc/self/exe", dllnameraw, 1024); +#endif + dllname.visit(dllnameraw); dllname.getDirName(&cwd); rack::global->vst2.program_dir = (const char*)cwd.chars; + Dprintf("xxx vstrack_plugin::openEffect: cd to \"%s\"\n", (const char*)cwd.chars); - // // ::SetCurrentDirectory("f:/vst_64bit/vstrack_plugin"); +#ifdef HAVE_WINDOWS ::SetCurrentDirectory((const char*)cwd.chars); +#elif defined(HAVE_UNIX) + chdir((const char*)cwd.chars); +#endif Dprintf("xxx vstrack_plugin::openEffect: cwd change done\n"); // cwd.replace('\\', '/'); @@ -552,7 +566,12 @@ public: vst2_set_shared_plugin_tls_globals(); Dprintf("xxx vstrack_plugin::openEffect: restore cwd=\"%s\"\n", oldCWD); + +#ifdef HAVE_WINDOWS ::SetCurrentDirectory(oldCWD); +#elif defined(HAVE_UNIX) + chdir(oldCWD); +#endif setSampleRate(sample_rate);