MCPcopy Create free account
hub / github.com/ModOrganizer2/modorganizer / adjustForVirtualized

Function adjustForVirtualized

src/processrunner.cpp:13–55  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11using namespace MOBase;
12
13void adjustForVirtualized(const IPluginGame* game, spawn::SpawnParameters& sp,
14 const Settings& settings)
15{
16 const QString modsPath = settings.paths().mods();
17
18 // Check if this a request with either an executable or a working directory
19 // under our mods folder then will start the process in a virtualized
20 // "environment" with the appropriate paths fixed:
21 // (i.e. mods\FNIS\path\exe => game\data\path\exe)
22 QString cwdPath = sp.currentDirectory.absolutePath();
23 QString trailedModsPath = modsPath;
24 if (!trailedModsPath.endsWith('/')) {
25 trailedModsPath = trailedModsPath + '/';
26 }
27 bool virtualizedCwd = cwdPath.startsWith(trailedModsPath, Qt::CaseInsensitive);
28 QString binPath = sp.binary.absoluteFilePath();
29 bool virtualizedBin = binPath.startsWith(trailedModsPath, Qt::CaseInsensitive);
30 if (virtualizedCwd || virtualizedBin) {
31 if (virtualizedCwd) {
32 int cwdOffset = cwdPath.indexOf('/', trailedModsPath.length());
33 QString adjustedCwd = cwdPath.mid(cwdOffset, -1);
34 cwdPath = game->dataDirectory().absolutePath();
35 if (cwdOffset >= 0)
36 cwdPath += adjustedCwd;
37 }
38
39 if (virtualizedBin) {
40 int binOffset = binPath.indexOf('/', trailedModsPath.length());
41 QString adjustedBin = binPath.mid(binOffset, -1);
42 binPath = game->dataDirectory().absolutePath();
43 if (binOffset >= 0)
44 binPath += adjustedBin;
45 }
46
47 QString cmdline = QString("launch \"%1\" \"%2\" %3")
48 .arg(QDir::toNativeSeparators(cwdPath),
49 QDir::toNativeSeparators(binPath), sp.arguments);
50
51 sp.binary = QFileInfo(QCoreApplication::applicationFilePath());
52 sp.arguments = cmdline;
53 sp.currentDirectory.setPath(QCoreApplication::applicationDirPath());
54 }
55}
56
57std::optional<ProcessRunner::Results> singleWait(HANDLE handle, DWORD pid)
58{

Callers 1

runBinaryMethod · 0.85

Calls 5

QStringClass · 0.85
modsMethod · 0.80
indexOfMethod · 0.80
setPathMethod · 0.80
absolutePathMethod · 0.45

Tested by

no test coverage detected