summaryrefslogtreecommitdiffstats
path: root/logic
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2014-01-18 03:32:31 +0100
committerPetr Mrázek <peterix@gmail.com>2014-01-18 03:33:04 +0100
commitecc80bd763111b0e368aa80366bd8382cd814ee6 (patch)
tree5f910b6b571653c79193e2a7a46236111d13fec5 /logic
parent188d0d58865f5e134b5803bda2cd631a61cf2915 (diff)
downloadMultiMC-ecc80bd763111b0e368aa80366bd8382cd814ee6.tar
MultiMC-ecc80bd763111b0e368aa80366bd8382cd814ee6.tar.gz
MultiMC-ecc80bd763111b0e368aa80366bd8382cd814ee6.tar.lz
MultiMC-ecc80bd763111b0e368aa80366bd8382cd814ee6.tar.xz
MultiMC-ecc80bd763111b0e368aa80366bd8382cd814ee6.zip
Change the native extraction/loading logic.
Diffstat (limited to 'logic')
-rw-r--r--logic/OneSixLibrary.cpp56
-rw-r--r--logic/OneSixLibrary.h2
-rw-r--r--logic/OneSixUpdate.cpp55
3 files changed, 68 insertions, 45 deletions
diff --git a/logic/OneSixLibrary.cpp b/logic/OneSixLibrary.cpp
index 4b6ed9dc..1d69b660 100644
--- a/logic/OneSixLibrary.cpp
+++ b/logic/OneSixLibrary.cpp
@@ -19,6 +19,9 @@
#include "OneSixRule.h"
#include "OpSys.h"
#include "logic/net/URLConstants.h"
+#include <pathutils.h>
+#include <JlCompress.h>
+#include "logger/QsLog.h"
void OneSixLibrary::finalize()
{
@@ -133,6 +136,59 @@ QString OneSixLibrary::hint()
return m_hint;
}
+bool OneSixLibrary::extractTo(QString target_dir)
+{
+ QString storage = storagePath();
+ if (storage.contains("${arch}"))
+ {
+ QString cooked_storage = storage;
+ cooked_storage.replace("${arch}", "32");
+ QString origin = PathCombine("libraries", cooked_storage);
+ QString target_dir_cooked = PathCombine(target_dir, "32");
+ if(!ensureFolderPathExists(target_dir_cooked))
+ {
+ QLOG_ERROR() << "Couldn't create folder " + target_dir_cooked;
+ return false;
+ }
+ if (JlCompress::extractWithExceptions(origin, target_dir_cooked, extract_excludes)
+ .isEmpty())
+ {
+ QLOG_ERROR() << "Couldn't extract " + origin;
+ return false;
+ }
+ cooked_storage = storage;
+ cooked_storage.replace("${arch}", "64");
+ origin = PathCombine("libraries", cooked_storage);
+ target_dir_cooked = PathCombine(target_dir, "32");
+ if(!ensureFolderPathExists(target_dir_cooked))
+ {
+ QLOG_ERROR() << "Couldn't create folder " + target_dir_cooked;
+ return false;
+ }
+ if (JlCompress::extractWithExceptions(origin, target_dir_cooked, extract_excludes)
+ .isEmpty())
+ {
+ QLOG_ERROR() << "Couldn't extract " + origin;
+ return false;
+ }
+ }
+ else
+ {
+ if(!ensureFolderPathExists(target_dir))
+ {
+ QLOG_ERROR() << "Couldn't create folder " + target_dir;
+ return false;
+ }
+ QString path = PathCombine("libraries", storage);
+ if (JlCompress::extractWithExceptions(path, target_dir, extract_excludes).isEmpty())
+ {
+ QLOG_ERROR() << "Couldn't extract " + path;
+ return false;
+ }
+ }
+ return true;
+}
+
QJsonObject OneSixLibrary::toJson()
{
QJsonObject libRoot;
diff --git a/logic/OneSixLibrary.h b/logic/OneSixLibrary.h
index 3f0bc83d..bc097348 100644
--- a/logic/OneSixLibrary.h
+++ b/logic/OneSixLibrary.h
@@ -126,4 +126,6 @@ public:
/// set a hint about how to treat the library. This is an MMC extension.
void setHint(QString hint);
QString hint();
+
+ bool extractTo(QString target_dir);
};
diff --git a/logic/OneSixUpdate.cpp b/logic/OneSixUpdate.cpp
index 5309a7e0..ee355308 100644
--- a/logic/OneSixUpdate.cpp
+++ b/logic/OneSixUpdate.cpp
@@ -340,7 +340,6 @@ void OneSixUpdate::prepareForLaunch()
// delete any leftovers, if they are present.
onesix_inst->cleanupAfterRun();
- // Acquire swag
QString natives_dir_raw = PathCombine(onesix_inst->instanceRoot(), "natives/");
auto version = onesix_inst->getFullVersion();
if (!version)
@@ -349,56 +348,22 @@ void OneSixUpdate::prepareForLaunch()
"it or changing the version.");
return;
}
- auto libs_to_extract = version->getActiveNativeLibs();
-
- // Acquire bag
- bool success = true;
- success &= ensureFolderPathExists(natives_dir_raw + "/32");
- success &= ensureFolderPathExists(natives_dir_raw + "/64");
- if (!success)
- {
- emitFailed("Could not create the native library folder:\n" + natives_dir_raw +
+/*
+ * emitFailed("Could not create the native library folder:\n" + natives_dir_raw +
"\nMake sure MultiMC has appropriate permissions and there is enough space "
"on the storage device.");
- return;
- }
-
- // Put swag in the bag
- for (auto lib : libs_to_extract)
+*/
+ for (auto lib : version->getActiveNativeLibs())
{
- auto f = [&](QString storage, QString arch = "")
+ if (!lib->extractTo(natives_dir_raw))
{
- QString path = "libraries/" + storage;
- QLOG_INFO() << "Will extract " << path.toLocal8Bit();
- if (JlCompress::extractWithExceptions(path, natives_dir_raw + "/" + arch,
- lib->extract_excludes).isEmpty())
- {
- emitFailed(
- "Could not extract the native library:\n" + path +
- "\nMake sure MultiMC has appropriate permissions and there is enough space "
- "on the storage device.");
- return false;
- }
- };
- QString storage = lib->storagePath();
- if (storage.contains("${arch}"))
- {
- QString cooked_storage = storage;
- cooked_storage.replace("${arch}", "32");
- if (!f(cooked_storage, "32"))
- return;
- cooked_storage = storage;
- cooked_storage.replace("${arch}", "64");
- if (!f(cooked_storage, "64"))
- return;
- }
- else
- {
- if (!f(storage))
- return;
+ emitFailed("Could not extract the native library:\n" + lib->storagePath() + " to " +
+ natives_dir_raw +
+ "\nMake sure MultiMC has appropriate permissions and there is enough "
+ "space on the storage device.");
+ return;
}
}
- // Show them your war face!
emitSucceeded();
}