NOISSUE use classparser for importing Legacy instances with undecided Minecraft versions

This commit is contained in:
Petr Mrázek 2017-09-27 15:39:13 +02:00
parent 9a2d203c0d
commit c51512f940
7 changed files with 28 additions and 18 deletions

View File

@ -84,6 +84,7 @@ add_subdirectory(libraries/pack200) # java pack200 compression
add_subdirectory(libraries/rainbow) # Qt extension for colors
add_subdirectory(libraries/iconfix) # fork of Qt's QIcon loader
add_subdirectory(libraries/LocalPeer) # fork of a library from Qt solutions
add_subdirectory(libraries/classparser) # google analytics library
############################### Built Artifacts ###############################

View File

@ -448,7 +448,7 @@ set_target_properties(MultiMC_logic PROPERTIES CXX_VISIBILITY_PRESET hidden VISI
generate_export_header(MultiMC_logic)
# Link
target_link_libraries(MultiMC_logic xz-embedded MultiMC_unpack200 systeminfo MultiMC_quazip ${NBT_NAME} ${ZLIB_LIBRARIES})
target_link_libraries(MultiMC_logic xz-embedded MultiMC_unpack200 systeminfo MultiMC_quazip MultiMC_classparser ${NBT_NAME} ${ZLIB_LIBRARIES})
qt5_use_modules(MultiMC_logic Core Xml Network Concurrent)
# Mark and export headers

View File

@ -31,8 +31,8 @@ LegacyInstance::LegacyInstance(SettingsObjectPtr globalSettings, SettingsObjectP
{
settings->registerSetting("NeedsRebuild", true);
settings->registerSetting("ShouldUpdate", false);
settings->registerSetting("JarVersion", "Unknown");
settings->registerSetting("IntendedJarVersion", "");
settings->registerSetting("JarVersion", QString());
settings->registerSetting("IntendedJarVersion", QString());
/*
* custom base jar has no default. it is determined in code... see the accessor methods for
*it

View File

@ -8,6 +8,7 @@
#include "LegacyInstance.h"
#include "minecraft/MinecraftInstance.h"
#include "minecraft/MinecraftProfile.h"
#include "classparser.h"
LegacyUpgradeTask::LegacyUpgradeTask(SettingsObjectPtr settings, const QString & stagingPath, InstancePtr origInstance, const QString & newName)
{
@ -50,7 +51,6 @@ static QString decideVersion(const QString& currentVersion, const QString& inten
return intendedVersion;
}
}
// TODO: possibly add fallback to the old jar/classfile analysis method from MultiMC4
return QString();
}
@ -74,9 +74,17 @@ void LegacyUpgradeTask::copyFinished()
QString preferredVersionNumber = decideVersion(legacyInst->currentVersionId(), legacyInst->intendedVersionId());
if(preferredVersionNumber.isNull())
{
// FIXME: let the user decide
emitFailed(tr("Could not decide Minecraft version."));
return;
// try to decide version based on the jar(s?)
preferredVersionNumber = classparser::GetMinecraftJarVersion(legacyInst->baseJar());
if(preferredVersionNumber.isNull())
{
preferredVersionNumber = classparser::GetMinecraftJarVersion(legacyInst->runnableJar());
if(preferredVersionNumber.isNull())
{
emitFailed(tr("Could not decide Minecraft version."));
return;
}
}
}
inst->setComponentVersion("net.minecraft", preferredVersionNumber);

View File

@ -18,7 +18,7 @@ include_directories(${Qt5Base_INCLUDE_DIRS})
set(CLASSPARSER_HEADERS
# Public headers
include/classparser_config.h
include/javautils.h
include/classparser.h
# Private headers
src/annotations.h
@ -30,12 +30,13 @@ src/membuffer.h
)
set(CLASSPARSER_SOURCES
src/javautils.cpp
src/classparser.cpp
src/annotations.cpp
)
add_definitions(-DCLASSPARSER_LIBRARY)
add_library(classparser SHARED ${CLASSPARSER_SOURCES} ${CLASSPARSER_HEADERS})
target_include_directories(classparser PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include")
qt5_use_modules(classparser Core)
add_library(MultiMC_classparser STATIC ${CLASSPARSER_SOURCES} ${CLASSPARSER_HEADERS})
target_include_directories(MultiMC_classparser PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include")
target_link_libraries(MultiMC_classparser MultiMC_quazip)
qt5_use_modules(MultiMC_classparser Core)

View File

@ -18,9 +18,7 @@
#include <QString>
#include "classparser_config.h"
#define MCVer_Unknown "Unknown"
namespace javautils
namespace classparser
{
/**
* @brief Get the version from a minecraft.jar by parsing its class files. Expensive!

View File

@ -15,17 +15,18 @@
* limitations under the License.
*/
#include "classfile.h"
#include "javautils.h"
#include "classparser.h"
#include <QFile>
#include <quazipfile.h>
#include <QDebug>
namespace javautils
namespace classparser
{
QString GetMinecraftJarVersion(QString jarName)
{
QString version = MCVer_Unknown;
QString version;
// check if minecraft.jar exists
QFile jar(jarName);
@ -61,6 +62,7 @@ QString GetMinecraftJarVersion(QString jarName)
if (constant.type != java::constant::j_string_data)
continue;
const std::string &str = constant.str_data;
qDebug() << QString::fromStdString(str);
if (str.compare(0, 20, "Minecraft Minecraft ") == 0)
{
version = str.substr(20).data();