Add code to find luprex root directory

This commit is contained in:
2023-05-10 15:24:47 -04:00
parent 9e74e67277
commit 64b4fc465d
9 changed files with 68 additions and 19 deletions

View File

@@ -13,6 +13,7 @@
#include <vector>
#include <string>
#include <filesystem>
#include <fstream>
#include <winsock2.h>
#include <ws2tcpip.h>
@@ -41,7 +42,14 @@ std::string path_to_plain_ascii(const std::filesystem::path &path) {
}
return oss.str();
}
std::filesystem::path get_exe_path() {
WCHAR exepath[MAX_PATH];
DWORD status = GetModuleFileNameW( NULL, exepath, MAX_PATH );
assert(status != 0);
return std::filesystem::path(exepath);
}
static void set_nonblocking(SOCKET sock) {
u_long mode = 1; // 1 to enable non-blocking socket
int status = ioctlsocket(sock, FIONBIO, &mode);
@@ -278,12 +286,19 @@ static void ssl_load_certificate_authorities(SSL_CTX *ctx) {
CertCloseStore(hStore, 0);
}
static void call_init_engine_wrapper(EngineWrapper *w) {
static void call_init_engine_wrapper(const std::filesystem::path &luprexroot, EngineWrapper *w) {
HMODULE exe = GetModuleHandleA(NULL);
using InitFn = void (*)(EngineWrapper *);
InitFn initfn = (InitFn)GetProcAddress(exe, "init_engine_wrapper");
if (initfn == nullptr) {
HMODULE dll = LoadLibraryA(".\\luprexlib.dll");
#if defined(_MSC_VER)
std::wstring path = luprexroot / "build/visual/luprexlib.dll";
#elif defined(__GNUC__)
std::wstring path = luprexroot / "build/mingw/luprexlib.dll";
#else
#error "Cannot detect OS type"
#endif
HMODULE dll = LoadLibraryW(path.c_str());
assert(dll != nullptr);
initfn = (InitFn)GetProcAddress(dll, "init_engine_wrapper");
}