void KConfigCompiler_Test::testBaselineComparison() { QFETCH(QString, testName); QFile file(QFINDTESTDATA(testName)); QFile fileRef(QFINDTESTDATA(testName + QLatin1String(".ref"))); if (!file.open(QIODevice::ReadOnly)) { qWarning() << "Failed to open" << file.fileName() << "(" << testName << ")"; QFAIL("Can't open file for comparison"); } if (!fileRef.open(QIODevice::ReadOnly)) { qWarning() << "Failed to open" << fileRef.fileName() << "(" << testName << ".ref )"; QFAIL("Can't open file for comparison"); } QString content = file.readAll(); QString contentRef = fileRef.readAll(); if (content != contentRef) { appendFileDiff(fileRef.fileName(), file.fileName()); } // use split('\n') to avoid // the whole output shown inline QCOMPARE(content.split('\n'), contentRef.split('\n')); QVERIFY(content == contentRef); }
ReplayGainReader::ReplayGainReader(const QString &path) { TagLib::MPEG::File fileRef(path.toLocal8Bit().constData()); if(fileRef.ID3v2Tag()) readID3v2(fileRef.ID3v2Tag()); if(m_values.isEmpty() && fileRef.APETag()) readAPE(fileRef.APETag()); }
QList<FileInfo *> DecoderMPCFactory::createPlayList(const QString &fileName, bool useMetaData, QStringList *) { FileInfo *info = new FileInfo(fileName); #if (TAGLIB_MAJOR_VERSION > 1) || ((TAGLIB_MAJOR_VERSION == 1) && (TAGLIB_MINOR_VERSION >= 8)) TagLib::FileStream stream(fileName.toLocal8Bit().constData(), true); TagLib::MPC::File fileRef(&stream); #else TagLib::MPC::File fileRef(fileName.toLocal8Bit().constData()); #endif TagLib::APE::Tag *tag = useMetaData ? fileRef.APETag() : 0; if (tag && !tag->isEmpty()) { info->setMetaData(Qmmp::ALBUM, QString::fromUtf8(tag->album().toCString(true)).trimmed()); info->setMetaData(Qmmp::ARTIST, QString::fromUtf8(tag->artist().toCString(true)).trimmed()); info->setMetaData(Qmmp::COMMENT, QString::fromUtf8(tag->comment().toCString(true)).trimmed()); info->setMetaData(Qmmp::GENRE, QString::fromUtf8(tag->genre().toCString(true)).trimmed()); info->setMetaData(Qmmp::TITLE, QString::fromUtf8(tag->title().toCString(true)).trimmed()); info->setMetaData(Qmmp::YEAR, tag->year()); info->setMetaData(Qmmp::TRACK, tag->track()); } if (fileRef.audioProperties()) info->setLength(fileRef.audioProperties()->length()); //additional metadata if(tag) { TagLib::APE::Item fld; if(!(fld = tag->itemListMap()["ALBUM ARTIST"]).isEmpty()) info->setMetaData(Qmmp::ALBUMARTIST, QString::fromUtf8(fld.toString().toCString(true)).trimmed()); if(!(fld = tag->itemListMap()["COMPOSER"]).isEmpty()) info->setMetaData(Qmmp::COMPOSER, QString::fromUtf8(fld.toString().toCString(true)).trimmed()); } QList <FileInfo*> list; list << info; return list; }
bool DebugDatabase::ResolveReferences(const std::string& mapName, RefType fileType, const std::set<ObjectOSMRef>& ids, const std::set<ObjectFileRef>& fileOffsets, std::map<ObjectOSMRef,ObjectFileRef>& idFileOffsetMap, std::map<ObjectFileRef,ObjectOSMRef>& fileOffsetIdMap) { FileScanner scanner; uint32_t entryCount; std::string filename=AppendFileToDir(path,mapName); if (!scanner.Open(filename,FileScanner::LowMemRandom,false)) { std::cerr << "Cannot open file '" << scanner.GetFilename() << "'!" << std::endl; return false; } if (!scanner.Read(entryCount)) { return false; } for (size_t i=1; i<=entryCount; i++) { Id id; uint8_t typeByte; OSMRefType osmType; FileOffset fileOffset; if (!scanner.Read(id)) { return false; } if (!scanner.Read(typeByte)) { return false; } osmType=(OSMRefType)typeByte; if (!scanner.ReadFileOffset(fileOffset)) { return false; } ObjectOSMRef osmRef(id,osmType); ObjectFileRef fileRef(fileOffset,fileType); if (ids.find(osmRef)!=ids.end() || fileOffsets.find(fileRef)!=fileOffsets.end()) { idFileOffsetMap.insert(std::make_pair(osmRef,fileRef)); fileOffsetIdMap.insert(std::make_pair(fileRef,osmRef)); } } return scanner.Close(); }
void DiscoverySingleDirectoryJob::directoryListingIteratedSlot(QString file, const QMap<QString, QString> &map) { if (!_ignoredFirst) { // The first entry is for the folder itself, we should process it differently. _ignoredFirst = true; if (map.contains("permissions")) { auto perm = RemotePermissions::fromServerString(map.value("permissions")); emit firstDirectoryPermissions(perm); _isExternalStorage = perm.hasPermission(RemotePermissions::IsMounted); } if (map.contains("data-fingerprint")) { _dataFingerprint = map.value("data-fingerprint").toUtf8(); if (_dataFingerprint.isEmpty()) { // Placeholder that means that the server supports the feature even if it did not set one. _dataFingerprint = "[empty]"; } } } else { // Remove <webDAV-Url>/folder/ from <webDAV-Url>/folder/subfile.txt file.remove(0, _lsColJob->reply()->request().url().path().length()); // remove trailing slash while (file.endsWith('/')) { file.chop(1); } // remove leading slash while (file.startsWith('/')) { file = file.remove(0, 1); } std::unique_ptr<csync_file_stat_t> file_stat(new csync_file_stat_t); file_stat->path = file.toUtf8(); file_stat->size = -1; propertyMapToFileStat(map, file_stat.get()); if (file_stat->type == ItemTypeDirectory) file_stat->size = 0; if (file_stat->type == ItemTypeSkip || file_stat->size == -1 || file_stat->remotePerm.isNull() || file_stat->etag.isEmpty() || file_stat->file_id.isEmpty()) { _error = tr("The server file discovery reply is missing data."); qCWarning(lcDiscovery) << "Missing properties:" << file << file_stat->type << file_stat->size << file_stat->modtime << file_stat->remotePerm.toString() << file_stat->etag << file_stat->file_id; } if (_isExternalStorage && file_stat->remotePerm.hasPermission(RemotePermissions::IsMounted)) { /* All the entries in a external storage have 'M' in their permission. However, for all purposes in the desktop client, we only need to know about the mount points. So replace the 'M' by a 'm' for every sub entries in an external storage */ file_stat->remotePerm.unsetPermission(RemotePermissions::IsMounted); file_stat->remotePerm.setPermission(RemotePermissions::IsMountedSub); } QStringRef fileRef(&file); int slashPos = file.lastIndexOf(QLatin1Char('/')); if (slashPos > -1) { fileRef = file.midRef(slashPos + 1); } _results.push_back(std::move(file_stat)); } //This works in concerto with the RequestEtagJob and the Folder object to check if the remote folder changed. if (map.contains("getetag")) { _etagConcatenation += map.value("getetag"); if (_firstEtag.isEmpty()) { _firstEtag = map.value("getetag"); // for directory itself } } }
//---------------------------------------- int32_t CMission::LoadAliasName(CStringList& aliases) { int32_t result = BRATHL_SUCCESS; const uint32_t MAX_LINE_LEN = 255; char line[MAX_LINE_LEN+1]; char name[MAX_LINE_LEN+1]; char alias[MAX_LINE_LEN+1]; bool bFoundInFile = false; aliases.InsertUnique(GetName()); std::string refFilePathName = CTools::FindDataFile(CMission::m_refAliasName); if (refFilePathName == "") { if (m_printWarnings) { printf("\nWARNING - CMission::LoadAliasName - Unabled to open file '%s' " "\nCheck directory '%s'", CMission::m_refAliasName, CTools::GetInternalDataDir().c_str()); } return BRATHL_WARNING_OPEN_FILE_ALIAS_MISSION; } // reads file contains value reference CFile fileRef(refFilePathName, CFile::modeRead); if (fileRef.IsOpen() == false) { if (m_printWarnings) { printf("\nWARNING - CMission::LoadAliasName - Unabled to open file '%s'\n", refFilePathName.c_str()); } return BRATHL_WARNING_OPEN_FILE_ALIAS_MISSION; } int32_t nbFields = EOF; int32_t size = fileRef.ReadLineData(line, MAX_LINE_LEN); while (size > 0) { nbFields = sscanf ( line, "%s %s", name, alias); if ( (nbFields < 2) ) { if (m_printWarnings) { printf("\nWARNING - CMission::LoadAliasName - Invalid reference mission file format - file name %s \n", refFilePathName.c_str()); } return BRATHL_WARNING_INVALID_REF_FILE_FIELD; } /*printf("name %s, alias %s\n", name, alias); */ if (strcmp(name, GetName()) == 0) { aliases.InsertUnique(CTools::StringTrim(alias)); bFoundInFile = true; } // reads next data size = fileRef.ReadLineData(line, MAX_LINE_LEN); } if (bFoundInFile == false) { if (m_printWarnings) { printf("\nWARNING - CMission::LoadAliasName - no alias for %s found in file %s \n" "Default values will be considered\n", name, refFilePathName.c_str()); } } fileRef.Close(); return result; }
//---------------------------------------- int32_t CMission::LoadRefMission(bool searchByID /* = true */ ) { int32_t result = BRATHL_SUCCESS; const uint32_t MAX_LINE_LEN = 255; char line[MAX_LINE_LEN+1]; brathl_mission id = 0; char name[CMission::m_maxLenName+1]; int32_t cycle = 0; int32_t pass = 0; double julian = 0.0; double repeat = 0.0; int32_t nbPass = 0; bool bFoundInFile = false; CMission missionSave = *this; std::string refFilePathName = CTools::FindDataFile( CMission::m_refFileName ); if (refFilePathName == "") { if (m_printWarnings) { printf( "\nWARNING - CMission::LoadRefMission - Unabled to open file '%s' " "\nCheck directory '%s'\n", CMission::m_refFileName, CTools::GetInternalDataDir().c_str()); } return BRATHL_WARNING_OPEN_FILE_REF_FILE; } // reads file contains conversion parameters CFile fileRef(refFilePathName, CFile::modeRead); if (fileRef.IsOpen() == false) { if (m_printWarnings) { printf( "\nWARNING - CMission::LoadRefMission - Unabled to open file '%s'\n", refFilePathName.c_str() ); } return BRATHL_WARNING_OPEN_FILE_REF_FILE; } int32_t nbFields = EOF; int32_t lineNb = 0; int32_t size = fileRef.ReadLineData(line, MAX_LINE_LEN); while (size > 0) { ++lineNb; nbFields = sscanf ( line, "%d %s %d %d %lf %lf %d", &id, name, &cycle, &pass, &julian, &repeat, &nbPass ); if ( nbFields < 7 ) { if (m_printWarnings) { printf( "\nWARNING - CMission::LoadRefMission - Invalid reference mission file format - line: %d of file: %s \n", lineNb, refFilePathName.c_str() ); } return BRATHL_WARNING_INVALID_REF_FILE_FIELD; } /*printf("id %d, name %s, cycle %d, pass %d, julian %lf, repead %lf, nbpass %d \n", id, name, cycle, pass, julian, repeat, nbPass);*/ if ( searchByID ) bFoundInFile = ( id == GetMission() ); else { std::string product_type ( GetName() ); // product type/label std::string name_read( name ); // mission name at reference file product_type = CTools::StringToLower(product_type).substr(0, name_read.size()); name_read = CTools::StringToLower(name_read); bFoundInFile = ( product_type == name_read ); } if ( bFoundInFile ) { missionSave = *this; // Assign mission conversion parameters m_mission = id; m_missionName = name; m_cycleRef = cycle; m_passRef = pass; m_repeat = repeat; m_nbPass = nbPass; result = m_dateRef.SetDateJulian(julian); if (result != BRATHL_SUCCESS) { if (m_printWarnings) { printf( "\nWARNING - CMission::LoadRefMission - Invalid reference date - file name %s \n" "mission %s, cycle %d, pass %d, julian %lf, repeat %lf, nb passes %d\n", refFilePathName.c_str(), name, cycle, pass, julian, repeat, nbPass ); } *this = missionSave; result = BRATHL_WARNING_INVALID_REF_FILE_FIELDDATE; } } // Breaks while loop if mission was found if ( bFoundInFile ) { break; } else { size = fileRef.ReadLineData(line, MAX_LINE_LEN); } // reads next line } if ( bFoundInFile == false ) { if ( m_printWarnings ) { if (searchByID) printf("\nWARNING - CMission::LoadRefMission - no mission ID=%d found in file: %s \n", GetMission(), refFilePathName.c_str()); else printf("\nWARNING - CMission::LoadRefMission - no mission name='%s' found in file: %s \n", GetName(), refFilePathName.c_str()); } m_missionName = CMission::m_nameUnknown; result = BRATHL_ERROR_INVALID_MISSION; } fileRef.Close(); return result; }