diff --git a/tools/oven/CMakeLists.txt b/tools/oven/CMakeLists.txt index 4ffdd13d26..3cf954b213 100644 --- a/tools/oven/CMakeLists.txt +++ b/tools/oven/CMakeLists.txt @@ -11,6 +11,9 @@ include_hifi_library_headers(script-engine) setup_memory_debugger() setup_thread_debugger() +add_crashpad() +target_breakpad() + if (WIN32) package_libraries_for_deployment() diff --git a/tools/oven/src/OvenCLIApplication.cpp b/tools/oven/src/OvenCLIApplication.cpp index 6d3a8912ab..c02b42c0dc 100644 --- a/tools/oven/src/OvenCLIApplication.cpp +++ b/tools/oven/src/OvenCLIApplication.cpp @@ -18,7 +18,7 @@ #include #include - +#include #include "BakerCLI.h" static const QString CLI_INPUT_PARAMETER = "i"; @@ -38,7 +38,7 @@ OvenCLIApplication::OvenCLIApplication(int argc, char* argv[]) : Q_ARG(QString, _outputUrlParameter.toString()), Q_ARG(QString, _typeParameter)); } -void OvenCLIApplication::parseCommandLine(int argc, char* argv[]) { +OvenCLIApplication::parseResult OvenCLIApplication::parseCommandLine(int argc, char* argv[], bool *enableCrashHandler) { // parse the command line parameters QCommandLineParser parser; @@ -50,6 +50,11 @@ void OvenCLIApplication::parseCommandLine(int argc, char* argv[]) { { CLI_DISABLE_TEXTURE_COMPRESSION_PARAMETER, "Disable texture compression." } }); + + const QCommandLineOption forceCrashReportingOption("forceCrashReporting", "Force crash reporting to initialize."); + parser.addOption(forceCrashReportingOption); + + auto versionOption = parser.addVersionOption(); auto helpOption = parser.addHelpOption(); @@ -65,6 +70,10 @@ void OvenCLIApplication::parseCommandLine(int argc, char* argv[]) { Q_UNREACHABLE(); } + if (parser.isSet(forceCrashReportingOption)) { + *enableCrashHandler = true; + } + if (parser.isSet(versionOption)) { parser.showVersion(); Q_UNREACHABLE(); @@ -75,20 +84,27 @@ void OvenCLIApplication::parseCommandLine(int argc, char* argv[]) { Q_UNREACHABLE(); } - if (!parser.isSet(CLI_INPUT_PARAMETER) || !parser.isSet(CLI_OUTPUT_PARAMETER)) { + // If one argument is given, so must be the other + if ((parser.isSet(CLI_INPUT_PARAMETER) != parser.isSet(CLI_OUTPUT_PARAMETER)) || !parser.positionalArguments().empty()) { std::cout << "Error: Input and Output not set" << std::endl; // Avoid Qt log spam QCoreApplication mockApp(argc, argv); // required for call to showHelp() parser.showHelp(); Q_UNREACHABLE(); } - _inputUrlParameter = QDir::fromNativeSeparators(parser.value(CLI_INPUT_PARAMETER)); - _outputUrlParameter = QDir::fromNativeSeparators(parser.value(CLI_OUTPUT_PARAMETER)); + if (parser.isSet(CLI_INPUT_PARAMETER) && parser.isSet(CLI_OUTPUT_PARAMETER)) { + _inputUrlParameter = QDir::fromNativeSeparators(parser.value(CLI_INPUT_PARAMETER)); + _outputUrlParameter = QDir::fromNativeSeparators(parser.value(CLI_OUTPUT_PARAMETER)); - _typeParameter = parser.isSet(CLI_TYPE_PARAMETER) ? parser.value(CLI_TYPE_PARAMETER) : QString(); + _typeParameter = parser.isSet(CLI_TYPE_PARAMETER) ? parser.value(CLI_TYPE_PARAMETER) : QString(); - if (parser.isSet(CLI_DISABLE_TEXTURE_COMPRESSION_PARAMETER)) { - qDebug() << "Disabling texture compression"; - TextureBaker::setCompressionEnabled(false); + if (parser.isSet(CLI_DISABLE_TEXTURE_COMPRESSION_PARAMETER)) { + qDebug() << "Disabling texture compression"; + TextureBaker::setCompressionEnabled(false); + } + + return OvenCLIApplication::CLIMode; + } else { + return OvenCLIApplication::GUIMode; } } diff --git a/tools/oven/src/OvenCLIApplication.h b/tools/oven/src/OvenCLIApplication.h index 21fc9e9ba1..e4f75df16e 100644 --- a/tools/oven/src/OvenCLIApplication.h +++ b/tools/oven/src/OvenCLIApplication.h @@ -21,7 +21,12 @@ class OvenCLIApplication : public QCoreApplication, public Oven { public: OvenCLIApplication(int argc, char* argv[]); - static void parseCommandLine(int argc, char* argv[]); + enum parseResult { + GUIMode, + CLIMode + }; + + static parseResult parseCommandLine(int argc, char* argv[], bool *enableCrashHandler); static OvenCLIApplication* instance() { return dynamic_cast(QCoreApplication::instance()); } diff --git a/tools/oven/src/main.cpp b/tools/oven/src/main.cpp index 586dae06a5..66e79806fa 100644 --- a/tools/oven/src/main.cpp +++ b/tools/oven/src/main.cpp @@ -14,24 +14,64 @@ #include #include #include +#include +#include +#include +#include + + +// This needs to be run after a QApplication has been created +void postAppInit(QCoreApplication *app, bool enableCrashHandler) { + Setting::init(); + + auto &ch = CrashHandler::getInstance(); + + + + QObject::connect(&ch, &CrashHandler::enabledChanged, [](bool enabled) { + Settings s; + s.beginGroup("Crash"); + s.setValue("ReportingEnabled", enabled); + s.endGroup(); + }); + + + Settings crashSettings; + crashSettings.beginGroup("Crash"); + ch.setEnabled(crashSettings.value("ReportingEnabled").toBool() || enableCrashHandler); + ch.startMonitor(app); +} + int main (int argc, char** argv) { setupHifiApplication("Oven"); + + DependencyManager::set(); + + auto &ch = CrashHandler::getInstance(); + ch.setPath(argv[0]); + + + // figure out if we're launching our GUI application or just the simple command line interface - if (argc > 1) { - OvenCLIApplication::parseCommandLine(argc, argv); + bool enableCrashHandler = false; + OvenCLIApplication::parseResult res = OvenCLIApplication::parseCommandLine(argc, argv, &enableCrashHandler); - // init the settings interface so we can save and load settings - Setting::init(); - - OvenCLIApplication app { argc, argv }; - return app.exec(); - } else { - // init the settings interface so we can save and load settings - Setting::init(); - - OvenGUIApplication app { argc, argv }; - return app.exec(); + switch(res) { + case OvenCLIApplication::CLIMode: + { + OvenCLIApplication app { argc, argv }; + postAppInit(&app, enableCrashHandler); + return app.exec(); + break; + } + case OvenCLIApplication::GUIMode: + { + OvenGUIApplication app { argc, argv }; + postAppInit(&app, enableCrashHandler); + return app.exec(); + break; + } } }