Revert "NOISSUE nuke builtin Minecraft versions"

This reverts commit 5ae3b2c11416eb897a08b0d9531843d0357332f8.

We need those builtin versions for now.
This commit is contained in:
Petr Mrázek
2016-10-20 01:02:28 +02:00
parent 1b4851a941
commit cee53f7f3c
15 changed files with 924 additions and 54 deletions

View File

@ -292,7 +292,7 @@ bool IconList::deleteIcon(const QString &key)
return false;
}
bool IconList::addIcon(QString key, QString name, QString path, IconType type)
bool IconList::addIcon(const QString &key, const QString &name, const QString &path, const IconType type)
{
// replace the icon even? is the input valid?
QIcon icon(path);
@ -323,6 +323,14 @@ bool IconList::addIcon(QString key, QString name, QString path, IconType type)
}
}
void IconList::saveIcon(const QString &key, const QString &path, const char * format) const
{
auto icon = getIcon(key);
auto pixmap = icon.pixmap(128, 128);
pixmap.save(path, format);
}
void IconList::reindex()
{
name_index.clear();
@ -334,7 +342,7 @@ void IconList::reindex()
}
}
QIcon IconList::getIcon(QString key)
QIcon IconList::getIcon(const QString &key) const
{
int icon_index = getIconIndex(key);
@ -349,15 +357,12 @@ QIcon IconList::getIcon(QString key)
return QIcon();
}
QIcon IconList::getBigIcon(QString key)
QIcon IconList::getBigIcon(const QString &key) const
{
int icon_index = getIconIndex(key);
if (icon_index == -1)
key = "infinity";
// Fallback for icons that don't exist.
icon_index = getIconIndex(key);
icon_index = getIconIndex(icon_index == -1 ? "infinity" : key);
if (icon_index == -1)
return QIcon();
@ -366,12 +371,9 @@ QIcon IconList::getBigIcon(QString key)
return QIcon(bigone);
}
int IconList::getIconIndex(QString key)
int IconList::getIconIndex(const QString &key) const
{
if (key == "default")
key = "infinity";
auto iter = name_index.find(key);
auto iter = name_index.find(key == "default" ? "infinity" : key);
if (iter != name_index.end())
return *iter;

View File

@ -37,9 +37,9 @@ public:
explicit IconList(QString builtinPath, QString path, QObject *parent = 0);
virtual ~IconList() {};
QIcon getIcon(QString key);
QIcon getBigIcon(QString key);
int getIconIndex(QString key);
QIcon getIcon(const QString &key) const;
QIcon getBigIcon(const QString &key) const;
int getIconIndex(const QString &key) const;
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const override;

View File

@ -21,6 +21,8 @@
#include "minecraft/launch/ModMinecraftJar.h"
#include "java/launch/CheckJava.h"
#include <icons/IIconList.h>
#define IBUS "@im=ibus"
// all of this because keeping things compatible with deprecated old settings
@ -392,6 +394,8 @@ std::shared_ptr<LaunchTask> MinecraftInstance::createLaunchTask(AuthSessionPtr s
auto process = LaunchTask::create(std::dynamic_pointer_cast<MinecraftInstance>(getSharedPtr()));
auto pptr = process.get();
ENV.icons()->saveIcon(iconKey(), FS::PathCombine(minecraftRoot(), "icon.png"), "PNG");
// print a header
{
process->appendStep(std::make_shared<TextPrint>(pptr, "Minecraft folder is:\n" + minecraftRoot() + "\n\n", MessageLevel::MultiMC));

View File

@ -3,22 +3,20 @@
#include "VersionBuildError.h"
#include "ProfileUtils.h"
#include "settings/SettingsObject.h"
#include "minecraft/VersionFilterData.h"
bool MinecraftVersion::usesLegacyLauncher()
{
return getReleaseDateTime() < g_VersionFilterData.legacyCutoffDate;
return m_traits.contains("legacyLaunch") || m_traits.contains("aplhaLaunch");
}
QString MinecraftVersion::descriptor()
{
return m_version;
return m_descriptor;
}
QString MinecraftVersion::name()
{
return m_version;
return m_name;
}
QString MinecraftVersion::typeString() const
@ -62,13 +60,13 @@ bool MinecraftVersion::isMinecraftVersion()
void MinecraftVersion::applyFileTo(MinecraftProfile *profile)
{
if(m_versionSource == Local && getVersionFile())
if(m_versionSource == VersionSource::Local && getVersionFile())
{
getVersionFile()->applyTo(profile);
}
else
{
throw VersionIncomplete(QObject::tr("Can't apply incomplete/builtin Minecraft version %1").arg(m_version));
throw VersionIncomplete(QObject::tr("Can't apply incomplete/builtin Minecraft version %1").arg(m_name));
}
}
@ -77,7 +75,7 @@ QString MinecraftVersion::getUrl() const
// legacy fallback
if(m_versionFileURL.isEmpty())
{
return QString("http://") + URLConstants::AWS_DOWNLOAD_VERSIONS + m_version + "/" + m_version + ".json";
return QString("http://") + URLConstants::AWS_DOWNLOAD_VERSIONS + m_descriptor + "/" + m_descriptor + ".json";
}
// current
return m_versionFileURL;
@ -85,8 +83,9 @@ QString MinecraftVersion::getUrl() const
VersionFilePtr MinecraftVersion::getVersionFile()
{
QFileInfo versionFile(QString("versions/%1/%1.dat").arg(m_version));
QFileInfo versionFile(QString("versions/%1/%1.dat").arg(m_descriptor));
m_problems.clear();
m_problemSeverity = PROBLEM_NONE;
if(!versionFile.exists())
{
if(m_loadedVersionFile)
@ -121,10 +120,12 @@ bool MinecraftVersion::isCustomizable()
{
switch(m_versionSource)
{
case Local:
case Remote:
case VersionSource::Local:
case VersionSource::Remote:
// locally cached file, or a remote file that we can acquire can be customized
return true;
case VersionSource::Builtin:
// builtins do not follow the normal OneSix format. They are not customizable.
default:
// Everything else is undefined and therefore not customizable.
return false;
@ -134,7 +135,7 @@ bool MinecraftVersion::isCustomizable()
const QList<PatchProblem> &MinecraftVersion::getProblems()
{
if(getVersionFile())
if(m_versionSource != VersionSource::Builtin && getVersionFile())
{
return getVersionFile()->getProblems();
}
@ -143,7 +144,7 @@ const QList<PatchProblem> &MinecraftVersion::getProblems()
ProblemSeverity MinecraftVersion::getProblemSeverity()
{
if(getVersionFile())
if(m_versionSource != VersionSource::Builtin && getVersionFile())
{
return getVersionFile()->getProblemSeverity();
}
@ -153,12 +154,24 @@ ProblemSeverity MinecraftVersion::getProblemSeverity()
void MinecraftVersion::applyTo(MinecraftProfile *profile)
{
// do we have this one cached?
if (m_versionSource == Local)
if (m_versionSource == VersionSource::Local)
{
applyFileTo(profile);
return;
}
throw VersionIncomplete(QObject::tr("Minecraft version %1 could not be applied: version files are missing.").arg(m_version));
// if not builtin, do not proceed any further.
if (m_versionSource != VersionSource::Builtin)
{
throw VersionIncomplete(QObject::tr(
"Minecraft version %1 could not be applied: version files are missing.").arg(m_descriptor));
}
profile->applyMinecraftVersion(m_descriptor);
profile->applyMainClass(m_mainClass);
profile->applyAppletClass(m_appletClass);
profile->applyMinecraftArguments(" ${auth_player_name} ${auth_session}"); // all builtin versions are legacy
profile->applyMinecraftVersionType(m_type);
profile->applyTraits(m_traits);
profile->applyProblemSeverity(m_problemSeverity);
}
int MinecraftVersion::getOrder()
@ -182,7 +195,7 @@ QString MinecraftVersion::getName()
}
QString MinecraftVersion::getVersion()
{
return m_version;
return m_descriptor;
}
QString MinecraftVersion::getID()
{
@ -200,16 +213,18 @@ QDateTime MinecraftVersion::getReleaseDateTime()
bool MinecraftVersion::needsUpdate()
{
return m_versionSource == Remote || hasUpdate();
return m_versionSource == VersionSource::Remote || hasUpdate();
}
bool MinecraftVersion::hasUpdate()
{
return m_versionSource == Remote || (m_versionSource == Local && upstreamUpdate);
return m_versionSource == VersionSource::Remote || (m_versionSource == VersionSource::Local && upstreamUpdate);
}
bool MinecraftVersion::isCustom()
{
// if we add any other source types, this will evaluate to false for them.
return m_versionSource != Local && m_versionSource != Remote;
return m_versionSource != VersionSource::Builtin
&& m_versionSource != VersionSource::Local
&& m_versionSource != VersionSource::Remote;
}

View File

@ -34,9 +34,7 @@ class MULTIMC_LOGIC_EXPORT MinecraftVersion : public BaseVersion, public Profile
friend class MinecraftVersionList;
public: /* methods */
// FIXME: nuke this.
bool usesLegacyLauncher();
virtual QString descriptor() override;
virtual QString name() override;
virtual QString typeString() const override;
@ -91,13 +89,25 @@ private: /* methods */
void applyFileTo(MinecraftProfile *profile);
protected: /* data */
VersionSource m_versionSource = Remote;
VersionSource m_versionSource = VersionSource::Builtin;
/// The URL that this version will be downloaded from.
QString m_versionFileURL;
/// the human readable version name
QString m_version;
QString m_name;
/// the version ID.
QString m_descriptor;
/// version traits. added by MultiMC
QSet<QString> m_traits;
/// The main class this version uses (if any, can be empty).
QString m_mainClass;
/// The applet class this version uses (if any, can be empty).
QString m_appletClass;
/// The type of this release
QString m_type;
@ -108,6 +118,9 @@ protected: /* data */
/// the time this version was last updated by Mojang
QDateTime m_updateTime;
/// MD5 hash of the minecraft jar
QString m_jarChecksum;
/// order of this file... default = -2
int order = -2;

View File

@ -89,6 +89,7 @@ public:
MinecraftVersionList::MinecraftVersionList(QObject *parent) : BaseVersionList(parent)
{
loadBuiltinList();
loadCachedList();
}
@ -146,7 +147,7 @@ void MinecraftVersionList::loadCachedList()
{
throw ListLoadError(tr("Error reading the version list."));
}
loadList(jsonDoc, Local);
loadMojangList(jsonDoc, VersionSource::Local);
}
catch (Exception &e)
{
@ -158,9 +159,59 @@ void MinecraftVersionList::loadCachedList()
m_hasLocalIndex = true;
}
void MinecraftVersionList::loadList(QJsonDocument jsonDoc, VersionSource source)
void MinecraftVersionList::loadBuiltinList()
{
qDebug() << "Loading" << ((source == Remote) ? "remote" : "local") << "version list.";
qDebug() << "Loading builtin version list.";
// grab the version list data from internal resources.
const QJsonDocument doc =
Json::requireDocument(QString(":/versions/minecraft.json"), "builtin version list");
const QJsonObject root = doc.object();
// parse all the versions
for (const auto version : Json::requireArray(root.value("versions")))
{
QJsonObject versionObj = version.toObject();
QString versionID = versionObj.value("id").toString("");
QString versionTypeStr = versionObj.value("type").toString("");
if (versionID.isEmpty() || versionTypeStr.isEmpty())
{
qCritical() << "Parsed version is missing ID or type";
continue;
}
if (g_VersionFilterData.legacyBlacklist.contains(versionID))
{
qWarning() << "Blacklisted legacy version ignored: " << versionID;
continue;
}
// Now, we construct the version object and add it to the list.
std::shared_ptr<MinecraftVersion> mcVersion(new MinecraftVersion());
mcVersion->m_name = mcVersion->m_descriptor = versionID;
// Parse the timestamp.
mcVersion->m_releaseTime = timeFromS3Time(versionObj.value("releaseTime").toString(""));
mcVersion->m_versionFileURL = QString();
mcVersion->m_versionSource = VersionSource::Builtin;
mcVersion->m_type = versionTypeStr;
mcVersion->m_appletClass = versionObj.value("appletClass").toString("");
mcVersion->m_mainClass = versionObj.value("mainClass").toString("");
mcVersion->m_jarChecksum = versionObj.value("checksum").toString("");
if (versionObj.contains("+traits"))
{
for (auto traitVal : Json::requireArray(versionObj.value("+traits")))
{
mcVersion->m_traits.insert(Json::requireString(traitVal));
}
}
m_lookup[versionID] = mcVersion;
m_vlist.append(mcVersion);
}
}
void MinecraftVersionList::loadMojangList(QJsonDocument jsonDoc, VersionSource source)
{
qDebug() << "Loading" << ((source == VersionSource::Remote) ? "remote" : "local") << "version list.";
if (!jsonDoc.isObject())
{
@ -215,11 +266,16 @@ void MinecraftVersionList::loadList(QJsonDocument jsonDoc, VersionSource source)
// Now, we construct the version object and add it to the list.
std::shared_ptr<MinecraftVersion> mcVersion(new MinecraftVersion());
mcVersion->m_version = versionID;
mcVersion->m_name = mcVersion->m_descriptor = versionID;
mcVersion->m_releaseTime = timeFromS3Time(versionObj.value("releaseTime").toString(""));
mcVersion->m_updateTime = timeFromS3Time(versionObj.value("time").toString(""));
if (mcVersion->m_releaseTime < g_VersionFilterData.legacyCutoffDate)
{
continue;
}
// depends on where we load the version from -- network request or local file?
mcVersion->m_versionSource = source;
mcVersion->m_versionFileURL = versionObj.value("url").toString("");
@ -251,11 +307,11 @@ void MinecraftVersionList::loadList(QJsonDocument jsonDoc, VersionSource source)
}
mcVersion->m_type = versionTypeStr;
qDebug() << "Loaded version" << versionID << "from"
<< ((source == Remote) ? "remote" : "local") << "version list.";
<< ((source == VersionSource::Remote) ? "remote" : "local") << "version list.";
tempList.append(mcVersion);
}
updateListData(tempList);
if(source == Remote)
if(source == VersionSource::Remote)
{
m_loaded = true;
}
@ -348,7 +404,7 @@ void MinecraftVersionList::updateListData(QList<BaseVersionPtr> versions)
// updateListData is called after Mojang list loads. those can be local or remote
// remote comes always after local
// any other options are ignored
if (orig->m_versionSource != Local || added->m_versionSource != Remote)
if (orig->m_versionSource != VersionSource::Local || added->m_versionSource != VersionSource::Remote)
{
continue;
}
@ -394,7 +450,7 @@ void MCVListLoadTask::list_downloaded()
throw ListLoadError(
tr("Error parsing version list JSON: %1").arg(jsonError.errorString()));
}
m_list->loadList(jsonDoc, Remote);
m_list->loadMojangList(jsonDoc, VersionSource::Remote);
}
catch (Exception &e)
{
@ -471,6 +527,8 @@ void MCVListVersionUpdateTask::json_downloaded()
// Strip LWJGL from the version file. We use our own.
ProfileUtils::removeLwjglFromPatch(file);
// TODO: recognize and add LWJGL versions here.
file->fileId = "net.minecraft";
// now dump the file to disk
@ -533,7 +591,7 @@ void MinecraftVersionList::saveCachedList()
{
auto mcversion = std::dynamic_pointer_cast<MinecraftVersion>(version);
// do not save the remote versions.
if (mcversion->m_versionSource != Local)
if (mcversion->m_versionSource != VersionSource::Local)
continue;
QJsonObject entryObj;
@ -594,18 +652,22 @@ void MinecraftVersionList::finalizeUpdate(QString version)
auto updatedVersion = std::dynamic_pointer_cast<MinecraftVersion>(m_vlist[idx]);
// reject any updates to builtin versions.
if (updatedVersion->m_versionSource == VersionSource::Builtin)
return;
// if we have an update for the version, replace it, make the update local
if (updatedVersion->upstreamUpdate)
{
auto updatedWith = updatedVersion->upstreamUpdate;
updatedWith->m_versionSource = Local;
updatedWith->m_versionSource = VersionSource::Local;
m_vlist[idx] = updatedWith;
m_lookup[version] = updatedWith;
}
else
{
// otherwise, just set the version as local;
updatedVersion->m_versionSource = Local;
updatedVersion->m_versionSource = VersionSource::Local;
}
dataChanged(index(idx), index(idx));

View File

@ -34,7 +34,8 @@ class MULTIMC_LOGIC_EXPORT MinecraftVersionList : public BaseVersionList
Q_OBJECT
private:
void sortInternal();
void loadList(QJsonDocument jsonDoc, VersionSource source);
void loadBuiltinList();
void loadMojangList(QJsonDocument jsonDoc, VersionSource source);
void loadCachedList();
void saveCachedList();
void finalizeUpdate(QString version);

View File

@ -16,8 +16,9 @@ enum ProblemSeverity
};
/// where is a version from?
enum VersionSource
enum class VersionSource
{
Builtin, //!< version loaded from the internal resources.
Local, //!< version loaded from a file in the cache.
Remote, //!< incomplete version on a remote server.
};

View File

@ -60,7 +60,7 @@ public: /* methods */
}
VersionSource getVersionSource() override
{
return Local;
return VersionSource::Local;
}
std::shared_ptr<class VersionFile> getVersionFile() override