Skip to content

Commit

Permalink
cache QCoreApplication::arguments() call
Browse files Browse the repository at this point in the history
  • Loading branch information
kambala-decapitator committed Feb 20, 2024
1 parent ca5bb1f commit 28d89c2
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,29 @@
#include <QNetworkProxy>
#include <QDebug>

#ifndef ALWAYS_DEBUG_OUTPUT
void noMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
Q_UNUSED(type);
Q_UNUSED(context);
Q_UNUSED(msg);
}
#endif

int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QString argFile = "";

const auto cmdArgs = app.arguments();

#ifndef ALWAYS_DEBUG_OUTPUT
if (app.arguments().contains("--debug") == false)
if (cmdArgs.contains("--debug") == false)
qInstallMessageHandler(noMessageOutput);
#endif

#ifdef Q_OS_MACOS
// If not running with root privileges, relaunch executable with sudo.
if (getuid() != 0 && app.arguments().contains("--elevated") == false)
if (getuid() != 0 && cmdArgs.contains("--elevated") == false)
{
const auto sudoPrompt = QLatin1String{"%1 requires admin permissions."}.arg(app.applicationDisplayName());
const QLatin1String appleScript{"do shell script \"sudo %1\" with prompt \"%2\" with administrator privileges"};
Expand All @@ -77,7 +80,7 @@ int main(int argc, char *argv[])

qDebug() << "App data: Version:" << BUILD_VERSION ", Build date: " BUILD_DATE;

if (app.arguments().contains("--no-proxy") == false) {
if (cmdArgs.contains("--no-proxy") == false) {
QNetworkProxyQuery npq(QUrl("http://releases.libreelec.tv/"));
QList<QNetworkProxy> listOfProxies = QNetworkProxyFactory::systemProxyForQuery(npq);
if (listOfProxies.size()) {
Expand All @@ -89,9 +92,10 @@ int main(int argc, char *argv[])
Privileges privileges = Privileges();
privileges.Whoami();

QString argFile;
// skip program filename
for (int i=1; i<app.arguments().size(); i++) {
QString file = app.arguments().at(i);
for (int i = 1; i < cmdArgs.size(); i++) {
QString file = cmdArgs.at(i);
QFileInfo checkFile(file);

if (checkFile.exists() && checkFile.isFile()) {
Expand Down

0 comments on commit 28d89c2

Please sign in to comment.