/** * Creates BDoc container manifest file and returns its path. * * Note: If non-ascii characters are present in XML data, we depend on the LANG variable to be set properly * (see iconv --list for the list of supported encoding values for libiconv). * * * @return returns created manifest file path. * @throws IOException exception is thrown if manifest file creation failed. */ std::string digidoc::BDoc::createManifest() throw(IOException) { DEBUG("digidoc::BDoc::createManifest()"); std::string fileName = util::File::tempFileName(); try { manifest::Manifest manifest; // Add container file entry with mimetype. manifest.file_entry().push_back(manifest::File_entry("/", getMimeType())); // Add documents with mimetypes. for(std::vector<Document>::const_iterator iter = documents.begin(); iter != documents.end(); iter++) { manifest::File_entry fileEntry(util::File::fileName(iter->getPath()), iter->getMediaType()); manifest.file_entry().push_back(fileEntry); } // Add signatures with mimetypes. unsigned int i = 0; for(std::vector<Signature*>::const_iterator iter = signatures.begin(); iter != signatures.end(); iter++) { manifest::File_entry fileEntry(util::String::format("META-INF/signature%u.xml", i++), (*iter)->getMediaType()); manifest.file_entry().push_back(fileEntry); } // Serialize XML to file. xml_schema::NamespaceInfomap map; map["manifest"].name = MANIFEST_NAMESPACE; DEBUG("Serializing manifest XML to '%s'", fileName.c_str()); // all XML data must be in UTF-8 std::ofstream ofs(digidoc::util::File::fstreamName(fileName).c_str()); manifest::manifest(ofs, manifest, map, "", xml_schema::Flags::dont_initialize); ofs.close(); if(ofs.fail()) { THROW_IOEXCEPTION("Failed to create manifest XML file to '%s'.", fileName.c_str()); } } catch(const xml_schema::Exception& e) { std::ostringstream oss; oss << e; THROW_IOEXCEPTION("Failed to create manifest XML file. Error: %s", oss.str().c_str()); } return fileName; }
//Internal for the file system bool FileSystem::saveFile(std::string filename, char* buffer, size_t length) { bool alreadyThere = false; filesLock.lock(); for(auto &file : files){ if(file.filename.compare(filename) == 0){ alreadyThere = true; break; } } filesLock.unlock(); if(alreadyThere) return true; std::string root = "files/"; std::ofstream newfile(root + filename, std::ofstream::binary); newfile.write(buffer, length); newfile.close(); FileEntry fileEntry(filename); filesLock.lock(); files.push_back( fileEntry ); filesLock.unlock(); logFile << "saveFile " << root + filename << " saved" << std::endl; // cout << "saveFile " << root + filename << " saved" << std::endl; // cout<<"saveFile: "<<fileEntry.filename<<endl; return true; }
// Load a music file into memory and optionally play it. bool MADDriverClass::LoadMusic(entry_ref* ref, OSType type, bool playIt) { // Safety check. if (!inited) return false; // Try to import the file. BEntry fileEntry(ref); BPath filePath; fileEntry.GetPath(&filePath); char plugName[5]; libraryError = MADMusicIdentifyCString(MADLib, plugName, filePath.Path()); if (libraryError == MADNoErr) { libraryError = MADLoadMusicFileCString(MADLib, &curMusic, plugName, filePath.Path()); if (libraryError == MADNoErr) { MADAttachDriverToMusic(curDriverRec, curMusic); if (playIt) StartMusic(); } } if (libraryError) return false; else return true; }
void Playlist::cleanupStaleEntries() { QSet<QString> entries = _entryPath.entryList({}, QDir::Files).toSet(); for (auto& entry : _entries) { entries.remove(entry.fileId); } for (auto& staleEntry : entries) { QFile fileEntry(_entryPath.filePath(staleEntry)); fileEntry.remove(); qInfo() << "Removed stale entry" << fileEntry.fileName(); } }
void N2pkFile::readFileTable(StreamHelperReader& stream) { m_logger << "Reading file table..." << std::endl; stream.SeekI(m_entryTableOffset, std::ios::beg); m_impl->Files.clear(); auto fileCount = stream.Read<unsigned int>(); for (unsigned int i = 0; i < fileCount; ++i) { auto v1 = stream.Read<unsigned int>(); auto nameLength = stream.Read<unsigned int>(); auto& name = nowide::narrow(stream.ReadWString(nameLength)); auto v2 = stream.Read<unsigned short>(); // Null-terminator? auto dataOffset = stream.Read<unsigned int>(); auto v3 = stream.Read<int>(); auto size = stream.Read<unsigned int>(); auto v4 = stream.Read<int>(); m_logger << std::left << std::setw(40) << std::setfill(' ') << name << "Unknown: " << v1 << ", " << v2 << ", " << v3 << ", " << v4 << std::endl; FileEntry fileEntry(m_dataffset + dataOffset, size, name); m_impl->Files.push_back(fileEntry); } }
bool CopyDir::copyDirAndFiles(QString srcDir, QString dstDir, QStringList *nameExcludeFilter, QStringList *nameIncludeFilter, QStringList *srcFileList, QStringList *dstFileList) { if(mExitNow) return false; mutex.lock(); if(mPause) { pauseThreads.wait(&mutex); } mutex.unlock(); bool isFirst = false; if(srcFileList == NULL) { isFirst = true; srcFileList = new QStringList; dstFileList = new QStringList; } QDir rootPath(QDir::toNativeSeparators(srcDir)); QDir destPath(QDir::toNativeSeparators(dstDir)); rootPath.setFilter(QDir::NoDotAndDotDot | QDir::AllDirs | QDir::Files); QFileInfoList entryList = rootPath.entryInfoList(); QRegExp rx; rx.setPatternSyntax(QRegExp::Wildcard); bool moveOn; QString dirName; for(int i=0; i<entryList.size(); i++) { if(mExitNow) { return false; } QFileInfo entry = entryList.at(i); // we do exclude list checking, a lot easier to exclude a couple file types than list all of the included ones moveOn = false; for(int j=0; j<nameExcludeFilter->size(); j++) { rx.setPattern(nameExcludeFilter->at(j)); QString name = entry.absoluteFilePath(); if(rx.exactMatch(name)) { moveOn = true; // now let's check to make sure this specific file isn't on the include list, that overrides exluded types for(int k=0; k<nameIncludeFilter->size(); k++) { // compare the file to the include file adding the root directory (the include filter should be relative files) QString filePath = QDir::toNativeSeparators(entry.filePath()); QString include = QDir::toNativeSeparators(mRootDir + "/" + nameIncludeFilter->at(k)); if(include.compare(filePath) == 0) { moveOn = false; break; } } break; } } // if we have been matched against the exclude list then lets skip if(moveOn) continue; // now we copy it over if(entry.isDir()) { dirName = entry.fileName(); bool pathCreated = false; QString targetSubPath(QDir::separator() + dirName); if(QDir(destPath.path() + targetSubPath).exists()) { pathCreated = true; } else { pathCreated = destPath.mkdir(dirName); } if(pathCreated) { copyDirAndFiles(srcDir + QDir::separator() + dirName, destPath.path() + QDir::separator() + dirName, nameExcludeFilter, nameIncludeFilter, srcFileList, dstFileList); } } else if(entry.isFile()) { srcFileList->push_back(entry.absoluteFilePath()); dstFileList->push_back(dstDir + QDir::separator() + entry.fileName()); } } if(isFirst) { emit updateFileCount(srcFileList->size()); for(int i=0; i<srcFileList->size(); i++) { if(mExitNow) return false; QFile fileEntry(srcFileList->at(i)); fileEntry.copy(dstFileList->at(i)); mutex.lock(); if(mPause) { pauseThreads.wait(&mutex); } mutex.unlock(); if(mExitNow) return false; emit updateFileProgress(i+1, QFileInfo(fileEntry.fileName()).fileName()); } } return true; }
//----------------------------------------------------------------------------- // Purpose: walks the file elements in the vcproj and inserts them into configs //----------------------------------------------------------------------------- bool CVCProjConvert::ExtractFiles( IXMLDOMDocument *pDoc ) { if (!pDoc) { return false; } Assert( m_Configurations.Count() ); // some configs must be loaded first #ifdef _WIN32 CComPtr<IXMLDOMNodeList> pFiles; pDoc->getElementsByTagName( _bstr_t("File"), &pFiles); if (pFiles) { long len = 0; pFiles->get_length(&len); for ( int i=0; i<len; i++ ) { CComPtr<IXMLDOMNode> pNode; pFiles->get_item( i, &pNode); if (pNode) { CComQIPtr<IXMLDOMElement> pElem( pNode ); CUtlSymbol fileName = GetXMLAttribValue(pElem,"RelativePath"); if ( fileName.IsValid() ) { CConfiguration::FileType_e type = GetFileType( fileName.String() ); CConfiguration::CFileEntry fileEntry( fileName.String(), type ); for ( int i = 0; i < m_Configurations.Count(); i++ ) // add the file to all configs { CConfiguration & config = m_Configurations[i]; config.InsertFile( fileEntry ); } IterateFileConfigurations( pElem, fileName ); // now remove the excluded ones } } }//for } #elif _LINUX DOMNodeList *nodes = pDoc->getElementsByTagName( _bstr_t("File") ); if (nodes) { int len = nodes->getLength(); for ( int i=0; i<len; i++ ) { DOMNode *node = nodes->item(i); if (node) { CUtlSymbol fileName = GetXMLAttribValue(node,"RelativePath"); if ( fileName.IsValid() ) { char fixedFileName[ MAX_PATH ]; Q_strncpy( fixedFileName, fileName.String(), sizeof(fixedFileName) ); if ( fixedFileName[0] == '.' && fixedFileName[1] == '\\' ) { Q_memmove( fixedFileName, fixedFileName+2, sizeof(fixedFileName)-2 ); } Q_FixSlashes( fixedFileName ); FindFileCaseInsensitive( fixedFileName, sizeof(fixedFileName) ); CConfiguration::FileType_e type = GetFileType( fileName.String() ); CConfiguration::CFileEntry fileEntry( fixedFileName, type ); for ( int i = 0; i < m_Configurations.Count(); i++ ) // add the file to all configs { CConfiguration & config = m_Configurations[i]; config.InsertFile( fileEntry ); } IterateFileConfigurations( node, fixedFileName ); // now remove the excluded ones } } }//for } #endif return true; }