-
Notifications
You must be signed in to change notification settings - Fork 0
/
FileSystem.cpp
95 lines (81 loc) · 1.79 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
84
85
86
87
88
89
90
91
92
93
94
95
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/*
* File: FileSystem.cpp
* Author: Krzysztof Tomczak
*
* Created on January 5, 2017, 5:19 PM
*/
#include "FileSystem.h"
FileSystem::FileSystem() : path(string(""))
{
this->root = new File;
}
FileSystem::FileSystem(string& path) : path(path)
{
mx.lock();
string rootName = "";
this->root = new File(rootName, path);
mx.unlock();
}
FileSystem::FileSystem(const FileSystem& orig) : path(orig.path)
{
}
FileSystem::~FileSystem()
{
delete root;
}
string FileSystem::ToString()
{
mx.lock();
//string result = this->path.ToString();
string result = root->ToString();
mx.unlock();
return result;
}
void FileSystem::SaveToFile(string& path)
{
mx.lock();
root->SaveToFile(path);
mx.unlock();
}
void FileSystem::LoadFromFile(string& path)
{
mx.lock();
root = new File();
root->LoadFromFile(path);
mx.unlock();
}
void FileSystem::FromString(string s)
{
mx.lock();
root->FromString(s);
mx.unlock();
}
//returns queue of events to perform on 'fs' in order to make it the same as calling FileSystem
deque<Event*> FileSystem::FindDifferences(FileSystem *f)
{
mx.lock();
deque<Event*> result = root->FindDifferences(f->root);
mx.unlock();
return result;
}
Path FileSystem::MakePathAbsolute(Path path)
{
Path p(this->path.GetPath() + "/" + path.GetPath());
return p;
}
Path FileSystem::MakePathRelative(Path path)
{
Path p(path.GetPath().replace(0, this->path.GetPath().length() + 1, ""));
return p;
}
File* FileSystem::GetFileByPath(string path)
{
mx.lock();
return root->GetFileFromPath(path);
mx.unlock();
}