2016-11-05 18:38:20 +01:00
|
|
|
#include "trayiconcontroller.h"
|
2016-04-30 10:35:01 +00:00
|
|
|
#include "openvroverlaycontroller.h"
|
2016-05-01 18:41:38 +00:00
|
|
|
#include "revivemanifestcontroller.h"
|
2016-11-05 22:25:01 +01:00
|
|
|
#include "windowsservices.h"
|
2016-05-14 16:41:27 +00:00
|
|
|
#include <qt_windows.h>
|
2016-12-05 14:14:53 +01:00
|
|
|
#include <winsparkle.h>
|
2016-05-14 16:41:27 +00:00
|
|
|
|
2016-11-05 19:13:53 +01:00
|
|
|
#include <QApplication>
|
2016-04-30 10:35:01 +00:00
|
|
|
#include <QQmlEngine>
|
|
|
|
|
#include <QQmlComponent>
|
|
|
|
|
#include <QQuickItem>
|
2016-05-01 10:24:04 +00:00
|
|
|
#include <QQmlContext>
|
2016-05-14 16:41:27 +00:00
|
|
|
#include <QUrl>
|
|
|
|
|
#include <QDir>
|
2016-05-18 15:46:15 +00:00
|
|
|
#include <QFile>
|
|
|
|
|
#include <QTextStream>
|
|
|
|
|
#include <QStandardPaths>
|
|
|
|
|
|
|
|
|
|
QFile* g_LogFile = nullptr;
|
|
|
|
|
|
|
|
|
|
void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg)
|
|
|
|
|
{
|
|
|
|
|
QByteArray localMsg = msg.toLocal8Bit();
|
|
|
|
|
QTextStream log(g_LogFile);
|
|
|
|
|
log << localMsg.constData() << "\n";
|
|
|
|
|
OutputDebugStringA(localMsg.constData());
|
2016-09-16 17:07:03 +02:00
|
|
|
OutputDebugStringA("\n");
|
2016-05-18 15:46:15 +00:00
|
|
|
|
|
|
|
|
if (type == QtFatalMsg)
|
|
|
|
|
abort();
|
|
|
|
|
}
|
2016-04-30 10:35:01 +00:00
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
|
{
|
2016-09-16 16:44:42 +02:00
|
|
|
// Open the log file and install our handler.
|
2016-05-18 15:46:15 +00:00
|
|
|
QString logPath = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
|
2017-02-15 17:11:35 +01:00
|
|
|
logPath.append("/Revive");
|
|
|
|
|
if (QDir().mkpath(logPath)) {
|
|
|
|
|
g_LogFile = new QFile(logPath + "/ReviveOverlay.txt");
|
2016-05-18 15:46:15 +00:00
|
|
|
g_LogFile->open(QIODevice::WriteOnly | QIODevice::Truncate);
|
2017-02-15 17:11:35 +01:00
|
|
|
|
|
|
|
|
// Remove obsolete log files
|
|
|
|
|
QDir logDir(logPath);
|
|
|
|
|
logDir.remove("ReviveOverlay.log");
|
|
|
|
|
logDir.remove("ReviveInjector.log");
|
2016-05-18 15:46:15 +00:00
|
|
|
}
|
|
|
|
|
qInstallMessageHandler(myMessageOutput);
|
|
|
|
|
|
2016-11-05 19:13:53 +01:00
|
|
|
QApplication a(argc, argv);
|
|
|
|
|
a.setQuitOnLastWindowClosed(false);
|
2016-04-30 10:35:01 +00:00
|
|
|
|
2016-09-16 16:44:42 +02:00
|
|
|
// Handle command-line arguments
|
2016-06-26 10:35:16 +00:00
|
|
|
if (a.arguments().contains("-manifest")) {
|
|
|
|
|
// Only initialize the manifest
|
|
|
|
|
vr::EVRInitError err = vr::VRInitError_None;
|
2017-12-13 19:22:18 +01:00
|
|
|
vr::VR_Init( &err, vr::VRApplication_Utility );
|
2016-06-26 10:35:16 +00:00
|
|
|
|
|
|
|
|
if ( err != vr::VRInitError_None )
|
|
|
|
|
return -1;
|
|
|
|
|
|
2016-11-15 01:29:39 +01:00
|
|
|
QString filePath = QDir::toNativeSeparators(QCoreApplication::applicationDirPath() + "/app.vrmanifest");
|
|
|
|
|
vr::VRApplications()->AddApplicationManifest(qPrintable(filePath));
|
|
|
|
|
vr::VRApplications()->SetApplicationAutoLaunch(CReviveManifestController::SharedInstance()->AppKey, true);
|
2016-06-26 10:35:16 +00:00
|
|
|
vr::VR_Shutdown();
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-16 16:44:42 +02:00
|
|
|
// Initialize singletons
|
2016-09-16 17:07:03 +02:00
|
|
|
if (!COpenVROverlayController::SharedInstance()->Init())
|
|
|
|
|
return -1;
|
2016-12-05 15:25:05 +01:00
|
|
|
if (!CTrayIconController::SharedInstance()->Init())
|
|
|
|
|
return -1;
|
2016-09-16 17:07:03 +02:00
|
|
|
if (!CReviveManifestController::SharedInstance()->Init())
|
|
|
|
|
return -1;
|
2016-05-01 20:58:39 +00:00
|
|
|
|
2016-04-30 10:35:01 +00:00
|
|
|
// Create a QML engine.
|
2016-05-01 00:03:27 +00:00
|
|
|
QQmlEngine qmlEngine;
|
2016-11-03 22:44:06 +01:00
|
|
|
qmlEngine.rootContext()->setContextProperty("Revive", CReviveManifestController::SharedInstance());
|
2016-09-15 15:59:56 +02:00
|
|
|
qmlEngine.rootContext()->setContextProperty("OpenVR", COpenVROverlayController::SharedInstance());
|
2016-04-30 22:45:21 +00:00
|
|
|
|
2016-05-01 10:24:04 +00:00
|
|
|
QQmlComponent qmlComponent( &qmlEngine, QUrl("qrc:/Overlay.qml"));
|
2016-05-01 00:03:27 +00:00
|
|
|
if (qmlComponent.isError())
|
2016-04-30 22:45:21 +00:00
|
|
|
{
|
2016-05-01 00:03:27 +00:00
|
|
|
qDebug(qUtf8Printable(qmlComponent.errorString()));
|
2016-05-01 10:24:04 +00:00
|
|
|
return -1;
|
2016-04-30 22:45:21 +00:00
|
|
|
}
|
2016-04-30 10:35:01 +00:00
|
|
|
|
2016-05-01 00:03:27 +00:00
|
|
|
QObject *rootObject = qmlComponent.create();
|
2016-04-30 10:35:01 +00:00
|
|
|
QQuickItem *rootItem = qobject_cast<QQuickItem*>( rootObject );
|
|
|
|
|
|
|
|
|
|
COpenVROverlayController::SharedInstance()->SetQuickItem( rootItem );
|
|
|
|
|
|
2016-12-05 14:14:53 +01:00
|
|
|
win_sparkle_set_appcast_url("https://raw.githubusercontent.com/LibreVR/Revive/master/appcast.xml");
|
2016-12-05 14:58:19 +01:00
|
|
|
win_sparkle_set_can_shutdown_callback([]() { return (BOOL)!QApplication::startingUp(); });
|
|
|
|
|
win_sparkle_set_shutdown_request_callback([]() { CTrayIconController::SharedInstance()->quit(); });
|
2016-12-05 14:14:53 +01:00
|
|
|
win_sparkle_init();
|
|
|
|
|
QObject::connect(&a, &QApplication::aboutToQuit, win_sparkle_cleanup);
|
2016-04-30 10:35:01 +00:00
|
|
|
return a.exec();
|
|
|
|
|
}
|