fix: improve code readability in Application.cpp

This commit is contained in:
Sefa Eyeoglu 2022-02-16 17:24:58 +01:00
parent 2cd837896d
commit 037b0d7190
No known key found for this signature in database
GPG Key ID: C10411294912A422

View File

@ -285,12 +285,29 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
return; return;
} }
} }
m_instanceIdToLaunch = args["launch"].toString(); m_instanceIdToLaunch = args["launch"].toString();
m_serverToJoin = args["server"].toString(); m_serverToJoin = args["server"].toString();
m_profileToUse = args["profile"].toString(); m_profileToUse = args["profile"].toString();
m_liveCheck = args["alive"].toBool(); m_liveCheck = args["alive"].toBool();
m_zipToImport = args["import"].toUrl(); 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 origcwdPath = QDir::currentPath();
QString binPath = applicationDirPath(); QString binPath = applicationDirPath();
QString adjustedBy; QString adjustedBy;
@ -359,20 +376,6 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
return; 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) #if defined(Q_OS_MAC)
// move user data to new location if on macOS and it still exists in Contents/MacOS // move user data to new location if on macOS and it still exists in Contents/MacOS
QDir fi(applicationDirPath()); QDir fi(applicationDirPath());
@ -566,26 +569,23 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
qDebug() << "<> Paths set."; qDebug() << "<> Paths set.";
} }
do // once
{
if(m_liveCheck) if(m_liveCheck)
{ {
QFile check(liveCheckFile); QFile check(liveCheckFile);
if(!check.open(QIODevice::WriteOnly | QIODevice::Truncate)) if(check.open(QIODevice::WriteOnly | QIODevice::Truncate))
{ {
qWarning() << "Could not open" << liveCheckFile << "for writing!";
break;
}
auto payload = appID.toString().toUtf8(); auto payload = appID.toString().toUtf8();
if(check.write(payload) != payload.size()) if(check.write(payload) == payload.size())
{ {
qWarning() << "Could not write into" << liveCheckFile << "!";
check.remove();
break;
}
check.close(); check.close();
} else {
qWarning() << "Could not write into" << liveCheckFile << "!";
check.remove(); // also closes file!
}
} else {
qWarning() << "Could not open" << liveCheckFile << "for writing!";
}
} }
} while(false);
// Initialize application settings // Initialize application settings
{ {