diff options
author | flow <flowlnlnln@gmail.com> | 2022-07-30 20:40:25 -0300 |
---|---|---|
committer | flow <flowlnlnln@gmail.com> | 2022-09-12 13:07:23 -0300 |
commit | be3fae65113023d77d2df59f9fd765a4c83f07f2 (patch) | |
tree | 64d99f9bbc66dfcad56d5a56d4ffd53e40ac152c | |
parent | 5932f36285ebf3ec7d852db1b80630589224eccc (diff) | |
download | PrismLauncher-be3fae65113023d77d2df59f9fd765a4c83f07f2.tar.gz PrismLauncher-be3fae65113023d77d2df59f9fd765a4c83f07f2.tar.bz2 PrismLauncher-be3fae65113023d77d2df59f9fd765a4c83f07f2.zip |
refactor: use std::filesystem for path deletion
Signed-off-by: flow <flowlnlnln@gmail.com>
-rw-r--r-- | launcher/FileSystem.cpp | 44 |
1 files changed, 5 insertions, 39 deletions
diff --git a/launcher/FileSystem.cpp b/launcher/FileSystem.cpp index e4db6d35..c1baf20a 100644 --- a/launcher/FileSystem.cpp +++ b/launcher/FileSystem.cpp @@ -179,49 +179,15 @@ bool copy::operator()(const QString& offset) bool deletePath(QString path) { - bool OK = true; - QFileInfo finfo(path); - if (finfo.isFile()) { - return QFile::remove(path); - } + std::error_code err; - QDir dir(path); + std::filesystem::remove_all(path.toStdString(), err); - if (!dir.exists()) { - return OK; + if (err) { + qWarning() << "Failed to remove files:" << QString::fromStdString(err.message()); } - auto allEntries = dir.entryInfoList(QDir::NoDotAndDotDot | QDir::System | QDir::Hidden | QDir::AllDirs | QDir::Files, QDir::DirsFirst); - for (auto& info : allEntries) { -#if defined Q_OS_WIN32 - QString nativePath = QDir::toNativeSeparators(info.absoluteFilePath()); - auto wString = nativePath.toStdWString(); - DWORD dwAttrs = GetFileAttributesW(wString.c_str()); - // Windows: check for junctions, reparse points and other nasty things of that sort - if (dwAttrs & FILE_ATTRIBUTE_REPARSE_POINT) { - if (info.isFile()) { - OK &= QFile::remove(info.absoluteFilePath()); - } else if (info.isDir()) { - OK &= dir.rmdir(info.absoluteFilePath()); - } - } -#else - // We do not trust Qt with reparse points, but do trust it with unix symlinks. - if (info.isSymLink()) { - OK &= QFile::remove(info.absoluteFilePath()); - } -#endif - else if (info.isDir()) { - OK &= deletePath(info.absoluteFilePath()); - } else if (info.isFile()) { - OK &= QFile::remove(info.absoluteFilePath()); - } else { - OK = false; - qCritical() << "Delete ERROR: Unknown filesystem object:" << info.absoluteFilePath(); - } - } - OK &= dir.rmdir(dir.absolutePath()); - return OK; + return err.value() == 0; } bool trash(QString path, QString *pathInTrash = nullptr) |