1 /*
2  Copyright (C) 2010-2014 Kristian Duske
3 
4  This file is part of TrenchBroom.
5 
6  TrenchBroom is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  TrenchBroom is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with TrenchBroom. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef TrenchBroom_DiskFileSystem
21 #define TrenchBroom_DiskFileSystem
22 
23 #include "IO/MappedFile.h"
24 #include "IO/FileSystem.h"
25 #include "IO/Path.h"
26 
27 namespace TrenchBroom {
28     namespace IO {
29         namespace Disk {
30             bool isCaseSensitive();
31 
32             Path fixPath(const Path& path);
33 
34             bool directoryExists(const Path& path);
35             bool fileExists(const Path& path);
36 
37             Path::List getDirectoryContents(const Path& path);
38             MappedFile::Ptr openFile(const Path& path);
39             Path getCurrentWorkingDir();
40 
41             IO::Path resolvePath(const Path::List& searchPaths, const Path& path);
42         }
43 
44         class DiskFileSystem : public FileSystem {
45         protected:
46             Path m_root;
47         public:
48             DiskFileSystem(const Path& root, const bool ensureExists = true);
49 
50             const Path& getPath() const;
51             const Path makeAbsolute(const Path& relPath) const;
52         protected:
53             Path fixPath(const Path& path) const;
54             Path fixCase(const Path& path) const;
55         private:
56             bool doDirectoryExists(const Path& path) const;
57             bool doFileExists(const Path& path) const;
58 
59             Path::List doGetDirectoryContents(const Path& path) const;
60             const MappedFile::Ptr doOpenFile(const Path& path) const;
61         };
62 
63         class WritableDiskFileSystem : public DiskFileSystem, public WritableFileSystem {
64         public:
65             WritableDiskFileSystem(const Path& root, const bool create);
66         private:
67             void doCreateDirectory(const Path& path);
68             void doDeleteFile(const Path& path);
69             void doMoveFile(const Path& sourcePath, const Path& destPath, const bool overwrite);
70         };
71     }
72 }
73 
74 #endif /* defined(TrenchBroom_DiskFileSystem) */
75