MCPcopy Create free account
hub / github.com/PolyMC/PolyMC / processZipPack

Method processZipPack

launcher/InstanceImportTask.cpp:128–194  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

126}
127
128void InstanceImportTask::processZipPack()
129{
130 setStatus(tr("Extracting modpack"));
131 QDir extractDir(m_stagingPath);
132 qDebug() << "Attempting to create instance from" << m_archivePath;
133
134 // open the zip and find relevant files in it
135 m_packZip.reset(new QuaZip(m_archivePath));
136 if (!m_packZip->open(QuaZip::mdUnzip))
137 {
138 emitFailed(tr("Unable to open supplied modpack zip file."));
139 return;
140 }
141
142 QuaZipDir packZipDir(m_packZip.get());
143
144 // https://docs.modrinth.com/docs/modpacks/format_definition/#storage
145 bool modrinthFound = packZipDir.exists("/modrinth.index.json");
146 bool technicFound = packZipDir.exists("/bin/modpack.jar") || packZipDir.exists("/bin/version.json");
147 QString root;
148
149 // NOTE: Prioritize modpack platforms that aren't searched for recursively.
150 // Especially Flame has a very common filename for its manifest, which may appear inside overrides for example
151 if(modrinthFound)
152 {
153 // process as Modrinth pack
154 qDebug() << "Modrinth:" << modrinthFound;
155 m_modpackType = ModpackType::Modrinth;
156 }
157 else if (technicFound)
158 {
159 // process as Technic pack
160 qDebug() << "Technic:" << technicFound;
161 extractDir.mkpath(".minecraft");
162 extractDir.cd(".minecraft");
163 m_modpackType = ModpackType::Technic;
164 }
165 else
166 {
167 auto [rootDirectory, fileName] = MMCZip::findFolderOfFileInZip(m_packZip.get(), {"manifest.json", "instance.cfg"});
168 if(fileName == "manifest.json")
169 {
170 // process as Flame pack
171 qDebug() << "Flame:" << rootDirectory;
172 root = rootDirectory;
173 m_modpackType = ModpackType::Flame;
174 }
175 else if (fileName == "instance.cfg")
176 {
177 // process as MultiMC instance/pack
178 qDebug() << "MultiMC:" << rootDirectory;
179 root = rootDirectory;
180 m_modpackType = ModpackType::MultiMC;
181 }
182 }
183 if(m_modpackType == ModpackType::Unknown)
184 {
185 emitFailed(tr("Archive does not contain a recognized modpack type."));

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