82 lines
2.3 KiB
C
82 lines
2.3 KiB
C
|
|
#ifndef ASIDEFILECLASS_H
|
||
|
|
#define ASIDEFILECLASS_H
|
||
|
|
#include <CCJSONObject.h>
|
||
|
|
#include <CCString.h>
|
||
|
|
|
||
|
|
#include "CCFile.h"
|
||
|
|
#include "CCList.h"
|
||
|
|
|
||
|
|
|
||
|
|
class AsideFileClass {
|
||
|
|
inline static CCMap<CTL::String,CCList<AsideFileClass>> AsideFileList;
|
||
|
|
inline static CCMutex _Mutex;
|
||
|
|
public:
|
||
|
|
static void AddData(const AsideFileClass data) {
|
||
|
|
CTL::AutoLock lock(_Mutex,[&]() {
|
||
|
|
AsideFileList[data.DirPath].emplace_back(data);
|
||
|
|
});
|
||
|
|
}
|
||
|
|
static void UpData(const CTL::String &data) {
|
||
|
|
const CCVar A = GetList(data);
|
||
|
|
CTL::AutoLock lock(_Mutex,[&]() {
|
||
|
|
AsideFileList[data] = A;
|
||
|
|
});
|
||
|
|
}
|
||
|
|
static void DeleteData(const AsideFileClass data) {
|
||
|
|
CTL::AutoLock lock(_Mutex,[&]() {
|
||
|
|
const CCFile file(data.Path);
|
||
|
|
if (bool F = file.Delete()) {
|
||
|
|
const CCVar A = GetList(data.DirPath);
|
||
|
|
AsideFileList[data.DirPath] = A;
|
||
|
|
}
|
||
|
|
});
|
||
|
|
}
|
||
|
|
static CCVector<JSON> GetData(const CTL::String& DirPath) {
|
||
|
|
CCVar List = AsideFileList[DirPath];
|
||
|
|
if (List.empty()) {
|
||
|
|
UpData(DirPath);
|
||
|
|
List = AsideFileList[DirPath];
|
||
|
|
}
|
||
|
|
CCVector<JSON> ListB;
|
||
|
|
for (CCVar & i : List) {
|
||
|
|
JSON json = i.GetJson();
|
||
|
|
ListB.emplace_back(json);
|
||
|
|
}
|
||
|
|
return ListB;
|
||
|
|
}
|
||
|
|
private:
|
||
|
|
static CCList<AsideFileClass> GetList(const CTL::String& DirPath) {
|
||
|
|
CCList<AsideFileClass> ListA;
|
||
|
|
const CCVar L = CCFile::GetDirectoryContents(DirPath);
|
||
|
|
for (const CCVar& List = L; const auto &[Name, Size, IsDirectory, LastWriteTime] : List) {
|
||
|
|
AsideFileClass data;
|
||
|
|
data.name = Name;
|
||
|
|
data.type = IsDirectory ? 1 : 0;
|
||
|
|
if (data.type != 1) {
|
||
|
|
data.size = Size;
|
||
|
|
}
|
||
|
|
data.DirPath = DirPath;
|
||
|
|
ListA.emplace_back(data);
|
||
|
|
}
|
||
|
|
return ListA;
|
||
|
|
}
|
||
|
|
public:
|
||
|
|
CTL::String name;
|
||
|
|
CTL::String Path;
|
||
|
|
CTL::String DirPath;
|
||
|
|
int size = 0;
|
||
|
|
int type = 0;
|
||
|
|
//-----------------------------------------------------------------------------------
|
||
|
|
JSON GetJson() {
|
||
|
|
JSON json;
|
||
|
|
json["name"] = name;
|
||
|
|
json["size"] = size;
|
||
|
|
json["type"] = type;
|
||
|
|
json["DirPath"] = DirPath;
|
||
|
|
json["Path"] = Path;
|
||
|
|
return json;
|
||
|
|
}
|
||
|
|
};
|
||
|
|
|
||
|
|
#endif
|