#include "commonutils.h" #include "LogIO.h" #include CCommonUtils::CCommonUtils() { } CCommonUtils::~CCommonUtils() { } bool CCommonUtils::getAllSlf(QString prjname, QVector &vecSlfList, QVector &vecWellList) { //Logdata QString folderPath; folderPath = GetLogdataPath(); folderPath = folderPath + prjname; folderPath = folderPath + "/"; //------------------- QStringList listFolders; QFileInfo mfi(folderPath); if(!mfi.isDir()) { //井文件 *.wwl if(!mfi.isFile()) { return false; } //listFiles.append(folderPath); } else { //井目录 //取当前当前目录内容 QDir dir(folderPath); dir.setFilter(QDir::Dirs |QDir::NoDotAndDotDot |QDir::Files | QDir::NoSymLinks); QFileInfoList list = dir.entryInfoList(); int file_count = list.count(); if(file_count <= 0)//判断目录是否为空,空目录返回 { return false; } //取当前目录内容,符合后缀文件 QStringList string_list; for(int i=0; iOpen(filename.toStdString().c_str(),CSlfIO::modeRead)) { delete logio; QString aa=filename+"文件打开失败,请检查!"; //qDebug() << aa; //AppendConsole(pai::log::PAI_ERROR,aa); continue; } // QString wellname=""; Slf_FILE_MESSAGE mssage; logio->GetFileMessage(mssage); wellname=mssage.WellName; wellname=wellname.toUpper(); if (wellname.isEmpty()||wellname.length()>64||wellname.indexOf('&')>-1) { //辨别井名是否有效,无效则采用文件名 QFileInfo fileInfo(filename); QString strWellName = fileInfo.completeBaseName(); strWellName=strWellName.toUpper(); // wellname=strWellName.toStdString().c_str(); int len=strlen(strWellName.toStdString().c_str()); if(len>sizeof(mssage.WellName)) len=sizeof(mssage.WellName); strncpy(mssage.WellName,strWellName.toStdString().c_str(),len); mssage.WellName[len]=0; logio->SetFileMessage(mssage); } wellname=wellname.toUpper(); //查找是否已经存在该井和井次 if(wellNames.contains(wellname)) { delete logio; continue; } wellNames.append(wellname); // vecWellList.append(wellname); //加载*.slf QStringList slffiles; QString pathTmp=GetLogdataPath(); pathTmp+=prjname+"/#"+wellname; chakan(pathTmp, slffiles, "*.slf"); foreach(QString slfFile1, slffiles ) { CLogIO * logioSLf=new CLogIO(); if(!logioSLf->Open(slfFile1.toStdString().c_str(),CSlfIO::modeRead)) { delete logioSLf; //QString aa=fileFull+"文件打开失败,请检查!"; //qDebug() << aa; //AppendConsole(pai::log::PAI_ERROR,aa); continue; } else { Slf_FILE_MESSAGE mssageSlf; logioSLf->GetFileMessage(mssageSlf); if(wellname != QString(mssageSlf.WellName)) { delete logioSLf; continue; } QString wellnameSLf=mssageSlf.Item; //if (wellnameSLf.isEmpty()||wellnameSLf.length()>64||wellnameSLf.indexOf('&')>-1) { QFileInfo fileinfo; fileinfo = QFileInfo(slfFile1); wellnameSLf = fileinfo.completeBaseName(); } // if(wellnameSLf != wellname) // { // //井次名称不一致 // //qDebug() << "井次名称不一致"; // delete logioSLf; // continue; // } vecSlfList.append(slfFile1); delete logioSLf; break; } } } return true; } QString CCommonUtils::GetLogdataPath() { // 1.获取当前运行程序的目录路径 QString applicationDirPath = QCoreApplication::applicationDirPath(); //获取上级目录 int index = applicationDirPath.lastIndexOf("/"); int index1 = applicationDirPath.lastIndexOf("\\"); if(index1 > index) { index = index1; } // QString strImagePath; strImagePath = applicationDirPath.mid(0,index+1) + "Logdata/"; // QDir dir(strImagePath); if( !dir.exists( strImagePath ) ) { dir.mkdir(strImagePath); } return strImagePath; } int CCommonUtils::chakan(QString path, QStringList &wellfs, QString strSuffix) { QDir dir(path); QFileInfoList fileInfos = dir.entryInfoList(QStringList() << strSuffix, QDir::Files); foreach(QFileInfo fileInfo, fileInfos) { wellfs.append(fileInfo.absoluteFilePath()); } return 1; }