-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
99 lines (79 loc) · 1.95 KB
/
main.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include <iostream>
#include <VFS.hpp>
#include <fstream>
using namespace std;
void PrintDirs(VFS::CVFS &vfs, const std::string &Path, const std::string &Shift = "")
{
auto node = vfs.GetNodeInfo(Path);
auto childs = vfs.List(node);
cout << Shift << "Dir: " << node->Name() << endl;
for (auto &&i : childs)
{
if(i->IsDir())
PrintDirs(vfs, Path + i->Name() + "/", Shift + " ");
else
cout << Shift << " File: " << i->Name() << " Size: " << vfs.FileSize(i) << endl;
}
}
int main()
{
VFS::CVFS vfs;
//Linux like file hierarchy.
vfs.CreateDir("/bin");
vfs.CreateDir("/boot");
vfs.CreateDir("/dev");
vfs.CreateDir("/etc");
vfs.CreateDir("/home");
vfs.CreateDir("/lib");
vfs.CreateDir("/media");
vfs.CreateDir("/mnt");
vfs.CreateDir("/opt");
vfs.CreateDir("/sbin");
vfs.CreateDir("/srv");
vfs.CreateDir("/tmp");
vfs.CreateDir("/usr");
vfs.CreateDir("/proc");
vfs.CreateDir("/tmp/Test");
//Reads the header file into the filesystem.
ifstream in("VFS.hpp", ios::in);
if(in.is_open())
{
auto fs = vfs.Open("/tmp/VFS.txt", VFS::FileMode::RW);
while (in.good())
{
char c;
in.read(&c, sizeof(c));
if(in.good())
fs->Write(&c, sizeof(c));
}
while (!fs->IsEOF())
{
cout << fs->ReadLine() << endl;
}
fs->Seek(VFS::Cursor::END, -3);
cout << fs->Read() << endl;
in.close();
vfs.Rename("/tmp/VFS.txt", "AVFS.hpp");
vfs.Move("/tmp/AVFS.hpp", "/usr");
vfs.Delete("/tmp/Test");
vfs.Copy("/usr/AVFS.hpp", "/tmp/AVFS.hpp");
vfs.Copy("tmp", "usr/tmp_copy");
}
auto fs = vfs.Open("/tmp/Test.txt", VFS::FileMode::RW);
fs->WriteLine("Hello World!");
// PrintDirs(vfs, "/");
auto strm = vfs.Serialize();
ofstream out("fs.cvfs", ios::binary);
if(out.is_open())
{
out.write(strm.data(), strm.size());
out.close();
}
VFS::CVFS vfs2;
vfs2.Deserialize(strm);
cout << "-----------ORIG-----------" << endl;
PrintDirs(vfs2, "/");
cout << "-----------Copy-----------" << endl;
PrintDirs(vfs2, "/");
return 0;
}