From 568597bddc205378de7b5f37ce2c4c15c8d397f3 Mon Sep 17 00:00:00 2001 From: Setsugennoao <41454651+Setsugennoao@users.noreply.github.com> Date: Fri, 3 Nov 2023 01:29:22 +0100 Subject: [PATCH] vapoursynth: Fix VSScript DLL loading We do this by first trying to fetch its location from the registry, then PATH --- src/vapoursynth_wrap.cpp | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/src/vapoursynth_wrap.cpp b/src/vapoursynth_wrap.cpp index d0f7f0173..addb3c6ac 100644 --- a/src/vapoursynth_wrap.cpp +++ b/src/vapoursynth_wrap.cpp @@ -32,6 +32,13 @@ #ifdef _WIN32 #define VSSCRIPT_SO "vsscript.dll" + +#ifdef _WIN64 +#define VS_INSTALL_REGKEY L"Software\\VapourSynth" +#else +#define VS_INSTALL_REGKEY L"Software\\VapourSynth-32" +#endif + #else #ifdef __APPLE__ #define VSSCRIPT_SO "libvapoursynth-script.dylib" @@ -61,11 +68,39 @@ VapourSynthWrapper::VapourSynthWrapper() { // VSScript assumes it's only loaded once, so unlike AVS we can't unload it when the refcount reaches zero if (!vs_loaded) { #ifdef _WIN32 + + std::wstring vsscriptDLLpath = L""; + + HKEY hKey; + LONG lRes = RegOpenKeyEx(HKEY_CURRENT_USER, VS_INSTALL_REGKEY, 0, KEY_READ, &hKey); + + if (lRes != ERROR_SUCCESS) { + lRes = RegOpenKeyEx(HKEY_LOCAL_MACHINE, VS_INSTALL_REGKEY, 0, KEY_READ, &hKey); + } + + if (lRes == ERROR_SUCCESS) { + WCHAR szBuffer[512]; + DWORD dwBufferSize = sizeof(szBuffer); + ULONG nError; + + nError = RegQueryValueEx(hKey, L"VSScriptDLL", 0, nullptr, (LPBYTE)szBuffer, &dwBufferSize); + RegCloseKey(hKey); + + if (nError == ERROR_SUCCESS) + vsscriptDLLpath = szBuffer; + } + + if (vsscriptDLLpath.length()) { + hLib = LoadLibraryW(vsscriptDLLpath.c_str()); + } + + if (!hLib) { #define CONCATENATE(x, y) x ## y #define _Lstr(x) CONCATENATE(L, x) - hLib = LoadLibraryW(_Lstr(VSSCRIPT_SO)); + hLib = LoadLibraryW(_Lstr(VSSCRIPT_SO)); #undef _Lstr #undef CONCATENATE + } #else hLib = dlopen(VSSCRIPT_SO, DLOPEN_FLAGS); #endif