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

Method processZipPack

launcher/InstanceImportTask.cpp:121–205  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

119}
120
121void InstanceImportTask::processZipPack()
122{
123 setStatus(tr("Attempting to determine instance type"));
124 QDir extractDir(m_stagingPath);
125 qDebug() << "Attempting to create instance from" << m_archivePath;
126
127 // open the zip and find relevant files in it
128 MMCZip::ArchiveReader packZip(m_archivePath);
129 qDebug() << "Attempting to determine instance type";
130
131 QString root;
132 // NOTE: Prioritize modpack platforms that aren't searched for recursively.
133 // Especially Flame has a very common filename for its manifest, which may appear inside overrides for example
134 // https://docs.modrinth.com/docs/modpacks/format_definition/#storage
135 auto detectInstance = [this, &extractDir, &root](MMCZip::ArchiveReader::File* f, bool& stop) {
136 if (!isRunning()) {
137 stop = true;
138 return true;
139 }
140 auto fileName = f->filename();
141 if (fileName == "modrinth.index.json") {
142 // process as Modrinth pack
143 qDebug() << "Modrinth:" << true;
144 m_modpackType = ModpackType::Modrinth;
145 stop = true;
146 } else if (fileName == "bin/modpack.jar" || fileName == "bin/version.json") {
147 // process as Technic pack
148 qDebug() << "Technic:" << true;
149 extractDir.mkpath("minecraft");
150 extractDir.cd("minecraft");
151 m_modpackType = ModpackType::Technic;
152 stop = true;
153 } else if (fileName == "manifest.json") {
154 qDebug() << "Flame:" << true;
155 m_modpackType = ModpackType::Flame;
156 stop = true;
157 } else if (QFileInfo fileInfo(fileName); fileInfo.fileName() == "instance.cfg") {
158 qDebug() << "MultiMC:" << true;
159 m_modpackType = ModpackType::MultiMC;
160 root = cleanPath(fileInfo.path());
161 stop = true;
162 }
163 QCoreApplication::processEvents();
164 return true;
165 };
166 if (!packZip.parse(detectInstance)) {
167 emitFailed(tr("Unable to open supplied modpack zip file."));
168 return;
169 }
170 if (m_modpackType == ModpackType::Unknown) {
171 emitFailed(tr("Archive does not contain a recognized modpack type."));
172 return;
173 }
174 setStatus(tr("Extracting modpack"));
175
176 // make sure we extract just the pack
177 auto zipTask = makeShared<MMCZip::ExtractZipTask>(m_archivePath, extractDir, root);
178

Callers

nothing calls this directly

Calls 9

cleanPathFunction · 0.85
appendMethod · 0.80
filenameMethod · 0.45
pathMethod · 0.45
parseMethod · 0.45
getMethod · 0.45
updateMethod · 0.45
resetMethod · 0.45
startMethod · 0.45

Tested by

no test coverage detected