From dc5402349e8c65945d46f1539fd92823a05a391c Mon Sep 17 00:00:00 2001 From: Rachel Powers <508861+Ryex@users.noreply.github.com> Date: Thu, 23 Feb 2023 19:08:35 -0700 Subject: [PATCH] refactor: use UUID toString mode Signed-off-by: Rachel Powers <508861+Ryex@users.noreply.github.com> --- launcher/FileSystem.cpp | 2 +- launcher/InstanceList.cpp | 2 +- launcher/StringUtils.cpp | 14 +++----------- launcher/StringUtils.h | 2 +- 4 files changed, 6 insertions(+), 14 deletions(-) diff --git a/launcher/FileSystem.cpp b/launcher/FileSystem.cpp index 2bd0cf52..714af4a0 100644 --- a/launcher/FileSystem.cpp +++ b/launcher/FileSystem.cpp @@ -442,7 +442,7 @@ void create_link::runPrivileged(const QString& offset) make_link_list(offset); - QString serverName = BuildConfig.LAUNCHER_APP_BINARY_NAME + "_filelink_server" + StringUtils::getRandomAlphaNumeric(8); + QString serverName = BuildConfig.LAUNCHER_APP_BINARY_NAME + "_filelink_server" + StringUtils::getRandomAlphaNumeric(); connect(&m_linkServer, &QLocalServer::newConnection, this, [&](){ diff --git a/launcher/InstanceList.cpp b/launcher/InstanceList.cpp index 179bfb9a..5b33d678 100644 --- a/launcher/InstanceList.cpp +++ b/launcher/InstanceList.cpp @@ -875,7 +875,7 @@ Task* InstanceList::wrapInstanceTask(InstanceTask* task) QString InstanceList::getStagedInstancePath() { - QString key = QUuid::createUuid().toString().remove("{").remove("}"); + QString key = QUuid::createUuid().toString(QUuid::WithoutBraces); QString tempDir = ".LAUNCHER_TEMP/"; QString relPath = FS::PathCombine(tempDir, key); QDir rootPath(m_instDir); diff --git a/launcher/StringUtils.cpp b/launcher/StringUtils.cpp index 93a44d4c..2fa56501 100644 --- a/launcher/StringUtils.cpp +++ b/launcher/StringUtils.cpp @@ -1,6 +1,6 @@ #include "StringUtils.h" -#include +#include /// If you're wondering where these came from exactly, then know you're not the only one =D @@ -77,15 +77,7 @@ int StringUtils::naturalCompare(const QString& s1, const QString& s2, Qt::CaseSe return QString::compare(s1, s2, cs); } -QString StringUtils::getRandomAlphaNumeric(const int length) +QString StringUtils::getRandomAlphaNumeric() { - const QString possibleCharacters("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"); - QString randomString; - for(int i=0; i < length; ++i) - { - int index = QRandomGenerator::global()->bounded(0, possibleCharacters.length()); - QChar nextChar = possibleCharacters.at(index); - randomString.append(nextChar); - } - return randomString; + return QUuid::createUuid().toString(QUuid::Id128); } diff --git a/launcher/StringUtils.h b/launcher/StringUtils.h index 1ba19555..c4a6ab31 100644 --- a/launcher/StringUtils.h +++ b/launcher/StringUtils.h @@ -30,5 +30,5 @@ inline QString fromStdString(string s) int naturalCompare(const QString& s1, const QString& s2, Qt::CaseSensitivity cs); -QString getRandomAlphaNumeric(const int length); +QString getRandomAlphaNumeric(); } // namespace StringUtils