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();