File indexing completed on 2024-11-10 05:11:09
0001 /* 0002 * Copyright 2018 by Aditya Mehra <aix.m@outlook.com> 0003 * 0004 * Licensed under the Apache License, Version 2.0 (the "License"); 0005 * you may not use this file except in compliance with the License. 0006 * You may obtain a copy of the License at 0007 * 0008 * http://www.apache.org/licenses/LICENSE-2.0 0009 * 0010 * Unless required by applicable law or agreed to in writing, software 0011 * distributed under the License is distributed on an "AS IS" BASIS, 0012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 0013 * See the License for the specific language governing permissions and 0014 * limitations under the License. 0015 * 0016 */ 0017 0018 #include "filereader.h" 0019 #include <QFile> 0020 #include <QDir> 0021 #include <QDebug> 0022 #include <QJsonArray> 0023 #include <QJsonObject> 0024 #include <QDirIterator> 0025 0026 FileReader::FileReader(QObject *parent) 0027 : QObject(parent) 0028 { 0029 } 0030 0031 QByteArray FileReader::read(const QString &filename) 0032 { 0033 QFile file(filename); 0034 if (!file.open(QIODevice::ReadOnly)) 0035 return QByteArray(); 0036 0037 return file.readAll(); 0038 } 0039 0040 bool FileReader::file_exists_local(const QString &filename) { 0041 return QFile(filename).exists(); 0042 } 0043 0044 QStringList FileReader::checkForMeta(const QString &rootDir, const QString &findFile){ 0045 QStringList dirList; 0046 QStringList containsMeta; 0047 QDirIterator iter(rootDir); 0048 while(iter.hasNext()){ 0049 dirList.append(iter.next()); 0050 } 0051 int count = dirList.count(); 0052 for(int i=0; i<count; i++){ 0053 bool metaExist = file_exists_local(dirList[i] + QStringLiteral("/") + findFile); 0054 if(metaExist){ 0055 containsMeta.append(dirList[i]); 0056 } 0057 } 0058 return containsMeta; 0059 }