Skip to content

Commit

Permalink
Merge branch 'vapoursynth' into feature
Browse files Browse the repository at this point in the history
  • Loading branch information
arch1t3cht committed Nov 3, 2023
2 parents 95500b8 + 568597b commit fd753c5
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion src/vapoursynth_wrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit fd753c5

Please sign in to comment.