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

Method fromInspectedFolder

launcher/mojang/PackageManifest.cpp:231–284  ·  view source on GitHub ↗

FIXME: Qt filesystem abstraction is bad, but ... let's hope it doesn't break too much? FIXME: The error handling is just DEFICIENT

Source from the content-addressed store, hash-verified

229// FIXME: Qt filesystem abstraction is bad, but ... let's hope it doesn't break too much?
230// FIXME: The error handling is just DEFICIENT
231Package Package::fromInspectedFolder(const QString& folderPath)
232{
233 QDir root(folderPath);
234
235 Package out;
236 QDirIterator iterator(folderPath, QDir::NoDotAndDotDot | QDir::AllEntries | QDir::System | QDir::Hidden, QDirIterator::Subdirectories);
237 while(iterator.hasNext()) {
238 iterator.next();
239
240 auto fileInfo = iterator.fileInfo();
241 auto relPath = root.relativeFilePath(fileInfo.filePath());
242 // FIXME: this is probably completely busted on Windows anyway, so just disable it.
243 // Qt makes shit up and doesn't understand the platform details
244 // TODO: Actually use a filesystem library that isn't terrible and has decen license.
245 // I only know one, and I wrote it. Sadly, currently proprietary. PAIN.
246#ifndef Q_OS_WIN32
247 if(fileInfo.isSymLink()) {
248 Path targetPath;
249 if(!actually_read_symlink_target(fileInfo.filePath(), targetPath)) {
250 qCritical() << "Folder inspection: Unknown filesystem object:" << fileInfo.absoluteFilePath();
251 out.valid = false;
252 }
253 out.addLink(relPath, targetPath);
254 }
255 else
256#endif
257 if(fileInfo.isDir()) {
258 out.addFolder(relPath);
259 }
260 else if(fileInfo.isFile()) {
261 File f;
262 f.executable = fileInfo.isExecutable();
263 f.size = fileInfo.size();
264 // FIXME: async / optimize the hashing
265 QFile input(fileInfo.absoluteFilePath());
266 if(!input.open(QIODevice::ReadOnly)) {
267 qCritical() << "Folder inspection: Failed to open file:" << fileInfo.absoluteFilePath();
268 out.valid = false;
269 break;
270 }
271 f.hash = QCryptographicHash::hash(input.readAll(), QCryptographicHash::Sha1).toHex().constData();
272 out.addFile(relPath, f);
273 }
274 else {
275 // Something else... oh my
276 qCritical() << "Folder inspection: Unknown filesystem object:" << fileInfo.absoluteFilePath();
277 out.valid = false;
278 break;
279 }
280 }
281 out.folders.insert(Path("."));
282 out.valid = true;
283 return out;
284}
285
286namespace {
287struct shallow_first_sort

Callers

nothing calls this directly

Calls 11

hashFunction · 0.85
PathClass · 0.85
nextMethod · 0.80
filePathMethod · 0.80
addLinkMethod · 0.80
addFolderMethod · 0.80
openMethod · 0.80
addFileMethod · 0.80
insertMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected