summaryrefslogtreecommitdiff
path: root/src/usvfsconnector.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/usvfsconnector.cpp')
-rw-r--r--src/usvfsconnector.cpp241
1 files changed, 132 insertions, 109 deletions
diff --git a/src/usvfsconnector.cpp b/src/usvfsconnector.cpp
index 5504684e..ffbdf3aa 100644
--- a/src/usvfsconnector.cpp
+++ b/src/usvfsconnector.cpp
@@ -18,160 +18,183 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
*/
#include "usvfsconnector.h"
-#include "organizercore.h"
#include "settings.h"
+#include "organizercore.h"
#include "shared/util.h"
-#include <QCoreApplication>
-#include <QDateTime>
-#include <QProgressDialog>
-#include <QTemporaryFile>
-#include <iomanip>
#include <memory>
-#include <qstandardpaths.h>
#include <sstream>
+#include <iomanip>
#include <usvfs.h>
+#include <QTemporaryFile>
+#include <QProgressDialog>
+#include <QDateTime>
+#include <QCoreApplication>
+#include <qstandardpaths.h>
static const char SHMID[] = "mod_organizer_instance";
-std::string to_hex(void* bufferIn, size_t bufferSize) {
- unsigned char* buffer = static_cast<unsigned char*>(bufferIn);
- std::ostringstream temp;
- temp << std::hex;
- for (size_t i = 0; i < bufferSize; ++i) {
- temp << std::setfill('0') << std::setw(2) << (unsigned int)buffer[i];
- if ((i % 16) == 15) {
- temp << "\n";
- } else {
- temp << " ";
- }
+
+std::string to_hex(void *bufferIn, size_t bufferSize)
+{
+ unsigned char *buffer = static_cast<unsigned char *>(bufferIn);
+ std::ostringstream temp;
+ temp << std::hex;
+ for (size_t i = 0; i < bufferSize; ++i) {
+ temp << std::setfill('0') << std::setw(2) << (unsigned int)buffer[i];
+ if ((i % 16) == 15) {
+ temp << "\n";
+ } else {
+ temp << " ";
}
- return temp.str();
+ }
+ return temp.str();
}
+
LogWorker::LogWorker()
- : m_Buffer(1024, '\0'), m_QuitRequested(false),
- m_LogFile(qApp->property("dataPath").toString() +
- QString("/logs/usvfs-%1.log").arg(QDateTime::currentDateTimeUtc().toString("yyyy-MM-dd_hh-mm-ss"))) {
- m_LogFile.open(QIODevice::WriteOnly);
- qDebug("usvfs log messages are written to %s", qPrintable(m_LogFile.fileName()));
+ : m_Buffer(1024, '\0')
+ , m_QuitRequested(false)
+ , m_LogFile(qApp->property("dataPath").toString()
+ + QString("/logs/usvfs-%1.log")
+ .arg(QDateTime::currentDateTimeUtc().toString(
+ "yyyy-MM-dd_hh-mm-ss")))
+{
+ m_LogFile.open(QIODevice::WriteOnly);
+ qDebug("usvfs log messages are written to %s",
+ qPrintable(m_LogFile.fileName()));
}
-LogWorker::~LogWorker() {}
+LogWorker::~LogWorker()
+{
+}
-void LogWorker::process() {
- int noLogCycles = 0;
- 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();
- noLogCycles = 0;
- } else {
- QThread::msleep(std::min(40, noLogCycles) * 5);
- ++noLogCycles;
- }
+void LogWorker::process()
+{
+ int noLogCycles = 0;
+ 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();
+ noLogCycles = 0;
+ } else {
+ QThread::msleep(std::min(40, noLogCycles) * 5);
+ ++noLogCycles;
}
- emit finished();
+ }
+ emit finished();
}
-void LogWorker::exit() { m_QuitRequested = true; }
+void LogWorker::exit()
+{
+ m_QuitRequested = true;
+}
-LogLevel logLevel(int level) {
- switch (level) {
+LogLevel logLevel(int level)
+{
+ switch (level) {
case LogLevel::Info:
- return LogLevel::Info;
+ return LogLevel::Info;
case LogLevel::Warning:
- return LogLevel::Warning;
+ return LogLevel::Warning;
case LogLevel::Error:
- return LogLevel::Error;
+ return LogLevel::Error;
default:
- return LogLevel::Debug;
- }
+ return LogLevel::Debug;
+ }
}
-CrashDumpsType crashDumpsType(int type) {
- switch (type) {
- case CrashDumpsType::Mini:
- return CrashDumpsType::Mini;
- case CrashDumpsType::Data:
- return CrashDumpsType::Data;
- case CrashDumpsType::Full:
- return CrashDumpsType::Full;
- default:
- return CrashDumpsType::None;
- }
+CrashDumpsType crashDumpsType(int type)
+{
+ switch (type) {
+ case CrashDumpsType::Mini:
+ return CrashDumpsType::Mini;
+ case CrashDumpsType::Data:
+ return CrashDumpsType::Data;
+ case CrashDumpsType::Full:
+ return CrashDumpsType::Full;
+ default:
+ return CrashDumpsType::None;
+ }
}
-UsvfsConnector::UsvfsConnector() {
- USVFSParameters params;
- LogLevel level = logLevel(Settings::instance().logLevel());
- CrashDumpsType dumpType = crashDumpsType(Settings::instance().crashDumpsType());
+UsvfsConnector::UsvfsConnector()
+{
+ USVFSParameters params;
+ LogLevel level = logLevel(Settings::instance().logLevel());
+ CrashDumpsType dumpType = crashDumpsType(Settings::instance().crashDumpsType());
- std::string dumpPath = MOShared::ToString(OrganizerCore::crashDumpsPath(), true);
- USVFSInitParameters(&params, SHMID, false, level, dumpType, dumpPath.c_str());
- InitLogging(false);
+ std::string dumpPath = MOShared::ToString(OrganizerCore::crashDumpsPath(), true);
+ USVFSInitParameters(&params, SHMID, false, level, dumpType, dumpPath.c_str());
+ InitLogging(false);
- qDebug("Initializing VFS <%s, %d, %d, %s>", params.instanceName, params.logLevel, params.crashDumpsType,
- params.crashDumpsPath);
+ qDebug("Initializing VFS <%s, %d, %d, %s>", params.instanceName, params.logLevel, params.crashDumpsType, params.crashDumpsPath);
- CreateVFS(&params);
+ CreateVFS(&params);
- BlacklistExecutable(L"TSVNCache.exe");
+ BlacklistExecutable(L"TSVNCache.exe");
- m_LogWorker.moveToThread(&m_WorkerThread);
+ m_LogWorker.moveToThread(&m_WorkerThread);
- connect(&m_WorkerThread, SIGNAL(started()), &m_LogWorker, SLOT(process()));
- connect(&m_LogWorker, SIGNAL(finished()), &m_WorkerThread, SLOT(quit()));
+ connect(&m_WorkerThread, SIGNAL(started()), &m_LogWorker, SLOT(process()));
+ connect(&m_LogWorker, SIGNAL(finished()), &m_WorkerThread, SLOT(quit()));
- m_WorkerThread.start(QThread::LowestPriority);
+ m_WorkerThread.start(QThread::LowestPriority);
}
-UsvfsConnector::~UsvfsConnector() {
- DisconnectVFS();
- m_LogWorker.exit();
- m_WorkerThread.quit();
- m_WorkerThread.wait();
+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(static_cast<int>(mapping.size()));
- progress.show();
- int value = 0;
- int files = 0;
- int dirs = 0;
- qDebug("Updating VFS mappings...");
+void UsvfsConnector::updateMapping(const MappingType &mapping)
+{
+ QProgressDialog progress;
+ progress.setLabelText(tr("Preparing vfs"));
+ progress.setMaximum(static_cast<int>(mapping.size()));
+ progress.show();
+ int value = 0;
+ int files = 0;
+ int dirs = 0;
- ClearVirtualMappings();
+ qDebug("Updating VFS mappings...");
- for (auto map : mapping) {
- progress.setValue(value++);
- if (value % 10 == 0) {
- QCoreApplication::processEvents();
- }
+ ClearVirtualMappings();
+
+ 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(),
- (map.createTarget ? LINKFLAG_CREATETARGET : 0) | LINKFLAG_RECURSIVE);
- ++dirs;
- } else {
- VirtualLinkFile(map.source.toStdWString().c_str(), map.destination.toStdWString().c_str(), 0);
- ++files;
- }
+ if (map.isDirectory) {
+ VirtualLinkDirectoryStatic(map.source.toStdWString().c_str(),
+ map.destination.toStdWString().c_str(),
+ (map.createTarget ? LINKFLAG_CREATETARGET : 0)
+ | LINKFLAG_RECURSIVE
+ );
+ ++dirs;
+ } else {
+ VirtualLinkFile(map.source.toStdWString().c_str(),
+ map.destination.toStdWString().c_str(), 0);
+ ++files;
}
+ }
- 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());
- */
+ 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());
+ */
}
void UsvfsConnector::updateParams(int logLevel, int crashDumpsType) {
- USVFSUpdateParams(::logLevel(logLevel), ::crashDumpsType(crashDumpsType));
+ USVFSUpdateParams(::logLevel(logLevel), ::crashDumpsType(crashDumpsType));
}