void Watcher::checkChanges(const QString& path) { // Getting name of appeared file delete dir; dir = new QDir(path); listOfFiles = dir->entryInfoList(); qDebug() << "Изменения в каталоге"; qDebug() << listOfFiles.length() << oldLength << "\n"; if (listOfFiles.length() > oldLength) { QFileInfoList::iterator i; QFileInfoList::iterator j; for (j = oldListOfFiles.begin(); j != oldListOfFiles.end(); ++j) { for (i = listOfFiles.begin(); i != listOfFiles.end(); ++i) { if (i->fileName().compare(j->fileName()) == 0) { listOfFiles.erase(i); break; } } } qDebug() << listOfFiles.first().fileName(); dialog = new Dialog(listOfFiles.first(), this); dialog->show(); setLabel(listOfFiles.first().fileName()); // Showing bubble notification in tray } oldListOfFiles = dir->entryInfoList(); oldLength = oldListOfFiles.length(); }
QString LeScienze500::getDvdPath() { #ifdef Q_WS_X11 QString path = "/media/LESCIENZE" ; QString path_1 = path + "/DVD1" ; QString path_2 = path + "/DVD2" ; if ( QFile().exists( path_1 ) || QFile().exists( path_2 ) ) return path ; else return QString() ; #endif #ifdef Q_WS_WIN QFileInfoList dev_list ; dev_list = QDir::drives() ; for ( QFileInfoList::iterator itr = dev_list.begin() ; itr < dev_list.end() ; itr++ ) { QString path = itr->absolutePath() ; QString path_1 = path + "/DVD1" ; QString path_2 = path + "/DVD2" ; if ( QFile().exists( path_1 ) || QFile().exists( path_2 ) ) { return path ; } } return QString() ; #endif }
void Application::updateGotCurrent() { if (!updateReply || updateThread) return; cSetLastUpdateCheck(unixtime()); QRegularExpressionMatch m = QRegularExpression(qsl("^\\s*(\\d+)\\s*:\\s*([\\x21-\\x7f]+)\\s*$")).match(QString::fromUtf8(updateReply->readAll())); if (m.hasMatch()) { int32 currentVersion = m.captured(1).toInt(); if (currentVersion > AppVersion) { updateThread = new QThread(); connect(updateThread, SIGNAL(finished()), updateThread, SLOT(deleteLater())); updateDownloader = new PsUpdateDownloader(updateThread, m.captured(2)); updateThread->start(); } } if (updateReply) updateReply->deleteLater(); updateReply = 0; if (!updateThread) { QDir updates(cWorkingDir() + "tupdates"); if (updates.exists()) { QFileInfoList list = updates.entryInfoList(QDir::Files); for (QFileInfoList::iterator i = list.begin(), e = list.end(); i != e; ++i) { if (QRegularExpression("^(tupdate|tmacupd|tlinuxupd|tlinux32upd)\\d+$", QRegularExpression::CaseInsensitiveOption).match(i->fileName()).hasMatch()) { QFile(i->absoluteFilePath()).remove(); } } } emit updateLatest(); } startUpdateCheck(true); App::writeConfig(); }
bool VideoMetadataImp::removeDir(const QString &dirName) { QDir d(dirName); QFileInfoList contents = d.entryInfoList(); if (!contents.size()) { return d.rmdir(dirName); } for (QFileInfoList::iterator p = contents.begin(); p != contents.end(); ++p) { if (p->fileName() == "." || p->fileName() == "..") { continue; } if (p->isDir()) { QString fileName = p->fileName(); if (!removeDir(fileName)) return false; } else { if (!QFile(p->fileName()).remove()) return false; } } return d.rmdir(dirName); }
/*递归删除文件夹内容 ** **dir :文件夹的名字,绝对路径和相对路径均可 ** **返回值 :成功后返回true;否则返回false */ bool removeFileWithDir(const QString &dirName) { static QVector<QString> dirNames; QDir dir; QFileInfoList filst; QFileInfoList::iterator curFi; //初始化 dirNames.clear(); if(dir.exists()){ dirNames<<dirName; } else{ return true; } //遍历各级文件夹,并将这些文件夹中的文件删除 for(int i=0;i<dirNames.size();++i) { dir.setPath(dirNames[i]); filst=dir.entryInfoList(QDir::Dirs|QDir::Files |QDir::Readable|QDir::Writable |QDir::Hidden|QDir::NoDotAndDotDot ,QDir::Name); if(filst.size()>0) { curFi=filst.begin(); while(curFi!=filst.end()) { //遇到文件夹,则添加至文件夹列表dirs尾部 if(curFi->isDir()) { dirNames.push_back(curFi->filePath()); } else if(curFi->isFile()) { //遇到文件,则删除之 if(!dir.remove(curFi->fileName())) { //return false; } } curFi++; }//end of while } } #if 0 //删除文件夹 for(int i=dirNames.size()-1;i>=0;--i) { if(!dir.rmdir(dirNames[i])) { //return false; } } #endif return true; }
void KTNEFMain::cleanup() { QDir d( KGlobal::dirs()->localkdedir() + "/share/apps/ktnef/tmp/" ); QFileInfoList list = d.entryInfoList( QDir::Files | QDir::Hidden, QDir::Unsorted ); QFileInfoList::iterator it; for ( it = list.begin(); it != list.end(); ++it ) { d.remove( it->absoluteFilePath() ); } }
void PsUpdateDownloader::initOutput() { QString fileName; QRegularExpressionMatch m = QRegularExpression(qsl("/([^/\\?]+)(\\?|$)")).match(updateUrl); if (m.hasMatch()) { fileName = m.captured(1).replace(QRegularExpression(qsl("[^a-zA-Z0-9_\\-]")), QString()); } if (fileName.isEmpty()) { fileName = qsl("tupdate-%1").arg(rand()); } QString dirStr = cWorkingDir() + qsl("tupdates/"); fileName = dirStr + fileName; QFileInfo file(fileName); QDir dir(dirStr); if (dir.exists()) { QFileInfoList all = dir.entryInfoList(QDir::Files); for (QFileInfoList::iterator i = all.begin(), e = all.end(); i != e; ++i) { if (i->absoluteFilePath() != file.absoluteFilePath()) { QFile::remove(i->absoluteFilePath()); } } } else { dir.mkdir(dir.absolutePath()); } outputFile.setFileName(fileName); if (file.exists()) { uint64 fullSize = file.size(); if (fullSize < INT_MAX) { int32 goodSize = (int32)fullSize; if (goodSize % UpdateChunk) { goodSize = goodSize - (goodSize % UpdateChunk); if (goodSize) { if (outputFile.open(QIODevice::ReadOnly)) { QByteArray goodData = outputFile.readAll().mid(0, goodSize); outputFile.close(); if (outputFile.open(QIODevice::WriteOnly)) { outputFile.write(goodData); outputFile.close(); QMutexLocker lock(&mutex); already = goodSize; } } } } else { QMutexLocker lock(&mutex); already = goodSize; } } if (!already) { QFile::remove(fileName); } } }
void MdPlottingCmapsProvider::appendAllFileNamesForFileType( QStringList &colorMapNames, QStringList &colorMapFiles, QString colorMapDirectory, QString fileType) { QDir directory(colorMapDirectory); QStringList filter(QString("*.%1").arg(fileType)); QFileInfoList info = directory.entryInfoList(filter, QDir::Files); for (QFileInfoList::iterator it = info.begin(); it != info.end(); ++it) { colorMapNames.append(it->baseName()); colorMapFiles.append(it->absoluteFilePath()); } }
void UniboardSankoreTransition::rollbackDocumentsTransition(QFileInfoList& fileInfoList) { QFileInfoList::iterator fileInfo; for (fileInfo = fileInfoList.begin(); fileInfo != fileInfoList.end(); fileInfo += 1) { if (fileInfo->isDir() && fileInfo->fileName().startsWith("Uniboard Document ")){ QString sankoreDocumentName = fileInfo->fileName(); sankoreDocumentName.replace("Uniboard","Sankore"); QString sankoreDocumentDirectoryPath = UBSettings::userDocumentDirectory() + "/" + sankoreDocumentName; if (QFileInfo(sankoreDocumentDirectoryPath).exists()){ UBFileSystemUtils::deleteDir(sankoreDocumentDirectoryPath); } } } }
void getAllIncludes(QString path, QFileInfoList h_files, QFileInfoList cpp_files, QStringList& includes) { for(QFileInfoList::iterator it = h_files.begin(); it != h_files.end(); it++) { QFile file(it->absoluteFilePath()); if(file.open(QFile::ReadOnly)) { QTextStream textStream(&file); while(!textStream.atEnd()) { QString line = textStream.readLine(); if( line.indexOf("#include ") != -1 && line.indexOf("Q") != -1 ) { addToStringList(includes, line); } } file.close(); } } for(QFileInfoList::iterator it = cpp_files.begin(); it != cpp_files.end(); it++) { QFile file(it->absoluteFilePath()); if(file.open(QFile::ReadOnly)) { QTextStream textStream(&file); while(!textStream.atEnd()) { QString line = textStream.readLine(); if( line.indexOf("//") == -1 && line.indexOf("#include ") != -1 && line.indexOf("Q") != -1 ) { addToStringList(includes, line); } } file.close(); } } }
void Application::startUpdateCheck(bool forceWait) { updateCheckTimer.stop(); if (updateRequestId || updateThread || updateReply || !cAutoUpdate()) return; int32 updateInSecs = cLastUpdateCheck() + 3600 + (rand() % 3600) - unixtime(); bool sendRequest = (updateInSecs <= 0 || updateInSecs > 7200); if (!sendRequest && !forceWait) { QDir updates(cWorkingDir() + "tupdates"); if (updates.exists()) { QFileInfoList list = updates.entryInfoList(QDir::Files); for (QFileInfoList::iterator i = list.begin(), e = list.end(); i != e; ++i) { if (QRegularExpression("^(tupdate|tmacupd|tlinuxupd|tlinux32upd)\\d+$", QRegularExpression::CaseInsensitiveOption).match(i->fileName()).hasMatch()) { sendRequest = true; } } } } if (cManyInstance() && !cDebug()) return; // only main instance is updating if (sendRequest) { QNetworkRequest checkVersion(cUpdateURL()); if (updateReply) updateReply->deleteLater(); App::setProxySettings(updateManager); updateReply = updateManager.get(checkVersion); connect(updateReply, SIGNAL(finished()), this, SLOT(updateGotCurrent())); connect(updateReply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(updateFailedCurrent(QNetworkReply::NetworkError))); // updateRequestId = MTP::send(MTPhelp_GetAppUpdate(MTP_string(cApiDeviceModel()), MTP_string(cApiSystemVersion()), MTP_string(cApiAppVersion()), MTP_string(cApiLang())), rpcDone(&Application::onAppUpdate), rpcFail(&Application::onAppUpdateFail); emit updateChecking(); } else { updateCheckTimer.start((updateInSecs + 5) * 1000); } }
bool LeScienze500::OpenPDF() { QFileInfoList drives = QDir::drives() ; for ( QFileInfoList::iterator it = drives.begin() ; it < drives.end() ; it++ ) { qDebug() << it->path() ; } if ( this->pdf_file.isEmpty() ) return false ; return this->OpenPDF( this->pdf_file ) ; }
void LunarMainWindow::processCacheCleaning() { QDir dir("cache/"); QFileInfoList listDir = dir.entryInfoList(QDir::AllEntries | QDir::NoDotAndDotDot); int i = 0; for(QFileInfoList::iterator it = listDir.begin(); it != listDir.end(); ++it) { if(it->lastModified().date() <= m_cacheDuration) { qDebug() << it->lastModified().date() << " " << m_cacheDuration << endl; QFile file("cache/" + it->fileName()); file.remove(); i++; } } qDebug() << "Cleaned " << i << " expired elements from the cache" << endl; }
/********** *返回值:0成功 *1原包名不存在 *2创建包出错 *3目的包名已经存在 *4替换包名过程出错 ***********/ int PathManager::RenamePak(QString &path, QString &oldPakName, QString &newPakName) { QString oldName = oldPakName; QString newName = newPakName; oldName.replace(".", "/"); newName.replace(".", "/"); QString srcDir = path + "/" + oldName; QString destDir = path + "/" + newName; QDir dirSrc(srcDir); QDir dirDest(destDir); if (!dirSrc.exists()){ return 1; } dirSrc.setFilter(QDir::NoDotAndDotDot | QDir::Files); QFileInfoList allFiles = dirSrc.entryInfoList(); if (allFiles.isEmpty()){ return 1; } if (!dirDest.exists() && !dirDest.mkpath(destDir)){ return 2; } dirDest.setFilter(QDir::NoDotAndDotDot | QDir::Files); if (!dirDest.entryInfoList().isEmpty()){ return 3; } for (QFileInfoList::iterator ite = allFiles.begin(); ite != allFiles.end(); ite++){ QString tmpName = ite->absoluteFilePath(); tmpName = tmpName.mid(tmpName.lastIndexOf("/") + 1); if (!dirDest.exists()){ if (dirDest.mkpath(destDir)){ return 4; } } if (!CopyFile(ite->absoluteFilePath(), destDir + "/" + tmpName, true) || !QFile::remove(ite->absoluteFilePath())){ return 4; } } RemoveEmptyDirFromDeepest(srcDir); return 0; }
int PathManager::ReplacePakInDec(QString &path, QString &oldName, QString &newName) { QVector<QString> dirNames; QDir dir(path); QFileInfoList filst; QFileInfoList::iterator curFi; //初始化 dirNames.clear(); if (dir.exists()){ dirNames << path; } else{ return 0; } //遍历各级文件夹,并将这些文件夹中的文件删除 for (int i = 0; i<dirNames.size(); ++i) { dir.setPath(dirNames[i]); filst = dir.entryInfoList(QDir::Dirs | QDir::Files | QDir::Readable | QDir::Writable | QDir::Hidden | QDir::NoDotAndDotDot , QDir::Name); if (filst.size()>0){ curFi = filst.begin(); while (curFi != filst.end()) { //遇到文件夹,则添加至文件夹列表dirs尾部 if (curFi->isDir()){ dirNames.push_back(curFi->filePath()); } else if (curFi->isFile()){ //遇到文件,则删除之 if (curFi->absoluteFilePath().toLower().endsWith(".smali")){ if (!ReplacePakNameInSmali(curFi->absoluteFilePath(), oldName, newName)){ return 1; } } else if (curFi->absoluteFilePath().toLower().endsWith(".xml")){ if (!ReplacePakNameInXml(path, curFi->absoluteFilePath(), oldName, newName)){ return 1; } } } curFi++; }//end of while } } int ret = 0; ret = RenamePakInDec(path, oldName, newName); if (ret != 0){ return ret; } return 0; }
static void recursiveFileInfoList(const QDir &dir, const QStringList &nameFilters, QDir::Filters filter, bool recursive, QFileInfoList *fileinfolist) { if (recursive) filter |= QDir::AllDirs; QFileInfoList entries = dir.entryInfoList(nameFilters, filter); QFileInfoList::iterator it; for (it = entries.begin(); it != entries.end(); ++it) { QString fname = it->fileName(); if (fname != QLatin1String(".") && fname != QLatin1String("..")) { if (it->isDir()) recursiveFileInfoList(QDir(it->absoluteFilePath()), nameFilters, filter, recursive, fileinfolist); else fileinfolist->append(*it); } } }
int UBFeaturesComputingThread::featuresCount(const QUrl &pPath) { int noItems = 0; QFileInfoList fileInfoList = UBFileSystemUtils::allElementsInDirectory(pPath.toLocalFile()); QFileInfoList::iterator fileInfo; for ( fileInfo = fileInfoList.begin(); fileInfo != fileInfoList.end(); fileInfo += 1) { QString fullFileName = fileInfo->absoluteFilePath(); UBFeatureElementType featureType = UBFeaturesController::fileTypeFromUrl(fullFileName); if (featureType != FEATURE_INVALID && !fullFileName.contains(".thumbnail.")) { noItems++; } if (featureType == FEATURE_FOLDER) { noItems += featuresCount(QUrl::fromLocalFile(fullFileName)); } } return noItems; }
void UBFeaturesComputingThread::scanFS(const QUrl & currentPath, const QString & currVirtualPath, const QSet<QUrl> &pFavoriteSet) { // Q_ASSERT(QFileInfo(currentPath.toLocalFile()).exists()); // if(QFileInfo(currentPath.toLocalFile()).exists()) // return; QFileInfoList fileInfoList = UBFileSystemUtils::allElementsInDirectory(currentPath.toLocalFile()); QFileInfoList::iterator fileInfo; for ( fileInfo = fileInfoList.begin(); fileInfo != fileInfoList.end(); fileInfo += 1) { if (abort) { return; } QString fullFileName = fileInfo->absoluteFilePath(); UBFeatureElementType featureType = UBFeaturesController::fileTypeFromUrl(fullFileName); QString fileName = fileInfo->fileName(); QImage icon = UBFeaturesController::getIcon(fullFileName, featureType); if ( fullFileName.contains(".thumbnail.")) continue; UBFeature testFeature(currVirtualPath + "/" + fileName, icon, fileName, QUrl::fromLocalFile(fullFileName), featureType); emit sendFeature(testFeature); emit featureSent(); emit scanPath(fullFileName); if ( pFavoriteSet.find(QUrl::fromLocalFile(fullFileName)) != pFavoriteSet.end()) { //TODO send favoritePath from the controller or make favoritePath public and static emit sendFeature(UBFeature( UBFeaturesController::favoritePath + "/" + fileName, icon, fileName, QUrl::fromLocalFile(fullFileName), featureType)); } if (featureType == FEATURE_FOLDER) { scanFS(QUrl::fromLocalFile(fullFileName), currVirtualPath + "/" + fileName, pFavoriteSet); } } }
QStringList BitmapFactoryInst::findIconFiles() const { QStringList files, filters; QList<QByteArray> formats = QImageReader::supportedImageFormats(); for (QList<QByteArray>::iterator it = formats.begin(); it != formats.end(); ++it) filters << QString::fromAscii("*.%1").arg(QString::fromAscii(*it).toLower()); QStringList paths = d->paths; #if QT_VERSION >= 0x040500 paths.removeDuplicates(); #endif for (QStringList::ConstIterator pt = paths.begin(); pt != paths.end(); ++pt) { QDir d(*pt); d.setNameFilters(filters); QFileInfoList fi = d.entryInfoList(); for (QFileInfoList::iterator it = fi.begin(); it != fi.end(); ++it) files << it->absoluteFilePath(); } #if QT_VERSION >= 0x040500 files.removeDuplicates(); #endif return files; }
bool PathManager::SearchDirContianSuffix(const QString &dirFrom, QStringList &result, QString &suffix) { QVector<QString> dirNames; QDir dir(dirFrom); QFileInfoList filst; QFileInfoList::iterator curFi; //初始化 dirNames.clear(); if (dir.exists()){ dirNames << dirFrom; } else{ return true; } //遍历各级文件夹,并将这些文件夹中的文件删除 for (int i = 0; i < dirNames.size(); ++i) { dir.setPath(dirNames[i]); filst = dir.entryInfoList(QDir::Dirs | QDir::Files | QDir::Readable | QDir::Writable | QDir::Hidden | QDir::NoDotAndDotDot , QDir::DirsFirst); if (filst.size()>0){ curFi = filst.begin(); while (curFi != filst.end()) { //遇到文件夹,则添加至文件夹列表dirs尾部 if (curFi->isDir()){ dirNames.push_back(curFi->filePath()); } else if (curFi->isFile()){ if (curFi->fileName().endsWith(suffix)){ result.push_back(curFi->absolutePath()); break; } } curFi++; }//end of while } } return true; }
int prepare(QFileInfo f, QStringList paths) { if (paths.isEmpty()) { cout << "No -path args were passed :(\n"; return -1; } int lastVersion = 0; QString lastVersionStr; QFileInfo last; QFileInfoList l = f.absoluteDir().entryInfoList(QDir::Files); for (QFileInfoList::iterator i = l.begin(), e = l.end(); i != e; ++i) { QRegularExpressionMatch m = QRegularExpression("/tsetup.((\\d+).(\\d+).(\\d+)).exe$").match(i->absoluteFilePath()); if (!m.hasMatch()) continue; int version = m.captured(2).toInt() * 1000000 + m.captured(3).toInt() * 1000 + m.captured(4).toInt(); if (version > lastVersion) { lastVersion = version; lastVersionStr = m.captured(1); last = *i; } } if (!lastVersion) { cout << "No tsetup.X.Y.Z.exe found :(\n"; return -1; } cout << "Last version: " << lastVersionStr.toUtf8().constData() << " (" << lastVersion << "), executing packer..\n"; QDir dir("deploy/" + lastVersionStr); if (dir.exists()) { cout << "Version " << lastVersionStr.toUtf8().constData() << " already exists in /deploy..\n"; return -1; } QString packer = QString("Packer.exe -version %1").arg(lastVersion); for (QStringList::iterator i = paths.begin(), e = paths.end(); i != e; ++i) { packer += " -path " + *i; } int res = system(packer.toUtf8().constData()); if (res) return res; dir.mkpath("."); paths.push_back("Telegram.pdb"); paths.push_back("Updater.pdb"); paths.push_back("tsetup." + lastVersionStr + ".exe"); paths.push_back(QString("tupdate%1").arg(lastVersion)); for (QStringList::iterator i = paths.begin(), e = paths.end(); i != e; ++i) { if (!QFile::copy(*i, "deploy/" + lastVersionStr + "/" + *i)) { cout << "Could not copy " << i->toUtf8().constData() << " to deploy/" << lastVersionStr.toUtf8().constData() << "\n"; return -1; } cout << "Copied " << i->toUtf8().constData() << "..\n"; } for (QStringList::iterator i = paths.begin(), e = paths.end(); i != e; ++i) { QFile::remove(*i); } cout << "Update created in deploy/" << lastVersionStr.toUtf8().constData() << "\n"; return 0; }
qint64 Dialog::countSize(QString filePath) { qint64 fileSize = 0; QList<QString> fileList; QFileInfo fileInfo(filePath); QString strTopDir; if(fileInfo.isDir()) {//文件夹加入堆栈 m_bFolder = true; if (filePath.contains('/')) { QStringList strList = filePath.split("/"); int iSize = strList.size(); strTopDir = strList.at(iSize-1); } else if(filePath.contains('\\')) { QStringList strList = filePath.split("\\"); int iSize = strList.size(); strTopDir = strList.at(iSize-1); } fileList.push_back(filePath); } else {//如果是文件的话就取文件的特特征码,文件特征码用文件的创建,最后的修改时间字符串和文件的路径取MD5 m_bFolder = false; m_fileList.push_front(filePath); fileSize = fileInfo.size(); QString createTime = fileInfo.created().toString(); QString modifiedTime = fileInfo.lastModified().toString(); QString checkString = createTime + modifiedTime; checkString += filePath; //m_fileCheck = MD5String(checkString.toLocal8Bit().data()); } while(!fileList.isEmpty()){//判断堆栈中是否有文件夹 QString filePath = fileList.value(0);//取堆栈的顶部位置 QDir dir(filePath);//文件夹信息 dir.setFilter(QDir::Dirs|QDir::Files|QDir::Hidden|QDir::System); dir.setSorting(QDir::DirsFirst); QFileInfoList list = dir.entryInfoList();//去得文件夹的文件信息 QFileInfoList::iterator iter; if (2 == list.size()) { qDebug() << "empty dir : " << filePath; m_emptyFolderList.push_back(filePath); } for(iter=list.begin(); iter!=list.end(); iter++) {//遍历文件夹内部 //m_stopMutex.lock(); // if(m_bStop) { // m_stopMutex.unlock(); // return -1; // } // m_stopMutex.unlock(); //qDebug() << "filename : " << iter->fileName(); if(iter->fileName() == "." || iter->fileName() == "..") { continue; } if(iter->isDir()) {//如果为文件夹的话加入到堆栈 fileList.push_back(iter->filePath()); } else {//如果是文件的话,取到文件的大小,并且把文件加入到发送list中 fileSize += iter->size(); //QString str m_fileList.push_front(iter->filePath()); } } fileList.pop_front();//堆栈顶部的元素已经处理完毕,出堆栈 } // if(m_fileCheck.size() == 0) {//文件夹的特征码是文件的所有路径取MD5 // QString checkString; // QList<QString>::iterator iter; // for(iter=m_fileList.begin(); iter!=m_fileList.end(); iter++) { // checkString += (*iter); // } // m_fileCheck = MD5String(checkString.toLocal8Bit().data()); // } qDebug() << "file or director size : " << fileSize; return fileSize; }
int LupdateApplication::start() { QStringList argv = arguments(); int argc = argv.count(); QString defaultContext; // This was QLatin1String("@default") before. MetaTranslator fetchedTor; QByteArray codecForTr; QByteArray codecForSource; QStringList tsFileNames; QStringList proFiles; QStringList sourceFiles; bool verbose = true; // verbose is on by default starting with Qt 4.2 bool noObsolete = false; bool onlyPlural = false; int numFiles = 0; bool standardSyntax = true; bool metTsFlag = false; QString extensions = m_defaultExtensions; QStringList extensionsNameFilters; int i; for ( i = 1; i < argc; i++ ) { if ( argv.at(i) == QLatin1String("-ts") ) standardSyntax = false; } for ( i = 1; i < argc; i++ ) { QString arg = argv.at(i); if ( arg == QLatin1String("-help") || arg == QLatin1String("--help") || arg == QLatin1String("-h")) { printUsage(); return 0; } else if ( arg == QLatin1String("-pluralonly") ) { onlyPlural = true; continue; } else if ( arg == QLatin1String("-noobsolete") ) { noObsolete = true; continue; } else if ( arg == QLatin1String("-silent") ) { verbose = false; continue; } else if ( arg == QLatin1String("-verbose") ) { verbose = true; continue; } else if ( arg == QLatin1String("-version") ) { Console::out(tr("lupdate version %1\n").arg(QLatin1String(QT_VERSION_STR)) ); return 0; } else if ( arg == QLatin1String("-ts") ) { metTsFlag = true; continue; } else if ( arg == QLatin1String("-extensions") ) { ++i; if (i == argc) { qWarning("The -extensions option should be followed by an extension list."); return 1; } extensions = argv.at(i); continue; } numFiles++; QString fullText; if ( standardSyntax && !metTsFlag ) { QFile f( arg ); if ( !f.open(QIODevice::ReadOnly) ) { #if defined(_MSC_VER) && _MSC_VER >= 1400 char buf[100]; strerror_s(buf, sizeof(buf), errno); qWarning("lupdate error: Cannot open file '%s': %s\n", qPrintable(arg), buf ); #else qWarning("lupdate error: Cannot open file '%s': %s\n", qPrintable(arg), strerror(errno) ); #endif return 1; } f.close(); } codecForTr.clear(); codecForSource.clear(); if (metTsFlag) { if ( arg.endsWith(QLatin1String(".ts"), Qt::CaseInsensitive) || arg.endsWith(QLatin1String(".xlf"), Qt::CaseInsensitive)) { QFileInfo fi( arg ); if ( !fi.exists() || fi.isWritable() ) { tsFileNames.append( QFileInfo(arg).absoluteFilePath() ); } else { qWarning("lupdate warning: For some reason, I cannot save '%s'\n", qPrintable(arg) ); } } else { qWarning("lupdate error: File '%s' lacks .ts or .xlf extension\n", qPrintable(arg) ); } } else if (arg.endsWith(QLatin1String(".pro"), Qt::CaseInsensitive)) { proFiles << arg; } else { QFileInfo fi(arg); if (fi.isDir()) { if ( verbose ) Console::out(tr("Scanning directory '%1'...\n").arg(arg)); QDir dir = QDir(fi.filePath()); if (extensionsNameFilters.isEmpty()) { extensions = extensions.trimmed(); // Remove the potential dot in front of each extension if (extensions.startsWith(QLatin1Char('.'))) extensions.remove(0,1); extensions.replace(QLatin1String(",."), QLatin1String(",")); extensions.insert(0, QLatin1String("*.")); extensions.replace(QLatin1Char(','), QLatin1String(",*.")); extensionsNameFilters = extensions.split(QLatin1Char(',')); } QDir::Filters filters = QDir::Files | QDir::NoSymLinks; QFileInfoList fileinfolist; recursiveFileInfoList(dir, extensionsNameFilters, filters, true, &fileinfolist); QFileInfoList::iterator ii; QString fn; for (ii = fileinfolist.begin(); ii != fileinfolist.end(); ++ii) { // Make sure the path separator is stored with '/' in the ts file fn = ii->canonicalFilePath().replace(QLatin1Char('\\'),QLatin1Char('/')); #ifdef LINGUIST_DEBUG qDebug() << fn; #endif sourceFiles << fn; } }else{ sourceFiles << fi.canonicalFilePath().replace(QLatin1Char('\\'),QLatin1Char('/')); } } } //for if ( proFiles.count() > 0 ) { proFiles = getListOfProfiles(proFiles, verbose); } bool firstPass = true; for (int pi = 0; firstPass || pi < proFiles.count(); ++pi) { QStringList tsFiles = tsFileNames; if (proFiles.count() > 0) { QString pf = proFiles.at(pi); QMap<QByteArray, QStringList> variables; if(!evaluateProFile(pf, verbose, &variables)) return 2; sourceFiles = variables.value("SOURCES"); QStringList tmp = variables.value("CODECFORTR"); if (!tmp.isEmpty()) { codecForTr = tmp.first().toAscii(); fetchedTor.setCodecForTr(codecForTr.constData()); } tmp = variables.value("CODECFORSRC"); if (!tmp.isEmpty()) { codecForSource = tmp.first().toAscii(); } tsFiles += variables.value("TRANSLATIONS"); } for (QStringList::iterator it = sourceFiles.begin(); it != sourceFiles.end(); ++it) { #ifdef LINGUIST_DEBUG qDebug() << " " << (*it); #endif if ( (*it).endsWith(QLatin1String(".java"), Qt::CaseInsensitive) ) { fetchtr_java( *it, &fetchedTor, defaultContext, true, codecForSource ); } else if ( (*it).endsWith(QLatin1String(".ui"), Qt::CaseInsensitive) ) { #ifdef LINGUIST_DEBUG qDebug() << " " << (*it) + ".h"; #endif fetchtr_ui( *it, &fetchedTor, defaultContext, true ); fetchtr_cpp( *it + QLatin1String(".h"), &fetchedTor, defaultContext, false, codecForSource ); } else { fetchtr_cpp( *it, &fetchedTor, defaultContext, true, codecForSource ); } } removeDuplicates(&tsFiles, false); if ( tsFiles.count() > 0) { updateTsFiles( fetchedTor, tsFiles, QString::fromLatin1(codecForTr.constData()), noObsolete, onlyPlural, verbose ); } firstPass = false; } if ( numFiles == 0 ) { printUsage(); return 1; } return 0; }
QString AudioPluginOSCGUI::getGUIFilePath(QString identifier) { QString type, soName, label; PluginIdentifier::parseIdentifier(identifier, type, soName, label); RG_DEBUG << "AudioPluginOSCGUI::getGUIFilePath(" << identifier << ")"; QFileInfo soInfo(soName); if (soInfo.isRelative()) { //!!! RG_DEBUG << "AudioPluginOSCGUI::AudioPluginOSCGUI: Unable to deal with relative .so path \"" << soName << "\" in identifier \"" << identifier << "\" yet"; throw Exception("Can't deal with relative .soname"); } QDir dir(soInfo.dir()); QString fileBase(soInfo.completeBaseName()); if (!dir.cd(fileBase)) { RG_DEBUG << "AudioPluginOSCGUI::AudioPluginOSCGUI: No GUI subdir for plugin .so " << soName; throw Exception("No GUI subdir available"); } QFileInfoList list = dir.entryInfoList(); // in order of preference: const char *suffixes[] = { "_rg", "_kde", "_qt", "_gtk2", "_gtk", "_x11", "_gui" }; int nsuffixes = int(sizeof(suffixes) / sizeof(suffixes[0])); for (int k = 0; k <= nsuffixes; ++k) { for (int fuzzy = 0; fuzzy <= 1; ++fuzzy) { QFileInfoList::iterator info; for (info = list.begin(); info != list.end(); ++info) { //### JAS Check for errors RG_DEBUG << "Looking at " << info->fileName() << " in path " << info->filePath() << " for suffix " << (k == nsuffixes ? "(none)" : suffixes[k]) << ", fuzzy " << fuzzy << endl; if (!(info->isFile() || info->isSymLink()) || !info->isExecutable()) { RG_DEBUG << "(not executable)"; continue; } if (fuzzy) { if (info->fileName().left(fileBase.length()) != fileBase) continue; RG_DEBUG << "(is file base)"; } else { if (info->fileName().left(label.length()) != label) continue; RG_DEBUG << "(is label)"; } if (k == nsuffixes || info->fileName().toLower().endsWith(suffixes[k])) { RG_DEBUG << "(ends with suffix " << (k == nsuffixes ? "(none)" : suffixes[k]) << " or out of suffixes)"; return info->filePath(); } RG_DEBUG << "(doesn't end with suffix " << (k == nsuffixes ? "(none)" : suffixes[k]) << ")"; } } } return QString(); }
QStringList StorageGroup::GetFileInfoList(QString Path) { QStringList files; QString relPath; bool badPath = true; if (Path.isEmpty() || Path == "/") { for (QStringList::Iterator it = m_dirlist.begin(); it != m_dirlist.end(); ++it) files << QString("sgdir::%1").arg(*it); return files; } for (QStringList::Iterator it = m_dirlist.begin(); it != m_dirlist.end(); ++it) { if (Path.startsWith(*it)) { relPath = Path; relPath.replace(*it,""); if (relPath.startsWith("/")) relPath.replace(0,1,""); badPath = false; } } LOG(VB_FILE, LOG_INFO, LOC + QString("GetFileInfoList: Reading '%1'").arg(Path)); if (badPath) return files; QDir d(Path); if (!d.exists()) return files; QFileInfoList list = d.entryInfoList(); if (!list.size()) return files; for (QFileInfoList::iterator p = list.begin(); p != list.end(); ++p) { if (p->fileName() == "." || p->fileName() == ".." || p->fileName() == "Thumbs.db") { continue; } QString tmp; if (p->isDir()) tmp = QString("dir::%1::0").arg(p->fileName()); else tmp = QString("file::%1::%2::%3%4").arg(p->fileName()).arg(p->size()) .arg(relPath).arg(p->fileName()); LOG(VB_FILE, LOG_DEBUG, LOC + QString("GetFileInfoList: (%1)").arg(tmp)); files.append(tmp); } return files; }
/********** *返回值:0成功 *1原包名不存在 *2创建包出错 *3目的包名已经存在 *4替换包名过程出错 *5替换app包名出错 ***********/ int PathManager::ReplaceAppPakInSrc(QString &path, QString &oldName, QString &newName) { QVector<QString> dirNames; QDir dir(path); QFileInfoList filst; QFileInfoList::iterator curFi; //初始化 dirNames.clear(); if (dir.exists()){ dirNames << path; } else{ return 0; } bool isTopDir = true; //遍历各级文件夹,并将这些文件夹中的文件删除 for (int i = 0; i<dirNames.size(); ++i) { dir.setPath(dirNames[i]); filst = dir.entryInfoList(QDir::Dirs | QDir::Files | QDir::Readable | QDir::Writable | QDir::Hidden | QDir::NoDotAndDotDot , QDir::Name); if (isTopDir){ isTopDir = false; for (int i = 0; i < filst.size(); i++) { if (filst[i].fileName() == "assets" || filst[i].fileName() == "bin" || filst[i].fileName() == "libs"){ filst.removeAt(i); i--; } } } if (filst.size()>0){ curFi = filst.begin(); while (curFi != filst.end()) { //遇到文件夹,则添加至文件夹列表dirs尾部 if (curFi->isDir()){ dirNames.push_back(curFi->filePath()); } else if (curFi->isFile()){ if (curFi->absoluteFilePath().toLower().endsWith(".java")){ if (!ReplaceAppPakNameInJava(path, curFi->absoluteFilePath(), oldName, newName)){ return 1; } } else if (curFi->absoluteFilePath().toLower().endsWith(".xml")){ if (!ReplaceAppPakNameInXml(path, curFi->absoluteFilePath(), oldName, newName)){ return 1; } } } curFi++; }//end of while } } if (!ReplaceAppPakNameInManifest(path, oldName, newName)){ return 5; } return 0; }
QFrame *TimeLapseWidget::tlConstruct(QWidget *, QSettings *qs) { QCCamera::initCamLibrary(); // Initialize GUI stuff QGridLayout *layout = new QGridLayout(); layout->addWidget(new QLabel("Available Cameras"),0,0,1,1); attachedCameras = new QComboBox; populateCameraList(); layout->addWidget(attachedCameras, 0,1,1,2); layout->addWidget(new QLabel("Output directory"),1,0,1,1); saveDirectory = new QLineEdit(); layout->addWidget( saveDirectory,1,1,1,1 ); QCompleter *completer = new QCompleter(this); completer->setModel(new QDirModel(completer)); saveDirectory->setCompleter(completer); directoryButton = new QPushButton( tr("Browse...") ); layout->addWidget( directoryButton,1,2,1,1 ); intervalBox = new QSpinBox; intervalBox->setMinimum(1); intervalBox->setMaximum(99999); lengthOfTimeBox = new QTimeEdit( QTime(0, 0, 0, 0), this ); lengthOfTimeBox->setDisplayFormat( "HH:mm:ss" ); layout->addWidget(new QLabel( "Interval" ), 2,0); layout->addWidget(intervalBox, 2,1); seconds = new QRadioButton( "S" ); seconds->setChecked( true ); minutes = new QRadioButton( "M" ); layout->addWidget( seconds, 2, 2, 1, 1, Qt::AlignLeft ); layout->addWidget( minutes, 2, 2, 1, 1, Qt::AlignRight ); layout->addWidget(new QLabel("Time to run"), 3,0); layout->addWidget( lengthOfTimeBox, 3,1); startButton = new QPushButton(QIcon(":/images/play.svgz"), "Start"); stopButton = new QPushButton(QIcon(":/images/stop.svgz"), "Stop"); layout->addWidget(startButton, 4,0); layout->addWidget(stopButton, 4,1); intervalBox->setFocus(); setupConnections(); startButton->setDisabled( false ); stopButton->setDisabled( true ); saveDirectory->setText("."); qs->beginGroup("TimeLapseTab"); intervalBox->setValue(qs->value("intervalBox", 15).toInt()); lengthOfTimeBox->setTime(qs->value("lengthOfTimeBox", QTime(0,0,0,0)).toTime()); saveDirectory->setText(qs->value("saveDirectory", ".").toString()); seconds->setChecked(qs->value("seconds", true).toBool()); minutes->setChecked(qs->value("minutes", false).toBool()); qs->endGroup(); saveDirectoryUpdated(); #ifndef CANON_SDK_BUILD camFinder = new QFileSystemWatcher(this); QFileInfoList dirs = QDir("/dev/bus/usb/").entryInfoList(); for (QFileInfoList::iterator iter = dirs.begin(); iter != dirs.end(); ++iter) { camFinder->addPath(iter->absoluteFilePath()); } connect(camFinder, SIGNAL(directoryChanged(QString)), this, SLOT(populateCameraList())); #endif QFrame *rv = new QFrame; rv->setLayout(layout); return rv; }
bool PathManager::CopyDir(const QString &source, const QString &destination, bool isCover) { /* 递归实现 */ /*QDir directory(source); if (!directory.exists()){ return false; } QString srcPath = QDir::toNativeSeparators(source); if (!srcPath.endsWith(QDir::separator())){ srcPath += QDir::separator(); } QString dstPath = QDir::toNativeSeparators(destination); if (!dstPath.endsWith(QDir::separator())){ dstPath += QDir::separator(); } QStringList fileNames = directory.entryList(QDir::AllEntries | QDir::NoDotAndDotDot | QDir::Hidden); for (QStringList::size_type i = 0; i != fileNames.size(); ++i) { QString fileName = fileNames.at(i); QString srcFilePath = srcPath + fileName; QString dstFilePath = dstPath + fileName; QFileInfo fileInfo(srcFilePath); if (fileInfo.isFile() || fileInfo.isSymLink()){ if (isCover){ QFile::setPermissions(dstFilePath, QFile::WriteOwner); } if (!QFile::copy(srcFilePath, dstFilePath)){ return false; } } else if (fileInfo.isDir()){ QDir dstDir(dstFilePath); dstDir.mkpath(dstFilePath); if (!CopyDir(srcFilePath, dstFilePath, isCover)){ return false; } } } return true;*/ QVector<QString> dirNames; QVector<QString> fileNames; QDir dir(source); if (!dir.exists()){ return false; } dirNames.clear(); dirNames << source; QFileInfoList filst; QFileInfoList::iterator curFi; for (int i = 0; i < dirNames.size(); ++i) { dir.setPath(dirNames[i]); filst = dir.entryInfoList(QDir::Dirs | QDir::Files | QDir::Readable | QDir::Writable | QDir::Hidden | QDir::NoDotAndDotDot , QDir::DirsFirst); if (filst.size() > 0){ curFi = filst.begin(); while (curFi != filst.end()) { if (curFi->isDir()){ dirNames.push_back(curFi->filePath()); } else if (curFi->isFile()){ fileNames.push_back(curFi->absoluteFilePath()); } curFi++; } } } for (QVector<QString>::Iterator ite = dirNames.begin(); ite != dirNames.end(); ite++) { QDir dirSrc(source); QDir dirDest(destination); ite->replace(dirSrc.absolutePath(), dirDest.absolutePath()); QDir dirTmp(*ite); if (!dirTmp.exists() && !dirTmp.mkpath(*ite)){ return false; } } for (QVector<QString>::Iterator ite = fileNames.begin(); ite != fileNames.end(); ite++) { QDir dirSrc(source); QDir dirDest(destination); QString srcPath = *ite; QString tar = ite->replace(dirSrc.absolutePath(), dirDest.absolutePath()); QFile file(tar); if (file.exists()){ if (isCover){ if (!file.remove()){ return false; } } else{ continue; } } if (!QFile::copy(srcPath, tar)){ return false; } } return true; }