This repository has been archived on 2025-06-17. You can view files and clone it, but cannot push or open issues or pull requests.
RelayFile/Information/InfoDirFile.hpp

85 lines
2.0 KiB
C++
Raw Normal View History

2025-05-06 23:21:10 +08:00
#ifndef DIRFILE_H
#define DIRFILE_H
#include <cereal/archives/binary.hpp>
#include <cereal/types/memory.hpp>
2025-05-10 21:43:25 +08:00
#include <cereal/types/vector.hpp>
2025-05-06 23:21:10 +08:00
#include <cstdint>
#include <string>
2025-05-08 12:46:49 +08:00
#include <vector>
2025-05-06 23:21:10 +08:00
#include <wx/wx.h>
enum FileType : uint32_t {
None = 0,
File,
Dir,
Link
};
struct DirFileInfo {
2025-05-12 22:07:06 +08:00
static wxString GetFileSize(uint64_t size)
{
const uint64_t KB = 1024;
const uint64_t MB = KB * 1024;
const uint64_t GB = MB * 1024;
if (size >= GB) {
return wxString::Format("%.2f GB", static_cast<double>(size) / GB);
} else if (size >= MB) {
return wxString::Format("%.2f MB", static_cast<double>(size) / MB);
} else if (size >= KB) {
return wxString::Format("%.2f KB", static_cast<double>(size) / KB);
} else {
return wxString::Format("%llu B", size);
}
}
static wxString GetStrTime(uint64_t time)
{
wxDateTime dt(static_cast<time_t>(time));
wxString dateStr = dt.Format("%Y/%m/%d %H:%M:%S");
return dateStr;
}
static wxString GetFileTypeName(FileType type)
{
switch (type) {
case None:
return _("None");
case File:
return _("File");
case Dir:
return _("Dir");
case Link:
return _("Link");
default:
return _("Unknown");
}
}
2025-05-06 23:21:10 +08:00
std::string name;
2025-05-08 12:46:49 +08:00
uint64_t size = 0;
2025-05-10 21:43:25 +08:00
FileType type = None;
std::string fullPath;
2025-05-08 12:46:49 +08:00
uint16_t permission = 0;
2025-05-10 21:43:25 +08:00
uint64_t lastModifyTime = 0;
2025-05-08 12:46:49 +08:00
DirFileInfo() = default;
2025-05-06 23:21:10 +08:00
template <class Archive> void serialize(Archive& archive)
{
2025-05-10 21:43:25 +08:00
archive(CEREAL_NVP(name), CEREAL_NVP(size), CEREAL_NVP(type), CEREAL_NVP(fullPath), CEREAL_NVP(permission),
CEREAL_NVP(lastModifyTime));
2025-05-08 12:46:49 +08:00
}
};
struct DirFileInfoVec {
std::vector<DirFileInfo> vec;
template <class Archive> void serialize(Archive& archive)
{
archive(CEREAL_NVP(vec));
2025-05-06 23:21:10 +08:00
}
};
#endif