diff --git a/launcher/include/utility.h b/launcher/include/utility.h index dcc86b7..eeaca31 100644 --- a/launcher/include/utility.h +++ b/launcher/include/utility.h @@ -11,4 +11,5 @@ namespace Utility QDir stateDirectory(); QString toWindowsPath(const QDir &dir); void printRequest(const QString &type, const QNetworkRequest &request); +void createPathIfNeeded(const QDir &dir); } \ No newline at end of file diff --git a/launcher/src/account.cpp b/launcher/src/account.cpp index 8437914..c41489b 100644 --- a/launcher/src/account.cpp +++ b/launcher/src/account.cpp @@ -14,6 +14,8 @@ #include "launchercore.h" #include "utility.h" +using namespace Qt::StringLiterals; + Account::Account(LauncherCore &launcher, const QString &key, QObject *parent) : QObject(parent) , m_config(key) @@ -222,9 +224,7 @@ void Account::fetchAvatar() } const QString cacheLocation = QStandardPaths::standardLocations(QStandardPaths::CacheLocation)[0] + QStringLiteral("/avatars"); - if (!QDir().exists(cacheLocation)) { - QDir().mkpath(cacheLocation); - } + Utility::createPathIfNeeded(cacheLocation); const QString filename = QStringLiteral("%1/%2.jpg").arg(cacheLocation, lodestoneId()); if (!QFile(filename).exists()) { @@ -242,7 +242,7 @@ void Account::fetchAvatar() connect(reply, &QNetworkReply::finished, [this, filename, reply] { auto document = QJsonDocument::fromJson(reply->readAll()); if (document.isObject()) { - const QNetworkRequest avatarRequest(QUrl(document.object()[QLatin1String("Character")].toObject()[QLatin1String("Avatar")].toString())); + const QNetworkRequest avatarRequest(QUrl(document.object()["Character"_L1].toObject()["Avatar"_L1].toString())); Utility::printRequest(QStringLiteral("GET"), avatarRequest); auto avatarReply = m_launcher.mgr()->get(avatarRequest); @@ -311,9 +311,7 @@ void Account::updateConfig() physis_cfg_set_value(cfgFile, "CutsceneMovieOpening", "1"); auto screenshotDir = m_launcher.settings()->screenshotDir(); - - if (!QDir().exists(screenshotDir)) - QDir().mkpath(screenshotDir); + Utility::createPathIfNeeded(screenshotDir); auto screenshotDirWin = Utility::toWindowsPath(screenshotDir); auto screenshotDirWinStd = screenshotDirWin.toStdString(); diff --git a/launcher/src/accountmanager.cpp b/launcher/src/accountmanager.cpp index 6f32a83..0de7660 100644 --- a/launcher/src/accountmanager.cpp +++ b/launcher/src/accountmanager.cpp @@ -6,6 +6,8 @@ #include +using namespace Qt::StringLiterals; + AccountManager::AccountManager(LauncherCore &launcher, QObject *parent) : QAbstractListModel(parent) , m_launcher(launcher) @@ -16,8 +18,8 @@ void AccountManager::load() { auto config = KSharedConfig::openStateConfig(); for (const auto &id : config->groupList()) { - if (id.contains(QLatin1String("account-"))) { - const QString uuid = QString(id).remove(QLatin1String("account-")); + if (id.contains("account-"_L1)) { + const QString uuid = QString(id).remove("account-"_L1); qInfo(ASTRA_LOG) << "Loading account" << uuid; auto account = new Account(m_launcher, uuid, this); diff --git a/launcher/src/assetupdater.cpp b/launcher/src/assetupdater.cpp index 128a9f7..b62859b 100644 --- a/launcher/src/assetupdater.cpp +++ b/launcher/src/assetupdater.cpp @@ -16,6 +16,8 @@ #include #include +using namespace Qt::StringLiterals; + AssetUpdater::AssetUpdater(Profile &profile, LauncherCore &launcher, QObject *parent) : QObject(parent) , launcher(launcher) @@ -36,14 +38,9 @@ QCoro::Task AssetUpdater::update() m_dalamudAssetDir = m_dalamudDir.absoluteFilePath(QStringLiteral("assets")); m_dalamudRuntimeDir = m_dalamudDir.absoluteFilePath(QStringLiteral("runtime")); - const auto createIfNeeded = [](const QDir &dir) { - if (!QDir().exists(dir.absolutePath())) - QDir().mkpath(dir.absolutePath()); - }; - - createIfNeeded(m_dalamudDir); - createIfNeeded(m_dalamudAssetDir); - createIfNeeded(m_dalamudRuntimeDir); + Utility::createPathIfNeeded(m_dalamudDir); + Utility::createPathIfNeeded(m_dalamudAssetDir); + Utility::createPathIfNeeded(m_dalamudRuntimeDir); if (!co_await checkRemoteDalamudAssetVersion()) { co_return false; @@ -72,8 +69,8 @@ QCoro::Task AssetUpdater::checkRemoteDalamudAssetVersion() const QJsonDocument doc = QJsonDocument::fromJson(reply->readAll()); - m_remoteDalamudAssetVersion = doc.object()[QLatin1String("version")].toInt(); - m_remoteDalamudAssetArray = doc.object()[QLatin1String("assets")].toArray(); + m_remoteDalamudAssetVersion = doc.object()["version"_L1].toInt(); + m_remoteDalamudAssetArray = doc.object()["assets"_L1].toArray(); qInfo(ASTRA_LOG) << "Dalamud asset remote version" << m_remoteDalamudAssetVersion; qInfo(ASTRA_LOG) << "Dalamud asset local version" << m_profile.dalamudAssetVersion(); @@ -110,9 +107,9 @@ QCoro::Task AssetUpdater::checkRemoteDalamudVersion() } const QJsonDocument doc = QJsonDocument::fromJson(reply->readAll()); - m_remoteDalamudVersion = doc[QLatin1String("assemblyVersion")].toString(); - m_remoteRuntimeVersion = doc[QLatin1String("runtimeVersion")].toString(); - m_remoteDalamudDownloadUrl = doc[QLatin1String("downloadUrl")].toString(); + m_remoteDalamudVersion = doc["assemblyVersion"_L1].toString(); + m_remoteRuntimeVersion = doc["runtimeVersion"_L1].toString(); + m_remoteDalamudDownloadUrl = doc["downloadUrl"_L1].toString(); qInfo(ASTRA_LOG) << "Latest available Dalamud version:" << m_remoteDalamudVersion << "local:" << m_profile.dalamudVersion(); qInfo(ASTRA_LOG) << "Latest available NET runtime:" << m_remoteRuntimeVersion; @@ -139,21 +136,19 @@ QCoro::Task AssetUpdater::installDalamudAssets() QFutureSynchronizer synchronizer; for (const auto &assetObject : m_remoteDalamudAssetArray) { - const QNetworkRequest assetRequest(QUrl(assetObject.toObject()[QLatin1String("url")].toString())); + const QNetworkRequest assetRequest(QUrl(assetObject.toObject()["url"_L1].toString())); Utility::printRequest(QStringLiteral("GET"), assetRequest); const auto assetReply = launcher.mgr()->get(assetRequest); const auto future = QtFuture::connect(assetReply, &QNetworkReply::finished).then([this, assetReply, assetObject] { - const QString fileName = assetObject.toObject()[QLatin1String("fileName")].toString(); - const QString dirPath = fileName.left(fileName.lastIndexOf(QLatin1Char('/'))); + const QString fileName = assetObject.toObject()["fileName"_L1].toString(); + const QString dirPath = fileName.left(fileName.lastIndexOf('/'_L1)); const QString path = m_dalamudAssetDir.absoluteFilePath(dirPath); + Utility::createPathIfNeeded(path); - if (!QDir().exists(path)) - QDir().mkpath(path); - - QFile file(m_dalamudAssetDir.absoluteFilePath(assetObject.toObject()[QLatin1String("fileName")].toString())); + QFile file(m_dalamudAssetDir.absoluteFilePath(assetObject.toObject()["fileName"_L1].toString())); file.open(QIODevice::WriteOnly); file.write(assetReply->readAll()); file.close(); diff --git a/launcher/src/gameinstaller.cpp b/launcher/src/gameinstaller.cpp index 241a015..d2bcf6f 100644 --- a/launcher/src/gameinstaller.cpp +++ b/launcher/src/gameinstaller.cpp @@ -28,7 +28,7 @@ void GameInstaller::installGame() { const QDir installDirectory = m_profile.gamePath(); - QNetworkRequest request((QUrl(installerUrl))); + const QNetworkRequest request = QNetworkRequest(QUrl(installerUrl)); auto reply = m_launcher.mgr()->get(request); Utility::printRequest(QStringLiteral("GET"), request); diff --git a/launcher/src/gamerunner.cpp b/launcher/src/gamerunner.cpp index 3264af9..5e934a5 100644 --- a/launcher/src/gamerunner.cpp +++ b/launcher/src/gamerunner.cpp @@ -12,6 +12,8 @@ #include "processlogger.h" #include "utility.h" +using namespace Qt::StringLiterals; + GameRunner::GameRunner(LauncherCore &launcher, QObject *parent) : QObject(parent) , m_launcher(launcher) @@ -75,9 +77,7 @@ void GameRunner::beginDalamudGame(const QString &gameExecutablePath, Profile &pr const QDir dalamudPluginDir = dalamudUserPluginDir.absoluteFilePath(QStringLiteral("installedPlugins")); const QString logDir = stateDir.absoluteFilePath(QStringLiteral("log")); - - if (!QDir().exists(logDir)) - QDir().mkpath(logDir); + Utility::createPathIfNeeded(logDir); const QDir dalamudRuntimeDir = dalamudDir.absoluteFilePath(QStringLiteral("runtime")); const QDir dalamudAssetDir = dalamudDir.absoluteFilePath(QStringLiteral("assets")); @@ -126,11 +126,7 @@ void GameRunner::beginDalamudGame(const QString &gameExecutablePath, Profile &pr QString GameRunner::getGameArgs(const Profile &profile, const LoginAuth &auth) { - struct Argument { - QString key, value; - }; - - QList gameArgs; + QList> gameArgs; gameArgs.push_back({QStringLiteral("DEV.DataPathType"), QString::number(1)}); gameArgs.push_back({QStringLiteral("DEV.UseSqPack"), QString::number(1)}); @@ -142,13 +138,8 @@ QString GameRunner::getGameArgs(const Profile &profile, const LoginAuth &auth) gameArgs.push_back({QStringLiteral("UserPath"), Utility::toWindowsPath(profile.account()->getConfigDir().absolutePath())}); // FIXME: this should belong somewhere else... - if (!QDir().exists(profile.account()->getConfigDir().absolutePath())) { - QDir().mkpath(profile.account()->getConfigDir().absolutePath()); - } - - if (!QDir().exists(profile.winePrefixPath())) { - QDir().mkpath(profile.winePrefixPath()); - } + Utility::createPathIfNeeded(profile.account()->getConfigDir().absolutePath()); + Utility::createPathIfNeeded(profile.winePrefixPath()); if (!auth.lobbyhost.isEmpty()) { gameArgs.push_back({QStringLiteral("DEV.GMServerHost"), auth.frontierHost}); @@ -159,14 +150,14 @@ QString GameRunner::getGameArgs(const Profile &profile, const LoginAuth &auth) } if (profile.account()->license() == Account::GameLicense::WindowsSteam) { - gameArgs.push_back({QStringLiteral("IsSteam"), QStringLiteral("1")}); + gameArgs.push_back({QStringLiteral("IsSteam"), QString::number(1)}); } const QString argFormat = m_launcher.settings()->argumentsEncrypted() ? QStringLiteral(" /%1 =%2") : QStringLiteral(" %1=%2"); QString argJoined; - for (const auto &arg : gameArgs) { - argJoined += argFormat.arg(arg.key, arg.value); + for (const auto &[key, value] : gameArgs) { + argJoined += argFormat.arg(key, value); } return m_launcher.settings()->argumentsEncrypted() ? encryptGameArg(argJoined) : argJoined; @@ -179,11 +170,9 @@ void GameRunner::launchExecutable(const Profile &profile, QProcess *process, con if (needsRegistrySetup) { #if defined(Q_OS_LINUX) || defined(Q_OS_MAC) - if (profile.account()->license() == Account::GameLicense::macOS) { - addRegistryKey(profile, QStringLiteral("HKEY_CURRENT_USER\\Software\\Wine"), QStringLiteral("HideWineExports"), QStringLiteral("0")); - } else { - addRegistryKey(profile, QStringLiteral("HKEY_CURRENT_USER\\Software\\Wine"), QStringLiteral("HideWineExports"), QStringLiteral("1")); - } + // FFXIV detects this as a "macOS" build by checking if Wine shows up + const int value = profile.account()->license() == Account::GameLicense::macOS ? 0 : 1; + addRegistryKey(profile, QStringLiteral("HKEY_CURRENT_USER\\Software\\Wine"), QStringLiteral("HideWineExports"), QString::number(value)); #endif } @@ -249,16 +238,16 @@ void GameRunner::launchExecutable(const Profile &profile, QProcess *process, con } QString dirName = fileInfo.fileName(); - if (dirName.contains(QLatin1String("Proton"))) { - if (dirName == QLatin1String("Proton - Experimental")) { + if (dirName.contains("Proton"_L1)) { + if (dirName == "Proton - Experimental"_L1) { highestVersion.setPath(dir); break; } else { - QString version = dirName.remove(QLatin1String("Proton ")); + QString version = dirName.remove("Proton "_L1); // Exclude "BattlEye Runtime" and other unrelated things - if (version.contains(QLatin1Char('.'))) { + if (version.contains('.'_L1)) { // TODO: better error handling (they might never be invalid, but better safe than sorry) - QStringList parts = version.split(QLatin1Char('.')); + QStringList parts = version.split('.'_L1); int versionNum = parts[0].toInt(); // TODO: doesn't handle minor versions, not like they really exist anymore anyway @@ -288,10 +277,10 @@ void GameRunner::launchExecutable(const Profile &profile, QProcess *process, con env.insert(QStringLiteral("DYLD_FALLBACK_LIBRARY_PATH"), xivLibPath); env.insert(QStringLiteral("DYLD_VERSIONED_LIBRARY_PATH"), xivLibPath); - env.insert(QStringLiteral("MVK_CONFIG_FULL_IMAGE_VIEW_SWIZZLE"), QStringLiteral("1")); - env.insert(QStringLiteral("MVK_CONFIG_RESUME_LOST_DEVICE"), QStringLiteral("1")); - env.insert(QStringLiteral("MVK_ALLOW_METAL_FENCES"), QStringLiteral("1")); - env.insert(QStringLiteral("MVK_CONFIG_USE_METAL_ARGUMENT_BUFFERS"), QStringLiteral("1")); + env.insert(QStringLiteral("MVK_CONFIG_FULL_IMAGE_VIEW_SWIZZLE"), QString::number(1)); + env.insert(QStringLiteral("MVK_CONFIG_RESUME_LOST_DEVICE"), QString::number(1)); + env.insert(QStringLiteral("MVK_ALLOW_METAL_FENCES"), QString::number(1)); + env.insert(QStringLiteral("MVK_CONFIG_USE_METAL_ARGUMENT_BUFFERS"), QString::number(1)); } #if defined(FLATPAK) diff --git a/launcher/src/launchercore.cpp b/launcher/src/launchercore.cpp index 136592c..d251053 100755 --- a/launcher/src/launchercore.cpp +++ b/launcher/src/launchercore.cpp @@ -20,6 +20,8 @@ #include "squareenixlogin.h" #include "utility.h" +using namespace Qt::StringLiterals; + LauncherCore::LauncherCore() : QObject() { @@ -42,7 +44,7 @@ LauncherCore::LauncherCore() } // set default profile, if found - if (auto profile = m_profileManager->getProfileByUUID(m_settings->currentProfile()); profile != nullptr) { + if (auto profile = m_profileManager->getProfileByUUID(m_settings->currentProfile())) { setCurrentProfile(profile); } @@ -109,7 +111,7 @@ CompatibilityToolInstaller *LauncherCore::createCompatInstaller() void LauncherCore::clearAvatarCache() { - const auto cacheLocation = QStandardPaths::standardLocations(QStandardPaths::CacheLocation)[0] + QStringLiteral("/avatars"); + const QString cacheLocation = QStandardPaths::standardLocations(QStandardPaths::CacheLocation)[0] + QStringLiteral("/avatars"); if (QDir(cacheLocation).exists()) { QDir(cacheLocation).removeRecursively(); } @@ -153,19 +155,17 @@ void LauncherCore::setCurrentProfile(Profile *profile) void LauncherCore::setAutoLoginProfile(Profile *profile) { - if (profile == nullptr) { + if (profile != nullptr) { + auto uuid = profile->uuid(); + if (uuid != m_settings->config()->autoLoginProfile()) { + m_settings->config()->setAutoLoginProfile(uuid); + } + } else { m_settings->config()->setAutoLoginProfile({}); - m_settings->config()->save(); - Q_EMIT autoLoginProfileChanged(); - return; } - auto uuid = profile->uuid(); - if (uuid != m_settings->config()->autoLoginProfile()) { - m_settings->config()->setAutoLoginProfile(uuid); - m_settings->config()->save(); - Q_EMIT autoLoginProfileChanged(); - } + m_settings->config()->save(); + Q_EMIT autoLoginProfileChanged(); } void LauncherCore::buildRequest(const Profile &settings, QNetworkRequest &request) @@ -317,41 +317,35 @@ QCoro::Task<> LauncherCore::fetchNews() const auto parseNews = [](QJsonObject object) -> News { News news; - news.date = QDateTime::fromString(object[QLatin1String("date")].toString(), Qt::DateFormat::ISODate); - news.id = object[QLatin1String("id")].toString(); - news.tag = object[QLatin1String("tag")].toString(); - news.title = object[QLatin1String("title")].toString(); + news.date = QDateTime::fromString(object["date"_L1].toString(), Qt::DateFormat::ISODate); + news.id = object["id"_L1].toString(); + news.tag = object["tag"_L1].toString(); + news.title = object["title"_L1].toString(); - if (object[QLatin1String("url")].toString().isEmpty()) { + if (object["url"_L1].toString().isEmpty()) { news.url = QUrl(QStringLiteral("https://na.finalfantasyxiv.com/lodestone/news/detail/%1").arg(news.id)); } else { - news.url = QUrl(object[QLatin1String("url")].toString()); + news.url = QUrl(object["url"_L1].toString()); } return news; }; - for (auto bannerObject : document.object()[QLatin1String("banner")].toArray()) { - auto banner = Banner(); - banner.link = QUrl(bannerObject.toObject()[QLatin1String("link")].toString()); - banner.bannerImage = QUrl(bannerObject.toObject()[QLatin1String("lsb_banner")].toString()); - - headline->banners.push_back(banner); + for (const auto bannerObject : document.object()["banner"_L1].toArray()) { + headline->banners.push_back( + {.link = QUrl(bannerObject.toObject()["link"_L1].toString()), .bannerImage = QUrl(bannerObject.toObject()["lsb_banner"_L1].toString())}); } - for (auto newsObject : document.object()[QLatin1String("news")].toArray()) { - auto news = parseNews(newsObject.toObject()); - headline->news.push_back(news); + for (const auto newsObject : document.object()["news"_L1].toArray()) { + headline->news.push_back(parseNews(newsObject.toObject())); } - for (auto pinnedObject : document.object()[QLatin1String("pinned")].toArray()) { - auto pinned = parseNews(pinnedObject.toObject()); - headline->pinned.push_back(pinned); + for (const auto pinnedObject : document.object()["pinned"_L1].toArray()) { + headline->pinned.push_back(parseNews(pinnedObject.toObject())); } - for (auto pinnedObject : document.object()[QLatin1String("topics")].toArray()) { - auto pinned = parseNews(pinnedObject.toObject()); - headline->topics.push_back(pinned); + for (const auto pinnedObject : document.object()["topics"_L1].toArray()) { + headline->topics.push_back(parseNews(pinnedObject.toObject())); } m_headline = headline; diff --git a/launcher/src/logger.cpp b/launcher/src/logger.cpp index 2f71560..e423b59 100644 --- a/launcher/src/logger.cpp +++ b/launcher/src/logger.cpp @@ -39,10 +39,7 @@ public: const QString filename{QStringLiteral("astra.log")}; const QDir logDirectory = Utility::stateDirectory().absoluteFilePath(QStringLiteral("log")); - - if (!logDirectory.exists()) { - QDir().mkpath(logDirectory.absolutePath()); - } + Utility::createPathIfNeeded(logDirectory); // Sort them from highest to lowest (4, 3, 2, 1, 0) auto existingLogEntries = logDirectory.entryList({filename + QStringLiteral(".*")}); diff --git a/launcher/src/main.cpp b/launcher/src/main.cpp index bfa2b8c..7fcaa76 100755 --- a/launcher/src/main.cpp +++ b/launcher/src/main.cpp @@ -19,6 +19,8 @@ #include "physis_logger.h" #include "sapphirelogin.h" +using namespace Qt::StringLiterals; + int main(int argc, char *argv[]) { initializeLogging(); @@ -98,7 +100,7 @@ int main(int argc, char *argv[]) const QStringList args = parser.positionalArguments(); // Steam tries to use as a compatibility tool, running installation scripts (like DirectX), so try to ignore it. - if (!args.empty() && !args[0].contains(QLatin1String("ffxivboot.exe"))) { + if (!args.empty() && !args[0].contains("ffxivboot.exe"_L1)) { return 0; } } diff --git a/launcher/src/patcher.cpp b/launcher/src/patcher.cpp index 92fb4b0..d456c71 100644 --- a/launcher/src/patcher.cpp +++ b/launcher/src/patcher.cpp @@ -18,6 +18,8 @@ #include "patchlist.h" #include "utility.h" +using namespace Qt::StringLiterals; + Patcher::Patcher(LauncherCore &launcher, const QString &baseDirectory, BootData &bootData, QObject *parent) : QObject(parent) , m_baseDirectory(baseDirectory) @@ -70,9 +72,7 @@ QCoro::Task Patcher::patch(const PatchList &patchList) const QString filename = QStringLiteral("%1.patch").arg(patch.name); const QDir repositoryDir = m_patchesDir.absoluteFilePath(patch.repository); - - if (!QDir().exists(repositoryDir.absolutePath())) - QDir().mkpath(repositoryDir.absolutePath()); + Utility::createPathIfNeeded(repositoryDir); const QString patchPath = repositoryDir.absoluteFilePath(filename); @@ -191,7 +191,7 @@ void Patcher::processPatch(const QueuedPatch &patch) if (isBoot()) { verFilePath = m_baseDirectory + QStringLiteral("/ffxivboot.ver"); } else { - if (patch.repository == QLatin1String("game")) { + if (patch.repository == "game"_L1) { verFilePath = m_baseDirectory + QStringLiteral("/ffxivgame.ver"); } else { verFilePath = m_baseDirectory + QStringLiteral("/sqpack/") + patch.repository + QStringLiteral("/") + patch.repository + QStringLiteral(".ver"); diff --git a/launcher/src/patchlist.cpp b/launcher/src/patchlist.cpp index 1ba9661..8bba1be 100644 --- a/launcher/src/patchlist.cpp +++ b/launcher/src/patchlist.cpp @@ -4,12 +4,14 @@ #include "patchlist.h" #include "astra_patcher_log.h" +using namespace Qt::StringLiterals; + PatchList::PatchList(const QString &patchList) { const QStringList parts = patchList.split(QStringLiteral("\r\n")); for (int i = 5; i < parts.size() - 2; i++) { - const QStringList patchParts = parts[i].split(QLatin1Char('\t')); + const QStringList patchParts = parts[i].split('\t'_L1); const int length = patchParts[0].toInt(); @@ -17,10 +19,10 @@ PatchList::PatchList(const QString &patchList) const long hashBlockSize = patchParts.size() == 9 ? patchParts[6].toLong() : 0; const QString &name = version; - const QStringList hashes = patchParts.size() == 9 ? (patchParts[7].split(QLatin1Char(','))) : QStringList(); + const QStringList hashes = patchParts.size() == 9 ? (patchParts[7].split(','_L1)) : QStringList(); const QString &url = patchParts[patchParts.size() == 9 ? 8 : 5]; - auto url_parts = url.split(QLatin1Char('/')); + auto url_parts = url.split('/'_L1); const QString repository = url_parts[url_parts.size() - 3]; m_patches.push_back( diff --git a/launcher/src/profile.cpp b/launcher/src/profile.cpp index c07881d..856918e 100644 --- a/launcher/src/profile.cpp +++ b/launcher/src/profile.cpp @@ -13,6 +13,8 @@ #include "launchercore.h" #include "profileconfig.h" +using namespace Qt::StringLiterals; + Profile::Profile(LauncherCore &launcher, const QString &key, QObject *parent) : QObject(parent) , m_uuid(key) @@ -42,13 +44,13 @@ void Profile::readDalamudInfo() QJsonDocument doc = QJsonDocument::fromJson(depsJson.readAll()); QString versionString; - for (const auto &target : doc[QLatin1String("targets")].toObject().keys()) { - if (target.contains(QLatin1String(".NETCoreApp"))) { - versionString = doc[QLatin1String("targets")].toObject()[target].toObject().keys().filter(QStringLiteral("Dalamud/"))[0]; + for (const auto &target : doc["targets"_L1].toObject().keys()) { + if (target.contains(".NETCoreApp"_L1)) { + versionString = doc["targets"_L1].toObject()[target].toObject().keys().filter(QStringLiteral("Dalamud/"))[0]; } } - m_dalamudVersion = versionString.remove(QLatin1String("Dalamud/")); + m_dalamudVersion = versionString.remove("Dalamud/"_L1); qInfo(ASTRA_LOG) << "Dalamud version:" << m_dalamudVersion; } diff --git a/launcher/src/profilemanager.cpp b/launcher/src/profilemanager.cpp index d8633d8..65d73e3 100644 --- a/launcher/src/profilemanager.cpp +++ b/launcher/src/profilemanager.cpp @@ -8,6 +8,8 @@ #include #include +using namespace Qt::StringLiterals; + ProfileManager::ProfileManager(LauncherCore &launcher, QObject *parent) : QAbstractListModel(parent) , m_launcher(launcher) @@ -91,8 +93,8 @@ void ProfileManager::load() { auto config = KSharedConfig::openStateConfig(); for (const auto &id : config->groupList()) { - if (id.contains(QLatin1String("profile-"))) { - const QString uuid = QString(id).remove(QLatin1String("profile-")); + if (id.contains("profile-"_L1)) { + const QString uuid = QString(id).remove("profile-"_L1); qInfo(ASTRA_LOG) << "Loading profile" << uuid; auto profile = new Profile(m_launcher, uuid, this); insertProfile(profile); diff --git a/launcher/src/sapphirelogin.cpp b/launcher/src/sapphirelogin.cpp index 574f5db..1b39c6c 100644 --- a/launcher/src/sapphirelogin.cpp +++ b/launcher/src/sapphirelogin.cpp @@ -10,6 +10,8 @@ #include #include +using namespace Qt::StringLiterals; + SapphireLogin::SapphireLogin(LauncherCore &window, QObject *parent) : QObject(parent) , m_launcher(window) @@ -37,9 +39,9 @@ QCoro::Task> SapphireLogin::login(const QString &lobbyU const QJsonDocument document = QJsonDocument::fromJson(reply->readAll()); if (!document.isEmpty()) { LoginAuth auth; - auth.SID = document[QLatin1String("sId")].toString(); - auth.lobbyhost = document[QLatin1String("lobbyHost")].toString(); - auth.frontierHost = document[QLatin1String("frontierHost")].toString(); + auth.SID = document["sId"_L1].toString(); + auth.lobbyhost = document["lobbyHost"_L1].toString(); + auth.frontierHost = document["frontierHost"_L1].toString(); auth.region = 3; co_return auth; @@ -64,9 +66,9 @@ void SapphireLogin::registerAccount(const QString &lobbyUrl, const LoginInformat const QJsonDocument document = QJsonDocument::fromJson(reply->readAll()); LoginAuth auth; - auth.SID = document[QLatin1String("sId")].toString(); - auth.lobbyhost = document[QLatin1String("lobbyHost")].toString(); - auth.frontierHost = document[QLatin1String("frontierHost")].toString(); + auth.SID = document["sId"_L1].toString(); + auth.lobbyhost = document["lobbyHost"_L1].toString(); + auth.frontierHost = document["frontierHost"_L1].toString(); auth.region = 3; // m_launcher.launchGame(*info.profile, auth); diff --git a/launcher/src/squareenixlogin.cpp b/launcher/src/squareenixlogin.cpp index ece309b..75b4391 100644 --- a/launcher/src/squareenixlogin.cpp +++ b/launcher/src/squareenixlogin.cpp @@ -18,6 +18,8 @@ #include "launchercore.h" #include "utility.h" +using namespace Qt::StringLiterals; + SquareEnixLogin::SquareEnixLogin(LauncherCore &window, QObject *parent) : QObject(parent) , m_launcher(window) @@ -69,7 +71,7 @@ QCoro::Task SquareEnixLogin::checkGateStatus() co_await reply; const QJsonDocument document = QJsonDocument::fromJson(reply->readAll()); - const bool isGateOpen = !document.isEmpty() && document.object()[QLatin1String("status")].toInt() != 0; + const bool isGateOpen = !document.isEmpty() && document.object()["status"_L1].toInt() != 0; if (isGateOpen) { qInfo(ASTRA_LOG) << "Gate is open!"; @@ -87,7 +89,7 @@ QCoro::Task<> SquareEnixLogin::checkBootUpdates() qInfo(ASTRA_LOG) << "Checking for updates to boot components..."; QString formattedDate = QDateTime::currentDateTimeUtc().toString(QStringLiteral("yyyy-MM-dd-HH-mm")); - formattedDate[15] = QLatin1Char('0'); + formattedDate[15] = '0'_L1; const QUrlQuery query{{QStringLiteral("time"), formattedDate}}; @@ -134,18 +136,18 @@ QCoro::Task> SquareEnixLogin::getStor // en is always used to the top url query.addQueryItem(QStringLiteral("lng"), QStringLiteral("en")); // for some reason, we always use region 3. the actual region is acquired later - query.addQueryItem(QStringLiteral("rgn"), QStringLiteral("3")); - query.addQueryItem(QStringLiteral("isft"), m_info->profile->account()->isFreeTrial() ? QStringLiteral("1") : QStringLiteral("0")); - query.addQueryItem(QStringLiteral("cssmode"), QStringLiteral("1")); - query.addQueryItem(QStringLiteral("isnew"), QStringLiteral("1")); - query.addQueryItem(QStringLiteral("launchver"), QStringLiteral("3")); + query.addQueryItem(QStringLiteral("rgn"), QString::number(3)); + query.addQueryItem(QStringLiteral("isft"), QString::number(m_info->profile->account()->isFreeTrial() ? 1 : 0)); + query.addQueryItem(QStringLiteral("cssmode"), QString::number(1)); + query.addQueryItem(QStringLiteral("isnew"), QString::number(1)); + query.addQueryItem(QStringLiteral("launchver"), QString::number(3)); if (m_info->profile->account()->license() == Account::GameLicense::WindowsSteam) { - query.addQueryItem(QStringLiteral("issteam"), QStringLiteral("1")); + query.addQueryItem(QStringLiteral("issteam"), QString::number(1)); // TODO: get steam ticket information from steam api - query.addQueryItem(QStringLiteral("session_ticket"), QStringLiteral("1")); - query.addQueryItem(QStringLiteral("ticket_size"), QStringLiteral("1")); + query.addQueryItem(QStringLiteral("session_ticket"), QString::number(1)); + query.addQueryItem(QStringLiteral("ticket_size"), QString::number(1)); } QUrl url; @@ -228,10 +230,10 @@ QCoro::Task SquareEnixLogin::loginOAuth() const QRegularExpression re(QStringLiteral(R"lit(window.external.user\("login=auth,ok,(?.*)\);)lit")); const QRegularExpressionMatch match = re.match(str); if (match.hasMatch()) { - const auto parts = match.captured(1).split(QLatin1Char(',')); + const auto parts = match.captured(1).split(','_L1); - const bool terms = parts[3] == QLatin1String("1"); - const bool playable = parts[9] == QLatin1String("1"); + const bool terms = parts[3] == "1"_L1; + const bool playable = parts[9] == "1"_L1; if (!playable) { Q_EMIT m_launcher.loginError(i18n("Your account is unplayable. Check that you have the correct license, and a valid subscription.")); diff --git a/launcher/src/utility.cpp b/launcher/src/utility.cpp index 138441d..63211ee 100644 --- a/launcher/src/utility.cpp +++ b/launcher/src/utility.cpp @@ -6,6 +6,8 @@ #include +using namespace Qt::StringLiterals; + QDir Utility::stateDirectory() { if (qEnvironmentVariableIsSet("XDG_STATE_HOME")) { @@ -20,10 +22,17 @@ QDir Utility::stateDirectory() QString Utility::toWindowsPath(const QDir &dir) { - return QStringLiteral("Z:") + dir.absolutePath().replace(QLatin1Char('/'), QLatin1Char('\\')); + return QStringLiteral("Z:") + dir.absolutePath().replace('/'_L1, '\\'_L1); } void Utility::printRequest(const QString &type, const QNetworkRequest &request) { qDebug(ASTRA_HTTP) << type.toUtf8().constData() << request.url().toDisplayString(); } + +void Utility::createPathIfNeeded(const QDir &dir) +{ + if (!QDir().exists(dir.absolutePath())) { + QDir().mkpath(dir.absolutePath()); + } +} \ No newline at end of file