aboutsummaryrefslogtreecommitdiff
path: root/launcher/FileSystem.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'launcher/FileSystem.cpp')
-rw-r--r--launcher/FileSystem.cpp41
1 files changed, 17 insertions, 24 deletions
diff --git a/launcher/FileSystem.cpp b/launcher/FileSystem.cpp
index 4026d6c1..987f4e74 100644
--- a/launcher/FileSystem.cpp
+++ b/launcher/FileSystem.cpp
@@ -44,7 +44,9 @@
#include <QStandardPaths>
#include <QTextStream>
#include <QUrl>
+
#include "DesktopServices.h"
+#include "StringUtils.h"
#if defined Q_OS_WIN32
#include <objbase.h>
@@ -79,22 +81,6 @@ namespace fs = std::filesystem;
namespace fs = ghc::filesystem;
#endif
-#if defined Q_OS_WIN32
-
-std::wstring toStdString(QString s)
-{
- return s.toStdWString();
-}
-
-#else
-
-std::string toStdString(QString s)
-{
- return s.toStdString();
-}
-
-#endif
-
namespace FS {
void ensureExists(const QDir& dir)
@@ -163,9 +149,13 @@ bool ensureFolderPathExists(QString foldernamepath)
return success;
}
-bool copy::operator()(const QString& offset)
+/// @brief Copies a directory and it's contents from src to dest
+/// @param offset subdirectory form src to copy to dest
+/// @return if there was an error during the filecopy
+bool copy::operator()(const QString& offset, bool dryRun)
{
using copy_opts = fs::copy_options;
+ m_copied = 0; // reset counter
// NOTE always deep copy on windows. the alternatives are too messy.
#if defined Q_OS_WIN32
@@ -185,18 +175,21 @@ bool copy::operator()(const QString& offset)
// Function that'll do the actual copying
auto copy_file = [&](QString src_path, QString relative_dst_path) {
- if (m_blacklist && m_blacklist->matches(relative_dst_path))
+ if (m_matcher && (m_matcher->matches(relative_dst_path) != m_whitelist))
return;
auto dst_path = PathCombine(dst, relative_dst_path);
- ensureFilePathExists(dst_path);
-
- fs::copy(toStdString(src_path), toStdString(dst_path), opt, err);
+ if (!dryRun) {
+ ensureFilePathExists(dst_path);
+ fs::copy(StringUtils::toStdString(src_path), StringUtils::toStdString(dst_path), opt, err);
+ }
if (err) {
qWarning() << "Failed to copy files:" << QString::fromStdString(err.message());
qDebug() << "Source file:" << src_path;
qDebug() << "Destination file:" << dst_path;
}
+ m_copied++;
+ emit fileCopied(relative_dst_path);
};
// We can't use copy_opts::recursive because we need to take into account the
@@ -213,7 +206,7 @@ bool copy::operator()(const QString& offset)
}
// If the root src is not a directory, the previous iterator won't run.
- if (!fs::is_directory(toStdString(src)))
+ if (!fs::is_directory(StringUtils::toStdString(src)))
copy_file(src, "");
return err.value() == 0;
@@ -223,7 +216,7 @@ bool deletePath(QString path)
{
std::error_code err;
- fs::remove_all(toStdString(path), err);
+ fs::remove_all(StringUtils::toStdString(path), err);
if (err) {
qWarning() << "Failed to remove files:" << QString::fromStdString(err.message());
@@ -414,7 +407,7 @@ bool overrideFolder(QString overwritten_path, QString override_path)
fs::copy_options opt = copy_opts::recursive | copy_opts::overwrite_existing;
// FIXME: hello traveller! Apparently std::copy does NOT overwrite existing files on GNU libstdc++ on Windows?
- fs::copy(toStdString(override_path), toStdString(overwritten_path), opt, err);
+ fs::copy(StringUtils::toStdString(override_path), StringUtils::toStdString(overwritten_path), opt, err);
if (err) {
qCritical() << QString("Failed to apply override from %1 to %2").arg(override_path, overwritten_path);