MCPcopy Create free account
hub / github.com/MultiMC/Launcher / processZipPack

Method processZipPack

launcher/InstanceImportTask.cpp:89–141  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

87}
88
89void InstanceImportTask::processZipPack()
90{
91 setStatus(tr("Extracting modpack"));
92 QDir extractDir(m_stagingPath);
93 qDebug() << "Attempting to create instance from" << m_archivePath;
94
95 // open the zip and find relevant files in it
96 m_packZip.reset(new QuaZip(m_archivePath));
97 if (!m_packZip->open(QuaZip::mdUnzip))
98 {
99 emitFailed(tr("Unable to open supplied modpack zip file."));
100 return;
101 }
102
103 QStringList blacklist = {"instance.cfg", "manifest.json"};
104 QString mmcFound = MMCZip::findFolderOfFileInZip(m_packZip.get(), "instance.cfg");
105 bool technicFound = QuaZipDir(m_packZip.get()).exists("/bin/modpack.jar") || QuaZipDir(m_packZip.get()).exists("/bin/version.json");
106 QString modrinthFound = MMCZip::findFolderOfFileInZip(m_packZip.get(), "modrinth.index.json");
107 QString root;
108 if(!mmcFound.isNull())
109 {
110 // process as MultiMC instance/pack
111 qDebug() << "MultiMC:" << mmcFound;
112 root = mmcFound;
113 m_modpackType = ModpackType::MultiMC;
114 }
115 else if (technicFound)
116 {
117 // process as Technic pack
118 qDebug() << "Technic:" << technicFound;
119 extractDir.mkpath(".minecraft");
120 extractDir.cd(".minecraft");
121 m_modpackType = ModpackType::Technic;
122 }
123 else if(!modrinthFound.isNull())
124 {
125 // process as Modrinth pack
126 qDebug() << "Modrinth:" << modrinthFound;
127 root = modrinthFound;
128 m_modpackType = ModpackType::Modrinth;
129 }
130 if(m_modpackType == ModpackType::Unknown)
131 {
132 emitFailed(tr("Archive does not contain a recognized modpack type."));
133 return;
134 }
135
136 // make sure we extract just the pack
137 m_extractFuture = QtConcurrent::run(QThreadPool::globalInstance(), MMCZip::extractSubDir, m_packZip.get(), root, extractDir.absolutePath());
138 connect(&m_extractFutureWatcher, &QFutureWatcher<QStringList>::finished, this, &InstanceImportTask::extractFinished);
139 connect(&m_extractFutureWatcher, &QFutureWatcher<QStringList>::canceled, this, &InstanceImportTask::extractAborted);
140 m_extractFutureWatcher.setFuture(m_extractFuture);
141}
142
143void InstanceImportTask::extractFinished()
144{

Callers

nothing calls this directly

Calls 5

runFunction · 0.85
openMethod · 0.80
existsMethod · 0.80
resetMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected