aboutsummaryrefslogtreecommitdiff
path: root/launcher/FileSystem.cpp
diff options
context:
space:
mode:
authorSefa Eyeoglu <contact@scrumplex.net>2022-06-12 10:50:57 +0200
committerGitHub <noreply@github.com>2022-06-12 10:50:57 +0200
commitc4f2e3a95584d9c50544a978a83650f8f83551fa (patch)
tree0a9edd553ebe4de68a671567e69e4c7e8c1ead9e /launcher/FileSystem.cpp
parent91301ec7fe5c6d78d7143be3790bd0bbf8c93e91 (diff)
parent37160f973f1d2fed450f40f38a55b8445787c4bd (diff)
downloadPrismLauncher-c4f2e3a95584d9c50544a978a83650f8f83551fa.tar.gz
PrismLauncher-c4f2e3a95584d9c50544a978a83650f8f83551fa.tar.bz2
PrismLauncher-c4f2e3a95584d9c50544a978a83650f8f83551fa.zip
Merge pull request #771 from flowln/modrinth_multiple_downloads
Diffstat (limited to 'launcher/FileSystem.cpp')
-rw-r--r--launcher/FileSystem.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/launcher/FileSystem.cpp b/launcher/FileSystem.cpp
index 6de20de6..3837d75f 100644
--- a/launcher/FileSystem.cpp
+++ b/launcher/FileSystem.cpp
@@ -454,4 +454,47 @@ bool createShortCut(QString location, QString dest, QStringList args, QString na
return false;
#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)
+{
+ 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);
+
+ qDebug() << QString("Applying override %1 in %2").arg(file, destination);
+
+ 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;
+ }
+ }
+
+ return true;
+}
+
}