mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-07-17 15:06:17 +02:00
Merge branch 'qt-launcher' of github.com:danteruiz/hifi into qt-launcher
This commit is contained in:
commit
bff38debff
7 changed files with 84 additions and 14 deletions
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
bool isCommandlineOption(const std::string& option) {
|
bool isCommandlineOption(const std::string& option) {
|
||||||
if (option.rfind("--", 0) == 0 && option.at(2) != '-') {
|
if (option.rfind("--", 0) == 0 && option.at(2) != '-') {
|
||||||
|
@ -18,7 +20,7 @@ void CommandlineOptions::parse(const int argc, char** argv) {
|
||||||
for (int index = 1; index < argc; index++) {
|
for (int index = 1; index < argc; index++) {
|
||||||
std::string option = argv[index];
|
std::string option = argv[index];
|
||||||
if (isCommandlineOption(option)) {
|
if (isCommandlineOption(option)) {
|
||||||
std::cout << "adding commandline option: " << option << "\n";
|
qDebug() << "adding commandline option: " << QString::fromStdString(option);
|
||||||
_commandlineOptions.push_back(option);
|
_commandlineOptions.push_back(option);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,11 @@
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
#include <QProcessEnvironment>
|
#include <QProcessEnvironment>
|
||||||
|
#include <QDateTime>
|
||||||
|
#include <QTextStream>
|
||||||
|
#include <QStandardPaths>
|
||||||
|
#include <iostream>
|
||||||
|
//#incluce <QTextStream>
|
||||||
|
|
||||||
|
|
||||||
QString getMetaverseAPIDomain() {
|
QString getMetaverseAPIDomain() {
|
||||||
|
@ -17,6 +22,43 @@ QString getMetaverseAPIDomain() {
|
||||||
return "https://metaverse.highfidelity.com";
|
return "https://metaverse.highfidelity.com";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void messageHandler(QtMsgType type, const QMessageLogContext& context, const QString& message) {
|
||||||
|
Q_UNUSED(context);
|
||||||
|
|
||||||
|
QString date = QDateTime::currentDateTime().toString("dd/MM/yyyy hh:mm:ss");
|
||||||
|
QString txt = QString("[%1] ").arg(date);
|
||||||
|
|
||||||
|
switch (type) {
|
||||||
|
case QtDebugMsg:
|
||||||
|
txt += QString("{Debug} \t\t %1").arg(message);
|
||||||
|
break;
|
||||||
|
case QtWarningMsg:
|
||||||
|
txt += QString("{Warning} \t %1").arg(message);
|
||||||
|
break;
|
||||||
|
case QtCriticalMsg:
|
||||||
|
txt += QString("{Critical} \t %1").arg(message);
|
||||||
|
break;
|
||||||
|
case QtFatalMsg:
|
||||||
|
txt += QString("{Fatal} \t\t %1").arg(message);
|
||||||
|
break;
|
||||||
|
case QtInfoMsg:
|
||||||
|
txt += QString("{Info} \t %1").arg(message);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
QDir launcherDirectory = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
|
||||||
|
launcherDirectory.mkpath(launcherDirectory.absolutePath());
|
||||||
|
QString filename = launcherDirectory.absoluteFilePath("Log.txt");
|
||||||
|
|
||||||
|
QFile outFile(filename);
|
||||||
|
outFile.open(QIODevice::WriteOnly | QIODevice::Append);
|
||||||
|
|
||||||
|
QTextStream textStream(&outFile);
|
||||||
|
std::cout << txt.toStdString() << "\n";
|
||||||
|
textStream << txt << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
void swapLaunchers(const QString& oldLauncherPath, const QString& newLauncherPath) {
|
void swapLaunchers(const QString& oldLauncherPath, const QString& newLauncherPath) {
|
||||||
if (!(QFileInfo::exists(oldLauncherPath) && QFileInfo::exists(newLauncherPath))) {
|
if (!(QFileInfo::exists(oldLauncherPath) && QFileInfo::exists(newLauncherPath))) {
|
||||||
qDebug() << "old launcher: " << oldLauncherPath << "new launcher: " << newLauncherPath << " file does not exist";
|
qDebug() << "old launcher: " << oldLauncherPath << "new launcher: " << newLauncherPath << " file does not exist";
|
||||||
|
@ -35,6 +77,21 @@ void swapLaunchers(const QString& oldLauncherPath, const QString& newLauncherPat
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void cleanLogFile() {
|
||||||
|
QDir launcherDirectory = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
|
||||||
|
launcherDirectory.mkpath(launcherDirectory.absolutePath());
|
||||||
|
QString filename = launcherDirectory.absoluteFilePath("Log.txt");
|
||||||
|
QString tmpFilename = launcherDirectory.absoluteFilePath("Log-last.txt");
|
||||||
|
if (QFile::exists(filename)) {
|
||||||
|
if (QFile::exists(tmpFilename)) {
|
||||||
|
QFile::remove(tmpFilename);
|
||||||
|
}
|
||||||
|
QFile::rename(filename, tmpFilename);
|
||||||
|
QFile::remove(filename);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QString getHTTPUserAgent() {
|
QString getHTTPUserAgent() {
|
||||||
#if defined(Q_OS_WIN)
|
#if defined(Q_OS_WIN)
|
||||||
return "HQLauncher/fixme (Windows)";
|
return "HQLauncher/fixme (Windows)";
|
||||||
|
|
|
@ -13,12 +13,15 @@ void launchClient(const QString& clientPath, const QString& homePath, const QStr
|
||||||
|
|
||||||
void launchAutoUpdater(const QString& autoUpdaterPath);
|
void launchAutoUpdater(const QString& autoUpdaterPath);
|
||||||
void swapLaunchers(const QString& oldLauncherPath = QString(), const QString& newLauncherPath = QString());
|
void swapLaunchers(const QString& oldLauncherPath = QString(), const QString& newLauncherPath = QString());
|
||||||
|
void messageHandler(QtMsgType type, const QMessageLogContext& context, const QString& message);
|
||||||
|
void cleanLogFile();
|
||||||
|
|
||||||
#ifdef Q_OS_MAC
|
#ifdef Q_OS_MAC
|
||||||
bool replaceDirectory(const QString& orginalDirectory, const QString& newDirectory);
|
bool replaceDirectory(const QString& orginalDirectory, const QString& newDirectory);
|
||||||
void closeInterfaceIfRunning();
|
void closeInterfaceIfRunning();
|
||||||
void waitForInterfaceToClose();
|
void waitForInterfaceToClose();
|
||||||
bool isLauncherAlreadyRunning();
|
bool isLauncherAlreadyRunning();
|
||||||
|
QString getBundlePath();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
|
|
|
@ -42,6 +42,10 @@ void launchClient(const QString& clientPath, const QString& homePath, const QStr
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString getBundlePath() {
|
||||||
|
return QString::fromNSString([[NSBundle mainBundle] bundlePath]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void launchAutoUpdater(const QString& autoUpdaterPath) {
|
void launchAutoUpdater(const QString& autoUpdaterPath) {
|
||||||
NSException *exception;
|
NSException *exception;
|
||||||
|
@ -55,13 +59,13 @@ void launchAutoUpdater(const QString& autoUpdaterPath) {
|
||||||
task.launchPath = [newLauncher stringByAppendingString: bundlePath];
|
task.launchPath = [newLauncher stringByAppendingString: bundlePath];
|
||||||
task.arguments = @[[[NSBundle mainBundle] bundlePath], newLauncher];
|
task.arguments = @[[[NSBundle mainBundle] bundlePath], newLauncher];
|
||||||
|
|
||||||
NSLog(@"launching updater: %@ %@", task.launchPath, task.arguments);
|
qDebug() << "launching updater: " << task.launchPath << task.arguments;
|
||||||
|
|
||||||
@try {
|
@try {
|
||||||
[task launch];
|
[task launch];
|
||||||
}
|
}
|
||||||
@catch (NSException *e) {
|
@catch (NSException *e) {
|
||||||
NSLog(@"couldn't launch updater: %@, %@", e.name, e.reason);
|
qDebug() << "couldn't launch updater: " << QString::fromNSString(e.name) << QString::fromNSString(e.reason);
|
||||||
exception = e;
|
exception = e;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -117,9 +121,9 @@ void waitForInterfaceToClose() {
|
||||||
|
|
||||||
bool isLauncherAlreadyRunning() {
|
bool isLauncherAlreadyRunning() {
|
||||||
NSArray* apps = [NSRunningApplication runningApplicationsWithBundleIdentifier:@"com.highfidelity.launcher"];
|
NSArray* apps = [NSRunningApplication runningApplicationsWithBundleIdentifier:@"com.highfidelity.launcher"];
|
||||||
NSLog(@"Count: %lu", [apps count]);
|
|
||||||
if ([apps count] > 1) {
|
if ([apps count] > 1) {
|
||||||
NSLog(@"launcher is already running");
|
NSLog(@"launcher is already running");
|
||||||
|
qDebug() << "launcher is already running";
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,6 @@ bool LauncherInstaller::runningOutsideOfInstallDir() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void LauncherInstaller::install() {
|
void LauncherInstaller::install() {
|
||||||
//qDebug() << "Is install dir empty: " << _launcherInstallDir.isEmpty();
|
|
||||||
if (runningOutsideOfInstallDir()) {
|
if (runningOutsideOfInstallDir()) {
|
||||||
qDebug() << "Installing HQ Launcher....";
|
qDebug() << "Installing HQ Launcher....";
|
||||||
QString oldLauncherPath = _launcherInstallDir.absolutePath() + "/HQ Launcher.exe";
|
QString oldLauncherPath = _launcherInstallDir.absolutePath() + "/HQ Launcher.exe";
|
||||||
|
|
|
@ -80,7 +80,6 @@ QString LauncherState::getClientExecutablePath() const {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QString LauncherState::getConfigFilePath() const {
|
QString LauncherState::getConfigFilePath() const {
|
||||||
QDir clientDirectory = getClientDirectory();
|
QDir clientDirectory = getClientDirectory();
|
||||||
return clientDirectory.absoluteFilePath("config.json");
|
return clientDirectory.absoluteFilePath("config.json");
|
||||||
|
@ -90,7 +89,7 @@ QString LauncherState::getLauncherFilePath() const {
|
||||||
#if defined(Q_OS_WIN)
|
#if defined(Q_OS_WIN)
|
||||||
return _launcherDirectory.absoluteFilePath("launcher.exe");
|
return _launcherDirectory.absoluteFilePath("launcher.exe");
|
||||||
#elif defined(Q_OS_MACOS)
|
#elif defined(Q_OS_MACOS)
|
||||||
return _launcherDirectory.absoluteFilePath("launcher.app");
|
return getBundlePath() + "/Contents/MacOS/HQ Launcher";
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -278,6 +277,7 @@ void LauncherState::getCurrentClientVersion() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qDebug() << "Is logged-in: " << _config.loggedIn;
|
||||||
if (_config.loggedIn) {
|
if (_config.loggedIn) {
|
||||||
downloadClient();
|
downloadClient();
|
||||||
} else {
|
} else {
|
||||||
|
@ -735,7 +735,7 @@ void LauncherState::launchClient() {
|
||||||
|
|
||||||
auto path = getConfigFilePath();
|
auto path = getConfigFilePath();
|
||||||
QFile configFile{ path };
|
QFile configFile{ path };
|
||||||
if (configFile.open(QIODevice::WriteOnly)) {
|
if (configFile.open(QIODevice::ReadWrite | QIODevice::Truncate)) {
|
||||||
QJsonDocument doc = QJsonDocument::fromJson(configFile.readAll());
|
QJsonDocument doc = QJsonDocument::fromJson(configFile.readAll());
|
||||||
doc.setObject({
|
doc.setObject({
|
||||||
{ configHomeLocationKey, _config.homeLocation },
|
{ configHomeLocationKey, _config.homeLocation },
|
||||||
|
@ -743,7 +743,11 @@ void LauncherState::launchClient() {
|
||||||
{ configLoggedInKey, _config.loggedIn },
|
{ configLoggedInKey, _config.loggedIn },
|
||||||
{ configLauncherPathKey, getLauncherFilePath() },
|
{ configLauncherPathKey, getLauncherFilePath() },
|
||||||
});
|
});
|
||||||
configFile.write(doc.toJson());
|
qint64 result = configFile.write(doc.toJson());
|
||||||
|
configFile.close();
|
||||||
|
qDebug() << "Wrote data to config data: " << result;
|
||||||
|
} else {
|
||||||
|
qDebug() << "Failed to open config file";
|
||||||
}
|
}
|
||||||
|
|
||||||
QString defaultScriptsPath;
|
QString defaultScriptsPath;
|
||||||
|
|
|
@ -29,7 +29,13 @@ bool hasSuffix(const std::string& path, const std::string& suffix) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
|
QString name { "High Fidelity" };
|
||||||
|
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
||||||
|
QCoreApplication::setOrganizationName(name);
|
||||||
|
QCoreApplication::setApplicationName("HQ Launcher");
|
||||||
Q_INIT_RESOURCE(resources);
|
Q_INIT_RESOURCE(resources);
|
||||||
|
cleanLogFile();
|
||||||
|
qInstallMessageHandler(messageHandler);
|
||||||
#ifdef Q_OS_MAC
|
#ifdef Q_OS_MAC
|
||||||
if (isLauncherAlreadyRunning()) {
|
if (isLauncherAlreadyRunning()) {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -59,11 +65,6 @@ int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
QString name { "High Fidelity" };
|
|
||||||
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
|
||||||
QCoreApplication::setOrganizationName(name);
|
|
||||||
QCoreApplication::setApplicationName("HQ Launcher");
|
|
||||||
|
|
||||||
Launcher launcher(argc, argv);
|
Launcher launcher(argc, argv);
|
||||||
|
|
||||||
return launcher.exec();
|
return launcher.exec();
|
||||||
|
|
Loading…
Reference in a new issue