aboutsummaryrefslogtreecommitdiff
path: root/launcher/minecraft/PackProfile.cpp
diff options
context:
space:
mode:
authorSefa Eyeoglu <contact@scrumplex.net>2023-01-25 10:43:23 +0100
committerSefa Eyeoglu <contact@scrumplex.net>2023-01-25 10:43:23 +0100
commit199a7df807994ded1469cc893e6c68c21307444f (patch)
tree9e7e5f464fca32cf6578cf58a73b09870d845d87 /launcher/minecraft/PackProfile.cpp
parentcd893e18d24d61c62f048d0c82c85b981f6e9a65 (diff)
downloadPrismLauncher-199a7df807994ded1469cc893e6c68c21307444f.tar.gz
PrismLauncher-199a7df807994ded1469cc893e6c68c21307444f.tar.bz2
PrismLauncher-199a7df807994ded1469cc893e6c68c21307444f.zip
refactor: add error handling to component import
Signed-off-by: Sefa Eyeoglu <contact@scrumplex.net>
Diffstat (limited to 'launcher/minecraft/PackProfile.cpp')
-rw-r--r--launcher/minecraft/PackProfile.cpp56
1 files changed, 28 insertions, 28 deletions
diff --git a/launcher/minecraft/PackProfile.cpp b/launcher/minecraft/PackProfile.cpp
index 270f3d22..54fbf7f3 100644
--- a/launcher/minecraft/PackProfile.cpp
+++ b/launcher/minecraft/PackProfile.cpp
@@ -733,21 +733,47 @@ void PackProfile::invalidateLaunchProfile()
void PackProfile::installJarMods(QStringList selectedFiles)
{
+ // FIXME: get rid of _internal
installJarMods_internal(selectedFiles);
}
void PackProfile::installCustomJar(QString selectedFile)
{
+ // FIXME: get rid of _internal
installCustomJar_internal(selectedFile);
}
-void PackProfile::installComponents(QStringList selectedFiles)
+bool PackProfile::installComponents(QStringList selectedFiles)
{
- installComponents_internal(selectedFiles);
+ const QString patchDir = FS::PathCombine(d->m_instance->instanceRoot(), "patches");
+ if (!FS::ensureFolderPathExists(patchDir))
+ return false;
+
+ bool result = true;
+ for (const QString& source : selectedFiles) {
+ const QFileInfo sourceInfo(source);
+
+ auto versionFile = ProfileUtils::parseJsonFile(sourceInfo, false);
+ const QString target = FS::PathCombine(patchDir, versionFile->uid + ".json");
+
+ if (!QFile::copy(source, target)) {
+ qWarning() << "Component" << source << "could not be copied to target" << target;
+ result = false;
+ continue;
+ }
+
+ appendComponent(new Component(this, versionFile->uid, versionFile));
+ }
+
+ scheduleSave();
+ invalidateLaunchProfile();
+
+ return result;
}
void PackProfile::installAgents(QStringList selectedFiles)
{
+ // FIXME: get rid of _internal
installAgents_internal(selectedFiles);
}
@@ -948,32 +974,6 @@ bool PackProfile::installCustomJar_internal(QString filepath)
return true;
}
-bool PackProfile::installComponents_internal(QStringList filepaths)
-{
- const QString patchDir = FS::PathCombine(d->m_instance->instanceRoot(), "patches");
- if (!FS::ensureFolderPathExists(patchDir))
- return false;
-
- for (const QString& source : filepaths) {
- const QFileInfo sourceInfo(source);
-
- auto versionFile = ProfileUtils::parseJsonFile(sourceInfo, false);
- const QString target = FS::PathCombine(patchDir, versionFile->uid + ".json");
-
- if (!QFile::copy(source, target))
- {
- return false;
- }
-
- appendComponent(new Component(this, versionFile->uid, versionFile));
- }
-
- scheduleSave();
- invalidateLaunchProfile();
-
- return true;
-}
-
bool PackProfile::installAgents_internal(QStringList filepaths)
{
// FIXME code duplication