Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new commits #1

Merged
merged 4 commits into from
Dec 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion ReviveOverlay/Overlay.qml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ Rectangle {
if (Revive.launchApplication(appKey)) {
activateSound.play();
currentAppId = appId;
Platform.reLogin(appId);
heartbeat.start();
} else {
failSound.play();
Expand Down
10 changes: 5 additions & 5 deletions ReviveOverlay/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "openvroverlaycontroller.h"
#include "revivemanifestcontroller.h"
#include "windowsservices.h"
#include "oculusplatform.h"
#include "oculusoauthtokencontroller.h"
#include <qt_windows.h>
#include <winsparkle.h>

Expand All @@ -19,7 +19,7 @@
#include <QSslSocket>

extern "C" {
__declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001;
__declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001;
__declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1;
}

Expand Down Expand Up @@ -81,14 +81,14 @@ int main(int argc, char *argv[])
if (!CReviveManifestController::SharedInstance()->Init())
qDebug("Failed to initialize the revive manifest");

if (!COculusPlatform::SharedInstance()->Init(CReviveManifestController::SharedInstance()->GetBasePath()))
qDebug("Failed to initialize the oculus platform");
if (!COculusOauthTokenController::SharedInstance()->Init())
qDebug("Failed to initialize the Oculus OAuth token");

// Create a QML engine.
QQmlEngine qmlEngine;
qmlEngine.rootContext()->setContextProperty("Revive", CReviveManifestController::SharedInstance());
qmlEngine.rootContext()->setContextProperty("OpenVR", COpenVROverlayController::SharedInstance());
qmlEngine.rootContext()->setContextProperty("Platform", COculusPlatform::SharedInstance());
qmlEngine.rootContext()->setContextProperty("Platform", COculusOauthTokenController::SharedInstance());

QQmlComponent qmlComponent( &qmlEngine, QUrl("qrc:/Overlay.qml"));
if (qmlComponent.isError())
Expand Down
90 changes: 90 additions & 0 deletions ReviveOverlay/oculusoauthtokencontroller.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#include "oculusoauthtokencontroller.h"
#include "trayiconcontroller.h"
#include "windowsservices.h"
#include <stdlib.h>

#include <QCoreApplication>

COculusOauthTokenController *COculusOauthTokenController::SharedInstance()
{
static COculusOauthTokenController *instance = nullptr;
if ( !instance )
{
instance = new COculusOauthTokenController();
}
return instance;
}

COculusOauthTokenController::COculusOauthTokenController()
: m_strAccessToken()
, m_roamingAppDataPath(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation))
, m_sqliteDb(QSqlDatabase::addDatabase( "QSQLITE" ))
{
}

COculusOauthTokenController::~COculusOauthTokenController()
{
}

bool COculusOauthTokenController::Init()
{
//cd up from %APPDATA%/Roaming/APPNAME to %APPDATA%/Roaming
m_roamingAppDataPath.cdUp();
QString oculusOfflineDb = m_roamingAppDataPath.filePath("Oculus/Sessions/_oaf/data.sqlite");
QString tempOculusOfflineDB = m_roamingAppDataPath.filePath("Oculus/Sessions/_oaf/revive_data.sqlite");

//Clean up saved credentials from previous versions as they're no longer needed
WindowsServices::DeleteCredentials();

if (!QFile::exists(oculusOfflineDb))
return false;

//Check for temp db that somehow missed cleanup
if (QFile::exists(tempOculusOfflineDB))
QFile::remove(tempOculusOfflineDB);

//The SQLite DB is locked by the oculus service, so we need to make a copy
QFile::copy(oculusOfflineDb, tempOculusOfflineDB);
m_sqliteDb.setDatabaseName(tempOculusOfflineDB);

if(!m_sqliteDb.open() || !LoadToken())
{
m_sqliteDb.close();
QFile::remove(tempOculusOfflineDB);
CTrayIconController::SharedInstance()->ShowInformation(TrayInfo_OculusAccessTokenNotFound);
return false;
}

m_sqliteDb.close();
QFile::remove(tempOculusOfflineDB);
return true;
}

bool COculusOauthTokenController::LoadToken()
{
QSqlQuery query = QSqlQuery( m_sqliteDb );
if( !query.exec( "SELECT value FROM 'Objects' WHERE hashkey = '__OAF_OFFLINE_DATA_KEY__'" ))
return false;

query.first();
QByteArray offlineDataByteArray = query.value(0).toByteArray();
qsizetype token_start_index = offlineDataByteArray.indexOf("last_valid_auth_token") + 31;
if (token_start_index == -1)
return false;

qsizetype token_stop_index = -1;
if(offlineDataByteArray.contains("last_valid_fb_access_token"))
token_stop_index = offlineDataByteArray.indexOf("last_valid_fb_access_token") - 4;

if (offlineDataByteArray.mid(token_start_index).contains("last_valid_auth_token_type"))
/*'last_valid_auth_token_type' matches 'last_valid_auth_token' in indexOf, so
search after the index of 'last_valid_auth_token' */
token_stop_index = offlineDataByteArray.mid(token_start_index).indexOf("last_valid_auth_token_type") - 4;

if (token_stop_index == -1)
return false;

m_strAccessToken = QString::fromStdString(offlineDataByteArray.mid(token_start_index, token_stop_index).toStdString());
TokenChanged();
return true;
}
45 changes: 45 additions & 0 deletions ReviveOverlay/oculusoauthtokencontroller.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#ifndef OCULUSOAUTHTOKENCONTROLLER_H
#define OCULUSOAUTHTOKENCONTROLLER_H

#include <QObject>
#include <QString>
#include <QLibrary>
#include <QTimer>
#include <QFile>
#include <QtSql>

typedef struct {
} ovrOculusInitParams;

class COculusOauthTokenController : public QObject
{
Q_OBJECT
typedef QObject BaseClass;

Q_PROPERTY(bool connected READ Connected NOTIFY TokenChanged);
Q_PROPERTY(QString AccessToken READ GetToken NOTIFY TokenChanged);
public:
static COculusOauthTokenController *SharedInstance();

public:
COculusOauthTokenController();
virtual ~COculusOauthTokenController();

bool Init();
bool LoadToken();

bool Connected() { return !m_strAccessToken.isEmpty(); }
QString GetToken() { return m_strAccessToken; }

signals:
void TokenChanged();

protected slots:

private:
QString m_strAccessToken;
QDir m_roamingAppDataPath;
QSqlDatabase m_sqliteDb;
};

#endif // OCULUSOAUTHTOKENCONTROLLER_H
137 changes: 0 additions & 137 deletions ReviveOverlay/oculusplatform.cpp

This file was deleted.

Loading