bool ExportCommon::download(ExportContext *ctx, QString url, QString to) { QString filePath = QDir::cleanPath(ctx->outputDir.absoluteFilePath(to)); QFileInfo fi = QFileInfo(filePath); ctx->outputDir.mkpath(fi.dir().absolutePath()); QFile file(filePath); if (file.exists()) return true; if (file.open(QIODevice::WriteOnly)) { exportInfo("Downloading %s\n", url.toStdString().c_str()); QUrl imageUrl(url); FileDownloader *m_pImgCtrl = new FileDownloader(imageUrl); QEventLoop loop; loop.connect(m_pImgCtrl, SIGNAL(downloaded()), &loop, SLOT(quit())); loop.exec(); QByteArray data = m_pImgCtrl->downloadedData(); delete m_pImgCtrl; if (data.length() > 0) { file.write(data); return true; } else exportError("Failed to download %s\n", url.toStdString().c_str()); } else exportError("Can't open file %s\n", to.toStdString().c_str()); return false; }
void DataExportHelper::startWorkerThread(const QString &tableName) { Q_ASSERT(workerThread==0); DataExporterOptions *exporterOptions = static_cast<DataExporterOptions*>(options); TableInfoForDataComparison tabOptions = tableOptions.value(tableName); if(!exporterOptions->singleFile && this->objectCount>1){ if(initialFileName.isEmpty()){ initialFileName = exporterOptions->exporter->filename; } if(!initialFileName.isEmpty()){ QFileInfo file(initialFileName); QString directory = file.path(); QString name = file.baseName(); QString extension = file.completeSuffix(); QString modifiedFilename = QString("%1/%2_%3.%4").arg(directory, name, toValidFilename(currentTableName), extension); exporterOptions->exporter->filename = modifiedFilename; } }else if(exporterOptions->singleFile && this->currentItemIxToCompare>1){ //currentItemIxToCompare is 1 based when reaching this function exporterOptions->exporter->setStreamOpenMode(QIODevice::Append); } InsertExporter *insertExporter = dynamic_cast<InsertExporter*>(exporterOptions->exporter); if(insertExporter){ if(insertExporter->schemaName.isEmpty()){ insertExporter->schemaName = sourceSchema; } insertExporter->tableName = tabOptions.targetTableName.isEmpty() ? tableName : tabOptions.targetTableName; } exporterOptions->exporter->reset(); DataExporterThread *exporterThread = new DataExporterThread(exporterOptions->exporter, QList<QStringList>(), 0, true, false, this); connect(exporterThread, SIGNAL(recordsExported(int)), this, SLOT(recordsExported(int))); connect(exporterThread, SIGNAL(exportComplete()), this, SLOT(tableDataExported())); connect(exporterThread, SIGNAL(exportError(QString)), this, SLOT(exportError(QString))); exporterThread->setOptions(sourceScheduler, sourceSchema, tableName, exporterOptions, tabOptions); workerThread = exporterThread; workerThread->start(); emit compareInfoAvailable(DataCompareInfo(this->currentTableName, tr("Exporting data"))); }
void PlaybackController::exporterError(const QString &message) { // Stop playback on error if(isPlaying()) setPlaying(false); emit exportError(message); exporterFinished(); }
void ExportCommon::copyTemplate(QString templatePath, QString templateDest, ExportContext *ctx, bool isPlugin, QStringList include, QStringList exclude) { QDir dir = QDir::currentPath(); if (!dir.cd(templatePath)) { exportError("Template source not found:%s\n", templatePath.toStdString().c_str()); return; } exportInfo("Processing template\n"); QDir dir2 = QDir(ctx->outputDir); if (!templateDest.isEmpty()) { dir2 = QDir(templateDest); } if (!isPlugin) { ctx->renameList << qMakePair(ctx->templatename, ctx->base); ctx->renameList << qMakePair(ctx->templatenamews, ctx->basews); } if (!include.count()) { if (ctx->assetsOnly) { include << "libgideros.so" << "libgideros.a" << "gideros.jar" << "gideros.dll" << "gid.dll" << "libgideros.dylib" << "libgideros.1.dylib" << "gideros.WindowsPhone.lib" << "gideros.Windows.lib" << "WindowsDesktopTemplate.exe" << "MacOSXDesktopTemplate"; } else include << "*"; } Utilities::copyFolder(dir, dir2, ctx->renameList, ctx->wildcards, ctx->replaceList, include, exclude); ctx->renameList.clear(); ctx->wildcards.clear(); ctx->replaceList.clear(); }
bool ExportCommon::unzip(ExportContext *ctx, QString file, QString dest) { QDir toPath = QFileInfo( QDir::cleanPath(ctx->outputDir.absoluteFilePath(dest))).dir(); QFile zfile(file); if (!zfile.open(QIODevice::ReadOnly)) { exportError("Can't open file %s\n", file.toStdString().c_str()); return false; } while (true) { struct _ZipHdr { quint32 Signature;// local file header signature 4 bytes (0x04034b50) #define ZIPHDR_SIG 0x04034b50 quint16 Version; // version needed to extract 2 bytes quint16 Flags; // general purpose bit flag 2 bytes quint16 Compression; // compression method 2 bytes quint16 ModTime; // last mod file time 2 bytes quint16 ModDate; // last mod file date 2 bytes quint32 Crc32; // crc-32 4 bytes quint32 CompSize; // compressed size 4 bytes quint32 OrigSize; // uncompressed size 4 bytes quint16 NameLen; // file name length 2 bytes quint16 ExtraLen;// extra field length 2 bytes }PACKED Hdr; if (zfile.read((char *) &Hdr, sizeof(Hdr)) != sizeof(Hdr)) break; if (_letohl(Hdr.Signature) != ZIPHDR_SIG) break; if (_letohs(Hdr.Version) > 20) { exportError("Unsupported ZIP version for %s [%d]\n", file.toStdString().c_str(), _letohs(Hdr.Version)); return false; } if (Hdr.Flags != 0) { exportError("Unsupported flags for %s [%04x]\n", file.toStdString().c_str(), Hdr.Flags); return false; } if ((Hdr.Compression > 0) && (_letohs(Hdr.Compression) != 8)) { exportError("Unsupported compression method for %s [%d]\n", file.toStdString().c_str(), _letohs(Hdr.Compression)); return false; } QByteArray fname = zfile.read(_letohs(Hdr.NameLen)); QString lname = QString(fname); zfile.read(_letohs(Hdr.ExtraLen)); exportInfo("Extracting %s\n",lname.toStdString().c_str()); QByteArray fcont = zfile.read( Hdr.Compression ? _letohl(Hdr.CompSize) : _letohl(Hdr.OrigSize)); if (Hdr.Compression) { QByteArray decomp; if (!gzInflate(fcont,decomp)) { exportError("Failed to uncompress %s\n", lname.toStdString().c_str()); break; } fcont = decomp; } if (lname.endsWith("/")) ctx->outputDir.mkpath(toPath.absoluteFilePath(lname)); else { QFile ofile(toPath.absoluteFilePath(lname)); if (ofile.open(QIODevice::WriteOnly)) { ofile.write(fcont); ofile.close(); } else { exportError("Can't open file %s\n", lname.toStdString().c_str()); break; } } } zfile.close(); return true; }
void ExportCommon::exportAssets(ExportContext *ctx, bool compileLua) { QStringList allluafiles; QStringList allluafiles_abs; if ((ctx->fileQueue.size() == 0) || (ctx->player)) //No assets -> Player return; exportInfo("Exporting assets\n"); for (std::size_t i = 0; i < ctx->folderList.size(); ++i) ctx->outputDir.mkdir(ctx->folderList[i]); ctx->allfiles.clear(); ctx->allfiles_abs.clear(); ctx->luafiles.clear(); ctx->luafiles_abs.clear(); QDir path(QFileInfo(ctx->projectFileName_).path()); ExportCommon::progressSteps(ctx->fileQueue.size()); for (std::size_t i = 0; i < ctx->fileQueue.size(); ++i) { const QString& s1 = ctx->fileQueue[i].first; const QString& s2 = ctx->fileQueue[i].second; exportInfo("Exporting %s\n", s1.toUtf8().constData()); ExportCommon::progressStep(s1.toUtf8().constData()); QString src = QDir::cleanPath(path.absoluteFilePath(s2)); QString dst = QDir::cleanPath(ctx->outputDir.absoluteFilePath(s1)); QString rdst = QDir::cleanPath(ctx->outputDir.relativeFilePath(s1)); QString suffix = QFileInfo(dst).suffix().toLower(); bool isJet = false; if ((!ctx->jetset.isEmpty()) && (!ctx->jetset.contains(suffix))) { dst += ".jet"; isJet = true; } ctx->allfiles.push_back(s1); ctx->allfiles_abs.push_back(dst); QFile::remove(dst); bool copied = false; if (QFileInfo(src).suffix().toLower() == "lua") { allluafiles.push_back(s1); allluafiles_abs.push_back(dst); if (std::find(ctx->topologicalSort.begin(), ctx->topologicalSort.end(), std::make_pair(s2, true)) == ctx->topologicalSort.end()) { ctx->luafiles.push_back(s1); ctx->luafiles_abs.push_back(dst); } // compile lua files (with luac) if (compileLua) { QDir toolsDir = QDir(QCoreApplication::applicationDirPath()); #if defined(Q_OS_WIN) QString luac = toolsDir.filePath("luac.exe"); #else QString luac = toolsDir.filePath("luac"); #endif QDir old = QDir::current(); QDir::setCurrent(ctx->outputDir.path()); QString dfile = "\"" + dst + "\""; QString sfile = "\"" + rdst + "\""; QFile::copy(src, rdst); QProcess::execute(quote(luac) + " -o " + dfile + " " + sfile); if (isJet) QFile::remove(rdst); copied = true; QDir::setCurrent(old.path()); } } if (!copied) QFile::copy(src, dst); } #if 0 // compile lua files if (false) { compileThread_ = new CompileThread(ctx->luafiles_abs, false, "", QString(), this); compileThread_->start(); compileThread_->wait(); delete compileThread_; } #endif // encrypt lua, png, jpg, jpeg and wav files if (true) { exportInfo("Encrypting assets\n"); ExportCommon::progressSteps(ctx->allfiles_abs.size()); for (int i = 0; i < ctx->allfiles_abs.size(); ++i) { ExportCommon::progressStep( ctx->allfiles_abs[i].toUtf8().constData()); QString filename = ctx->allfiles_abs[i]; QString ext = QFileInfo(ctx->allfiles[i]).suffix().toLower(); exportInfo("Encrypting %s [%s]\n", filename.toUtf8().constData(), ext.toUtf8().constData()); if (ext != "lua" && ext != "png" && ext != "jpeg" && ext != "jpg" && ext != "wav") continue; QByteArray encryptionKey = (ext == "lua") ? ctx->codeKey : ctx->assetsKey; QFile fis(filename); if (!fis.open(QIODevice::ReadOnly)) { exportError("Failed to open %s\n", filename.toUtf8().constData()); continue; } QByteArray data = fis.readAll(); fis.close(); int ks = encryptionKey.size(); for (int j = 32; j < data.size(); ++j) data[j] = data[j] ^ encryptionKey[((j * 13) + ((j / ks) * 31)) % ks]; QFile fos(filename); if (!fos.open(QIODevice::WriteOnly)) { exportError("Failed to save %s\n", filename.toUtf8().constData()); continue; } fos.write(data); fos.close(); } } // compress lua files if (false) { for (int i = 0; i < ctx->luafiles_abs.size(); ++i) { QString file = "\"" + ctx->luafiles_abs[i] + "\""; QProcess::execute( "Tools/lua Tools/LuaSrcDiet.lua --quiet " + file + " -o " + file); } } ctx->assetfiles = ctx->allfiles; ctx->assetfiles_abs = ctx->allfiles_abs; }