forked from LibreVR/Revive
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from LibreVR/master
new commits
- Loading branch information
Showing
13 changed files
with
161 additions
and
395 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.