Esempio n. 1
0
FileInfoPtr FileInfoService::query(const std::string& _filename)
{
	std::string filename(_filename[_filename.size() - 1] == '/'
			? _filename.substr(0, _filename.size() - 1)
			: _filename);

	auto i = cache_.find(filename);
	if (i != cache_.end()) {
		FileInfoPtr fi = i->second;
		if (isValid(fi.get())) {
			TRACE("query.cached(%s) len:%ld\n", filename.c_str(), fi->size());
			return fi;
		}

		TRACE("query.expired(%s) len:%ld\n", filename.c_str(), fi->size());
#if defined(HAVE_SYS_INOTIFY_H)
		if (fi->inotifyId_ >= 0) {
			inotify_rm_watch(handle_, fi->inotifyId_);
			auto i = inotifies_.find(fi->inotifyId_);
			if (i != inotifies_.end())
				inotifies_.erase(i);
		}
#endif
		cache_.erase(i);
	}

	if (FileInfoPtr fi = FileInfoPtr(new FileInfo(*this, filename))) {
		fi->mimetype_ = get_mimetype(filename);
		fi->etag_ = make_etag(*fi);

#if defined(HAVE_SYS_INOTIFY_H)
		int wd = handle_ != -1 && fi->exists()
				? ::inotify_add_watch(handle_, filename.c_str(),
					/*IN_ONESHOT |*/ IN_ATTRIB | IN_DELETE_SELF | IN_MOVE_SELF | IN_UNMOUNT |
					IN_DELETE_SELF | IN_MOVE_SELF)
				: -1;
		TRACE("query(%s).new -> %d len:%ld\n", filename.c_str(), wd, fi->size());

		if (wd != -1) {
			fi->inotifyId_ = wd;
			inotifies_[wd] = fi;
		}
		cache_[filename] = fi;
#else
		TRACE("query(%s)! len:%ld\n", filename.c_str(), fi->size());
		cache_[filename] = fi;
#endif

		return fi;
	}

	TRACE("query(%s) failed (%s)\n", filename.c_str(), strerror(errno));
	// either ::stat() or caching failed.

	return FileInfoPtr();
}
void MainWindow::startPatching()
{
    Q_D(MainWindow);

    d->bytes = 0;
    d->maxBytes = 0;
    d->files = 0;
    d->maxFiles = 0;

    d->progressBar->setMaximum(0);
    d->progressBar->setValue(0);
    d->detailsLbl->clear();

    if (!d->supported) {
        if (d->presetSel->currentIndex() == 0) {
            d->patchInfo = new mbp::PatchInfo(); // TODO: Memory leak here!

            d->patchInfo->addAutoPatcher("StandardPatcher",
                                         mbp::PatchInfo::AutoPatcherArgs());
            d->patchInfo->setHasBootImage(d->hasBootImageCb->isChecked());
            if (d->patchInfo->hasBootImage()) {
                d->patchInfo->setRamdisk(d->device->id() + "/default");
                QString text = d->bootImageLe->text().trimmed();
                if (!text.isEmpty()) {
                    QStringList split = text.split(QStringLiteral(","));
                    std::vector<std::string> bootImages;
                    for (const QString &bootImage : split) {
                        bootImages.push_back(bootImage.toUtf8().constData());
                    }
                    d->patchInfo->setBootImages(std::move(bootImages));
                }
            }

            d->patchInfo->setDeviceCheck(!d->deviceCheckCb->isChecked());
        } else {
            d->patchInfo = d->patchInfos[d->presetSel->currentIndex() - 1];
        }
    }

    d->state = MainWindowPrivate::Patching;
    updateWidgetsVisibility();

    FileInfoPtr fileInfo = new mbp::FileInfo();
    fileInfo->setFilename(d->fileName.toUtf8().constData());
    fileInfo->setDevice(d->device);
    fileInfo->setPatchInfo(d->patchInfo);
    QString romId;
    if (d->instLocSel->currentIndex() >= d->instLocs.size()) {
        romId = QStringLiteral("data-slot-%1").arg(d->instLocLe->text());
    } else {
        romId = d->instLocs[d->instLocSel->currentIndex()].id;
    }
    fileInfo->setRomId(romId.toUtf8().constData());

    emit runThread(d->patcher, fileInfo);
}
Esempio n. 3
0
void PatcherTask::patch(PatcherPtr patcher, FileInfoPtr info)
{
    patcher->setFileInfo(info);

    bool ret = patcher->patchFile(&progressUpdatedCbWrapper,
                                  &filesUpdatedCbWrapper,
                                  &detailsUpdatedCbWrapper,
                                  this);

    QString newFile(QString::fromStdString(info->outputPath()));

    patcher->setFileInfo(nullptr);
    delete info;

    if (!ret) {
        emit finished(QString(), true, errorToString(patcher->error()));
    } else {
        emit finished(newFile, false, QString());
    }
}
Esempio n. 4
0
void MainWindow::startPatching()
{
    Q_D(MainWindow);

    d->bytes = 0;
    d->maxBytes = 0;
    d->files = 0;
    d->maxFiles = 0;

    d->progressBar->setMaximum(0);
    d->progressBar->setValue(0);
    d->detailsLbl->clear();

    d->state = MainWindowPrivate::Patching;
    updateWidgetsVisibility();

    QString romId;
    if (d->instLocSel->currentIndex() == d->instLocs.size()) {
        romId = QStringLiteral("data-slot-%1").arg(d->instLocLe->text());
    } else if (d->instLocSel->currentIndex() == d->instLocs.size() + 1) {
        romId = QStringLiteral("extsd-slot-%1").arg(d->instLocLe->text());
    } else {
        romId = d->instLocs[d->instLocSel->currentIndex()].id;
    }


    QStringList suffixes;
    suffixes << QStringLiteral(".tar.md5");
    suffixes << QStringLiteral(".tar.md5.gz");
    suffixes << QStringLiteral(".tar.md5.xz");
    suffixes << QStringLiteral(".zip");

    QFileInfo qFileInfo(d->fileName);
    QString suffix;
    QString outputName;
    bool isOdin = false;

    for (const QString &suffix : suffixes) {
        if (d->fileName.endsWith(suffix)) {
            // Input name: <parent path>/<base name>.<suffix>
            // Output name: <parent path>/<base name>_<rom id>.zip
            outputName = d->fileName.left(d->fileName.size() - suffix.size())
                    % QStringLiteral("_")
                    % romId
                    % QStringLiteral(".zip");
            isOdin = suffix.contains(QStringLiteral(".tar.md5"));
            break;
        }
    }
    if (outputName.isEmpty()) {
        outputName = qFileInfo.completeBaseName()
                % QStringLiteral("_")
                % romId
                % QStringLiteral(".")
                % qFileInfo.suffix();
    }

    QString inputPath(QDir::toNativeSeparators(qFileInfo.filePath()));
    QString outputPath(QDir::toNativeSeparators(
            qFileInfo.dir().filePath(outputName)));

    FileInfoPtr fileInfo = new mbp::FileInfo();
    fileInfo->setInputPath(inputPath.toUtf8().constData());
    fileInfo->setOutputPath(outputPath.toUtf8().constData());
    fileInfo->setDevice(d->device);
    fileInfo->setRomId(romId.toUtf8().constData());

    if (isOdin) {
        d->patcher = d->pc->createPatcher("OdinPatcher");
    } else {
        d->patcher = d->pc->createPatcher("MultiBootPatcher");
    }

    emit runThread(d->patcher, fileInfo);
}