diff options
| author | isanae <14251494+isanae@users.noreply.github.com> | 2020-11-07 16:31:35 -0500 |
|---|---|---|
| committer | isanae <14251494+isanae@users.noreply.github.com> | 2020-11-07 20:16:26 -0500 |
| commit | a8187e7dc47cd344fd309a2be3675e4687f95aaa (patch) | |
| tree | 3e33e1b3f64208caaa97e6f00c542ce86c089797 /src/moapplication.cpp | |
| parent | 90ea45328d72f9664ace3cfbdce700dbe7a1d016 (diff) | |
moved dlls stuff to MOApplication
Diffstat (limited to 'src/moapplication.cpp')
| -rw-r--r-- | src/moapplication.cpp | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/moapplication.cpp b/src/moapplication.cpp index 659b5a12..f514050f 100644 --- a/src/moapplication.cpp +++ b/src/moapplication.cpp @@ -19,6 +19,7 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>. #include "moapplication.h"
#include "settings.h"
+#include "env.h"
#include <iplugingame.h>
#include <report.h>
#include <utility.h>
@@ -32,6 +33,12 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>. #include <QStyleOption>
#include <QDebug>
+// see addDllsToPath() below
+#pragma comment(linker, "/manifestDependency:\"" \
+ "name='dlls' " \
+ "processorArchitecture='x86' " \
+ "version='1.0.0.0' " \
+ "type='win32' \"")
using namespace MOBase;
@@ -73,6 +80,45 @@ public: };
+// This adds the `dlls` directory to the path so the dlls can be found. How
+// MO is able to find dlls in there is a bit convoluted:
+//
+// Dependencies on DLLs can be baked into an executable by passing a
+// `manifestdependency` option to the linker. This can be done on the command
+// line or with a pragma. Typically, the dependency will not be a hardcoded
+// filename, but an assembly name, such as Microsoft.Windows.Common-Controls.
+//
+// When Windows loads the exe, it will look for this assembly in a variety of
+// places, such as in the WinSxS folder, but also in the program's folder. It
+// will look for `assemblyname.dll` or `assemblyname/assemblyname.dll` and try
+// to load that.
+//
+// If these files don't exist, then the loader gets creative and looks for
+// `assemblyname.manifest` and `assemblyname/assemblyname.manifest`. A manifest
+// file is just an XML file that can contain a list of DLLs to load for this
+// assembly.
+//
+// In MO's case, there's a `pragma` at the beginning of this file which adds
+// `dlls` as an "assembly" dependency. This is a bit of a hack to just force
+// the loader to eventually find `dlls/dlls.manifest`, which contains the list
+// of all the DLLs MO requires to load.
+//
+// This file was handwritten in `modorganizer/src/dlls.manifest.qt5` and
+// is copied and renamed in CMakeLists.txt into `bin/dlls/dlls.manifest`. Note
+// that the useless and incorrect .qt5 extension is removed.
+//
+void addDllsToPath()
+{
+ const auto dllsPath = QDir::toNativeSeparators(
+ QCoreApplication::applicationDirPath() + "/dlls");
+
+ QCoreApplication::setLibraryPaths(
+ QStringList(dllsPath) + QCoreApplication::libraryPaths());
+
+ env::prependToPath(dllsPath);
+}
+
+
MOApplication::MOApplication(int& argc, char** argv)
: QApplication(argc, argv)
{
@@ -83,11 +129,13 @@ MOApplication::MOApplication(int& argc, char** argv) m_DefaultStyle = style()->objectName();
setStyle(new ProxyStyle(style()));
+ addDllsToPath();
}
MOApplication MOApplication::create(int& argc, char** argv)
{
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
+
return MOApplication(argc, argv);
}
|
