Re-randomise key until it does not collide

Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
This commit is contained in:
TheKodeToad 2024-02-24 13:38:19 +00:00
parent aac6fea724
commit 6a9f5540d3
No known key found for this signature in database
GPG Key ID: 5E39D70B4C93C38E

View File

@ -934,22 +934,21 @@ Task* InstanceList::wrapInstanceTask(InstanceTask* task)
QString InstanceList::getStagedInstancePath() QString InstanceList::getStagedInstancePath()
{ {
QString tempDir = ".LAUNCHER_TEMP/"; const QString tempRoot = FS::PathCombine(m_instDir, ".LAUNCHER_TEMP");
auto tempPath = FS::PathCombine(m_instDir, tempDir);
if (QFileInfo::exists(tempPath)) { QString result;
FS::deletePath(tempPath); // clean the path to prevent any collisions
} do {
QString key = QUuid::createUuid().toString(QUuid::WithoutBraces).left(6); // reduce the size from 36 to 6 const QString key = QUuid::createUuid().toString(QUuid::Id128).left(6);
QString relPath = FS::PathCombine(tempDir, key); result = FS::PathCombine(tempRoot, key);
QDir rootPath(m_instDir); } while (QFileInfo::exists(result));
auto path = FS::PathCombine(m_instDir, relPath);
if (!rootPath.mkpath(relPath)) { if (!QDir::current().mkpath(result))
return QString(); return {};
}
#ifdef Q_OS_WIN32 #ifdef Q_OS_WIN32
SetFileAttributesA(tempPath.toStdString().c_str(), FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_NOT_CONTENT_INDEXED); SetFileAttributesA(tempPath.toStdString().c_str(), FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_NOT_CONTENT_INDEXED);
#endif #endif
return path; return result;
} }
bool InstanceList::commitStagedInstance(const QString& path, bool InstanceList::commitStagedInstance(const QString& path,