300TC 机载系统 完整功能,(1)采集影像(2)采集和解析惯导数据(3)惯导磁场校正
This commit is contained in:
199
Source_Files/fileoperation.cpp
Normal file
199
Source_Files/fileoperation.cpp
Normal file
@ -0,0 +1,199 @@
|
||||
#include "Header_Files/fileoperation.h"
|
||||
|
||||
FileOperation::FileOperation()
|
||||
{
|
||||
m_copyFileStatus = 0;
|
||||
}
|
||||
|
||||
bool FileOperation::copyFileToPath(QString sourceDir ,QString toDir, bool coverFileIfExist)
|
||||
{
|
||||
toDir.replace("\\","/");
|
||||
if (sourceDir == toDir){
|
||||
return true;
|
||||
}
|
||||
if (!QFile::exists(sourceDir)){
|
||||
return false;
|
||||
}
|
||||
QDir *createfile = new QDir;
|
||||
bool exist = createfile->exists(toDir);
|
||||
if (exist){
|
||||
if(coverFileIfExist){
|
||||
createfile->remove(toDir);
|
||||
}
|
||||
}//end if
|
||||
|
||||
if(!QFile::copy(sourceDir, toDir))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
QStringList FileOperation::getSubfolders(QDir parentFolder)
|
||||
{
|
||||
QStringList entryList= parentFolder.entryList();
|
||||
QStringList result;
|
||||
|
||||
//
|
||||
for(int i=0;i<entryList.size();i++)
|
||||
{
|
||||
auto element=entryList.at(i).toLocal8Bit().constData();
|
||||
QString tmp=entryList.at(i);
|
||||
|
||||
if(!strcmp(element,".") || !strcmp(element,".."))//QString::compare()
|
||||
{
|
||||
//std::cout<<"11111111111111111111111111111"<<std::endl;
|
||||
continue;
|
||||
}
|
||||
|
||||
result.append(entryList.at(i));
|
||||
//std::cout<<""<<entryList.at(i).toLocal8Bit().constData()<<std::endl;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
QString FileOperation::getFlashDrivePath()
|
||||
{
|
||||
//获取u盘路径
|
||||
QDir flashDrivePath("/media");
|
||||
QStringList subfolders=getSubfolders(flashDrivePath);
|
||||
flashDrivePath.cd(subfolders.at(0));
|
||||
|
||||
QStringList result=getSubfolders(flashDrivePath);
|
||||
|
||||
|
||||
if(result.isEmpty())
|
||||
{
|
||||
//std::cout<<"FileOperation::getFlashDrivePath--------------------------: 请插入u盘!"<<std::endl;
|
||||
return "";
|
||||
}
|
||||
|
||||
if(!flashDrivePath.cd(result.at(0)))
|
||||
{
|
||||
std::cout<<"进入u盘失败!"<<std::endl;
|
||||
return "";
|
||||
}
|
||||
|
||||
if(!flashDrivePath.exists("ximeaImageData"))
|
||||
{
|
||||
flashDrivePath.mkdir("ximeaImageData");
|
||||
}
|
||||
flashDrivePath.cd("ximeaImageData");
|
||||
|
||||
QString destinationFolder=flashDrivePath.absolutePath();
|
||||
std::cout<<"进入u盘成功:"<<destinationFolder.toStdString()<<std::endl;
|
||||
|
||||
return destinationFolder;
|
||||
}
|
||||
|
||||
QDir FileOperation::getSourcePath()
|
||||
{
|
||||
//获取源数据文件夹
|
||||
|
||||
QDir sourcePath("/media/nvme");
|
||||
|
||||
// QString homePath=QDir::homePath();
|
||||
// QDir sourcePath(homePath);
|
||||
// bool re=sourcePath.exists("ximeaImageData");
|
||||
// if(!re)
|
||||
// {
|
||||
// std::cout<<"No data!"<<std::endl;
|
||||
// sourcePath.mkdir("ximeaImageData");
|
||||
// }
|
||||
//
|
||||
// sourcePath.cd("ximeaImageData");
|
||||
|
||||
return sourcePath;
|
||||
}
|
||||
|
||||
void FileOperation::copyFile()
|
||||
{
|
||||
QString destinationFolder= getFlashDrivePath();
|
||||
QDir sourcePath= getSourcePath();
|
||||
|
||||
if(destinationFolder.isEmpty())
|
||||
{
|
||||
m_copyFileStatus = 3;
|
||||
emit copyFileStatus(m_copyFileStatus);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
QStringList timesFilter,sbgFilter,hdrFilter,datFilter;
|
||||
timesFilter<<"*.times";
|
||||
sbgFilter<<"*.sbg";
|
||||
hdrFilter<<"*.hdr";
|
||||
datFilter<<"*.dat";
|
||||
|
||||
QStringList timesEntryList=sourcePath.entryList(timesFilter,QDir::Files);
|
||||
QStringList sbgEntryList=sourcePath.entryList(sbgFilter,QDir::Files);
|
||||
QStringList hdrEntryList=sourcePath.entryList(hdrFilter,QDir::Files);
|
||||
QStringList datEntryList=sourcePath.entryList(datFilter,QDir::Files);
|
||||
|
||||
if(timesEntryList.isEmpty() && sbgEntryList.isEmpty() && hdrEntryList.isEmpty() && datEntryList.isEmpty())
|
||||
{
|
||||
m_copyFileStatus = 2;
|
||||
emit copyFileStatus(m_copyFileStatus);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
m_copyFileStatus = 1;
|
||||
emit copyFileStatus(m_copyFileStatus);
|
||||
|
||||
|
||||
//copy times file
|
||||
std::cout<<"copy times file"<<std::endl;
|
||||
for(int i=0;i<timesEntryList.size();i++)
|
||||
{
|
||||
// std::cout<<"------"<<timesEntryList.at(i).toLocal8Bit().constData()<<std::endl;
|
||||
// std::cout<<"------"<<timesEntryList.at(i).<<std::endl;
|
||||
|
||||
QString source=sourcePath.absolutePath()+"/"+timesEntryList.at(i);
|
||||
QString destination=destinationFolder+"/"+timesEntryList.at(i);
|
||||
|
||||
copyFileToPath(source,destination,false);
|
||||
}
|
||||
|
||||
//copy sbg file
|
||||
std::cout<<"copy sbg file"<<std::endl;
|
||||
for(int i=0;i<sbgEntryList.size();i++)
|
||||
{
|
||||
QString source=sourcePath.absolutePath()+"/"+sbgEntryList.at(i);
|
||||
QString destination=destinationFolder+"/"+sbgEntryList.at(i);
|
||||
|
||||
copyFileToPath(source,destination,false);
|
||||
}
|
||||
|
||||
//copy hdr file
|
||||
std::cout<<"copy hdr file"<<std::endl;
|
||||
for(int i=0;i<hdrEntryList.size();i++)
|
||||
{
|
||||
QString source=sourcePath.absolutePath()+"/"+hdrEntryList.at(i);
|
||||
QString destination=destinationFolder+"/"+hdrEntryList.at(i);
|
||||
|
||||
copyFileToPath(source,destination,false);
|
||||
}
|
||||
|
||||
//copy image file
|
||||
std::cout<<"copy image file"<<std::endl;
|
||||
for(int i=0;i<datEntryList.size();i++)
|
||||
{
|
||||
QString source=sourcePath.absolutePath()+"/"+datEntryList.at(i);
|
||||
QString destination=destinationFolder+"/"+datEntryList.at(i);
|
||||
|
||||
copyFileToPath(source,destination,false);
|
||||
}
|
||||
|
||||
m_copyFileStatus = 0;
|
||||
emit copyFileStatus(m_copyFileStatus);
|
||||
}
|
||||
|
||||
void FileOperation::deleteFile()
|
||||
{
|
||||
QDir sourcePath= getSourcePath();
|
||||
|
||||
sourcePath.removeRecursively();
|
||||
}
|
Reference in New Issue
Block a user