Change the native extraction/loading logic.

This commit is contained in:
Petr Mrázek 2014-01-18 03:32:31 +01:00
parent 188d0d5886
commit ecc80bd763
4 changed files with 71 additions and 47 deletions

View File

@ -70,7 +70,7 @@ public class OneSixLauncher implements Launcher
List<String> allNativePaths = new ArrayList<String>(); List<String> allNativePaths = new ArrayList<String>();
boolean is_64 = property.equalsIgnoreCase("x86_64") || property.equalsIgnoreCase("amd64"); boolean is_64 = property.equalsIgnoreCase("x86_64") || property.equalsIgnoreCase("amd64");
allNativePaths.add(natives); allNativePaths.add(natives);
allNativePaths.add(Utils.combine(natives, is_64 ? "64" : "32")); allNativePaths.add(natives + "/" + (is_64 ? "64" : "32"));
// print the pretty things // print the pretty things
{ {
@ -110,7 +110,8 @@ public class OneSixLauncher implements Launcher
final ClassLoader cl = ClassLoader.getSystemClassLoader(); final ClassLoader cl = ClassLoader.getSystemClassLoader();
// set up the natives path(s). // set up the natives path(s).
System.setProperty("java.library.path", Utils.join(allNativePaths, String.valueOf(File.pathSeparatorChar)) ); String libpath = Utils.join(allNativePaths, String.valueOf(File.pathSeparatorChar));
System.setProperty("java.library.path", libpath);
Field fieldSysPath; Field fieldSysPath;
try try
{ {

View File

@ -19,6 +19,9 @@
#include "OneSixRule.h" #include "OneSixRule.h"
#include "OpSys.h" #include "OpSys.h"
#include "logic/net/URLConstants.h" #include "logic/net/URLConstants.h"
#include <pathutils.h>
#include <JlCompress.h>
#include "logger/QsLog.h"
void OneSixLibrary::finalize() void OneSixLibrary::finalize()
{ {
@ -133,6 +136,59 @@ QString OneSixLibrary::hint()
return m_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 OneSixLibrary::toJson()
{ {
QJsonObject libRoot; QJsonObject libRoot;

View File

@ -126,4 +126,6 @@ public:
/// set a hint about how to treat the library. This is an MMC extension. /// set a hint about how to treat the library. This is an MMC extension.
void setHint(QString hint); void setHint(QString hint);
QString hint(); QString hint();
bool extractTo(QString target_dir);
}; };

View File

@ -340,7 +340,6 @@ void OneSixUpdate::prepareForLaunch()
// delete any leftovers, if they are present. // delete any leftovers, if they are present.
onesix_inst->cleanupAfterRun(); onesix_inst->cleanupAfterRun();
// Acquire swag
QString natives_dir_raw = PathCombine(onesix_inst->instanceRoot(), "natives/"); QString natives_dir_raw = PathCombine(onesix_inst->instanceRoot(), "natives/");
auto version = onesix_inst->getFullVersion(); auto version = onesix_inst->getFullVersion();
if (!version) if (!version)
@ -349,56 +348,22 @@ void OneSixUpdate::prepareForLaunch()
"it or changing the version."); "it or changing the version.");
return; return;
} }
auto libs_to_extract = version->getActiveNativeLibs(); /*
* emitFailed("Could not create the native library folder:\n" + natives_dir_raw +
// 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 +
"\nMake sure MultiMC has appropriate permissions and there is enough space " "\nMake sure MultiMC has appropriate permissions and there is enough space "
"on the storage device."); "on the storage device.");
return; */
} for (auto lib : version->getActiveNativeLibs())
// Put swag in the bag
for (auto lib : libs_to_extract)
{ {
auto f = [&](QString storage, QString arch = "") if (!lib->extractTo(natives_dir_raw))
{ {
QString path = "libraries/" + storage; emitFailed("Could not extract the native library:\n" + lib->storagePath() + " to " +
QLOG_INFO() << "Will extract " << path.toLocal8Bit(); natives_dir_raw +
if (JlCompress::extractWithExceptions(path, natives_dir_raw + "/" + arch, "\nMake sure MultiMC has appropriate permissions and there is enough "
lib->extract_excludes).isEmpty()) "space on the storage device.");
{
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; return;
} }
} }
// Show them your war face!
emitSucceeded(); emitSucceeded();
} }