Add support of private packs.
Fix instance ID problems related to FTB instances.
This commit is contained in:
Petr Mrázek 2014-01-15 22:49:37 +01:00
parent 555cbe00ce
commit d85e820a07
6 changed files with 54 additions and 34 deletions

View File

@ -57,7 +57,7 @@ public:
/// The instance's ID. The ID SHALL be determined by MMC internally. The ID IS guaranteed to /// The instance's ID. The ID SHALL be determined by MMC internally. The ID IS guaranteed to
/// be unique. /// be unique.
QString id() const; virtual QString id() const;
/// get the type of this instance /// get the type of this instance
QString instanceType() const; QString instanceType() const;

View File

@ -14,3 +14,8 @@ bool LegacyFTBInstance::menuActionEnabled(QString action_name) const
{ {
return false; return false;
} }
QString LegacyFTBInstance::id() const
{
return "FTB/" + BaseInstance::id();
}

View File

@ -10,4 +10,5 @@ public:
QObject *parent = 0); QObject *parent = 0);
virtual QString getStatusbarDescription(); virtual QString getStatusbarDescription();
virtual bool menuActionEnabled(QString action_name) const; virtual bool menuActionEnabled(QString action_name) const;
virtual QString id() const;
}; };

View File

@ -92,6 +92,11 @@ OneSixFTBInstance::OneSixFTBInstance(const QString &rootDir, SettingsObject *set
} }
} }
QString OneSixFTBInstance::id() const
{
return "FTB/" + BaseInstance::id();
}
QString OneSixFTBInstance::getStatusbarDescription() QString OneSixFTBInstance::getStatusbarDescription()
{ {
return "OneSix FTB: " + intendedVersionId(); return "OneSix FTB: " + intendedVersionId();

View File

@ -15,6 +15,8 @@ public:
virtual std::shared_ptr<Task> doUpdate(bool only_prepare) override; virtual std::shared_ptr<Task> doUpdate(bool only_prepare) override;
virtual QString id() const;
private: private:
std::shared_ptr<OneSixLibrary> m_forge; std::shared_ptr<OneSixLibrary> m_forge;
}; };

View File

@ -308,45 +308,52 @@ void InstanceList::loadForgeInstances(QMap<QString, QString> groupMap)
return; return;
} }
dir.cd("ModPacks"); dir.cd("ModPacks");
auto fpath = dir.absoluteFilePath("modpacks.xml"); auto allFiles = dir.entryList(QDir::Readable | QDir::Files, QDir::Name);
QFile f(fpath); for(auto filename: allFiles)
QLOG_INFO() << "Discovering FTB instances -- " << fpath;
if (!f.open(QFile::ReadOnly))
return;
// read the FTB packs XML.
QXmlStreamReader reader(&f);
while (!reader.atEnd())
{ {
switch (reader.readNext()) if(!filename.endsWith(".xml"))
continue;
auto fpath = dir.absoluteFilePath(filename);
QFile f(fpath);
QLOG_INFO() << "Discovering FTB instances -- " << fpath;
if (!f.open(QFile::ReadOnly))
continue;
// read the FTB packs XML.
QXmlStreamReader reader(&f);
while (!reader.atEnd())
{ {
case QXmlStreamReader::StartElement: switch (reader.readNext())
{
if (reader.name() == "modpack")
{ {
QXmlStreamAttributes attrs = reader.attributes(); case QXmlStreamReader::StartElement:
FTBRecord record; {
record.dir = attrs.value("dir").toString(); if (reader.name() == "modpack")
QDir test(dataDir.absoluteFilePath(record.dir)); {
if(!test.exists()) QXmlStreamAttributes attrs = reader.attributes();
continue; FTBRecord record;
record.name = attrs.value("name").toString(); record.dir = attrs.value("dir").toString();
record.logo = attrs.value("logo").toString(); QDir test(dataDir.absoluteFilePath(record.dir));
record.mcVersion = attrs.value("mcVersion").toString(); if(!test.exists())
record.description = attrs.value("description").toString(); continue;
records.append(record); record.name = attrs.value("name").toString();
record.logo = attrs.value("logo").toString();
record.mcVersion = attrs.value("mcVersion").toString();
record.description = attrs.value("description").toString();
records.append(record);
}
break;
}
case QXmlStreamReader::EndElement:
break;
case QXmlStreamReader::Characters:
break;
default:
break;
} }
break;
}
case QXmlStreamReader::EndElement:
break;
case QXmlStreamReader::Characters:
break;
default:
break;
} }
f.close();
} }
f.close();
if(!records.size()) if(!records.size())
{ {
QLOG_INFO() << "No FTB instances to load."; QLOG_INFO() << "No FTB instances to load.";