-
Notifications
You must be signed in to change notification settings - Fork 5
/
SubFileSystem.cpp
83 lines (67 loc) · 2.08 KB
/
SubFileSystem.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 "SubFileSystem.hpp"
#include "File.hpp"
#include "InputStream.hpp"
#include "OutputStream.hpp"
#include "Exception.hpp"
BEGIN_INANITY
SubFileSystem::SubFileSystem(ptr<FileSystem> fileSystem, const String& userPath)
: fileSystem(fileSystem), path(userPath)
{
if(path.length() && path[path.length() - 1] != '/')
path += "/";
}
String SubFileSystem::GetName(const String& fileName) const
{
if(fileName.empty() || fileName[0] != '/')
THROW("File name should begin with slash");
return path + fileName.substr(1);
}
ptr<File> SubFileSystem::LoadFile(const String& fileName)
{
return fileSystem->LoadFile(GetName(fileName));
}
ptr<File> SubFileSystem::TryLoadFile(const String& fileName)
{
return fileSystem->TryLoadFile(GetName(fileName));
}
ptr<InputStream> SubFileSystem::LoadStream(const String& fileName)
{
return fileSystem->LoadStream(GetName(fileName));
}
void SubFileSystem::SaveFile(ptr<File> file, const String& fileName)
{
fileSystem->SaveFile(file, GetName(fileName));
}
ptr<OutputStream> SubFileSystem::SaveStream(const String& fileName)
{
return fileSystem->SaveStream(GetName(fileName));
}
time_t SubFileSystem::GetFileMTime(const String& fileName)
{
return fileSystem->GetFileMTime(GetName(fileName));
}
void SubFileSystem::GetDirectoryEntries(const String& directoryName, std::vector<String>& entries) const
{
fileSystem->GetDirectoryEntries(GetName(directoryName), entries);
}
void SubFileSystem::GetAllDirectoryEntries(const String& directoryName, std::vector<String>& entries) const
{
fileSystem->GetAllDirectoryEntries(GetName(directoryName), entries);
}
void SubFileSystem::MakeDirectory(const String& directoryName)
{
fileSystem->MakeDirectory(GetName(directoryName));
}
void SubFileSystem::DeleteEntry(const String& entryName)
{
fileSystem->DeleteEntry(GetName(entryName));
}
FileSystem::EntryType SubFileSystem::GetEntryType(const String& entryName) const
{
return fileSystem->GetEntryType(GetName(entryName));
}
ptr<FileSystem> SubFileSystem::GetSubFileSystem(const String& folderName)
{
return NEW(SubFileSystem(fileSystem, GetName(folderName)));
}
END_INANITY