std::unique_ptr<File> LinkingContext::createEntrySymbolFile(StringRef filename) const { if (entrySymbolName().empty()) return nullptr; std::unique_ptr<SimpleFile> entryFile(new SimpleFile(filename)); entryFile->addAtom( *(new (_allocator) SimpleUndefinedAtom(*entryFile, entrySymbolName()))); return std::move(entryFile); }
void RuntimeEngine::updateConfigParser() { // set entry file auto parser = ConfigParser::getInstance(); string entryFile(_project.getScriptFileRealPath()); if (entryFile.find(_project.getProjectDir()) != string::npos) { entryFile.erase(0, _project.getProjectDir().length()); } std::replace(entryFile.begin(), entryFile.end(), '\\', '/'); parser->setEntryFile(entryFile); parser->setBindAddress(_project.getBindAddress()); }
void Playlist::onFetchEntryFinished() { auto reply = qobject_cast<QNetworkReply*>(sender()); reply->deleteLater(); if (reply->error() != QNetworkReply::NoError) { qWarning() << "Failed to download item at url" << _refreshIterator->url << ", removing entry"; _refreshEntries.erase(_refreshIterator); } else { QFile entryFile(_entryPath.filePath(_refreshIterator->fileId)); entryFile.open(QIODevice::WriteOnly); entryFile.write(reply->readAll()); _refreshIterator->loaded = true; ++_refreshIterator; } downloadEntries(); }
void Playlist::downloadEntries() { if (_refreshIterator == _refreshEntries.end()) { _entries = _refreshEntries; _playbackIterator = _entries.end(); --_playbackIterator; emit playlistAvailable(); cleanupStaleEntries(); return; } QFile entryFile(_entryPath.filePath(_refreshIterator->fileId)); if (! entryFile.exists()) { qDebug() << "Downloading" << _refreshIterator->url; auto reply = _nam.get(QNetworkRequest(_refreshIterator->url)); connect(reply, &QNetworkReply::finished, this, &Playlist::onFetchEntryFinished); } else { ++_refreshIterator; downloadEntries(); } }
void K3bCddbLocalSubmit::doSubmit() { QString path = m_cddbDir; if( path.startsWith( "~" ) ) path.replace( 0, 1, QDir::homeDirPath() + "/" ); else if( !path.startsWith( "/" ) ) path.prepend( QDir::homeDirPath() + "/" ); if( path[path.length()-1] != '/' ) path.append( "/" ); if( !QFile::exists( path ) && !QDir().mkdir( path ) ) { kdDebug() << "(K3bCddbLocalSubmit) could not create directory: " << path << endl; setError( IO_ERROR ); emit submitFinished( this ); return; } if( QFile::exists( path ) ) { // if the category dir does not exists // create it path += resultEntry().category; if( !QFile::exists( path ) ) { if( !QDir().mkdir( path ) ) { kdDebug() << "(K3bCddbLocalSubmit) could not create directory: " << path << endl; setError( IO_ERROR ); emit submitFinished( this ); return; } } // we always overwrite existing entries path += "/" + resultEntry().discid; QFile entryFile( path ); if( entryFile.exists() ) { kdDebug() << "(K3bCddbLocalSubmit) file already exists: " << path << endl; } if( !entryFile.open( IO_WriteOnly ) ) { kdDebug() << "(K3bCddbLocalSubmit) could not create file: " << path << endl; setError( IO_ERROR ); emit submitFinished( this ); } else { kdDebug() << "(K3bCddbLocalSubmit) creating file: " << path << endl; QTextStream entryStream( &entryFile ); entryStream.setEncoding( QTextStream::UnicodeUTF8 ); entryStream << resultEntry().rawData; entryFile.close(); setError( SUCCESS ); emit submitFinished( this ); } } else { kdDebug() << "(K3bCddbLocalSubmit) could not find directory: " << path << endl; setError( IO_ERROR ); emit infoMessage( i18n("Could not find directory: %1").arg(path) ); emit submitFinished( this ); } }
void MainWindow::generateImage(const QString &path) { try { QFile imageFile(path); if (!imageFile.open(QIODevice::WriteOnly)) { throw tr("<p>Could not write the image file</p><p>The error message was: %1</p>").arg(imageFile.errorString()); } QDataStream ds(&imageFile); // First calculate everything. struct DirectoryEntry { QString filePath; // The path of the file. quint32 startBlock; // The start block, relative to the directory size. quint32 fileSize; // The size of the file. quint8 fileNameSize; // The size of the file name. QByteArray fileName; // The file name in ascii format. }; QRegularExpression reValidFileName("^[-a-z0-9_]{1,16}$", QRegularExpression::CaseInsensitiveOption); QSet<QString> identifiers; QList<DirectoryEntry> directoryEntries; quint32 currentStartBlock = 0; for (int i = 0; i < ui->fileList->topLevelItemCount(); ++i) { // Gather all available information and check if everything is in range. const auto item = ui->fileList->topLevelItem(i); const QString identifier = item->text(0); if (identifiers.contains(identifier)) { throw tr("The identifier \"%1\" exists multiple times.").arg(identifier); } const QString filePath = item->data(0, DataPath).toString(); QFileInfo fileInfo(filePath); if (!fileInfo.exists()) { throw tr("Could not find file \"%1\" with path \"%2\".").arg(identifier).arg(filePath); } if (!fileInfo.isReadable()) { throw tr("File \"%1\" with path \"%2\" is not readable.").arg(identifier).arg(filePath); } const qint64 fileSize = fileInfo.size(); if (fileSize > Q_INT64_C(0xffffffff)) { throw tr("The file size of file \"%1\" with path \"%2\" exceeds the maximum size of 4.2GB.").arg(identifier).arg(filePath); } if (fileSize == 0) { throw tr("The file size of file \"%1\" with path \"%2\" is zero. This is not supported.").arg(identifier).arg(filePath); } if (!reValidFileName.match(identifier).hasMatch()) { throw tr("The identifier \"%1\" is not valid. Only characters a-z, 0-9, _ and - are allowed. The length of the identifier must be between 1 and 16 characters.").arg(identifier); } // Create the directory entry. DirectoryEntry entry; entry.filePath = filePath; entry.startBlock = currentStartBlock; entry.fileSize = static_cast<quint32>(fileSize); entry.fileName = identifier.toUtf8(); entry.fileNameSize = static_cast<quint8>(entry.fileName.size()); identifiers.insert(identifier); directoryEntries.append(entry); const quint32 numberOfBlocks = static_cast<quint32>(((fileSize-Q_INT64_C(1))/static_cast<qint64>(cSDBlockSize)))+1; currentStartBlock += numberOfBlocks; } // Calculate the directory size. quint32 directorySize = (4 + 4); // 4 bytes magic + 4 bytes end mark. for (auto entry : directoryEntries) { directorySize += (9 + entry.fileNameSize); } const quint32 firstDataBlock = ((directorySize-1)/512u)+1u; // Write the directory. if (ds.writeRawData("HCDI", 4) != 4) { throw tr("Could not write the magic to the image file."); } ds.setByteOrder(QDataStream::LittleEndian); for (auto entry : directoryEntries) { if (ui->nonHcCards->isChecked()) { ds << static_cast<quint32>((entry.startBlock + firstDataBlock) * 512); } else { ds << static_cast<quint32>(entry.startBlock + firstDataBlock); } ds << static_cast<quint32>(entry.fileSize); ds << static_cast<quint8>(entry.fileNameSize); if (ds.writeRawData(entry.fileName.constData(), entry.fileNameSize) != entry.fileNameSize) { throw tr("There was a problem writing to the image file."); } } // Write the end mark. ds << static_cast<quint32>(0); // Fill bytes to the next full block size. while ((imageFile.pos() & cSDBlockSizeMask) != 0) { ds << static_cast<quint8>(0); } // Now copy all files char buffer[cSDBlockSize]; for (auto entry : directoryEntries) { QFile entryFile(entry.filePath); if (!entryFile.open(QIODevice::ReadOnly)) { throw tr("Could not open the file \"%1\" with path \"%2\". The error message was: %3").arg(QString::fromLatin1(entry.fileName)).arg(entry.filePath).arg(entryFile.errorString()); } while (!entryFile.atEnd()) { const qint64 readBytes = entryFile.read(buffer, cSDBlockSize); if (readBytes > 0) { qint64 writeIndex = 0; qint64 writtenBytes = 0; while (writeIndex < readBytes) { writtenBytes = imageFile.write(buffer + writeIndex, readBytes - writeIndex); if (writtenBytes < 0) { throw tr("There was a problem writing data to the image."); } writeIndex += writtenBytes; } // Fill bytes to the next full block size. while ((imageFile.pos() & cSDBlockSizeMask) != 0) { ds << static_cast<quint8>(0); } } } entryFile.close(); } imageFile.close(); // Successfully wrote the image file. } catch (const QString &message) { QMessageBox m(this); m.setIcon(QMessageBox::Critical); m.setText(message); m.exec(); } }