file: get remote file success.
This commit is contained in:
@@ -1,16 +1,61 @@
|
||||
#include "LocalFile.h"
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
|
||||
bool LocalFile::GetHome()
|
||||
{
|
||||
return false;
|
||||
auto home = Util::GetUserHome();
|
||||
pathCall_(home);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool LocalFile::GetDirFile(const QString& dir)
|
||||
{
|
||||
return false;
|
||||
DirFileInfoVec vec;
|
||||
if (!GetDirFile(dir, vec)) {
|
||||
return false;
|
||||
}
|
||||
fileCall_(vec);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool LocalFile::GetDirFile(const QString& dir, DirFileInfoVec& vec)
|
||||
{
|
||||
return false;
|
||||
vec.vec.clear();
|
||||
|
||||
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();
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -2,7 +2,9 @@
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
#include <QMutex>
|
||||
#include <QStandardPaths>
|
||||
#include <iostream>
|
||||
#include <spdlog/fmt/bundled/color.h>
|
||||
#include <spdlog/fmt/fmt.h>
|
||||
@@ -21,6 +23,16 @@ Util::Util()
|
||||
{
|
||||
}
|
||||
|
||||
QString Util::GetUserHome()
|
||||
{
|
||||
QString homePath = QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
|
||||
if (homePath.isEmpty()) {
|
||||
qWarning() << "Failed to get user home directory";
|
||||
homePath = QDir::homePath();
|
||||
}
|
||||
return homePath;
|
||||
}
|
||||
|
||||
void Util::InitLogger(const QString& logPath, const QString& mark)
|
||||
{
|
||||
auto file_sink = std::make_shared<spdlog::sinks::rotating_file_sink_mt>(logPath.toStdString(), 1024 * 1024 * 50, 3);
|
||||
|
||||
@@ -11,12 +11,13 @@ public:
|
||||
Util();
|
||||
|
||||
public:
|
||||
static QString GetUserHome();
|
||||
static void InitLogger(const QString& logPath, const QString& mark);
|
||||
static void ConsoleMsgHander(QtMsgType type, const QMessageLogContext& context, const QString& msg);
|
||||
};
|
||||
|
||||
class DirFileHelper
|
||||
{
|
||||
class DirFileHelper : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
DirFileHelper() = default;
|
||||
virtual ~DirFileHelper() = default;
|
||||
|
||||
Reference in New Issue
Block a user