summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2016-07-18 10:13:55 +0200
committerStanislaw Halik <sthalik@misaki.pl>2016-07-18 10:13:55 +0200
commitc3a1174b922040da29b9c979343aa9fba24b46ba (patch)
tree1fa467287152cde194f651f636a1ef6190943826
parentde4e1cb93cb73a247858a1afb950d5ae86acdc41 (diff)
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.
-rw-r--r--gui/main.cpp57
1 files changed, 57 insertions, 0 deletions
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 <stdlib.h>
+# include <vector>
+# include <QCoreApplication>
+# include <QFile>
+# include <QString>
#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<const char*> 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 ? "<null>" : 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<MainWindow>();