static QString CreateTempFile(QuaZip& zip, QString zipFilename) { if (!zip.setCurrentFile(zipFilename)) { ccLog::Warning(QString("[Photoscan] Failed to locate '%1' in the Photoscan archive").arg(zipFilename)); return QString(); } //decompress the file QuaZipFile zipFile(&zip); if (!zipFile.open(QFile::ReadOnly)) { ccLog::Warning(QString("[Photoscan] Failed to extract '%1' from Photoscan archive").arg(zipFilename)); return QString(); } QDir tempDir = QDir::temp(); QString tempFilename = tempDir.absoluteFilePath(zipFilename); QFile tempFile(tempFilename); if (!tempFile.open(QFile::WriteOnly)) { ccLog::Warning(QString("[Photoscan] Failed to create temp file '%1'").arg(tempFilename)); return QString(); } tempFile.write(zipFile.readAll()); tempFile.close(); return tempFilename; }
ZipArchive ZipManipulator::commit() { // write to a tmp file std::string outFile(_zipFile + ".tmp"); ZipArchive retVal(compress(outFile)); //renaming { Poco::File aFile(_zipFile); if (_backupOriginalFile) { Poco::File tmp(_zipFile+".bak"); if (tmp.exists()) tmp.remove(); aFile.renameTo(_zipFile+".bak"); } else aFile.remove(); } { Poco::File resFile(outFile); Poco::File zipFile(_zipFile); if (zipFile.exists()) zipFile.remove(); resFile.renameTo(_zipFile); } return retVal; }
void TestJlCompress::compressFile() { QFETCH(QString, zipName); QFETCH(QString, fileName); QDir curDir; if (curDir.exists(zipName)) { if (!curDir.remove(zipName)) QFAIL("Can't remove zip file"); } if (!createTestFiles(QStringList() << fileName)) { QFAIL("Can't create test file"); } QVERIFY(JlCompress::compressFile(zipName, "tmp/" + fileName)); // get the file list and check it QStringList fileList = JlCompress::getFileList(zipName); QCOMPARE(fileList.count(), 1); QVERIFY(fileList[0] == fileName); // now test the QIODevice* overload of getFileList() QFile zipFile(zipName); QVERIFY(zipFile.open(QIODevice::ReadOnly)); fileList = JlCompress::getFileList(zipName); QCOMPARE(fileList.count(), 1); QVERIFY(fileList[0] == fileName); zipFile.close(); removeTestFiles(QStringList() << fileName); curDir.remove(zipName); }
void FileLogAppender::compressionDayBeforeLogFile() { namespace FS = std::tr2::sys; namespace ZIP = libzippp; date::year_month_day dayBefore(date::floor<date::days>(date::sys_days::clock::now() - date::days{ 1 })); std::wostringstream ostr; ostr << dayBefore; auto dayBeforeLogPath = ostr.str(); std::tr2::sys::path dayBeforePath(logFilePath_ + dayBeforeLogPath); auto dayBeforeZipFullFilePath = dayBeforePath.wstring() + L".zip"; if (FS::exists(dayBeforePath)) { return; } // 將前一天的資料夾壓縮 ZIP::ZipArchive zipFile(utils::formUtf16(dayBeforeZipFullFilePath)); zipFile.open(ZIP::ZipArchive::OpenMode::NEW); platform::MemoryMappedFile mappedFile(utils::formUtf16(dayBeforePath.wstring() + L"\\" + logFileName_)); // libzippp只支援'/'(Unix)資料路徑格式所以要轉換 zipFile.addData(utils::formUtf16(dayBeforeLogPath) + "/" + utils::formUtf16(logFileName_), mappedFile.data(), mappedFile.getFileSize()); }
void Test_ZipUnzip::zipUnzip() { auto path = createTemporaryFilePath(); QString testString = "Lorem ipsum dolor sit amet"; { QFile file(path); ZipArchive zipArchive(&file); zipArchive.open(); ZipFile zipFile(&zipArchive, "test.txt"); zipFile.open(); QTextStream stream(&zipFile); stream << testString; } { QFile file(path); UnzipArchive unzArchive(&file); unzArchive.open(); UnzipFile unzipFile(&unzArchive, "test.txt"); unzipFile.open(); QTextStream stream(&unzipFile); QCOMPARE(stream.readAll(), testString); } }
void KArchiveTest::testCreateZip() { KZip zip( s_zipFileName ); QVERIFY( zip.open( QIODevice::WriteOnly ) ); zip.setExtraField( KZip::NoExtraField ); zip.setCompression( KZip::NoCompression ); QByteArray zipMimeType( s_zipMimeType ); zip.writeFile( "mimetype", "", "", zipMimeType.data(), zipMimeType.size() ); zip.setCompression( KZip::DeflateCompression ); writeTestFilesToArchive( &zip ); QVERIFY( zip.close() ); QFile zipFile( QFile::encodeName( s_zipFileName ) ); QFileInfo fileInfo( zipFile ); QVERIFY( fileInfo.exists() ); QVERIFY( fileInfo.size() > 300 ); // Check that the header with no-compression and no-extrafield worked. // (This is for the "magic" for koffice documents) QVERIFY( zipFile.open( QIODevice::ReadOnly ) ); QByteArray arr = zipFile.read( 4 ); QCOMPARE( arr, QByteArray( "PK\003\004" ) ); QVERIFY( zipFile.seek( 30 ) ); arr = zipFile.read( 8 ); QCOMPARE( arr, QByteArray( "mimetype" ) ); arr = zipFile.read( zipMimeType.size() ); QCOMPARE( arr, zipMimeType ); }
bool SRTMProvider::fillTile(int index, SRTMTile **tile){ bool tileFilled = false; QString fileName; // Name incl. Pfad (wird aus _cachedir und Index erstellt) loadFileList(); // per loadFilelist(): fileListe vorhanden? falls nicht: erstellen! if (fileList.contains(index)){ fileName = _cachedir+fileList[index]; QFile zipFile(fileName); int fileIndex = index; //Bugfixversuch: fileIndex if(!zipFile.open(QIODevice::ReadOnly) && !downloadZipFile(fileIndex, fileName, zipFile)){ //Bugfixversuch: fileIndex return tileFilled; } tileFilled = (*tile)->fillTile(fileName); } return tileFilled; }
void SelfUpdater::extract() { qDebug() << "SelfUpdater::extract"; QUrl url(versionInfo["url"].toString()); QString fileToExtract = "wpn-xm.exe"; QString zipFile(QDir::toNativeSeparators(downloadFolder + QDir::separator() + url.fileName())); QString targetPath(QDir::toNativeSeparators(QCoreApplication::applicationDirPath())); if(!QFile(zipFile).exists()) { qDebug() << "[SelfUpdater] Zip File missing" << zipFile; } qDebug() << "[SelfUpdater] Extracting " << fileToExtract << "from" << zipFile << "to" << targetPath; // WTF? extractFile() doesn't work ??? //qDebug() << "[SelfUpdater] Filelist:" << JlCompress::getFileList(zipFile); //qDebug() << JlCompress::extractFile( zipFile, fileToExtract, QDir::toNativeSeparators(downloadFolder)); //qDebug() << JlCompress::extractFile( zipFile, fileToExtract, targetPath); // thanks to me, the zip file contains only the executable // so extractDir() is basically extractFile(), but still.... grrrr QStringList extractedFiles = JlCompress::extractDir(zipFile, targetPath); if(QFileInfo(extractedFiles.at(0)).fileName() == "wpn-xm.exe") { qDebug() << "[SelfUpdater] ---- Success! ----"; if(settings->get("selfupdater/autorestart").toBool()) { emit notifyRestartNeeded(versionInfo); } else { askForRestart(); } } }
void writeGridToAsciiFile(Grid *grid, char *file_name, int zip_status) { FILE *fp = fopen(file_name,"w"); printGrid(grid, fp); fclose(fp); zipFile(file_name,zip_status); }
void ResourceManager::download() { QPushButton *button = dynamic_cast<QPushButton*>( sender() ); QString data = buttonMap[button]; QString hash = buttonHashMap[button]; button->setText(tr("Updating")); button->setDisabled(1); QString baseAddress = baseAddr + data; DownloadUtils *dl = new DownloadUtils(this); dl->setTarget(baseAddress); qDebug() << baseAddress; QString localPath = dataPath + "/locale/" + data.split('/')[1]; dl->setLocalFile(localPath); dl->download(); if( !dl->saveFile() || !verifyFile(localPath, hash)) { button->setText(tr("Failed, try again")); button->setEnabled(1); } else { // unzip and delete MQZipReader zipFile(localPath); QFileInfo zfi(localPath); QString destinationDir(zfi.absolutePath()); QList<MQZipReader::FileInfo> allFiles = zipFile.fileInfoList(); bool result = true; foreach (MQZipReader::FileInfo fi, allFiles) { const QString absPath = destinationDir + QDir::separator() + fi.filePath; if (fi.isFile) { QFile f(absPath); if (!f.open(QIODevice::WriteOnly)) { result = false; break; } f.write(zipFile.fileData(fi.filePath)); f.setPermissions(fi.permissions); f.close(); } } zipFile.close(); if (result) { QFile::remove(localPath); button->setText(tr("Updated")); // retranslate the UI if current language is updated if (data == buttonMap.first()) setMscoreLocale(localeName); } else { button->setText(tr("Failed, try again")); button->setEnabled(1); } } }
int CDiagramTemplateManager::loadPackage(const QString &zipFileName) { int count = 0; QDir dir(m_templatesRoot); QString fileName, filePath; QuaZip zip(zipFileName); QuaZipFile zipFile(&zip); CDiagramTemplate *tpl = NULL; if (zip.open(QuaZip::mdUnzip)) { for(bool more = zip.goToFirstFile(); more; more = zip.goToNextFile()) { fileName = zip.getCurrentFileName(); if (fileName.toLower().endsWith(TEMPLATE_SUFFIX) && zipFile.open(QIODevice::ReadOnly)) { int len = 0; char chs[1026]; QByteArray zipData, unzipData; QDataStream stream(&zipFile); while ( (len = stream.readRawData(chs, 1024)) > 0) { zipData.append(chs, len); } unzipData = qUncompress( zipData ); tpl = loadStringAsTemplate( unzipData ); if (tpl) { fileName = QString( QCryptographicHash::hash(unzipData, QCryptographicHash::Md5).toBase64() ); filePath = dir.absoluteFilePath( QString("%1.%2").arg(fileName).arg(TEMPLATE_SUFFIX) ); saveTemplateData(unzipData, filePath); tpl->filePath = filePath; addTemplate(tpl); ++count; } zipFile.close(); } } zip.close(); } return count; }
bool KmzHandler::open( const QString &kmz ) { QuaZip zip( kmz ); if ( !zip.open( QuaZip::mdUnzip ) ) { mDebug() << "Failed to extract " << kmz; return false; } QTemporaryFile outputDir ( QDir::tempPath() + "/marble-kmz-XXXXXX" ); outputDir.setAutoRemove( false ); outputDir.open(); if ( !QFile::remove( outputDir.fileName() ) || !QDir("/").mkdir( outputDir.fileName() ) ) { mDebug() << "Failed to create temporary storage for extracting " << kmz; return false; } m_kmzPath = outputDir.fileName(); QuaZipFile zipFile( &zip ); for ( bool moreFiles=zip.goToFirstFile(); moreFiles; moreFiles=zip.goToNextFile() ) { QFileInfo output = QFileInfo( outputDir.fileName() + "/" + zip.getCurrentFileName() ); if ( !output.dir().exists() ) { QDir::root().mkpath( output.dir().absolutePath() ); } QFile outputFile( output.absoluteFilePath() ); outputFile.open( QIODevice::WriteOnly ); zipFile.open( QIODevice::ReadOnly ); outputFile.write( zipFile.readAll() ); outputFile.close(); zipFile.close(); m_kmzFiles << output.absoluteFilePath(); if ( output.suffix().toLower() == "kml" ) { if ( !m_kmlFile.isEmpty() ) { mDebug() << "File" << kmz << "contains more than one .kml files"; } m_kmlFile = output.absoluteFilePath(); } } zip.close(); return true; }
bool BooksDBUtil::canRemoveFile(const std::string &filePath) { ZLFile bookFile(filePath); std::string physicalPath = bookFile.physicalFilePath(); if (filePath != physicalPath) { ZLFile zipFile(physicalPath); shared_ptr<ZLDir> zipDir = zipFile.directory(); if (zipDir.isNull()) { return false; } std::vector<std::string> entries; zipDir->collectFiles(entries, false); // TODO: replace with BooksDB call??? if (entries.size() != 1) { return false; } if (zipDir->itemPath(entries[0]) != filePath) { return false; } } return ZLFile(physicalPath).canRemove(); }
void Unpack::unzip(const QString* const PIG_PATH, const QString *path, const QString *sum) { int exitCode = 0; QFile origin(*path); if ((origin.open(QIODevice::ReadOnly)) && (*sum == (QCryptographicHash::hash(origin.readAll(), QCryptographicHash::Md5).toHex()))) { origin.close(); QuaZip zip(*path); if (zip.open(QuaZip::mdUnzip)) { QuaZipFile zipFile(&zip); for (bool f = zip.goToFirstFile(); f; f = zip.goToNextFile()) { zipFile.open(QIODevice::ReadOnly); QFile target(*PIG_PATH+"/tmp/update/"+zipFile.getActualFileName()); target.open(QIODevice::WriteOnly); if (target.write(zipFile.readAll()) == -1) { zipFile.close(); zip.close(); target.close(); exitCode = -1; } zipFile.close(); target.close(); } zip.close(); } else { exitCode = -1; } } else { if (origin.isOpen()) origin.close(); exitCode = -1; } emit sendExitCode(exitCode); }
bool UBExportDocumentSetAdaptor::addDocumentToZip(const QModelIndex &pIndex, UBDocumentTreeModel *model, QuaZip &zip) { static int i = 0; i++; QModelIndex parentIndex = pIndex; if (!parentIndex.isValid()) { return false; } UBDocumentProxy *pDocumentProxy = model->proxyForIndex(parentIndex); if (pDocumentProxy) { // Q_ASSERT(QFileInfo(pDocumentProxy->persistencePath()).exists()); // UBForeighnObjectsHandler cleaner; // cleaner.cure(pDocumentProxy->persistencePath()); UniboardSankoreTransition document; QString documentPath(pDocumentProxy->persistencePath()); document.checkDocumentDirectory(documentPath); QDir documentDir = QDir(pDocumentProxy->persistencePath()); QuaZipFile zipFile(&zip); UBFileSystemUtils::compressDirInZip(documentDir, QFileInfo(documentPath).fileName() + "/", &zipFile, false); if(zip.getZipError() != 0) { qWarning("Export failed. Cause: zip.close(): %d", zip.getZipError()); } } for (int i = 0; i < model->rowCount(parentIndex); ++i) { QModelIndex curIndex = model->index(i, 0, parentIndex); if (!addDocumentToZip(curIndex, model, zip)) { return false; } } return true; }
int ArchiveExtractor::readFile(const QString &archiveName, const QString &fileName, QByteArray &buffer) const { QFile zipFile(archiveName); QuaZip zip(&zipFile); if (zip.open(QuaZip::mdUnzip)) { zip.setFileNameCodec("UTF-8"); if (zip.setCurrentFile(fileName)) { QuaZipFile file(&zip); if (file.open(QIODevice::ReadOnly)) { buffer = file.readAll(); } else { return 1; } } else { return 1; } } if (buffer.isEmpty()) { if (ArchiveRar::loadlib()) { // TODO: Check return value ArchiveRar::readFile(archiveName, fileName, buffer); } } return 0; }
bool Import_Argo::loadFromZArgoFile(QIODevice &file, UMLPackage *parentPkg) { Q_UNUSED(parentPkg); KZip zipFile(&file); if (!zipFile.open(QIODevice::ReadOnly)) return false; const KArchiveDirectory *directory = zipFile.directory(); bool result = true; foreach(const QString &name, directory->entries()) { const KArchiveEntry *entry = directory->entry(name); if (entry->isFile()) { const KArchiveFile *file = static_cast<const KArchiveFile*>(entry); if (file == 0) { uError() << "Could not read file from" << file; continue; } if (name.endsWith(QLatin1String(".argo"))) result = loadFromArgoFile(zipFile, name); } } return result; }
void wxCrafterTab::DoCreateProject(const ProjectInfo& projectInfo) { // Create the project folder wxFileName::Mkdir( projectInfo.cbp_path.GetPath(), 0777, wxPATH_MKDIR_FULL); // Get the resources Zip file wxString dataFolder = ConfigManager::GetDataFolder(); wxFileName zipFile(dataFolder, wxT("wxCrafterCB.zip")); // Extract the files to this folder wxString dummy; wxcHelper::ExtractFileFromZip(zipFile.GetFullPath(), wxT("main.cpp"), projectInfo.cbp_path.GetPath(), dummy); wxcHelper::ExtractFileFromZip(zipFile.GetFullPath(), wxT("MainFrame.cpp"), projectInfo.cbp_path.GetPath(), dummy); wxcHelper::ExtractFileFromZip(zipFile.GetFullPath(), wxT("MainFrame.h"), projectInfo.cbp_path.GetPath(), dummy); wxcHelper::ExtractFileFromZip(zipFile.GetFullPath(), wxT("wxcrafter.cpp"), projectInfo.cbp_path.GetPath(), dummy); wxcHelper::ExtractFileFromZip(zipFile.GetFullPath(), wxT("wxcrafter.h"), projectInfo.cbp_path.GetPath(), dummy); wxcHelper::ExtractFileFromZip(zipFile.GetFullPath(), wxT("wxcrafter.wxcp"), projectInfo.cbp_path.GetPath(), dummy); wxcHelper::ExtractFileFromZip(zipFile.GetFullPath(), wxT("wxcrafter_bitmaps.cpp"), projectInfo.cbp_path.GetPath(), dummy); wxcHelper::ExtractFileFromZip(zipFile.GetFullPath(), wxT("wxCrafterCBTemplate.cbp"), projectInfo.cbp_path.GetPath(), dummy); wxcHelper::ExtractFileFromZip(zipFile.GetFullPath(), wxT("resources.rc"), projectInfo.cbp_path.GetPath(), dummy); // Perform a simple string replace on the cbp file wxFileName projectFile(projectInfo.cbp_path.GetPath(), wxT("wxCrafterCBTemplate.cbp")); wxString fileContent; wxcHelper::ReadFileContent( projectFile.GetFullPath(), fileContent ); // Replace the place holders wxString buildType, components; if ( projectInfo.wx_build_type.Contains(wxT("Dynamic")) ) { buildType = wxT("gcc_dll"); } else { buildType = wxT("gcc_lib"); } for(size_t i=0; i<projectInfo.wx_components.GetCount(); ++i) { components << projectInfo.wx_components.Item(i) << wxT(","); } if ( !components.IsEmpty() ) { components.RemoveLast(); } fileContent.Replace(wxT("${PROJECT_NAME}"), projectInfo.cbp_path.GetName()); fileContent.Replace(wxT("${WX_COMPONENTS}"), components); #ifdef __WXMSW__ fileContent.Replace(wxT("${WX_BUILD_TYPE}"), buildType); fileContent.Replace(wxT("${WX_PREFIX}"), projectInfo.wx_prefix); #else // Remove these placeholders on Linux fileContent.Replace(wxT("--prefix=${WX_PREFIX}"), wxT("")); fileContent.Replace(wxT("--wxcfg=${WX_BUILD_TYPE}/mswud"), wxT("")); fileContent.Replace(wxT("--wxcfg=${WX_BUILD_TYPE}/mswu"), wxT("")); #endif wxcHelper::WriteFileContent( projectFile.GetFullPath(), fileContent ); ::wxRenameFile(projectFile.GetFullPath(), projectInfo.cbp_path.GetFullPath()); // And finally, load the project Manager::Get()->GetProjectManager()->LoadProject( projectInfo.cbp_path.GetFullPath() ); }
Grid *readGridFromBinaryFile(char *file_name) { FILE *fp; Grid *grid; char *file_base; int zip_status; checkUnzipFile(file_name,&zip_status,&file_base); /* open file and allocate Grid */ fp = fopen(file_base,"r"); grid = allocateGrid(); if( fp != NULL) { fread(&(grid->num_dims), sizeof(int), 1, fp); fread(grid->x_lo, sizeof(LSMLIB_REAL), 3, fp); fread(grid->x_hi, sizeof(LSMLIB_REAL), 3, fp); fread(grid->x_lo_ghostbox, sizeof(LSMLIB_REAL), 3, fp); fread(grid->x_hi_ghostbox, sizeof(LSMLIB_REAL), 3, fp); fread(grid->grid_dims, sizeof(int), 3, fp); fread(grid->grid_dims_ghostbox, sizeof(int), 3, fp); fread(grid->dx, sizeof(LSMLIB_REAL), 3, fp); fread(&(grid->num_gridpts), sizeof(int), 1, fp); fread(&(grid->ilo_gb), sizeof(int), 1, fp); fread(&(grid->ihi_gb), sizeof(int), 1, fp); fread(&(grid->jlo_gb), sizeof(int), 1, fp); fread(&(grid->jhi_gb), sizeof(int), 1, fp); fread(&(grid->klo_gb), sizeof(int), 1, fp); fread(&(grid->khi_gb), sizeof(int), 1, fp); fread(&(grid->ilo_fb), sizeof(int), 1, fp); fread(&(grid->ihi_fb), sizeof(int), 1, fp); fread(&(grid->jlo_fb), sizeof(int), 1, fp); fread(&(grid->jhi_fb), sizeof(int), 1, fp); fread(&(grid->klo_fb), sizeof(int), 1, fp); fread(&(grid->khi_fb), sizeof(int), 1, fp); fread(&(grid->ilo_D1_fb), sizeof(int), 1, fp); fread(&(grid->ihi_D1_fb), sizeof(int), 1, fp); fread(&(grid->jlo_D1_fb), sizeof(int), 1, fp); fread(&(grid->jhi_D1_fb), sizeof(int), 1, fp); fread(&(grid->klo_D1_fb), sizeof(int), 1, fp); fread(&(grid->khi_D1_fb), sizeof(int), 1, fp); fread(&(grid->ilo_D2_fb), sizeof(int), 1, fp); fread(&(grid->ihi_D2_fb), sizeof(int), 1, fp); fread(&(grid->jlo_D2_fb), sizeof(int), 1, fp); fread(&(grid->jhi_D2_fb), sizeof(int), 1, fp); fread(&(grid->klo_D2_fb), sizeof(int), 1, fp); fread(&(grid->khi_D2_fb), sizeof(int), 1, fp); fread(&(grid->ilo_D3_fb), sizeof(int), 1, fp); fread(&(grid->ihi_D3_fb), sizeof(int), 1, fp); fread(&(grid->jlo_D3_fb), sizeof(int), 1, fp); fread(&(grid->jhi_D3_fb), sizeof(int), 1, fp); fread(&(grid->klo_D3_fb), sizeof(int), 1, fp); fread(&(grid->khi_D3_fb), sizeof(int), 1, fp); fread(&(grid->num_nb_levels), sizeof(int), 1, fp); fread(&(grid->mark_gb), sizeof(unsigned char), 1, fp); fread(&(grid->mark_D1), sizeof(unsigned char), 1, fp); fread(&(grid->mark_D2), sizeof(unsigned char), 1, fp); fread(&(grid->mark_D3), sizeof(unsigned char), 1, fp); fread(&(grid->mark_fb), sizeof(unsigned char), 1, fp); fread(&(grid->beta), sizeof(LSMLIB_REAL), 1, fp); fread(&(grid->gamma), sizeof(LSMLIB_REAL), 1, fp); fclose(fp); zipFile(file_base,zip_status); free(file_base); } else { printf("\nCould not open file %s",file_base); } return grid; }
void writeGridToBinaryFile(Grid *grid, char *file_name, int zip_status) { FILE *fp; fp = fopen(file_name,"w"); fwrite(&(grid->num_dims), sizeof(int), 1, fp); fwrite(grid->x_lo, sizeof(LSMLIB_REAL), 3, fp); fwrite(grid->x_hi, sizeof(LSMLIB_REAL), 3, fp); fwrite(grid->x_lo_ghostbox, sizeof(LSMLIB_REAL), 3, fp); fwrite(grid->x_hi_ghostbox, sizeof(LSMLIB_REAL), 3, fp); fwrite(grid->grid_dims, sizeof(int), 3, fp); fwrite(grid->grid_dims_ghostbox, sizeof(int), 3, fp); fwrite(grid->dx, sizeof(LSMLIB_REAL), 3, fp); fwrite(&(grid->num_gridpts), sizeof(int), 1, fp); fwrite(&(grid->ilo_gb), sizeof(int), 1, fp); fwrite(&(grid->ihi_gb), sizeof(int), 1, fp); fwrite(&(grid->jlo_gb), sizeof(int), 1, fp); fwrite(&(grid->jhi_gb), sizeof(int), 1, fp); fwrite(&(grid->klo_gb), sizeof(int), 1, fp); fwrite(&(grid->khi_gb), sizeof(int), 1, fp); fwrite(&(grid->ilo_fb), sizeof(int), 1, fp); fwrite(&(grid->ihi_fb), sizeof(int), 1, fp); fwrite(&(grid->jlo_fb), sizeof(int), 1, fp); fwrite(&(grid->jhi_fb), sizeof(int), 1, fp); fwrite(&(grid->klo_fb), sizeof(int), 1, fp); fwrite(&(grid->khi_fb), sizeof(int), 1, fp); fwrite(&(grid->ilo_D1_fb), sizeof(int), 1, fp); fwrite(&(grid->ihi_D1_fb), sizeof(int), 1, fp); fwrite(&(grid->jlo_D1_fb), sizeof(int), 1, fp); fwrite(&(grid->jhi_D1_fb), sizeof(int), 1, fp); fwrite(&(grid->klo_D1_fb), sizeof(int), 1, fp); fwrite(&(grid->khi_D1_fb), sizeof(int), 1, fp); fwrite(&(grid->ilo_D2_fb), sizeof(int), 1, fp); fwrite(&(grid->ihi_D2_fb), sizeof(int), 1, fp); fwrite(&(grid->jlo_D2_fb), sizeof(int), 1, fp); fwrite(&(grid->jhi_D2_fb), sizeof(int), 1, fp); fwrite(&(grid->klo_D2_fb), sizeof(int), 1, fp); fwrite(&(grid->khi_D2_fb), sizeof(int), 1, fp); fwrite(&(grid->ilo_D3_fb), sizeof(int), 1, fp); fwrite(&(grid->ihi_D3_fb), sizeof(int), 1, fp); fwrite(&(grid->jlo_D3_fb), sizeof(int), 1, fp); fwrite(&(grid->jhi_D3_fb), sizeof(int), 1, fp); fwrite(&(grid->klo_D3_fb), sizeof(int), 1, fp); fwrite(&(grid->khi_D3_fb), sizeof(int), 1, fp); fwrite(&(grid->num_nb_levels), sizeof(int), 1, fp); fwrite(&(grid->mark_gb), sizeof(unsigned char), 1, fp); fwrite(&(grid->mark_D1), sizeof(unsigned char), 1, fp); fwrite(&(grid->mark_D2), sizeof(unsigned char), 1, fp); fwrite(&(grid->mark_D3), sizeof(unsigned char), 1, fp); fwrite(&(grid->mark_fb), sizeof(unsigned char), 1, fp); fwrite(&(grid->beta), sizeof(LSMLIB_REAL), 1, fp); fwrite(&(grid->gamma), sizeof(LSMLIB_REAL), 1, fp); fclose(fp); zipFile(file_name,zip_status); }
void Zip::extract(QNetworkReply* reply) { #ifdef Q_OS_MAC // CFURLRef appURLRef = CFBundleCopyBundleURL(CFBundleGetMainBundle()); // char path[PATH_MAX]; // if (!CFURLGetFileSystemRepresentation(appURLRef, TRUE, (UInt8 *)path, PATH_MAX)) { // // error! // } // CFRelease(appURLRef); // QString filePath = QString(path); // QString rootDirectory = filePath.left(filePath.lastIndexOf("/")); QDir dir = QDir(QCoreApplication::applicationDirPath()); dir.cdUp(); dir.cdUp(); #else QString rootDirectory = QCoreApplication::applicationDirPath() + "/"; #endif // Write download into File QFileInfo fileInfo=reply->url().path(); qDebug() << reply->url().path(); QString fileName = rootDirectory + fileInfo.fileName(); qDebug()<<"Writing downloaded file into "<<fileName; QFile file(fileName); file.open(QIODevice::WriteOnly); file.write(reply->readAll()); file.close(); zip_file zipFile(fileName.toStdString()); try { std::vector <zip_info> updateFiles = zipFile.infolist(); // Rename all current files with available update. for (size_t i=0;i<updateFiles.size();i++) { QString sourceFilePath = rootDirectory + QString::fromStdString(updateFiles[i].filename); QDir appDir( QCoreApplication::applicationDirPath() ); QFileInfo file( sourceFilePath ); if(file.exists()) { //qDebug()<<tr("Moving file %1 to %2").arg(sourceFilePath).arg(sourceFilePath+".oldversion"); appDir.rename( sourceFilePath, sourceFilePath+".oldversion" ); } } // Install updated Files extractAll(&zipFile); } catch(std::exception const& e) { qDebug() << "Exception: " << e.what() << "\n"; } // Delete update archive while(QFile::remove(fileName) ) { }; /// Restart extracted Updater in install mode /// ./extractedpath/TARGET appPath extractedpath QApplication::exit(200); // Restart ap to clean up and start usual business ///d->manager()->helper()->restartApplication(); }
Grid *readGridFromAsciiFile(char *file_name) { Grid *grid; FILE *fp; float x_lo_float[3], x_hi_float[3]; float x_lo_ghostbox_float[3], x_hi_ghostbox_float[3]; float dx_float[3], beta_float, gamma_float; char *line[80]; char *file_base; int zip_status; checkUnzipFile(file_name,&zip_status,&file_base); /* open file and allocate Grid */ fp = fopen(file_base,"r"); grid = allocateGrid(); fscanf(fp, "Number of dimensions: %d\n", &(grid->num_dims)); if (grid->num_dims == 2) { fscanf(fp, "Geometric limits (without ghostcells): [%g,%g] x [%g,%g]\n", &(x_lo_float[0]), &(x_hi_float[0]), &(x_lo_float[1]), &(x_hi_float[1])); grid->x_lo[0] = x_lo_float[0]; grid->x_hi[0] = x_hi_float[0]; grid->x_lo[1] = x_lo_float[1]; grid->x_hi[1] = x_hi_float[1]; fscanf(fp,"Geometric limits (with ghostcells): [%g,%g] x [%g,%g]\n", &(x_lo_ghostbox_float[0]), &(x_hi_ghostbox_float[0]), &(x_lo_ghostbox_float[1]), &(x_hi_ghostbox_float[1])); grid->x_lo_ghostbox[0] = x_lo_ghostbox_float[0]; grid->x_hi_ghostbox[0] = x_hi_ghostbox_float[0]; grid->x_lo_ghostbox[1] = x_lo_ghostbox_float[1]; grid->x_hi_ghostbox[1] = x_hi_ghostbox_float[1]; fscanf(fp,"Grid size (without ghostcells): %d x %d\n", &((grid->grid_dims)[0]), &((grid->grid_dims)[1])); fscanf(fp,"Grid size (with ghostcells): %d x %d\n", &((grid->grid_dims_ghostbox)[0]), &((grid->grid_dims_ghostbox)[1])); fscanf(fp,"Grid spacing: dx = %g, dy = %g \n", &(dx_float[0]), &(dx_float[1])); grid->dx[0] = dx_float[0]; grid->dx[1] = dx_float[1]; } else { fscanf(fp, "Geometric limits (without ghostcells): [%g,%g] x [%g,%g] x [%g,%g]\n", &(x_lo_float[0]), &(x_hi_float[0]), &(x_lo_float[1]), &(x_hi_float[1]), &(x_lo_float[2]), &(x_hi_float[2])); grid->x_lo[0] = x_lo_float[0]; grid->x_hi[0] = x_hi_float[0]; grid->x_lo[1] = x_lo_float[1]; grid->x_hi[1] = x_hi_float[1]; grid->x_lo[2] = x_lo_float[2]; grid->x_hi[2] = x_hi_float[2]; fscanf(fp,"Geometric limits (with ghostcells): [%g,%g] x [%g,%g] x [%g,%g]\n", &(x_lo_ghostbox_float[0]), &(x_hi_ghostbox_float[0]), &(x_lo_ghostbox_float[1]), &(x_hi_ghostbox_float[1]), &(x_lo_ghostbox_float[2]), &(x_hi_ghostbox_float[2])); grid->x_lo_ghostbox[0] = x_lo_ghostbox_float[0]; grid->x_hi_ghostbox[0] = x_hi_ghostbox_float[0]; grid->x_lo_ghostbox[1] = x_lo_ghostbox_float[1]; grid->x_hi_ghostbox[1] = x_hi_ghostbox_float[1]; grid->x_lo_ghostbox[2] = x_lo_ghostbox_float[2]; grid->x_hi_ghostbox[2] = x_hi_ghostbox_float[2]; fscanf(fp,"Grid size (without ghostcells): %d x %d x %d\n", &((grid->grid_dims)[0]), &((grid->grid_dims)[1]), &((grid->grid_dims)[2])); fscanf(fp,"Grid size (with ghostcells): %d x %d x %d\n", &((grid->grid_dims_ghostbox)[0]), &((grid->grid_dims_ghostbox)[1]), &((grid->grid_dims_ghostbox)[2])); fscanf(fp,"Grid spacing: dx = %g, dy = %g, dz = %g\n", &(dx_float[0]), &(dx_float[1]), &(dx_float[2])); grid->dx[0] = dx_float[0]; grid->dx[1] = dx_float[1]; grid->dx[2] = dx_float[2]; } fscanf(fp, "Total number of grid points: %d\n", &(grid->num_gridpts)); /* fscanf(fp,"%s\n",line); */ if (grid->num_dims == 2) { fscanf(fp, "Ghost box: [%d,%d] x [%d,%d]\n", &(grid->ilo_gb), &(grid->ihi_gb), &(grid->jlo_gb), &(grid->jhi_gb)); fscanf(fp, "Fill box: [%d,%d] x [%d,%d]\n", &(grid->ilo_fb), &(grid->ihi_fb), &(grid->jlo_fb), &(grid->jhi_fb)); fscanf(fp, "1st order differences fill box: [%d,%d] x [%d,%d]\n", &(grid->ilo_D1_fb), &(grid->ihi_D1_fb), &(grid->jlo_D1_fb), &(grid->jhi_D1_fb)); fscanf(fp, "2nd order differences fill box: [%d,%d] x [%d,%d]\n", &(grid->ilo_D2_fb), &(grid->ihi_D2_fb), &(grid->jlo_D2_fb), &(grid->jhi_D2_fb)); fscanf(fp, "3rd order differences fill box: [%d,%d] x [%d,%d]\n", &(grid->ilo_D3_fb), &(grid->ihi_D3_fb), &(grid->jlo_D3_fb), &(grid->jhi_D3_fb)); } else { fscanf(fp, "Ghost box: [%d,%d] x [%d,%d] x [%d,%d]\n", &(grid->ilo_gb), &(grid->ihi_gb), &(grid->jlo_gb), &(grid->jhi_gb), &(grid->klo_gb), &(grid->khi_gb)); fscanf(fp, "Fill box: [%d,%d] x [%d,%d] x [%d,%d]\n", &(grid->ilo_fb), &(grid->ihi_fb), &(grid->jlo_fb), &(grid->jhi_fb), &(grid->klo_fb), &(grid->khi_fb)); fscanf(fp, "1st order differences fill box: [%d,%d] x [%d,%d] x [%d,%d]\n", &(grid->ilo_D1_fb), &(grid->ihi_D1_fb), &(grid->jlo_D1_fb), &(grid->jhi_D1_fb), &(grid->klo_D1_fb), &(grid->khi_D1_fb)); fscanf(fp, "2nd order differences fill box: [%d,%d] x [%d,%d] x [%d,%d]\n", &(grid->ilo_D2_fb), &(grid->ihi_D2_fb), &(grid->jlo_D2_fb), &(grid->jhi_D2_fb), &(grid->klo_D2_fb), &(grid->khi_D2_fb)); fscanf(fp, "3rd order differences fill box: [%d,%d] x [%d,%d] x [%d,%d]\n", &(grid->ilo_D3_fb), &(grid->ihi_D3_fb), &(grid->jlo_D3_fb), &(grid->jhi_D3_fb), &(grid->klo_D3_fb), &(grid->khi_D3_fb)); } fscanf(fp, "Number of narrow band levels (local method) %d\n", &(grid->num_nb_levels)); fscanf(fp, "Boundary layer marks (local method) gb %c D1 %c D2 %c D3 %c fb %c\n", &(grid->mark_gb), &(grid->mark_D1),&(grid->mark_D2), &(grid->mark_D3),&(grid->mark_fb)); fscanf(fp, "Narrow band width (local method) beta(inner) %g gamma(outer) %g\n", &beta_float, &gamma_float); grid->beta = beta_float; grid->gamma = gamma_float; fclose(fp); zipFile(file_base,zip_status); free(file_base); return grid; }
static std::string get_packagename_from_apk(const char* apkPath) { #undef open std::unique_ptr<android::ZipFileRO> zipFile(android::ZipFileRO::open(apkPath)); #define open ___xxx_unix_open if (zipFile == nullptr) { perror_exit("Could not open %s", apkPath); } android::ZipEntryRO entry = zipFile->findEntryByName("AndroidManifest.xml"); if (entry == nullptr) { error_exit("Could not find AndroidManifest.xml inside %s", apkPath); } uint32_t manifest_len = 0; if (!zipFile->getEntryInfo(entry, NULL, &manifest_len, NULL, NULL, NULL, NULL)) { error_exit("Could not read AndroidManifest.xml inside %s", apkPath); } std::vector<char> manifest_data(manifest_len); if (!zipFile->uncompressEntry(entry, manifest_data.data(), manifest_len)) { error_exit("Could not uncompress AndroidManifest.xml inside %s", apkPath); } android::ResXMLTree tree; android::status_t setto_status = tree.setTo(manifest_data.data(), manifest_len, true); if (setto_status != android::OK) { error_exit("Could not parse AndroidManifest.xml inside %s", apkPath); } android::ResXMLParser::event_code_t code; while ((code = tree.next()) != android::ResXMLParser::BAD_DOCUMENT && code != android::ResXMLParser::END_DOCUMENT) { switch (code) { case android::ResXMLParser::START_TAG: { size_t element_name_length; const char16_t* element_name = tree.getElementName(&element_name_length); if (element_name == nullptr) { continue; } std::u16string element_name_string(element_name, element_name_length); if (element_name_string == u"manifest") { for (size_t i = 0; i < tree.getAttributeCount(); i++) { size_t attribute_name_length; const char16_t* attribute_name_text = tree.getAttributeName(i, &attribute_name_length); if (attribute_name_text == nullptr) { continue; } std::u16string attribute_name_string(attribute_name_text, attribute_name_length); if (attribute_name_string == u"package") { size_t attribute_value_length; const char16_t* attribute_value_text = tree.getAttributeStringValue(i, &attribute_value_length); if (attribute_value_text == nullptr) { continue; } return get_string_from_utf16(attribute_value_text, attribute_value_length); } } } break; } default: break; } } error_exit("Could not find package name tag in AndroidManifest.xml inside %s", apkPath); }
bool EasyZip::Unzip(QString fileToUnzip, QString unzipFileName) { QFile zipFile(fileToUnzip); QuaZip zip(&zipFile); if(!zip.open(QuaZip::mdUnzip)) { qWarning("testRead(): zip.open(): %d", zip.getZipError()); return false; } zip.setFileNameCodec("UTF-8"); QuaZipFile file(&zip); QFile out; QString name; char c; for(bool more=zip.goToFirstFile(); more; more=zip.goToNextFile()) { if(!file.open(QIODevice::ReadOnly)) { qWarning("testRead(): file.open(): %d", file.getZipError()); return false; } name=file.getActualFileName(); if(file.getZipError()!=UNZ_OK) { qWarning("testRead(): file.getFileName(): %d", file.getZipError()); return false; } QString dirn = unzipFileName + name; if (name.contains('/')) { // subdirectory support // there must be a more elegant way of doing this // but I couldn't find anything useful in QDir dirn.chop(dirn.length() - dirn.lastIndexOf("/")); QDir().mkpath(dirn); } out.setFileName(unzipFileName + name); out.open(QIODevice::WriteOnly); char buf[4096]; int len = 0; while (file.getChar(&c)) { // we could just do this, but it's about 40% slower: // out.putChar(c); buf[len++] = c; if (len >= 4096) { out.write(buf, len); len = 0; } } if (len > 0) { out.write(buf, len); } out.close(); if(file.getZipError()!=UNZ_OK) { qWarning("testRead(): file.getFileName(): %d", file.getZipError()); return false; } if(!file.atEnd()) { qWarning("testRead(): read all but not EOF"); return false; } file.close(); if(file.getZipError()!=UNZ_OK) { qWarning("testRead(): file.close(): %d", file.getZipError()); return false; } } zip.close(); if(zip.getZipError()!=UNZ_OK) { qWarning("testRead(): zip.close(): %d", zip.getZipError()); return false; } return true; }
void TestQuaZipNewInfo::setFileNTFSTimes() { QString zipName = "newtimes.zip"; QStringList testFiles; testFiles << "test.txt"; QDir curDir; if (curDir.exists(zipName)) { if (!curDir.remove(zipName)) QFAIL("Can't remove zip file"); } if (!createTestFiles(testFiles)) { QFAIL("Can't create test file"); } QDateTime base(QDate(1601, 1, 1), QTime(0, 0), Qt::UTC); quint64 mTicks, aTicks, cTicks; { // create QuaZip zip(zipName); QVERIFY(zip.open(QuaZip::mdCreate)); QuaZipFile zipFile(&zip); QFileInfo fileInfo("tmp/test.txt"); mTicks = base.msecsTo(fileInfo.lastModified()) * 10000; aTicks = base.msecsTo(fileInfo.lastRead()) * 10000; cTicks = base.msecsTo(fileInfo.created()) * 10000; QuaZipNewInfo newInfo("test.txt", "tmp/test.txt"); newInfo.setFileNTFSTimes("tmp/test.txt"); QVERIFY(zipFile.open(QIODevice::WriteOnly, newInfo)); zipFile.close(); zip.close(); } { // check QuaZip zip(zipName); QVERIFY(zip.open(QuaZip::mdUnzip)); zip.goToFirstFile(); QuaZipFileInfo64 fileInfo; QVERIFY(zip.getCurrentFileInfo(&fileInfo)); zip.close(); QByteArray &extra = fileInfo.extra; bool ntfsFound = false; int timesFound = 0; for (int i = 0; i <= extra.size() - 4; ) { unsigned type = static_cast<unsigned>(static_cast<unsigned char>( extra.at(i))) | (static_cast<unsigned>(static_cast<unsigned char>( extra.at(i + 1))) << 8); i += 2; unsigned length = static_cast<unsigned>(static_cast<unsigned char>( extra.at(i))) | (static_cast<unsigned>(static_cast<unsigned char>( extra.at(i + 1))) << 8); i += 2; if (type == 0x000Au && length >= 32) { ntfsFound = true; i += 4; // reserved while (i <= extra.size() - 4) { unsigned tag = static_cast<unsigned>( static_cast<unsigned char>(extra.at(i))) | (static_cast<unsigned>( static_cast<unsigned char>(extra.at(i + 1))) << 8); i += 2; unsigned tagsize = static_cast<unsigned>( static_cast<unsigned char>(extra.at(i))) | (static_cast<unsigned>( static_cast<unsigned char>(extra.at(i + 1))) << 8); i += 2; QCOMPARE(tagsize, static_cast<unsigned>(24)); if (tag == 0x0001u && tagsize >= 24) { for (int timesPos = i; i < timesPos + 24; i += 8, tagsize -= 8) { quint64 time = static_cast<quint64>( static_cast<unsigned char>(extra.at(i))) | (static_cast<quint64>(static_cast<unsigned char>( extra.at(i + 1))) << 8) | (static_cast<quint64>(static_cast<unsigned char>( extra.at(i + 2))) << 16) | (static_cast<quint64>(static_cast<unsigned char>( extra.at(i + 3))) << 24) | (static_cast<quint64>(static_cast<unsigned char>( extra.at(i + 4))) << 32) | (static_cast<quint64>(static_cast<unsigned char>( extra.at(i + 5))) << 40) | (static_cast<quint64>(static_cast<unsigned char>( extra.at(i + 6))) << 48) | (static_cast<quint64>(static_cast<unsigned char>( extra.at(i + 7))) << 56); ++timesFound; if (i - timesPos == 0) { QCOMPARE(time, mTicks); } else if (i - timesPos == 8) { QCOMPARE(time, aTicks); } else if (i - timesPos == 16) { QCOMPARE(time, cTicks); } else { QFAIL("Wrong position"); } } i += tagsize; } else { i += tagsize; } } } else { i += length; } } QVERIFY(ntfsFound); QCOMPARE(timesFound, 3); } removeTestFiles(testFiles); curDir.remove(zipName); }
void UTLauncher::startServerBrowser() { splashTimer.singleShot(2000, this, SLOT(closeSplash())); if(!settings.value("StartMinimized", false).toBool()) { browser->show(); } else { qApp->setQuitOnLastWindowClosed(false); // workaround for app not starting } browser->setMOTD(bootstrap.MOTD()); auto hasEditorSupport = [=] { QString editorPath = bootstrap.editorExePath(); QString projectPath = bootstrap.projectPath(); return QFile::exists(editorPath) && QFile::exists(projectPath); }; auto openSettings = [=](bool mandatoryEditor = false) { ConfigDialog dialog(settings, mandatoryEditor); dialog.exec(); browser->setEditorSupport(hasEditorSupport()); browser->setHideOnClose(settings.value("MinimizeToTrayOnClose").toBool()); }; connect(browser, &ServerBrowser::openServer, [=](QString url, bool spectate, bool inEditor) { if(inEditor) { QString editorPath = bootstrap.editorExePath(); QString projectPath = bootstrap.projectPath(); if(!editorPath.length() || !projectPath.length()) { openSettings(true); return; } QProcess::startDetached(editorPath, QStringList() << projectPath << "-GAME" << (url + (spectate?"?SpectatorOnly=1":"")) ); } else { QString exePath = bootstrap.programExePath(); if(!exePath.length()) { openSettings(); return; } const auto serverEntry = browser->serverEntryFromAddress(url); auto launch = [=] { qDebug() << "Launching!!\n"; QProcess::startDetached(exePath, QStringList() #ifdef LAUNCH_WITH_UE4 << "UnrealTournament" #endif << (url + (spectate?"?SpectatorOnly=1":"")) << "-SaveToUserDir"); }; if(serverEntry) { if(bootstrap.isStockMap(serverEntry->map)) { launch(); return; } QString exePath = bootstrap.programExePath(); QFileInfo exeInfo(exePath); auto contentDir = QDir(exeInfo.dir()); contentDir.cdUp(); contentDir.cdUp(); contentDir.cd("Content"); auto zipFilePath = contentDir.absoluteFilePath(serverEntry->map + ".zip"); if(QFile::exists(zipFilePath)) { launch(); return; } Download mapDownload; mapDownload.setTarget("https://ut.rushbase.net/customcontent/Data/" + serverEntry->map + ".zip"); QProgressDialog dialog("Downloading map: " + serverEntry->map, "Cancel", 0, 100); QFile zipFile(zipFilePath); zipFile.open(QIODevice::WriteOnly); int httpCode = 200; connect(&mapDownload, &Download::error, [&](int code) { httpCode = code; if(code != 200) { zipFile.remove(); QMessageBox::critical(nullptr, "Unable to download map", QString("Got code %1 while trying to download map:<br>%2").arg(code).arg(serverEntry->map)); } }); connect(&mapDownload, &Download::chunk, [&](QByteArray chunk) { qDebug() << "Reading!\n"; zipFile.write(chunk); }); connect(&mapDownload, &Download::progress, [&](double progress) { dialog.setValue(100*progress); if(progress == 1.0) { dialog.accept(); } }); mapDownload.download(); qDebug() << "Downloading map " << serverEntry->map; if(!dialog.exec() || httpCode != 200) { zipFile.remove(); // remove unfinished download return; } zipFile.close(); QProgressDialog installDialog("Installing map: " + serverEntry->map, "", 0, 100); installDialog.setWindowModality(Qt::ApplicationModal); installDialog.show(); installDialog.setValue(0); qDebug() << "Installed!!\n"; QuaZip zip(zipFilePath); auto textCodec = QTextCodec::codecForName("TSCII"); zip.setFileNameCodec(textCodec); zip.setCommentCodec(textCodec); zip.open(QuaZip::mdUnzip); QuaZipFile file(&zip); size_t totalSize = 0; for(bool f=zip.goToFirstFile(); f; f=zip.goToNextFile()) { QuaZipFileInfo info; zip.getCurrentFileInfo(&info); totalSize += info.uncompressedSize; } qDebug() << "Total size " << totalSize; size_t accumulatedSize = 0; /* TODO!!!!: this whole thing needs to be redone asynchronously */ for(bool f=zip.goToFirstFile(); f; f=zip.goToNextFile()) { file.open(QIODevice::ReadOnly); //same functionality as QIODevice::readData() -- data is a char*, maxSize is qint64 //file.readData(data,maxSize); QString filename = file.getActualFileName(); if(file.isOpen()) { qApp->processEvents(); qDebug() << installDialog.isVisible() << installDialog.value(); if(!installDialog.isVisible() && installDialog.value() != 100 && installDialog.value() != -1) return; bool isDir = (filename.right(1) == "/"); if(isDir) { contentDir.mkpath(filename); } else { QFile f(contentDir.absoluteFilePath(filename)); f.open(QIODevice::WriteOnly); auto data = file.readAll(); accumulatedSize += data.size(); qDebug() << accumulatedSize; installDialog.setValue(100 * (double)accumulatedSize / totalSize); qApp->processEvents(); qDebug() << installDialog.isVisible() << installDialog.value(); if(!installDialog.isVisible() && installDialog.value() != 100 && installDialog.value() != -1) return; f.write(data); } qDebug() << file.getActualFileName() << isDir; //do something with the data if(file.isOpen()) file.close(); qApp->processEvents(); qDebug() << installDialog.isVisible() << installDialog.value(); if(!installDialog.isVisible() && installDialog.value() != 100 && installDialog.value() != -1) return; } else { qDebug() << "Cannot open" << filename << "inside zip";; } } qDebug() << "Closing zip\n"; zip.close(); launch(); } } }); disconnect(&bootstrap, &Bootstrap::ready, this, &UTLauncher::prepareConfig); connect(&bootstrap, &Bootstrap::ready, this, [=] { browser->setMOTD(bootstrap.MOTD()); }); connect(browser, &ServerBrowser::openSettings, openSettings); browser->setEditorSupport(hasEditorSupport()); browser->setHideOnClose(settings.value("MinimizeToTrayOnClose", false).toBool()); systemTray.setToolTip("UTLauncher"); auto systemTrayMenu = new QMenu(browser); auto showBrowser = new QAction(awesome->icon(fa::listalt), "Server List", this); connect(showBrowser, &QAction::triggered, [=]() { browser->showNormal(); browser->raise(); browser->activateWindow(); }); auto runUTAction = new QAction(awesome->icon( fa::gamepad ),"Run UT", this); connect(runUTAction, &QAction::triggered, [=]() { QString exePath = bootstrap.programExePath(); if(!exePath.length()) { browser->show(); openSettings(); return; } QProcess::startDetached(exePath #ifdef LAUNCH_WITH_UE4 , QStringList() << "UnrealTournament" << "-SaveToUserDir" #endif ); }); auto runEditorAction = new QAction(awesome->icon( fa::code ),"Run Editor", this); connect(runEditorAction, &QAction::triggered, [=]() { QString editorPath = bootstrap.editorExePath(); QString projectPath = bootstrap.projectPath(); QProcess::startDetached(editorPath, QStringList() << projectPath); }); auto quitAction = new QAction(awesome->icon( fa::signout ),"Quit", this); connect(quitAction, &QAction::triggered, [=]() { QApplication::quit(); }); systemTrayMenu->addAction(showBrowser); systemTrayMenu->addSeparator(); systemTrayMenu->addAction(runUTAction); systemTrayMenu->addAction(runEditorAction); systemTrayMenu->addSeparator(); systemTrayMenu->addAction(quitAction); systemTray.setContextMenu(systemTrayMenu); systemTray.show(); connect(&systemTray, &QSystemTrayIcon::activated, [=](QSystemTrayIcon::ActivationReason reason) { qApp->setQuitOnLastWindowClosed(true); runEditorAction->setVisible(hasEditorSupport()); switch(reason) { case QSystemTrayIcon::Trigger: { if(browser->isHidden()) { browser->show(); } else { browser->hide(); } break; } } }); }
bool GERBVIEW_FRAME::unarchiveFiles( const wxString& aFullFileName, REPORTER* aReporter ) { wxString msg; // Extract the path of aFullFileName. We use it to store temporary files wxFileName fn( aFullFileName ); wxString unzipDir = fn.GetPath(); wxFFileInputStream zipFile( aFullFileName ); if( !zipFile.IsOk() ) { if( aReporter ) { msg.Printf( _( "Zip file \"%s\" cannot be opened" ), GetChars( aFullFileName ) ); aReporter->Report( msg, REPORTER::RPT_ERROR ); } return false; } // Update the list of recent zip files. UpdateFileHistory( aFullFileName, &m_zipFileHistory ); // The unzipped file in only a temporary file. Give it a filename // which cannot conflict with an usual filename. // TODO: make Read_GERBER_File() and Read_EXCELLON_File() able to // accept a stream, and avoid using a temp file. wxFileName temp_fn( "$tempfile.tmp" ); temp_fn.MakeAbsolute( unzipDir ); wxString unzipped_tempfile = temp_fn.GetFullPath(); bool success = true; wxZipInputStream zipArchive( zipFile ); wxZipEntry* entry; bool reported_no_more_layer = false; while( ( entry = zipArchive.GetNextEntry() ) ) { wxString fname = entry->GetName(); wxFileName uzfn = fname; wxString curr_ext = uzfn.GetExt().Lower(); // The archive contains Gerber and/or Excellon drill files. Use the right loader. // However it can contain a few other files (reports, pdf files...), // which will be skipped. // Gerber files ext is usually "gbr", but can be also an other value, starting by "g" // old gerber files ext from kicad is .pho // drill files do not have a well defined ext // It is .drl in kicad, but .txt in Altium for instance // Allows only .drl for drill files. if( curr_ext[0] != 'g' && curr_ext != "pho" && curr_ext != "drl" ) { if( aReporter ) { msg.Printf( _( "Info: skip file <i>\"%s\"</i> (unknown type)\n" ), GetChars( entry->GetName() ) ); aReporter->Report( msg, REPORTER::RPT_WARNING ); } continue; } int layer = GetActiveLayer(); if( layer == NO_AVAILABLE_LAYERS ) { success = false; if( aReporter ) { if( !reported_no_more_layer ) aReporter->Report( MSG_NO_MORE_LAYER, REPORTER::RPT_ERROR ); reported_no_more_layer = true; // Report the name of not loaded files: msg.Printf( MSG_NOT_LOADED, GetChars( entry->GetName() ) ); aReporter->Report( msg, REPORTER::RPT_ERROR ); } delete entry; continue; } // Create the unzipped temporary file: { wxFFileOutputStream temporary_ofile( unzipped_tempfile ); if( temporary_ofile.Ok() ) temporary_ofile.Write( zipArchive ); else { success = false; if( aReporter ) { msg.Printf( _( "<b>Unable to create temporary file \"%s\"</b>\n"), GetChars( unzipped_tempfile ) ); aReporter->Report( msg, REPORTER::RPT_ERROR ); } } } bool read_ok = true; if( curr_ext[0] == 'g' || curr_ext == "pho" ) { // Read gerber files: each file is loaded on a new GerbView layer read_ok = Read_GERBER_File( unzipped_tempfile ); } else // if( curr_ext == "drl" ) { read_ok = Read_EXCELLON_File( unzipped_tempfile ); } delete entry; // The unzipped file is only a temporary file, delete it. wxRemoveFile( unzipped_tempfile ); if( !read_ok ) { success = false; if( aReporter ) { msg.Printf( _("<b>unzipped file %s read error</b>\n"), GetChars( unzipped_tempfile ) ); aReporter->Report( msg, REPORTER::RPT_ERROR ); } } else { GERBER_FILE_IMAGE* gerber_image = GetGbrImage( layer ); if( gerber_image ) gerber_image->m_FileName = fname; layer = getNextAvailableLayer( layer ); SetActiveLayer( layer, false ); } } return success; }