Skip to content

Commit

Permalink
Try fetching the VSScript DLL from the registry then PATH
Browse files Browse the repository at this point in the history
  • Loading branch information
Setsugennoao committed Nov 3, 2023
1 parent c8bcbf2 commit 9da5579
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
- name: Configure and build
run: |
./autogen.sh
VSSCRIPT_CFLAGS="-I vapoursynth/sdk/include/" VSSCRIPT_LIBS="-L vapoursynth/ -l:vsscript.dll" ./configure
VSSCRIPT_CFLAGS="-I vapoursynth/sdk/include/" VSSCRIPT_LIBS="-L vapoursynth/" ./configure
make -j$(nproc)
- name: Package
Expand Down
2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
warningflags = -Wall -Wextra -Wshadow
includeflags = -I$(srcdir) -I$(srcdir)/src/shared
commoncflags = $(FPIC) -O2 $(warningflags) $(includeflags)
commoncflags = $(FPIC) -O2 $(warningflags) $(includeflags) -DUNICODE -D_UNICODE
AM_CXXFLAGS = -std=c++23 $(commoncflags)
AM_CFLAGS = -std=c23 $(commoncflags)
AM_CPPFLAGS = $(QT5PLATFORMSUPPORT_CFLAGS) $(QT5WIDGETS_CFLAGS) $(VSSCRIPT_CFLAGS)
Expand Down
81 changes: 81 additions & 0 deletions src/shared/WobblyShared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,36 @@ SOFTWARE.


#include "WobblyShared.h"
#include "WobblyException.h"

#include <cstdlib>
#include <vector>

#ifdef _WIN32
#include <windows.h>
#else
#include <dlfcn.h>
#endif

#ifdef _WIN32
#define VSSCRIPT_SO "vsscript.dll"
#else
#ifdef __APPLE__
#define VSSCRIPT_SO "libvapoursynth-script.dylib"
#define DLOPEN_FLAGS RTLD_LAZY | RTLD_GLOBAL
#else
#define VSSCRIPT_SO "libvapoursynth-script.so"
#define DLOPEN_FLAGS RTLD_LAZY | RTLD_GLOBAL | RTLD_DEEPBIND
#endif
#endif

namespace {
#ifdef _WIN32
HINSTANCE hLib = nullptr;
#else
void* hLib = nullptr;
#endif
}

struct PluginDetectionInfo {
const char *nice_name;
Expand Down Expand Up @@ -83,4 +111,57 @@ uint8_t *packRGBFrame(const VSAPI *vsapi, const VSFrame *frame) {
}

return frame_data;
}

GetVSScriptAPIFunc fetchVSScript() {

#ifdef _WIN32
std::wstring vsscriptDLLpath{L""};

HKEY hKey;
LONG lRes = RegOpenKeyEx(HKEY_CURRENT_USER, L"Software\\VapourSynth", 0, KEY_READ, &hKey);

if (lRes != ERROR_SUCCESS) {
lRes = RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"Software\\VapourSynth", 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 (ERROR_SUCCESS == nError)
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));
#undef _Lstr
#undef CONCATENATE
}
#else
hLib = dlopen(VSSCRIPT_SO, DLOPEN_FLAGS);
#endif

if (!hLib)
throw WobblyException("Could not load " VSSCRIPT_SO ". Make sure VapourSynth is installed correctly.");

#ifdef _WIN32
GetVSScriptAPIFunc _getVSScriptAPI = (GetVSScriptAPIFunc)(void *)GetProcAddress(hLib, "getVSScriptAPI");
#else
GetVSScriptAPIFunc _getVSScriptAPI = (GetVSScriptAPIFunc)(void *)dlsym(hLib, "getVSScriptAPI");
#endif
if (!_getVSScriptAPI)
throw WobblyException("Failed to get address of getVSScriptAPI from " VSSCRIPT_SO);

return _getVSScriptAPI;
}
12 changes: 11 additions & 1 deletion src/shared/WobblyShared.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,22 @@ SOFTWARE.
#include <string>
#include <cstdint>

#include <VSScript4.h>
#include <VapourSynth4.h>

enum class FilterState { MissingPlugin, MissingFilter, Exists };
enum class FilterState
{
MissingPlugin,
MissingFilter,
Exists
};

typedef const VSSCRIPTAPI *(VS_CC *GetVSScriptAPIFunc)(int version)VS_NOEXCEPT;

std::map<std::string, FilterState> getRequiredFilterStates(const VSAPI *vsapi, VSCore *vscore);

uint8_t *packRGBFrame(const VSAPI *vsapi, const VSFrame *frame);

GetVSScriptAPIFunc fetchVSScript();

#endif // WOBBLYSHARED_H
7 changes: 6 additions & 1 deletion src/wibbly/WibblyWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,12 @@ void WibblyWindow::vsLogPopup(int msgType, const QString &msg) {


void WibblyWindow::initialiseVapourSynth() {
vssapi = getVSScriptAPI(VSSCRIPT_API_VERSION);
GetVSScriptAPIFunc newVSScriptAPI = fetchVSScript();

std::string oldlocale(setlocale(LC_ALL, NULL));
vssapi = newVSScriptAPI(VSSCRIPT_API_VERSION);
setlocale(LC_ALL, oldlocale.c_str());

if (!vssapi)
throw WobblyException("Fatal error: failed to initialise VSScript. Your VapourSynth installation is probably broken. Python probably couldn't 'import vapoursynth'.");

Expand Down
11 changes: 8 additions & 3 deletions src/wobbly/WobblyWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ SOFTWARE.
#include <QHBoxLayout>
#include <QVBoxLayout>

#include <VSScript4.h>

#include "CombedFramesCollector.h"
#include "ProgressDialog.h"
#include "RandomStuff.h"
Expand All @@ -55,6 +53,8 @@ SOFTWARE.
#include "WobblyWindow.h"
#include "WobblyShared.h"

#include "string"


// To avoid duplicating the string literals passed to QSettings
#define KEY_STATE QStringLiteral("user_interface/state")
Expand Down Expand Up @@ -3303,7 +3303,12 @@ void WobblyWindow::vsLogPopup(int msgType, const QString &msg) {


void WobblyWindow::initialiseVapourSynth() {
vssapi = getVSScriptAPI(VSSCRIPT_API_VERSION);
GetVSScriptAPIFunc newVSScriptAPI = fetchVSScript();

std::string oldlocale(setlocale(LC_ALL, NULL));
vssapi = newVSScriptAPI(VSSCRIPT_API_VERSION);
setlocale(LC_ALL, oldlocale.c_str());

if (!vssapi)
throw WobblyException("Fatal error: failed to initialise VSScript. Your VapourSynth installation is probably broken. Python probably couldn't 'import vapoursynth'.");

Expand Down

0 comments on commit 9da5579

Please sign in to comment.