From d41cd8d877223db1f35c12667bf59966d4d377cc Mon Sep 17 00:00:00 2001 From: Eran Mizrahi Date: Wed, 27 Dec 2017 00:17:18 +0200 Subject: Virtualize spawning of executable also if working directory is under mods folder --- src/organizercore.cpp | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/organizercore.cpp b/src/organizercore.cpp index 7668485c..121de21a 100644 --- a/src/organizercore.cpp +++ b/src/organizercore.cpp @@ -1196,30 +1196,35 @@ HANDLE OrganizerCore::spawnBinaryProcess(const QFileInfo &binary, QString modsPath = settings().getModDirectory(); + // Check if this a request with either an executable or a working directory under our mods folder + // then will start the processs in a virtualized "environment" with the appropriate paths fixed: + // (i.e. mods\FNIS\path\exe => game\data\path\exe) + QString cwdPath = currentDirectory.absolutePath(); + bool virtualizedCwd = cwdPath.startsWith(modsPath, Qt::CaseInsensitive); QString binPath = binary.absoluteFilePath(); - if (binPath.startsWith(modsPath, Qt::CaseInsensitive)) { - // binary was installed as a MO mod. Need to start it through a (hooked) - // proxy to ensure pathes are correct - - QString cwdPath = currentDirectory.absolutePath(); - - int binOffset = binPath.indexOf('/', modsPath.length() + 1); - int cwdOffset = cwdPath.indexOf('/', modsPath.length() + 1); - QString dataBinPath = m_GamePlugin->dataDirectory().absolutePath() - + binPath.mid(binOffset, -1); - QString dataCwd = m_GamePlugin->dataDirectory().absolutePath() - + cwdPath.mid(cwdOffset, -1); + bool virtualizedBin = binPath.startsWith(modsPath, Qt::CaseInsensitive); + if (virtualizedCwd || virtualizedBin) { + if (virtualizedCwd) { + int cwdOffset = cwdPath.indexOf('/', modsPath.length() + 1); + cwdPath = m_GamePlugin->dataDirectory().absolutePath() + cwdPath.mid(cwdOffset, -1); + } + + if (virtualizedBin) { + int binOffset = binPath.indexOf('/', modsPath.length() + 1); + binPath = m_GamePlugin->dataDirectory().absolutePath() + binPath.mid(binOffset, -1); + } + QString cmdline = QString("launch \"%1\" \"%2\" %3") - .arg(QDir::toNativeSeparators(dataCwd), - QDir::toNativeSeparators(dataBinPath), arguments); + .arg(QDir::toNativeSeparators(cwdPath), + QDir::toNativeSeparators(binPath), arguments); qDebug() << "Spawning proxyed process <" << cmdline << ">"; return startBinary(QFileInfo(QCoreApplication::applicationFilePath()), cmdline, QCoreApplication::applicationDirPath(), true); } else { - qDebug() << "Spawning direct process <" << binary.absoluteFilePath() << "," << arguments << "," << currentDirectory.absolutePath() << ">"; + qDebug() << "Spawning direct process <" << binPath << "," << arguments << "," << cwdPath << ">"; return startBinary(binary, arguments, currentDirectory, true); } } else { -- cgit v1.3.1