From 30d05aa5e9d9fea72d0b06a8691623704210be5e Mon Sep 17 00:00:00 2001 From: Elias Steurer Date: Thu, 17 Jun 2021 15:50:33 +0200 Subject: [PATCH] Fix sentry and ffmpeg --- ScreenPlay/app.cpp | 10 +--- ScreenPlay/src/createimportvideo.cpp | 48 ++++++++++++++----- ScreenPlay/src/settings.cpp | 13 ++++- .../inc/public/ScreenPlayUtil/util.h | 3 +- ScreenPlayUtil/src/util.cpp | 13 ++++- 5 files changed, 63 insertions(+), 24 deletions(-) diff --git a/ScreenPlay/app.cpp b/ScreenPlay/app.cpp index eea20dd8..20339a2c 100644 --- a/ScreenPlay/app.cpp +++ b/ScreenPlay/app.cpp @@ -158,14 +158,8 @@ void App::init() sentry_options_t* options = sentry_options_new(); sentry_options_set_dsn(options, "https://425ea0b77def4f91a5a9decc01b36ff4@o428218.ingest.sentry.io/5373419"); - - const QString appPath = QGuiApplication::applicationDirPath(); - QString exectuableFileEnding = ""; -#ifdef Q_OS_WIN - exectuableFileEnding = ".exe"; -#endif - sentry_options_set_handler_path(options, QString(appPath + "/crashpad_handler" + exectuableFileEnding).toStdString().c_str()); - sentry_options_set_database_path(options, appPath.toStdString().c_str()); + sentry_options_set_handler_path(options, QString(QGuiApplication::applicationDirPath() + "/crashpad_handler" + ScreenPlayUtil::executableBinEnding()).toStdString().c_str()); + sentry_options_set_database_path(options, QGuiApplication::applicationDirPath().toStdString().c_str()); const int sentryInitStatus = sentry_init(options); if (sentryInitStatus != 0) { qWarning() << "Unable to inti sentry crashhandler with statuscode: " << sentryInitStatus; diff --git a/ScreenPlay/src/createimportvideo.cpp b/ScreenPlay/src/createimportvideo.cpp index 0c60835d..2e0cb1ab 100644 --- a/ScreenPlay/src/createimportvideo.cpp +++ b/ScreenPlay/src/createimportvideo.cpp @@ -33,18 +33,19 @@ CreateImportVideo::CreateImportVideo(const QString& videoPath, const QString& ex : QObject(parent) , m_quality(quality) { - m_videoPath = videoPath; m_exportPath = exportPath; m_codec = codec; - m_process = std::make_unique(this); + m_ffprobeExecutable = QApplication::applicationDirPath() + "/ffprobe" + ScreenPlayUtil::executableBinEnding(); + m_ffmpegExecutable = QApplication::applicationDirPath() + "/ffmpeg" + ScreenPlayUtil::executableBinEnding(); - QString fileEnding ; -#ifdef Q_OS_WIN - fileEnding = ScreenPlayUtil::executableEnding(); -#endif - m_ffprobeExecutable = QApplication::applicationDirPath() + "/ffprobe" + fileEnding; - m_ffmpegExecutable = QApplication::applicationDirPath() + "/ffmpeg" + fileEnding ; + if (!QFileInfo::exists(m_ffprobeExecutable)) { + qFatal("FFPROBE executable not found!"); + } + + if (!QFileInfo::exists(m_ffmpegExecutable)) { + qFatal("FFMPEG executable not found!"); + } } /*! @@ -62,7 +63,7 @@ CreateImportVideo::CreateImportVideo(const QString& videoPath, const QString& ex void CreateImportVideo::process() { - qInfo() << "createWallpaperInfo()"; + qInfo() << "createWallpaperInfo()" << m_videoPath << m_exportPath << m_codec << m_ffmpegExecutable << m_ffprobeExecutable; if (!createWallpaperInfo() || QThread::currentThread()->isInterruptionRequested()) { emit abortAndCleanup(); return; @@ -268,7 +269,7 @@ bool CreateImportVideo::analyzeVideo(const QJsonObject& obj) QJsonObject videoStream; - for (const auto stream : arrayStream) { + for (const auto& stream : arrayStream) { QString codec_type = stream.toObject().value("codec_type").toString(); if (codec_type == "video") { videoStream = stream.toObject(); @@ -751,19 +752,42 @@ QString CreateImportVideo::waitForFinished( const Executable executable) { + m_process = std::make_unique(); + QObject::connect(m_process.get(), &QProcess::errorOccurred, [=](QProcess::ProcessError error) { + qDebug() << "error enum val = " << error << m_process->errorString(); + emit createWallpaperStateChanged(ImportVideoState::AnalyseVideoError); + m_process->terminate(); + if (!m_process->waitForFinished(1000)) { + m_process->kill(); + } + }); if (executable == Executable::FFMPEG) { m_process->setProgram(m_ffmpegExecutable); } else { m_process->setProgram(m_ffprobeExecutable); } + +#ifdef Q_OS_OSX + QProcess changeChmod; + changeChmod.setProgram("chmod"); + changeChmod.setArguments({ "+x", m_process->program() }); + changeChmod.start(); + if (!changeChmod.waitForFinished()) { + qCritical() << "Unable to change permission " << m_process->program() << " to be exectuable"; + } +#endif + m_process->setProcessChannelMode(processChannelMode); m_process->setArguments(args); + m_process->setWorkingDirectory(QApplication::applicationDirPath()); m_process->start(); - while (!m_process->waitForFinished(100)) //Wake up every 10ms and check if we must exit + qInfo() << m_process->workingDirectory() << m_process->program() << m_process->arguments(); + + while (!m_process->waitForFinished(10)) //Wake up every 10ms and check if we must exit { if (QThread::currentThread()->isInterruptionRequested()) { - qDebug() << "Interrupt thread"; + qInfo() << "Interrupt thread"; m_process->terminate(); if (!m_process->waitForFinished(1000)) { m_process->kill(); diff --git a/ScreenPlay/src/settings.cpp b/ScreenPlay/src/settings.cpp index 67315b9e..8f4c0472 100644 --- a/ScreenPlay/src/settings.cpp +++ b/ScreenPlay/src/settings.cpp @@ -1,6 +1,7 @@ #include "settings.h" #include "ScreenPlayUtil/util.h" +#include namespace ScreenPlay { @@ -140,8 +141,8 @@ void Settings::setupWidgetAndWindowPaths() { QDir workingDir(QGuiApplication::applicationDirPath()); #ifdef Q_OS_WIN - m_globalVariables->setWidgetExecutablePath(QUrl(workingDir.path() + "/ScreenPlayWidget" + ScreenPlayUtil::executableEnding())); - m_globalVariables->setWallpaperExecutablePath(QUrl(workingDir.path() + "/ScreenPlayWallpaper" + ScreenPlayUtil::executableEnding())); + m_globalVariables->setWidgetExecutablePath(QUrl(workingDir.path() + "/ScreenPlayWidget" + ScreenPlayUtil::executableBinEnding())); + m_globalVariables->setWallpaperExecutablePath(QUrl(workingDir.path() + "/ScreenPlayWallpaper" + ScreenPlayUtil::executableBinEnding())); #endif #ifdef Q_OS_OSX @@ -152,7 +153,15 @@ void Settings::setupWidgetAndWindowPaths() m_globalVariables->setWidgetExecutablePath(QUrl::fromUserInput(workingDir.path() + "/ScreenPlayWidget.app/Contents/MacOS/ScreenPlayWidget").toLocalFile()); m_globalVariables->setWallpaperExecutablePath(QUrl::fromUserInput(workingDir.path() + "/ScreenPlayWallpaper.app/Contents/MacOS/ScreenPlayWallpaper").toLocalFile()); + #endif + + if (!QFileInfo::exists(m_globalVariables->widgetExecutablePath().toString())) { + qFatal("widget executable not found!"); + } + if (!QFileInfo::exists(m_globalVariables->wallpaperExecutablePath().toString())) { + qFatal("wallpaper executable not found!"); + } } /*! diff --git a/ScreenPlayUtil/inc/public/ScreenPlayUtil/util.h b/ScreenPlayUtil/inc/public/ScreenPlayUtil/util.h index fcd691b2..bf9acc11 100644 --- a/ScreenPlayUtil/inc/public/ScreenPlayUtil/util.h +++ b/ScreenPlayUtil/inc/public/ScreenPlayUtil/util.h @@ -56,7 +56,8 @@ bool copyPreviewThumbnail(QJsonObject& obj, const QString& previewThumbnail, con QString toString(const QStringList& list); QString toLocal(const QString& url); QString generateRandomString(quint32 length = 32); -QString executableEnding(); +QString executableAppEnding(); +QString executableBinEnding(); QStringList getAvailableWallpaper(); QStringList getAvailableWidgets(); QStringList getAvailableTypes(); diff --git a/ScreenPlayUtil/src/util.cpp b/ScreenPlayUtil/src/util.cpp index 4df0b32c..5f92d39b 100644 --- a/ScreenPlayUtil/src/util.cpp +++ b/ScreenPlayUtil/src/util.cpp @@ -114,7 +114,18 @@ QString generateRandomString(quint32 length) /*! \brief Return .exe on windows otherwise empty string. */ -QString executableEnding() +QString executableBinEnding() +{ +#ifdef Q_OS_WIN + return ".exe"; +#endif + return ""; +} + +/*! + \brief Return .exe on windows, .app on osx otherwise empty string. +*/ +QString executableAppEnding() { #ifdef Q_OS_WIN return ".exe";