Merge branch 'qt-launcher' of github.com:danteruiz/hifi into qt-launcher

This commit is contained in:
Ryan Huffman 2019-10-08 12:55:18 -07:00
commit bff38debff
7 changed files with 84 additions and 14 deletions

View file

@ -2,6 +2,8 @@
#include <algorithm>
#include <iostream>
#include <QDebug>
#include <QString>
bool isCommandlineOption(const std::string& option) {
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++) {
std::string option = argv[index];
if (isCommandlineOption(option)) {
std::cout << "adding commandline option: " << option << "\n";
qDebug() << "adding commandline option: " << QString::fromStdString(option);
_commandlineOptions.push_back(option);
}
}

View file

@ -7,6 +7,11 @@
#include <QFile>
#include <QProcess>
#include <QProcessEnvironment>
#include <QDateTime>
#include <QTextStream>
#include <QStandardPaths>
#include <iostream>
//#incluce <QTextStream>
QString getMetaverseAPIDomain() {
@ -17,6 +22,43 @@ QString getMetaverseAPIDomain() {
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) {
if (!(QFileInfo::exists(oldLauncherPath) && QFileInfo::exists(newLauncherPath))) {
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() {
#if defined(Q_OS_WIN)
return "HQLauncher/fixme (Windows)";

View file

@ -13,12 +13,15 @@ void launchClient(const QString& clientPath, const QString& homePath, const QStr
void launchAutoUpdater(const QString& autoUpdaterPath);
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
bool replaceDirectory(const QString& orginalDirectory, const QString& newDirectory);
void closeInterfaceIfRunning();
void waitForInterfaceToClose();
bool isLauncherAlreadyRunning();
QString getBundlePath();
#endif
#ifdef Q_OS_WIN

View file

@ -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) {
NSException *exception;
@ -55,13 +59,13 @@ void launchAutoUpdater(const QString& autoUpdaterPath) {
task.launchPath = [newLauncher stringByAppendingString: bundlePath];
task.arguments = @[[[NSBundle mainBundle] bundlePath], newLauncher];
NSLog(@"launching updater: %@ %@", task.launchPath, task.arguments);
qDebug() << "launching updater: " << task.launchPath << task.arguments;
@try {
[task launch];
}
@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;
continue;
}
@ -117,9 +121,9 @@ void waitForInterfaceToClose() {
bool isLauncherAlreadyRunning() {
NSArray* apps = [NSRunningApplication runningApplicationsWithBundleIdentifier:@"com.highfidelity.launcher"];
NSLog(@"Count: %lu", [apps count]);
if ([apps count] > 1) {
NSLog(@"launcher is already running");
qDebug() << "launcher is already running";
return true;
}

View file

@ -31,7 +31,6 @@ bool LauncherInstaller::runningOutsideOfInstallDir() {
}
void LauncherInstaller::install() {
//qDebug() << "Is install dir empty: " << _launcherInstallDir.isEmpty();
if (runningOutsideOfInstallDir()) {
qDebug() << "Installing HQ Launcher....";
QString oldLauncherPath = _launcherInstallDir.absolutePath() + "/HQ Launcher.exe";

View file

@ -80,7 +80,6 @@ QString LauncherState::getClientExecutablePath() const {
#endif
}
QString LauncherState::getConfigFilePath() const {
QDir clientDirectory = getClientDirectory();
return clientDirectory.absoluteFilePath("config.json");
@ -90,7 +89,7 @@ QString LauncherState::getLauncherFilePath() const {
#if defined(Q_OS_WIN)
return _launcherDirectory.absoluteFilePath("launcher.exe");
#elif defined(Q_OS_MACOS)
return _launcherDirectory.absoluteFilePath("launcher.app");
return getBundlePath() + "/Contents/MacOS/HQ Launcher";
#endif
}
@ -278,6 +277,7 @@ void LauncherState::getCurrentClientVersion() {
}
}
qDebug() << "Is logged-in: " << _config.loggedIn;
if (_config.loggedIn) {
downloadClient();
} else {
@ -735,7 +735,7 @@ void LauncherState::launchClient() {
auto path = getConfigFilePath();
QFile configFile{ path };
if (configFile.open(QIODevice::WriteOnly)) {
if (configFile.open(QIODevice::ReadWrite | QIODevice::Truncate)) {
QJsonDocument doc = QJsonDocument::fromJson(configFile.readAll());
doc.setObject({
{ configHomeLocationKey, _config.homeLocation },
@ -743,7 +743,11 @@ void LauncherState::launchClient() {
{ configLoggedInKey, _config.loggedIn },
{ 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;

View file

@ -29,7 +29,13 @@ bool hasSuffix(const std::string& path, const std::string& suffix) {
}
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);
cleanLogFile();
qInstallMessageHandler(messageHandler);
#ifdef Q_OS_MAC
if (isLauncherAlreadyRunning()) {
return 0;
@ -59,11 +65,6 @@ int main(int argc, char *argv[]) {
#endif
QString name { "High Fidelity" };
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QCoreApplication::setOrganizationName(name);
QCoreApplication::setApplicationName("HQ Launcher");
Launcher launcher(argc, argv);
return launcher.exec();