2025-06-19 15:37:39 +08:00
|
|
|
#include "LocalFile.h"
|
2025-06-15 14:31:54 +08:00
|
|
|
|
2025-06-15 23:13:30 +08:00
|
|
|
#include <QDateTime>
|
|
|
|
|
#include <QDir>
|
|
|
|
|
#include <QFileInfo>
|
|
|
|
|
|
2025-06-19 15:37:39 +08:00
|
|
|
LocalFile::LocalFile(QObject* parent) : DirFileHelper(parent)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-15 14:31:54 +08:00
|
|
|
bool LocalFile::GetHome()
|
|
|
|
|
{
|
2025-06-15 23:13:30 +08:00
|
|
|
auto home = Util::GetUserHome();
|
2025-06-19 15:37:39 +08:00
|
|
|
emit sigHome(home);
|
2025-06-15 23:13:30 +08:00
|
|
|
return true;
|
2025-06-15 14:31:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool LocalFile::GetDirFile(const QString& dir)
|
|
|
|
|
{
|
2025-06-15 23:13:30 +08:00
|
|
|
DirFileInfoVec vec;
|
|
|
|
|
if (!GetDirFile(dir, vec)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2025-06-19 15:37:39 +08:00
|
|
|
emit sigDirFile(vec);
|
2025-06-15 23:13:30 +08:00
|
|
|
return true;
|
2025-06-15 14:31:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool LocalFile::GetDirFile(const QString& dir, DirFileInfoVec& vec)
|
|
|
|
|
{
|
2025-06-15 23:13:30 +08:00
|
|
|
vec.vec.clear();
|
2025-06-15 23:31:27 +08:00
|
|
|
vec.root = dir;
|
2025-06-15 23:13:30 +08:00
|
|
|
|
|
|
|
|
QDir qdir(dir);
|
|
|
|
|
if (!qdir.exists()) {
|
|
|
|
|
err_ = tr("Path does not exist");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!qdir.isReadable()) {
|
|
|
|
|
err_ = tr("Directory is not readable");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const auto entries = qdir.entryInfoList(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot);
|
|
|
|
|
|
|
|
|
|
for (const auto& entry : entries) {
|
|
|
|
|
DirFileInfo info;
|
|
|
|
|
info.fullPath = entry.absoluteFilePath();
|
|
|
|
|
info.name = entry.fileName();
|
2025-07-10 18:44:09 +08:00
|
|
|
info.permission = entry.permissions();
|
2025-06-15 23:13:30 +08:00
|
|
|
|
|
|
|
|
if (entry.isDir()) {
|
|
|
|
|
info.type = Dir;
|
|
|
|
|
info.size = 0;
|
|
|
|
|
} else if (entry.isFile()) {
|
|
|
|
|
info.type = File;
|
|
|
|
|
info.size = entry.size();
|
|
|
|
|
} else {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
info.lastModified = entry.lastModified().toMSecsSinceEpoch();
|
|
|
|
|
vec.vec.push_back(info);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
2025-06-15 14:31:54 +08:00
|
|
|
}
|