You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
91 lines
2.6 KiB
C++
91 lines
2.6 KiB
C++
#ifndef _SOLAR_CELL_HELPER_H__
|
|
#define _SOLAR_CELL_HELPER_H__
|
|
|
|
#include <QDebug>
|
|
#include <windows.h>
|
|
#include <QImage>
|
|
#include <QFileInfo>
|
|
#include <QFileInfoList>
|
|
#include <QDir>
|
|
|
|
|
|
namespace solarCell
|
|
{
|
|
class SolarCellHelper
|
|
{
|
|
public:
|
|
static inline qint64 GetDiskFreeSpace(QString strDriver)
|
|
{
|
|
LPCWSTR lpcwstrDriver = (LPCWSTR)strDriver.utf16();
|
|
|
|
ULARGE_INTEGER liFreeBytesAvailable, liTotalBytes, liTotalFreeBytes;
|
|
|
|
if (!GetDiskFreeSpaceEx(lpcwstrDriver, &liFreeBytesAvailable, &liTotalBytes, &liTotalFreeBytes))
|
|
{
|
|
qWarning() << "ERROR: Call to GetDiskFreeSpaceEx() failed.";
|
|
return 0;
|
|
}
|
|
|
|
//返回MB
|
|
return (quint64)liTotalFreeBytes.QuadPart / 1024 / 1024;
|
|
}
|
|
static inline void GetFileInfoList(QFileInfoList& fileInfoList, QString strFolder)
|
|
{
|
|
QDir qDir(strFolder);
|
|
QFileInfoList filesListTmp = qDir.entryInfoList(QDir::Files | QDir::NoDotAndDotDot, QDir::Time);
|
|
fileInfoList += filesListTmp;
|
|
|
|
QStringList dirList = qDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
|
|
for (int i = 0; i < dirList.size(); i++)
|
|
{
|
|
GetFileInfoList(fileInfoList, strFolder + "/" + dirList.at(i));
|
|
}
|
|
}
|
|
|
|
static inline void GetDirInfoList_child(QFileInfoList& dirInfoList, QString strFolder)
|
|
{
|
|
QDir qDir(strFolder);
|
|
QFileInfoList filesListTmp = qDir.entryInfoList(QDir::Dirs, QDir::Time);
|
|
dirInfoList += filesListTmp;
|
|
|
|
QStringList dirList = qDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
|
|
for (int i = 0; i < dirList.size(); i++)
|
|
{
|
|
GetDirInfoList_child(dirInfoList, strFolder + "/" + dirList.at(i));
|
|
}
|
|
}
|
|
|
|
static inline void GetDirInfoList_root(QFileInfoList& dirInfoList, QString strFolder)
|
|
{
|
|
QDir qDir(strFolder);
|
|
QFileInfoList filesListTmp = qDir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Time);
|
|
dirInfoList += filesListTmp;
|
|
}
|
|
|
|
static inline bool DelDiretory(const QString &dirPath)
|
|
{
|
|
if (dirPath.isEmpty())
|
|
return false;
|
|
QDir qDir(dirPath);
|
|
if (!qDir.exists())
|
|
return true;
|
|
qDir.setFilter(QDir::AllEntries | QDir::NoDotAndDotDot);
|
|
QFileInfoList qFileList = qDir.entryInfoList();
|
|
foreach(QFileInfo qFileInfo, qFileList)
|
|
{
|
|
if (qFileInfo.isFile())
|
|
qFileInfo.dir().remove(qFileInfo.fileName());
|
|
else
|
|
DelDiretory(qFileInfo.absoluteFilePath());
|
|
}
|
|
return qDir.rmpath(qDir.absolutePath());
|
|
}
|
|
|
|
|
|
};//Class SolarCellHelper
|
|
|
|
}
|
|
#endif//_SOLAR_CELL_HELPER_H__
|
|
|
|
|