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