diff options
| author | Tannin <sherb@gmx.net> | 2015-11-17 18:58:00 +0100 |
|---|---|---|
| committer | Tannin <sherb@gmx.net> | 2015-11-17 18:58:00 +0100 |
| commit | 7f4f4cafea5a196ddf824adf7c4e65cec5d44d88 (patch) | |
| tree | 64f47f30b6958c5a0aaf8f7394e8d32c5e765044 /src/usvfsconnector.cpp | |
| parent | 7d93a9a2003f31188e4da8cbcd7e5df0352bb900 (diff) | |
first work on interfacing with usvfs
Diffstat (limited to 'src/usvfsconnector.cpp')
| -rw-r--r-- | src/usvfsconnector.cpp | 141 |
1 files changed, 141 insertions, 0 deletions
diff --git a/src/usvfsconnector.cpp b/src/usvfsconnector.cpp new file mode 100644 index 00000000..6e1e5b31 --- /dev/null +++ b/src/usvfsconnector.cpp @@ -0,0 +1,141 @@ +/* +Copyright (C) 2015 Sebastian Herbord. All rights reserved. + +This file is part of Mod Organizer. + +Mod Organizer is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Mod Organizer is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>. +*/ + + +#include "usvfsconnector.h" +#include <memory> +#include <QTemporaryFile> +#include <QProgressDialog> +#include <QCoreApplication> + + +static const char SHMID[] = "mod_organizer_instance"; + + +/* +extern "C" DLLEXPORT BOOL WINAPI VirtualLinkFile(LPCWSTR source, LPCWSTR destination, BOOL failIfExists); +extern "C" DLLEXPORT BOOL WINAPI VirtualLinkDirectoryStatic(LPCWSTR source, LPCWSTR destination, unsigned int flags); +extern "C" DLLEXPORT BOOL WINAPI ConnectVFS(const usvfs::Parameters *parameters); +extern "C" DLLEXPORT void WINAPI DisconnectVFS(); +extern "C" DLLEXPORT void WINAPI GetCurrentVFSName(char *buffer, size_t size); +extern "C" DLLEXPORT BOOL WINAPI CreateProcessHooked(LPCWSTR lpApplicationName + , LPWSTR lpCommandLine + , LPSECURITY_ATTRIBUTES lpProcessAttributes + , LPSECURITY_ATTRIBUTES lpThreadAttributes + , BOOL bInheritHandles + , DWORD dwCreationFlags + , LPVOID lpEnvironment + , LPCWSTR lpCurrentDirectory + , LPSTARTUPINFOW lpStartupInfo + , LPPROCESS_INFORMATION lpProcessInformation + ); +extern "C" DLLEXPORT void __cdecl InitLogging(bool toLocal = false); +extern "C" DLLEXPORT void __cdecl InitHooks(LPVOID userData, size_t userDataSize); +*/ + + +LogWorker::LogWorker() + : m_Buffer(1024, '\0') + , m_QuitRequested(false) + , m_LogFile(new QTemporaryFile("usvfs-XXXXXX.log")) +{ + m_LogFile->open(QIODevice::WriteOnly); + qDebug("usvfs log messages are written to %s", qPrintable(m_LogFile->fileName())); +} + +LogWorker::~LogWorker() +{ + delete m_LogFile; +} + +void LogWorker::process() +{ + while (!m_QuitRequested) { + if (GetLogMessages(&m_Buffer[0], m_Buffer.size(), false)) { + m_LogFile->write(m_Buffer.c_str()); + m_LogFile->write("\n"); + m_LogFile->flush(); + + //emit outputLog(QString::fromStdString(m_Buffer)); + } else { + QThread::sleep(1); + } + } + emit finished(); +} + +void LogWorker::exit() +{ + m_QuitRequested = true; + +} + +UsvfsConnector::UsvfsConnector() +{ + usvfs::Parameters params(SHMID, true, LogLevel::Debug); + InitLogging(false); + ConnectVFS(¶ms); + + m_LogWorker.moveToThread(&m_WorkerThread); + + connect(&m_WorkerThread, SIGNAL(started()), &m_LogWorker, SLOT(process())); + connect(&m_LogWorker, SIGNAL(finished()), &m_WorkerThread, SLOT(quit())); + + m_WorkerThread.start(QThread::LowestPriority); +} + +UsvfsConnector::~UsvfsConnector() +{ + DisconnectVFS(); + m_LogWorker.exit(); + m_WorkerThread.quit(); + //m_WorkerThread.wait(); +} + +void UsvfsConnector::updateMapping(const MappingType &mapping) +{ + QProgressDialog progress; + progress.setLabelText(tr("Preparing vfs")); + progress.setMaximum(mapping.size()); + progress.show(); + int value = 0; + for (auto map : mapping) { + progress.setValue(value++); + if (value % 10 == 0) { + QCoreApplication::processEvents(); + } + if (map.isDirectory) { + VirtualLinkDirectoryStatic(map.source.toStdWString().c_str() + , map.destination.toStdWString().c_str() + , 0); + } else { + VirtualLinkFile(map.source.toStdWString().c_str() + , map.destination.toStdWString().c_str() + , 0); + } + } +/* + size_t dumpSize = 0; + CreateVFSDump(nullptr, &dumpSize); + std::unique_ptr<char[]> buffer(new char[dumpSize]); + CreateVFSDump(buffer.get(), &dumpSize); + qDebug(buffer.get()); +*/ +} + |
