From 382226bb46541f07e62ce689cfeaf395aa673a44 Mon Sep 17 00:00:00 2001 From: Tannin Date: Fri, 11 Oct 2013 23:03:49 +0200 Subject: - added new plugin to test if fnis needs to be run - some functionality to the plugin interface to enable them to search for files&directories in the virtual FS (rudimentary atm) - functionality for plugins to react to application being started from MO - broken ESPs are no longer reported as popup windows but only in the log file - bugfix: plugins couldn't store persistent data if they had no user-editable settings --- src/mainwindow.cpp | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 83 insertions(+), 4 deletions(-) (limited to 'src/mainwindow.cpp') diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 1ea35d74..1ee4b66e 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1276,10 +1276,15 @@ HANDLE MainWindow::spawnBinaryDirect(const QFileInfo &binary, const QString &arg QCoreApplication::processEvents(); } - return startBinary(binary, arguments, profileName, m_Settings.logLevel(), currentDirectory, true); + if (m_AboutToRun(binary.absoluteFilePath())) { + return startBinary(binary, arguments, profileName, m_Settings.logLevel(), currentDirectory, true); + } else { + qDebug("start of \"%s\" canceled by plugin", qPrintable(binary.absoluteFilePath())); + return INVALID_HANDLE_VALUE; + } } - +/* void MainWindow::spawnProgram(const QString &fileName, const QString &argumentsArg, const QString &profileName, const QDir ¤tDirectory) { @@ -1299,7 +1304,7 @@ void MainWindow::spawnProgram(const QString &fileName, const QString &argumentsA } spawnBinaryDirect(binary, arguments, profileName, currentDirectory, steamAppID); } - +*/ void MainWindow::spawnBinary(const QFileInfo &binary, const QString &arguments, const QDir ¤tDirectory, bool closeAfterStart, const QString &steamAppID) { @@ -1895,7 +1900,6 @@ void MainWindow::activateProxy(bool activate) busyDialog.hide(); } - void MainWindow::readSettings() { QSettings settings(ToQString(GameInfo::instance().getIniFilename()), QSettings::IniFormat); @@ -2053,11 +2057,86 @@ QString MainWindow::resolvePath(const QString &fileName) const } } +QStringList MainWindow::listDirectories(const QString &directoryName) const +{ + QStringList result; + DirectoryEntry *dir = m_DirectoryStructure->findSubDirectoryRecursive(ToWString(directoryName)); + if (dir != NULL) { + std::vector::iterator current, end; + dir->getSubDirectories(current, end); + for (; current != end; ++current) { + result.append(ToQString((*current)->getName())); + } + } + return result; +} + +QStringList MainWindow::findFiles(const QString &path, const std::function &filter) const +{ + QStringList result; + DirectoryEntry *dir = m_DirectoryStructure->findSubDirectoryRecursive(ToWString(path)); + if (dir != NULL) { + std::vector files = dir->getFiles(); + foreach (FileEntry::Ptr file, files) { + if (filter(ToQString(file->getName()))) { + result.append(ToQString(file->getFullPath())); + } + } + } else { + qWarning("directory %s not found", qPrintable(path)); + } + return result; +} + IDownloadManager *MainWindow::downloadManager() { return &m_DownloadManager; } +HANDLE MainWindow::startApplication(const QString &executable, const QStringList &args, const QString &cwd, const QString &profile) +{ + QFileInfo binary; + QString arguments = args.join(" "); + QString currentDirectory = cwd; + QString profileName = (profile.length() > 0) ? profile : m_CurrentProfile->getName(); + QString steamAppID; + if (executable.contains('\\') || executable.contains('/')) { + // file path + binary = QFileInfo(executable); + if (binary.isRelative()) { + // relative path, should be relative to game directory + binary = QFileInfo(QDir::fromNativeSeparators(ToQString(GameInfo::instance().getGameDirectory())) + "/" + executable); + } + if (cwd.length() == 0) { + currentDirectory = binary.absolutePath(); + } + } else { + // only a file name, search executables list + try { + const Executable &exe = m_ExecutablesList.find(executable); + steamAppID = exe.m_SteamAppID; + if (arguments == "") { + arguments = exe.m_Arguments; + } + binary = exe.m_BinaryInfo; + if (cwd.length() == 0) { + currentDirectory = exe.m_WorkingDirectory; + } + } catch (const std::runtime_error&) { + qWarning("\"%s\" not set up as executable", executable.toUtf8().constData()); + return INVALID_HANDLE_VALUE; + } + } + + return spawnBinaryDirect(binary, arguments, profileName, currentDirectory, steamAppID); +} + +bool MainWindow::onAboutToRun(const boost::function &func) +{ + auto conn = m_AboutToRun.connect(func); + return conn.connected(); +} + std::vector MainWindow::activeProblems() const { std::vector problems; -- cgit v1.3.1