From c3a1174b922040da29b9c979343aa9fba24b46ba Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Mon, 18 Jul 2016 10:13:55 +0200 Subject: gui: add application path and modules subdir to PATH Without it, win32 won't load some modules. This is probably a security feature on windows nt. --- gui/main.cpp | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) (limited to 'gui/main.cpp') diff --git a/gui/main.cpp b/gui/main.cpp index be42ac7a..5b1bb5c7 100644 --- a/gui/main.cpp +++ b/gui/main.cpp @@ -1,5 +1,11 @@ #ifdef _WIN32 +# define MINGW_HAS_SECURE_API 1 +# include "opentrack-library-path.h" # include +# include +# include +# include +# include #endif #include "ui.h" @@ -58,6 +64,57 @@ int main(int argc, char** argv) QApplication::setAttribute(Qt::AA_X11InitThreads, true); QApplication app(argc, argv); +#ifdef _WIN32 + // see https://software.intel.com/en-us/articles/limitation-to-the-length-of-the-system-path-variable + static char env_path[4096] { '\0', }; + { + QString lib_path = OPENTRACK_BASE_PATH; + lib_path.replace("/", "\\"); + const QByteArray lib_path_ = QFile::encodeName(lib_path); + + QString mod_path = OPENTRACK_BASE_PATH + QString(OPENTRACK_LIBRARY_PATH); + mod_path.replace("/", "\\"); + const QByteArray mod_path_ = QFile::encodeName(mod_path); + + std::vector contents + { + "PATH=", + lib_path_.constData(), + ";", + mod_path_.constData(), + ";", + getenv("PATH"), + }; + + bool ok = true; + + for (const char* ptr : contents) + { + strcat_s(env_path, sizeof(env_path), ptr); + + if (ptr == nullptr || ptr[0] == '\0' || env_path[0] == '\0') + { + qDebug() << "bad path element, debug info:" + << (ptr == nullptr ? "" : ptr) + << (ptr != nullptr && ptr[0] == '\0') + << (env_path[0] == '\0'); + ok = false; + break; + } + } + + if (ok) + { + const int error = _putenv(env_path); + + if (error) + qDebug() << "can't _putenv win32 path"; + } + else + qDebug() << "can't set win32 path"; + } +#endif + MainWindow::set_working_directory(); auto w = std::make_shared(); -- cgit v1.2.3