From 7c15500b77bf031f274a12ae87c09bce7c55eaa2 Mon Sep 17 00:00:00 2001 From: dante ruiz Date: Mon, 7 Oct 2019 16:46:23 -0700 Subject: [PATCH 1/3] adding log file and fixing config file for mac --- launchers/qt/src/CommandlineOptions.cpp | 4 +- launchers/qt/src/Helper.cpp | 57 +++++++++++++++++++ launchers/qt/src/Helper.h | 2 + launchers/qt/src/Helper_darwin.mm | 6 +- .../qt/src/LauncherInstaller_windows.cpp | 1 - launchers/qt/src/LauncherState.cpp | 9 ++- launchers/qt/src/main.cpp | 11 ++-- 7 files changed, 78 insertions(+), 12 deletions(-) diff --git a/launchers/qt/src/CommandlineOptions.cpp b/launchers/qt/src/CommandlineOptions.cpp index 162d3414f3..9254644f8f 100644 --- a/launchers/qt/src/CommandlineOptions.cpp +++ b/launchers/qt/src/CommandlineOptions.cpp @@ -2,6 +2,8 @@ #include #include +#include +#include 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); } } diff --git a/launchers/qt/src/Helper.cpp b/launchers/qt/src/Helper.cpp index 38e6040a16..30de16cdcc 100644 --- a/launchers/qt/src/Helper.cpp +++ b/launchers/qt/src/Helper.cpp @@ -7,6 +7,11 @@ #include #include #include +#include +#include +#include +#include +//#incluce 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)"; diff --git a/launchers/qt/src/Helper.h b/launchers/qt/src/Helper.h index e5a3c4f502..669dd26f3b 100644 --- a/launchers/qt/src/Helper.h +++ b/launchers/qt/src/Helper.h @@ -13,6 +13,8 @@ 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); diff --git a/launchers/qt/src/Helper_darwin.mm b/launchers/qt/src/Helper_darwin.mm index 6e306d795b..47866a8ffb 100644 --- a/launchers/qt/src/Helper_darwin.mm +++ b/launchers/qt/src/Helper_darwin.mm @@ -55,13 +55,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 +117,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; } diff --git a/launchers/qt/src/LauncherInstaller_windows.cpp b/launchers/qt/src/LauncherInstaller_windows.cpp index c91a001754..e8f1d785a7 100644 --- a/launchers/qt/src/LauncherInstaller_windows.cpp +++ b/launchers/qt/src/LauncherInstaller_windows.cpp @@ -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"; diff --git a/launchers/qt/src/LauncherState.cpp b/launchers/qt/src/LauncherState.cpp index ddb5ab2dd8..97911c8a4d 100644 --- a/launchers/qt/src/LauncherState.cpp +++ b/launchers/qt/src/LauncherState.cpp @@ -271,6 +271,7 @@ void LauncherState::getCurrentClientVersion() { } } + qDebug() << "Is logged-in: " << _config.loggedIn; if (_config.loggedIn) { downloadClient(); } else { @@ -718,14 +719,18 @@ void LauncherState::launchClient() { auto path = getConfigFilePath(); QFile configFile{ path }; - if (configFile.open(QIODevice::WriteOnly)) { + if (configFile.open(QIODevice::ReadWrite)) { QJsonDocument doc = QJsonDocument::fromJson(configFile.readAll()); doc.setObject({ { configHomeLocationKey, _config.homeLocation }, { configLoggedInKey, _config.loggedIn }, { configLauncherPathKey, _config.launcherPath }, }); - 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; diff --git a/launchers/qt/src/main.cpp b/launchers/qt/src/main.cpp index a6d512b593..7526ccc8be 100644 --- a/launchers/qt/src/main.cpp +++ b/launchers/qt/src/main.cpp @@ -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(); From 4179ef3391b1fce7d1c8091adab5e746a0656b09 Mon Sep 17 00:00:00 2001 From: dante ruiz Date: Tue, 8 Oct 2019 10:23:13 -0700 Subject: [PATCH 2/3] fix mac application path --- launchers/qt/src/Helper.h | 1 + launchers/qt/src/Helper_darwin.mm | 4 ++++ launchers/qt/src/LauncherState.cpp | 3 +-- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/launchers/qt/src/Helper.h b/launchers/qt/src/Helper.h index 669dd26f3b..2d1f06052f 100644 --- a/launchers/qt/src/Helper.h +++ b/launchers/qt/src/Helper.h @@ -21,6 +21,7 @@ bool replaceDirectory(const QString& orginalDirectory, const QString& newDirecto void closeInterfaceIfRunning(); void waitForInterfaceToClose(); bool isLauncherAlreadyRunning(); +QString getBundlePath(); #endif #ifdef Q_OS_WIN diff --git a/launchers/qt/src/Helper_darwin.mm b/launchers/qt/src/Helper_darwin.mm index 47866a8ffb..684143e11b 100644 --- a/launchers/qt/src/Helper_darwin.mm +++ b/launchers/qt/src/Helper_darwin.mm @@ -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; diff --git a/launchers/qt/src/LauncherState.cpp b/launchers/qt/src/LauncherState.cpp index 97911c8a4d..ec5a2c048d 100644 --- a/launchers/qt/src/LauncherState.cpp +++ b/launchers/qt/src/LauncherState.cpp @@ -79,7 +79,6 @@ QString LauncherState::getClientExecutablePath() const { #endif } - QString LauncherState::getConfigFilePath() const { QDir clientDirectory = getClientDirectory(); return clientDirectory.absoluteFilePath("config.json"); @@ -89,7 +88,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 } From 86f1286face75be63f3c1c78b634a2e9ec8fe429 Mon Sep 17 00:00:00 2001 From: dante ruiz Date: Tue, 8 Oct 2019 10:43:12 -0700 Subject: [PATCH 3/3] do not add double entries to config.json --- launchers/qt/src/LauncherState.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/launchers/qt/src/LauncherState.cpp b/launchers/qt/src/LauncherState.cpp index ec5a2c048d..5ad437ec84 100644 --- a/launchers/qt/src/LauncherState.cpp +++ b/launchers/qt/src/LauncherState.cpp @@ -718,7 +718,7 @@ void LauncherState::launchClient() { auto path = getConfigFilePath(); QFile configFile{ path }; - if (configFile.open(QIODevice::ReadWrite)) { + if (configFile.open(QIODevice::ReadWrite | QIODevice::Truncate)) { QJsonDocument doc = QJsonDocument::fromJson(configFile.readAll()); doc.setObject({ { configHomeLocationKey, _config.homeLocation },