diff options
author | Rachel Powers <508861+Ryex@users.noreply.github.com> | 2022-12-29 17:21:54 -0700 |
---|---|---|
committer | Rachel Powers <508861+Ryex@users.noreply.github.com> | 2022-12-29 17:21:54 -0700 |
commit | c470f05abf090232b27faac6014f9e1cbe9dab9b (patch) | |
tree | 6dcca30406fb8bf97a4ee4f3a09c9143230a40d1 /launcher | |
parent | 3691f3a2963c77dbd7b469b4b90ca79b61014d43 (diff) | |
download | PrismLauncher-c470f05abf090232b27faac6014f9e1cbe9dab9b.tar.gz PrismLauncher-c470f05abf090232b27faac6014f9e1cbe9dab9b.tar.bz2 PrismLauncher-c470f05abf090232b27faac6014f9e1cbe9dab9b.zip |
refactor: use std::filesystem::rename insted of copy and then moving.
Signed-off-by: Rachel Powers <508861+Ryex@users.noreply.github.com>
Diffstat (limited to 'launcher')
-rw-r--r-- | launcher/FileSystem.cpp | 16 | ||||
-rw-r--r-- | launcher/FileSystem.h | 8 | ||||
-rw-r--r-- | launcher/modplatform/flame/FlameInstanceCreationTask.cpp | 15 |
3 files changed, 25 insertions, 14 deletions
diff --git a/launcher/FileSystem.cpp b/launcher/FileSystem.cpp index 3e8e10a5..4390eed9 100644 --- a/launcher/FileSystem.cpp +++ b/launcher/FileSystem.cpp @@ -213,6 +213,22 @@ bool copy::operator()(const QString& offset, bool dryRun) return err.value() == 0; } +bool move(const QString& source, const QString& dest) +{ + std::error_code err; + + ensureFilePathExists(dest); + fs::rename(StringUtils::toStdString(source), StringUtils::toStdString(dest), err); + + if (err) { + qWarning() << "Failed to move file:" << QString::fromStdString(err.message()); + qDebug() << "Source file:" << source; + qDebug() << "Destination file:" << dest; + } + + return err.value() == 0; +} + bool deletePath(QString path) { std::error_code err; diff --git a/launcher/FileSystem.h b/launcher/FileSystem.h index ac893725..1e3a60d9 100644 --- a/launcher/FileSystem.h +++ b/launcher/FileSystem.h @@ -122,6 +122,14 @@ class copy : public QObject { }; /** + * @brief moves a file by renaming it + * @param source source file path + * @param dest destination filepath + * + */ +bool move(const QString& source, const QString& dest); + +/** * Delete a folder recursively */ bool deletePath(QString path); diff --git a/launcher/modplatform/flame/FlameInstanceCreationTask.cpp b/launcher/modplatform/flame/FlameInstanceCreationTask.cpp index 79104e17..0a91879d 100644 --- a/launcher/modplatform/flame/FlameInstanceCreationTask.cpp +++ b/launcher/modplatform/flame/FlameInstanceCreationTask.cpp @@ -539,19 +539,6 @@ void FlameCreationTask::copyBlockedMods(QList<BlockedMod> const& blocked_mods) setAbortable(true); } -bool moveFile(QString src, QString dst) -{ - if (!FS::copy(src, dst)()) { // copy - qDebug() << "Copy of" << src << "to" << dst << "failed!"; - return false; - } else { - if (!FS::deletePath(src)) { // remove original - qDebug() << "Deletion of" << src << "failed!"; - return false; - }; - } - return true; -} void FlameCreationTask::validateZIPResouces() { @@ -567,7 +554,7 @@ void FlameCreationTask::validateZIPResouces() qDebug() << "Target folder of" << fileName << "is incorrect, it belongs in" << realTarget; auto destPath = FS::PathCombine(m_stagingPath, "minecraft", realTarget, fileName); qDebug() << "Moving" << localPath << "to" << destPath; - if (moveFile(localPath, destPath)) { + if (FS::move(localPath, destPath)) { return destPath; } } |