From f7d7661d58d9b0d158fd959978b29c9c1a3a8de7 Mon Sep 17 00:00:00 2001 From: Seth Riley <17361645+Qudix@users.noreply.github.com> Date: Mon, 2 Nov 2020 13:20:05 -0600 Subject: Changing the location of several directories --- src/CMakeLists.txt | 14 ++++---- src/dlls.manifest | 29 ++++++++++++++++ src/dlls.manifest.qt5 | 29 ---------------- src/env.cpp | 7 ++++ src/env.h | 1 + src/main.cpp | 91 ++++++++++++++------------------------------------- src/qt.conf | 8 +++-- 7 files changed, 76 insertions(+), 103 deletions(-) create mode 100644 src/dlls.manifest delete mode 100644 src/dlls.manifest.qt5 (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e95179b8..79389e42 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -223,17 +223,19 @@ target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE ) -install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/dlls.manifest.qt5 +install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/dlls.manifest DESTINATION bin/dlls RENAME dlls.manifest) -install(FILES ${qm_files} DESTINATION bin/translations) +install(FILES ${qm_files} DESTINATION bin/dlls/translations) install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/stylesheets - ${CMAKE_CURRENT_SOURCE_DIR}/tutorials - DESTINATION bin) + DESTINATION bin) + +install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/tutorials + DESTINATION bin/dlls) deploy_qt(BINARIES ModOrganizer.exe uibase.dll plugins/bsa_packer.dll) -install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/../qdds.dll DESTINATION bin/dlls/imageformats) -install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/resources/markdown.html DESTINATION bin/resources) +install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/../qdds.dll DESTINATION bin/dlls/QtPlugins/imageformats) +install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/resources/markdown.html DESTINATION bin/dlls/resources) diff --git a/src/dlls.manifest b/src/dlls.manifest new file mode 100644 index 00000000..846a02ae --- /dev/null +++ b/src/dlls.manifest @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/dlls.manifest.qt5 b/src/dlls.manifest.qt5 deleted file mode 100644 index cae74df1..00000000 --- a/src/dlls.manifest.qt5 +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/env.cpp b/src/env.cpp index 2862aa95..4e5ad196 100644 --- a/src/env.cpp +++ b/src/env.cpp @@ -394,6 +394,13 @@ QString path() return get("PATH"); } +QString prependToPath(const QString& s) +{ + auto old = path(); + set("PATH", s + ";" + old); + return old; +} + QString addPath(const QString& s) { auto old = path(); diff --git a/src/env.h b/src/env.h index 5c7492c6..954c7bb0 100644 --- a/src/env.h +++ b/src/env.h @@ -236,6 +236,7 @@ QString get(const QString& name); QString set(const QString& name, const QString& value); QString path(); +QString prependToPath(const QString& s); QString addPath(const QString& s); QString setPath(const QString& s); diff --git a/src/main.cpp b/src/main.cpp index a81ae962..60b06817 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -464,69 +464,6 @@ MOBase::IPluginGame *determineCurrentGame( return nullptr; } - -// extend path to include dll directory so plugins don't need a manifest -// (using AddDllDirectory would be an alternative to this but it seems fairly -// complicated esp. -// since it isn't easily accessible on Windows < 8 -// SetDllDirectory replaces other search directories and this seems to -// propagate to child processes) -void setupPath() -{ - static const int BUFSIZE = 4096; - - QCoreApplication::setLibraryPaths(QStringList(QCoreApplication::applicationDirPath() + "/dlls") + QCoreApplication::libraryPaths()); - - boost::scoped_array oldPath(new TCHAR[BUFSIZE]); - DWORD offset = ::GetEnvironmentVariable(TEXT("PATH"), oldPath.get(), BUFSIZE); - if (offset > BUFSIZE) { - oldPath.reset(new TCHAR[offset]); - ::GetEnvironmentVariable(TEXT("PATH"), oldPath.get(), offset); - } - - std::wstring newPath(ToWString(QDir::toNativeSeparators( - QCoreApplication::applicationDirPath())) + L"\\dlls"); - newPath += L";"; - newPath += oldPath.get(); - - ::SetEnvironmentVariableW(L"PATH", newPath.c_str()); -} - -void preloadDll(const QString& filename) -{ - if (GetModuleHandleW(filename.toStdWString().c_str())) { - // already loaded, this can happen when "restarting" MO by switching - // instances, for example - return; - } - - const auto appPath = QDir::toNativeSeparators( - QCoreApplication::applicationDirPath()); - - const auto dllPath = appPath + "\\" + filename; - - if (!QFile::exists(dllPath)) { - log::warn("{} not found", dllPath); - return; - } - - if (!LoadLibraryW(dllPath.toStdWString().c_str())) { - const auto e = GetLastError(); - log::warn("failed to load {}: {}", dllPath, formatSystemMessage(e)); - } -} - -void preloadSsl() -{ -#if Q_PROCESSOR_WORDSIZE == 8 - preloadDll("libcrypto-1_1-x64.dll"); - preloadDll("libssl-1_1-x64.dll"); -#elif Q_PROCESSOR_WORDSIZE == 4 - preloadDll("libcrypto-1_1.dll"); - preloadDll("libssl-1_1.dll"); -#endif -} - static QString getVersionDisplayString() { return createVersionInfo().displayString(3); @@ -543,7 +480,6 @@ int runApplication(MOApplication &application, SingleInstance &instance, getVersionDisplayString(), GITID, QCoreApplication::applicationDirPath(), MOShared::getUsvfsVersionString()); - preloadSsl(); if (!QSslSocket::supportsSsl()) { log::warn("no ssl support"); } @@ -889,6 +825,25 @@ void initLogging() qInstallMessageHandler(qtLogCallback); } +void preloadDll(const QString& filename) +{ + if (GetModuleHandleW(filename.toStdWString().c_str())) + return; + + const auto appPath = QDir::toNativeSeparators(QDir::currentPath()); + const auto dllPath = appPath + "\\dlls\\" + filename; + + if (!QFile::exists(dllPath)) { + log::warn("{} not found", dllPath); + return; + } + + if (!LoadLibraryW(dllPath.toStdWString().c_str())) { + const auto e = GetLastError(); + log::warn("failed to load {}: {}", dllPath, formatSystemMessage(e)); + } +} + int main(int argc, char *argv[]) { @@ -905,6 +860,9 @@ int main(int argc, char *argv[]) } } + preloadDll("libcrypto-1_1-x64.dll"); + preloadDll("libssl-1_1-x64.dll"); + initLogging(); //Make sure the configured temp folder exists @@ -925,9 +883,10 @@ int main(int argc, char *argv[]) MOApplication application(argc, argv); QStringList arguments = application.arguments(); - SetThisThreadName("main"); + env::prependToPath(QDir::toNativeSeparators( + QCoreApplication::applicationDirPath() + "/dlls")); - setupPath(); + SetThisThreadName("main"); bool forcePrimary = false; if (arguments.contains("update")) { diff --git a/src/qt.conf b/src/qt.conf index f834a22a..d5a3f6ac 100644 --- a/src/qt.conf +++ b/src/qt.conf @@ -1,3 +1,7 @@ [Paths] -Prefix=. -Plugins=dlls +Prefix=dlls +Libraries=. +LibraryExecutables=. +Plugins=QtPlugins +Imports=QtImports +Qml2Imports=QtImports \ No newline at end of file -- cgit v1.3.1