diff options
author | flow <flowlnlnln@gmail.com> | 2022-08-07 08:50:39 -0300 |
---|---|---|
committer | flow <flowlnlnln@gmail.com> | 2022-09-12 13:07:23 -0300 |
commit | 1cf949226e786e827de2d477516c5a14ecfbd6bd (patch) | |
tree | ddd1e61045ebdff2a82288bc32a09aa4bde7fe24 /launcher/FileSystem.cpp | |
parent | be3fae65113023d77d2df59f9fd765a4c83f07f2 (diff) | |
download | PrismLauncher-1cf949226e786e827de2d477516c5a14ecfbd6bd.tar.gz PrismLauncher-1cf949226e786e827de2d477516c5a14ecfbd6bd.tar.bz2 PrismLauncher-1cf949226e786e827de2d477516c5a14ecfbd6bd.zip |
refactor: use std::filesystem for overrides
Signed-off-by: flow <flowlnlnln@gmail.com>
Diffstat (limited to 'launcher/FileSystem.cpp')
-rw-r--r-- | launcher/FileSystem.cpp | 41 |
1 files changed, 9 insertions, 32 deletions
diff --git a/launcher/FileSystem.cpp b/launcher/FileSystem.cpp index c1baf20a..fefa6dd1 100644 --- a/launcher/FileSystem.cpp +++ b/launcher/FileSystem.cpp @@ -403,47 +403,24 @@ bool createShortCut(QString location, QString dest, QStringList args, QString na #endif } -QStringList listFolderPaths(QDir root) -{ - auto createAbsPath = [](QFileInfo const& entry) { return FS::PathCombine(entry.path(), entry.fileName()); }; - - QStringList entries; - - root.refresh(); - for (auto entry : root.entryInfoList(QDir::Filter::Files)) { - entries.append(createAbsPath(entry)); - } - - for (auto entry : root.entryInfoList(QDir::Filter::AllDirs | QDir::Filter::NoDotAndDotDot)) { - entries.append(listFolderPaths(createAbsPath(entry))); - } - - return entries; -} - bool overrideFolder(QString overwritten_path, QString override_path) { + using copy_opts = std::filesystem::copy_options; + if (!FS::ensureFolderPathExists(overwritten_path)) return false; - QStringList paths_to_override; - QDir root_override (override_path); - for (auto file : listFolderPaths(root_override)) { - QString destination = file; - destination.replace(override_path, overwritten_path); - ensureFilePathExists(destination); + std::error_code err; + std::filesystem::copy_options opt = copy_opts::recursive | copy_opts::overwrite_existing; - qDebug() << QString("Applying override %1 in %2").arg(file, destination); + std::filesystem::copy(override_path.toStdString(), overwritten_path.toStdString(), opt, err); - if (QFile::exists(destination)) - QFile::remove(destination); - if (!QFile::rename(file, destination)) { - qCritical() << QString("Failed to apply override from %1 to %2").arg(file, destination); - return false; - } + if (err) { + qCritical() << QString("Failed to apply override from %1 to %2").arg(override_path, overwritten_path); + qCritical() << "Reason:" << QString::fromStdString(err.message()); } - return true; + return err.value() == 0; } } |