summaryrefslogtreecommitdiff
path: root/src/usvfsconnector.cpp
diff options
context:
space:
mode:
authorChris Bessent <lost.dragonist@gmail.com>2020-01-06 05:17:01 -0700
committerGitHub <noreply@github.com>2020-01-06 05:17:01 -0700
commitdfa600996c49c1b23dca884c963dc917bd9cfc0a (patch)
treec6def4277cc962822d0dcde71fa9148e050f693f /src/usvfsconnector.cpp
parente69078e2399a88bda7bb9ffae7a3d57db9a4e9cf (diff)
parentd1a788dfad341b32235abc25c2ba1645f8be1ace (diff)
Merge pull request #954 from ModOrganizer2/Develop
Stage for release 2.2.2
Diffstat (limited to 'src/usvfsconnector.cpp')
-rw-r--r--src/usvfsconnector.cpp135
1 files changed, 108 insertions, 27 deletions
diff --git a/src/usvfsconnector.cpp b/src/usvfsconnector.cpp
index b752667d..59880754 100644
--- a/src/usvfsconnector.cpp
+++ b/src/usvfsconnector.cpp
@@ -20,6 +20,7 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
#include "usvfsconnector.h"
#include "settings.h"
#include "organizercore.h"
+#include "envmodule.h"
#include "shared/util.h"
#include <memory>
#include <sstream>
@@ -32,7 +33,7 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
#include <qstandardpaths.h>
static const char SHMID[] = "mod_organizer_instance";
-
+using namespace MOBase;
std::string to_hex(void *bufferIn, size_t bufferSize)
{
@@ -60,8 +61,7 @@ LogWorker::LogWorker()
"yyyy-MM-dd_hh-mm-ss")))
{
m_LogFile.open(QIODevice::WriteOnly);
- qDebug("usvfs log messages are written to %s",
- qUtf8Printable(m_LogFile.fileName()));
+ log::debug("usvfs log messages are written to {}", m_LogFile.fileName());
}
LogWorker::~LogWorker()
@@ -90,15 +90,16 @@ void LogWorker::exit()
m_QuitRequested = true;
}
-LogLevel logLevel(int level)
+LogLevel toUsvfsLogLevel(log::Levels level)
{
- switch (static_cast<LogLevel>(level)) {
- case LogLevel::Info:
+ switch (level) {
+ case log::Info:
return LogLevel::Info;
- case LogLevel::Warning:
+ case log::Warning:
return LogLevel::Warning;
- case LogLevel::Error:
+ case log::Error:
return LogLevel::Error;
+ case log::Debug: // fall-through
default:
return LogLevel::Debug;
}
@@ -120,20 +121,41 @@ CrashDumpsType crashDumpsType(int type)
UsvfsConnector::UsvfsConnector()
{
- USVFSParameters params;
- LogLevel level = logLevel(Settings::instance().logLevel());
- CrashDumpsType dumpType = crashDumpsType(Settings::instance().crashDumpsType());
+ using namespace std::chrono;
+
+ const auto& s = Settings::instance();
+ const LogLevel logLevel = toUsvfsLogLevel(s.diagnostics().logLevel());
+ const CrashDumpsType dumpType = s.diagnostics().crashDumpsType();
+ const auto delay = duration_cast<milliseconds>(s.diagnostics().spawnDelay());
std::string dumpPath = MOShared::ToString(OrganizerCore::crashDumpsPath(), true);
- USVFSInitParameters(&params, SHMID, false, level, dumpType, dumpPath.c_str());
+
+ usvfsParameters* params = usvfsCreateParameters();
+
+ usvfsSetInstanceName(params, SHMID);
+ usvfsSetDebugMode(params, false);
+ usvfsSetLogLevel(params, logLevel);
+ usvfsSetCrashDumpType(params, dumpType);
+ usvfsSetCrashDumpPath(params, dumpPath.c_str());
+ usvfsSetProcessDelay(params, delay.count());
+
InitLogging(false);
- qDebug("Initializing VFS <%s, %d, %d, %s>", params.instanceName, params.logLevel, params.crashDumpsType, params.crashDumpsPath);
+ log::debug(
+ "initializing usvfs:\n"
+ " . instance: {}\n"
+ " . log: {}\n"
+ " . dump: {} ({})",
+ SHMID,
+ usvfsLogLevelToString(logLevel),
+ dumpPath.c_str(),
+ usvfsCrashDumpTypeToString(dumpType));
- CreateVFS(&params);
+ usvfsCreateVFS(params);
+ usvfsFreeParameters(params);
ClearExecutableBlacklist();
- for (auto exec : Settings::instance().executablesBlacklist().split(";")) {
+ for (auto exec : s.executablesBlacklist().split(";")) {
std::wstring buf = exec.toStdWString();
BlacklistExecutable(buf.data());
}
@@ -159,15 +181,16 @@ UsvfsConnector::~UsvfsConnector()
void UsvfsConnector::updateMapping(const MappingType &mapping)
{
- QProgressDialog progress;
+ QProgressDialog progress(qApp->activeWindow());
progress.setLabelText(tr("Preparing vfs"));
progress.setMaximum(static_cast<int>(mapping.size()));
progress.show();
+
int value = 0;
int files = 0;
int dirs = 0;
- qDebug("Updating VFS mappings...");
+ log::debug("Updating VFS mappings...");
ClearVirtualMappings();
@@ -195,19 +218,27 @@ void UsvfsConnector::updateMapping(const MappingType &mapping)
}
}
- qDebug("VFS mappings updated <linked %d dirs, %d files>", dirs, files);
- /*
- size_t dumpSize = 0;
- CreateVFSDump(nullptr, &dumpSize);
- std::unique_ptr<char[]> buffer(new char[dumpSize]);
- CreateVFSDump(buffer.get(), &dumpSize);
- qDebug(buffer.get());
- */
+ log::debug("VFS mappings updated <linked {} dirs, {} files>", dirs, files);
}
-void UsvfsConnector::updateParams(int logLevel, int crashDumpsType, QString executableBlacklist)
+void UsvfsConnector::updateParams(
+ MOBase::log::Levels logLevel, CrashDumpsType crashDumpsType,
+ const QString& crashDumpsPath, std::chrono::seconds spawnDelay,
+ QString executableBlacklist)
{
- USVFSUpdateParams(::logLevel(logLevel), ::crashDumpsType(crashDumpsType));
+ using namespace std::chrono;
+
+ usvfsParameters* p = usvfsCreateParameters();
+
+ usvfsSetDebugMode(p, FALSE);
+ usvfsSetLogLevel(p, toUsvfsLogLevel(logLevel));
+ usvfsSetCrashDumpType(p, crashDumpsType);
+ usvfsSetCrashDumpPath(p, crashDumpsPath.toStdString().c_str());
+ usvfsSetProcessDelay(p, duration_cast<milliseconds>(spawnDelay).count());
+
+ usvfsUpdateParameters(p);
+ usvfsFreeParameters(p);
+
ClearExecutableBlacklist();
for (auto exec : executableBlacklist.split(";")) {
std::wstring buf = exec.toStdWString();
@@ -227,3 +258,53 @@ void UsvfsConnector::updateForcedLibraries(const QList<MOBase::ExecutableForcedL
}
}
}
+
+
+std::vector<HANDLE> getRunningUSVFSProcesses()
+{
+ std::vector<DWORD> pids;
+
+ {
+ size_t count = 0;
+ DWORD* buffer = nullptr;
+ if (!::GetVFSProcessList2(&count, &buffer)) {
+ log::error("failed to get usvfs process list");
+ return {};
+ }
+
+ if (buffer) {
+ pids.assign(buffer, buffer + count);
+ std::free(buffer);
+ }
+ }
+
+ const auto thisPid = GetCurrentProcessId();
+ std::vector<HANDLE> v;
+
+ const auto rights =
+ PROCESS_QUERY_LIMITED_INFORMATION | // exit code, image name, etc.
+ SYNCHRONIZE | // wait functions
+ PROCESS_SET_QUOTA | PROCESS_TERMINATE; // add to job
+
+ for (auto&& pid : pids) {
+ if (pid == thisPid) {
+ continue; // obviously don't wait for MO process
+ }
+
+ HANDLE handle = ::OpenProcess(rights, FALSE, pid);
+
+ if (handle == INVALID_HANDLE_VALUE) {
+ const auto e = GetLastError();
+
+ log::warn(
+ "failed to open usvfs process {}: {}",
+ pid, formatSystemMessage(e));
+
+ continue;
+ }
+
+ v.push_back(handle);
+ }
+
+ return v;
+}