From 037b0d71902667dcacf737a17741b39cbb399a56 Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Wed, 16 Feb 2022 17:24:58 +0100 Subject: [PATCH 1/2] fix: improve code readability in Application.cpp --- launcher/Application.cpp | 54 ++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/launcher/Application.cpp b/launcher/Application.cpp index a3d6216e..2165dd2e 100644 --- a/launcher/Application.cpp +++ b/launcher/Application.cpp @@ -285,12 +285,29 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv) return; } } + m_instanceIdToLaunch = args["launch"].toString(); m_serverToJoin = args["server"].toString(); m_profileToUse = args["profile"].toString(); m_liveCheck = args["alive"].toBool(); m_zipToImport = args["import"].toUrl(); + // error if --launch is missing with --server + if(m_instanceIdToLaunch.isEmpty() && !m_serverToJoin.isEmpty()) + { + std::cerr << "--server can only be used in combination with --launch!" << std::endl; + m_status = Application::Failed; + return; + } + + // error if --launch is missing with --account + if(m_instanceIdToLaunch.isEmpty() && !m_profileToUse.isEmpty()) + { + std::cerr << "--account can only be used in combination with --launch!" << std::endl; + m_status = Application::Failed; + return; + } + QString origcwdPath = QDir::currentPath(); QString binPath = applicationDirPath(); QString adjustedBy; @@ -359,20 +376,6 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv) return; } - if(m_instanceIdToLaunch.isEmpty() && !m_serverToJoin.isEmpty()) - { - std::cerr << "--server can only be used in combination with --launch!" << std::endl; - m_status = Application::Failed; - return; - } - - if(m_instanceIdToLaunch.isEmpty() && !m_profileToUse.isEmpty()) - { - std::cerr << "--account can only be used in combination with --launch!" << std::endl; - m_status = Application::Failed; - return; - } - #if defined(Q_OS_MAC) // move user data to new location if on macOS and it still exists in Contents/MacOS QDir fi(applicationDirPath()); @@ -566,26 +569,23 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv) qDebug() << "<> Paths set."; } - do // once + if(m_liveCheck) { - if(m_liveCheck) + QFile check(liveCheckFile); + if(check.open(QIODevice::WriteOnly | QIODevice::Truncate)) { - QFile check(liveCheckFile); - if(!check.open(QIODevice::WriteOnly | QIODevice::Truncate)) - { - qWarning() << "Could not open" << liveCheckFile << "for writing!"; - break; - } auto payload = appID.toString().toUtf8(); - if(check.write(payload) != payload.size()) + if(check.write(payload) == payload.size()) { + check.close(); + } else { qWarning() << "Could not write into" << liveCheckFile << "!"; - check.remove(); - break; + check.remove(); // also closes file! } - check.close(); + } else { + qWarning() << "Could not open" << liveCheckFile << "for writing!"; } - } while(false); + } // Initialize application settings { From 6b4469c6cce517dabe967c12b30648e0c41f12d5 Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Thu, 17 Feb 2022 15:29:09 +0100 Subject: [PATCH 2/2] fix: combine errors if --launch is missing --- launcher/Application.cpp | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/launcher/Application.cpp b/launcher/Application.cpp index 2165dd2e..e916dcf7 100644 --- a/launcher/Application.cpp +++ b/launcher/Application.cpp @@ -292,18 +292,10 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv) m_liveCheck = args["alive"].toBool(); m_zipToImport = args["import"].toUrl(); - // error if --launch is missing with --server - if(m_instanceIdToLaunch.isEmpty() && !m_serverToJoin.isEmpty()) + // error if --launch is missing with --server or --profile + if((!m_serverToJoin.isEmpty() || !m_profileToUse.isEmpty()) && m_instanceIdToLaunch.isEmpty()) { - std::cerr << "--server can only be used in combination with --launch!" << std::endl; - m_status = Application::Failed; - return; - } - - // error if --launch is missing with --account - if(m_instanceIdToLaunch.isEmpty() && !m_profileToUse.isEmpty()) - { - std::cerr << "--account can only be used in combination with --launch!" << std::endl; + std::cerr << "--server and --profile can only be used in combination with --launch!" << std::endl; m_status = Application::Failed; return; }