-
Notifications
You must be signed in to change notification settings - Fork 5
/
FileSystem.cpp
115 lines (98 loc) · 3.07 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include "FileSystem.hpp"
#include "File.hpp"
#include "FileInputStream.hpp"
#include "SubFileSystem.hpp"
#include "OutputStream.hpp"
#include "Exception.hpp"
BEGIN_INANITY
ptr<File> FileSystem::LoadFile(const String& fileName)
{
ptr<File> file = TryLoadFile(fileName);
if(file)
return file;
THROW("Can't load file " + fileName);
}
ptr<File> FileSystem::TryLoadFile(const String& fileName)
{
try
{
return LoadFile(fileName);
}
catch(Exception* exception)
{
MakePointer(exception);
return 0;
}
}
ptr<Storage> FileSystem::LoadStorage(const String& fileName)
{
return LoadFile(fileName);
}
ptr<InputStream> FileSystem::LoadStream(const String& fileName)
{
try
{
return NEW(FileInputStream(LoadFile(fileName)));
}
catch(Exception* exception)
{
THROW_SECONDARY("Can't load file " + fileName + " as stream", exception);
}
}
void FileSystem::SaveFile(ptr<File> file, const String& fileName)
{
THROW("Saving files in this filesystem is not supported");
}
ptr<OutputStream> FileSystem::SaveStream(const String& fileName)
{
THROW("Saving files as stream in this filesystem is not supported");
}
time_t FileSystem::GetFileMTime(const String& fileName)
{
THROW("Getting mtime in this filesystem is not supported");
}
void FileSystem::GetFileNames(std::vector<String>& fileNames) const
{
THROW("Getting file names in this filesystem is not supported");
}
void FileSystem::GetDirectoryEntries(const String& directoryName, std::vector<String>& entries) const
{
THROW("Getting directory entries in this filesystem is not supported");
}
void FileSystem::GetAllDirectoryEntries(const String& directoryName, std::vector<String>& entries) const
{
// получить (нерекурсивно) файлы и каталоги в заданном каталоге
size_t size1 = entries.size();
GetDirectoryEntries(directoryName, entries);
size_t size2 = entries.size();
// перебрать полученные файлы и каталоги
for(size_t i = size1; i < size2; ++i)
{
// получить файл
String& entry = entries[i];
// добавить к имени имя текущего каталога, чтобы сделать абсолютные имена
entry = directoryName + entry;
// если это каталог
if(entry.length() && entry[entry.length() - 1] == '/')
// рекурсивно получить файлы и каталоги в нём
// копия имени делается, так как ссылка может стать недействительной
GetAllDirectoryEntries(String(entry), entries);
}
}
void FileSystem::MakeDirectory(const String& directoryName)
{
THROW("Making directory in this filesystem is not supported");
}
void FileSystem::DeleteEntry(const String& entryName)
{
THROW("Removing entry in this filesystem is not supported");
}
FileSystem::EntryType FileSystem::GetEntryType(const String& entryName) const
{
THROW("Getting entry type in this filesystem is not supported");
}
ptr<FileSystem> FileSystem::GetSubFileSystem(const String& folderName)
{
return NEW(SubFileSystem(this, folderName));
}
END_INANITY