-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilesystem.cpp
83 lines (68 loc) · 2.08 KB
/
filesystem.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include "filesystem.h"
#include <dokanyThread.h>
#include <QDebug>
FileSystem::FileSystem(DokanyThread *dokany, QString sshRootPath) : m_dokany(dokany), root(new FileNode),
sshRootPath(sshRootPath)
{
root->fileName = "/";
root->isDirectory = true;
fileIndexTable.insert("/", root);
}
void FileSystem::createFile(QString fileName, bool isDir, quint32 fileAttr, quint64 filesize)
{
if (!fileIndexTable.contains(fileName))
{
FileNodePtr node(new FileNode);
node->size = filesize;
node->isDirectory = isDir;
node->file_attr = fileAttr;
fileIndexTable[fileName] = node;
int pos = fileName.lastIndexOf("/");
QString parentPath = fileName.left(pos + 1);
node->setFileName(fileName.remove("/"));
// qDebug() << Q_FUNC_INFO << fileName << parentPath;
if (fileIndexTable.contains(parentPath))
{
FileNodePtr &parentNode = fileIndexTable[parentPath];
parentNode->children.append(node);
}
}
else
{
FileNodePtr node = fileIndexTable[fileName];
node->size = filesize;
node->isDirectory = isDir;
node->file_attr = fileAttr;
node->setFileName(fileName.remove("\\"));
}
}
QVector<FileNodePtr> FileSystem::listFolder(QString path)
{
path = path.replace("\\", "/");
qDebug() << "listFolder " << path;
return m_dokany->getSshThread()->openDir(sshRootPath + path);
}
FileNodePtr FileSystem::find(QString fileName)
{
if (fileIndexTable.contains(fileName))
{
return fileIndexTable.value(fileName);
}
return nullptr;
}
int FileSystem::readFile(QString path, QByteArray &buffer, int offset)
{
path = path.replace("\\", "/");
return m_dokany->getSshThread()->readFile(sshRootPath + path, buffer, offset);
}
void FileNode::setFileName(QString name)
{
// locker.lock();
fileName = name;
// locker.unlock();
}
FileNode::FileNode(const FileNode &src)
{
fileName = src.fileName;
size = src.size;
}