Source/Gorgon/Filesystem.h

Tue, 06 Jul 2021 10:22:49 +0300

author
cemkalyoncu
date
Tue, 06 Jul 2021 10:22:49 +0300
branch
4.x-dev
changeset 1701
b168349a931d
parent 1607
31c7f370894e
permissions
-rw-r--r--

* Image/Bitmap rotate

764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
1 ///@file Filesystem.h contains filesystem functions.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
2
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
3 #pragma once
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
4
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
5 #include <string>
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
6 #include <stdexcept>
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
7 #include <vector>
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
8
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
9 namespace Gorgon {
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
10
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
11 /// Contains filesystem functions. All file related functions in Gorgon
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
12 /// uses forward slash as directory separator. This includes return values
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
13 /// from these functions as well.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
14 /// @warning This is a rudimentary filesystem module. Its not meant
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
15 /// to be used in serious filesystem tasks. Most functions will not provide
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
16 /// any choices related to hard/symbolic links. Additionally, Copy, Delete
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
17 /// functions are fully blocking without any reporting facilities.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
18 namespace Filesystem {
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
19
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
20 /// This object is thrown from functions that return
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
21 /// information rather than status.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
22 class PathNotFoundError : public std::runtime_error {
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
23 public:
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
24 ///
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
25 /// Default constructor
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
26 PathNotFoundError() : std::runtime_error("File not found") { }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
27
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
28 ///
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
29 /// Constructor that sets error text
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
30 PathNotFoundError(const std::string &what) : std::runtime_error(what) { }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
31 };
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
32
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
33 /// This class represents filesystem entry points (roots, drives). On Linux like systems, the
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
34 /// only entry point is '/', however, user home, root and removable devices are also listed.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
35 /// On Windows all drives as listed. @see EntryPoints
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
36 class EntryPoint {
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
37 public:
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
38
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
39 ///
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
40 /// Default constructor
1188
ba9b052fccd3 * Linux: filename pattern matching
cemkalyoncu
parents: 922
diff changeset
41 EntryPoint() { }
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
42
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
43 /// The path of the entry point
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
44 std::string Path;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
45
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
46 /// Whether the entry point is readable. Currently all entry points are readable
1188
ba9b052fccd3 * Linux: filename pattern matching
cemkalyoncu
parents: 922
diff changeset
47 bool Readable = false;
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
48
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
49 /// Whether the entry point is writable. Notice that even an entry point is writable
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
50 /// it doesn't mean that the immediate path of the entry point is writable. It is
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
51 /// possible that the user has no write access to the root of the entry point. If false
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
52 /// this denotes the entry point is fully read-only (like a CDROM)
1188
ba9b052fccd3 * Linux: filename pattern matching
cemkalyoncu
parents: 922
diff changeset
53 bool Writable = false;
ba9b052fccd3 * Linux: filename pattern matching
cemkalyoncu
parents: 922
diff changeset
54
ba9b052fccd3 * Linux: filename pattern matching
cemkalyoncu
parents: 922
diff changeset
55 /// Whether the device is removable.
ba9b052fccd3 * Linux: filename pattern matching
cemkalyoncu
parents: 922
diff changeset
56 bool Removable = false;
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
57
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
58 /// Name or label of the entry point.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
59 std::string Name;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
60 };
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
61
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
62
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
63 /// Initializes the filesystem module. Gorgon system requires every module
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
64 /// to have initialization function even if they are not used. Currently
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
65 /// used for following tasks:
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
66 /// * Set startup directory
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
67 void Initialize();
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
68
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
69
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
70 /// Creates a new directory. This function works recursively to
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
71 /// create any missing parent directories as well. If directory
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
72 /// exists, this function returns true.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
73 /// @param path is the path of the directory to be created. Should contain
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
74 /// forward slash as directory separator.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
75 /// @return true if the directory is ready to be used, false
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
76 /// otherwise
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
77 bool CreateDirectory(const std::string &path);
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
78
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
79 /// Checks whether the given path is a directory.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
80 /// @param path is the directory to be checked. Should contain
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
81 /// forward slash as directory separator.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
82 /// @return true if the given path is present and a directory
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
83 bool IsDirectory(const std::string &path);
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
84
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
85 /// Checks whether the given path is a file
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
86 /// @param path is the file to be checked. Should contain
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
87 /// forward slash as directory separator.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
88 /// @return true if the given path is present and a file
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
89 bool IsFile(const std::string &path);
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
90
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
91 /// Checks whether the given path exists
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
92 /// @param path is the file to be checked. Should contain
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
93 /// forward slash as directory separator.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
94 /// @return true if the given path is present
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
95 bool IsExists(const std::string &path);
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
96
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
97 /// Checks whether the given path is writable. This does not check if
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
98 /// the file is locked or not. Also, even if the file is not marked
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
99 /// as writable, a write operation might succeed.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
100 /// @param path is the directory or file to be checked. Should contain
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
101 /// forward slash as directory separator.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
102 /// @return true if the given file/path exists and is writable.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
103 bool IsWritable(const std::string &path);
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
104
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
105 /// Checks whether the given path is hidden
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
106 /// @param path is the directory to be checked. Should contain
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
107 /// forward slash as directory separator.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
108 /// @return true if the path should be hidden.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
109 bool IsHidden(const std::string &path);
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
110
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
111 /// Canonicalizes a given relative path. This method always return with a path
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
112 /// that contains at least one slash. However, a slash should be appended
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
113 /// to string as it never leaves a slash at the end unless, the path is a
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
114 /// root path therefore, it is save to append an extra slash.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
115 /// @param path is the file/directory to be canonized. Should contain
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
116 /// forward slash as directory separator.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
117 /// @return the full path of the given relative path. Forward slashes are
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
118 /// used as directory separator. If the directory is a root directory
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
119 /// this method will return a path ending with slash, otherwise it will
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
120 /// never return a path ending with slash.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
121 /// @throw PathNotFoundError if canonize fails.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
122 std::string Canonical(const std::string &path);
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
123
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
124 /// Determine shortest relative path from the given path. Using "." in
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
125 /// second parameter will return the path relative to current directory.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
126 /// This function never returns a path ending with a slash unless its safe
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
127 /// to append another slash (i.e. a root path)
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
128 /// @param path is the path to be relativized.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
129 /// @param base is the base path that will be used to find relative path
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
130 /// @return relative path. Note that in Windows it is may be impossible
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
131 /// to find relative path.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
132 std::string Relative(std::string path, std::string base=".");
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
133
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
134 /// Deletes the given file or directory. If the directory is not empty,
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
135 /// this function will delete all its contents.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
136 /// @param path is the file/directory to be deleted. Should contain
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
137 /// forward slash as directory separator.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
138 /// @return true if the given path is deleted. If the given path does
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
139 /// not exists, this function will still return true.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
140 bool Delete(const std::string &path);
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
141
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
142 /// Changes current working directory.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
143 /// @param path is the directory to become current directory. Should contain
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
144 /// forward slash as directory separator.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
145 /// @return false if directory does not exist
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
146 bool ChangeDirectory(const std::string &path);
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
147
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
148 /// Returns the current working directory.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
149 /// @return the current working directory Forward slashes are
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
150 /// used as directory separator
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
151 std::string CurrentDirectory();
781
4735258a2a74 * Gorgon::Resource can now save folders and images without the need of another
cemkalyoncu <cemkalyoncu@gmail.com>
parents: 764
diff changeset
152
4735258a2a74 * Gorgon::Resource can now save folders and images without the need of another
cemkalyoncu <cemkalyoncu@gmail.com>
parents: 764
diff changeset
153 /// Joins two given paths or a path and filename
4735258a2a74 * Gorgon::Resource can now save folders and images without the need of another
cemkalyoncu <cemkalyoncu@gmail.com>
parents: 764
diff changeset
154 inline std::string Join(std::string path1, const std::string &path2) {
1251
b0655bf8d5c7 * Automatic UI generation framework
cemkalyoncu
parents: 1188
diff changeset
155 if(path1.empty() || path1.back()!='/') {
781
4735258a2a74 * Gorgon::Resource can now save folders and images without the need of another
cemkalyoncu <cemkalyoncu@gmail.com>
parents: 764
diff changeset
156 path1.push_back('/');
4735258a2a74 * Gorgon::Resource can now save folders and images without the need of another
cemkalyoncu <cemkalyoncu@gmail.com>
parents: 764
diff changeset
157 }
4735258a2a74 * Gorgon::Resource can now save folders and images without the need of another
cemkalyoncu <cemkalyoncu@gmail.com>
parents: 764
diff changeset
158 path1+=path2;
4735258a2a74 * Gorgon::Resource can now save folders and images without the need of another
cemkalyoncu <cemkalyoncu@gmail.com>
parents: 764
diff changeset
159
4735258a2a74 * Gorgon::Resource can now save folders and images without the need of another
cemkalyoncu <cemkalyoncu@gmail.com>
parents: 764
diff changeset
160 return path1;
4735258a2a74 * Gorgon::Resource can now save folders and images without the need of another
cemkalyoncu <cemkalyoncu@gmail.com>
parents: 764
diff changeset
161 }
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
162
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
163 /// Returns the directory portion of a file path. If the file path does not contain any directory
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
164 /// related information, this method returns current directory. This function expects the input
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
165 /// to have / as directory separator.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
166 /// @param filepath path that contains the filename
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
167 inline std::string GetDirectory(std::string filepath) {
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
168 auto pos=filepath.find_last_of('/');
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
169
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
170 if(pos!=filepath.npos) {
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
171 filepath=filepath.substr(0,pos);
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
172 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
173 else {
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
174 filepath=CurrentDirectory();
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
175 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
176
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
177 return filepath;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
178 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
179
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
180 /// Returns the filename portion of a file path. This function expects the input to
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
181 /// have / as directory separator. If path does not contain any /, it will return whole input.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
182 /// @param path path that contains the filename
832
c13dae194887 * More design documents
cemkalyoncu <cemkalyoncu@gmail.com>
parents: 781
diff changeset
183 inline std::string GetFilename(std::string path) {
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
184 auto pos=path.find_last_of('/');
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
185
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
186 if(pos!=path.npos) {
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
187 path=path.substr(pos+1);
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
188 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
189
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
190 return path;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
191 }
913
21d5cb584994 * GetBasename / GetExtension function
cemkalyoncu
parents: 832
diff changeset
192
21d5cb584994 * GetBasename / GetExtension function
cemkalyoncu
parents: 832
diff changeset
193 /// Returns the extension of the given path, also converts the extension to lower case
21d5cb584994 * GetBasename / GetExtension function
cemkalyoncu
parents: 832
diff changeset
194 std::string GetExtension(std::string path);
21d5cb584994 * GetBasename / GetExtension function
cemkalyoncu
parents: 832
diff changeset
195
21d5cb584994 * GetBasename / GetExtension function
cemkalyoncu
parents: 832
diff changeset
196 /// Returns the filename from the given path, without extension
21d5cb584994 * GetBasename / GetExtension function
cemkalyoncu
parents: 832
diff changeset
197 inline std::string GetBasename(std::string path) {
21d5cb584994 * GetBasename / GetExtension function
cemkalyoncu
parents: 832
diff changeset
198 path = GetFilename(path);
21d5cb584994 * GetBasename / GetExtension function
cemkalyoncu
parents: 832
diff changeset
199
21d5cb584994 * GetBasename / GetExtension function
cemkalyoncu
parents: 832
diff changeset
200 auto pos = path.find_last_of('.');
21d5cb584994 * GetBasename / GetExtension function
cemkalyoncu
parents: 832
diff changeset
201
21d5cb584994 * GetBasename / GetExtension function
cemkalyoncu
parents: 832
diff changeset
202 if(pos == path.npos) return path;
21d5cb584994 * GetBasename / GetExtension function
cemkalyoncu
parents: 832
diff changeset
203
922
02f6eed8821f * Bitmap font ImportFolder, missing trim and toalpha
cemkalyoncu
parents: 913
diff changeset
204 path = path.substr(0, pos);
913
21d5cb584994 * GetBasename / GetExtension function
cemkalyoncu
parents: 832
diff changeset
205
21d5cb584994 * GetBasename / GetExtension function
cemkalyoncu
parents: 832
diff changeset
206 return path;
21d5cb584994 * GetBasename / GetExtension function
cemkalyoncu
parents: 832
diff changeset
207 }
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
208
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
209 /// Copies a file or directory from the given source to destination.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
210 /// Hard link sources will be copied instead of links themselves.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
211 /// @param source file or directory. Should either be a single file, or single directory
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
212 /// @param target is the new filename or directory name
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
213 /// @return true on success
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
214 bool Copy(const std::string &source, const std::string &target);
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
215
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
216 /// Copies list of files and/or directories from the given source to destination.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
217 /// Hard link sources will be copied instead of links themselves.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
218 /// @param source list of source files or directories
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
219 /// @param target is directory to copy files or directories into. This directory
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
220 /// should exist before calling this function
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
221 /// @return true on success
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
222 template<template<class> class C_>
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
223 bool Copy(const C_<std::string> &source, const std::string &target) {
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
224 for(const auto &s : source) {
832
c13dae194887 * More design documents
cemkalyoncu <cemkalyoncu@gmail.com>
parents: 781
diff changeset
225 if(!Copy(s, target+"/"+GetFilename(s))) return false;
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
226 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
227
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
228 return true;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
229 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
230
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
231 /// Copies list of files and/or directories from the given source to destination.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
232 /// Hard link sources will be copied instead of links themselves.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
233 /// @param source list of source files or directories
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
234 /// @param target is directory to copy files or directories into. This directory
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
235 /// should exist before calling this function
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
236 /// @return true on success
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
237 template<template<class, class> class C_, class A_>
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
238 bool Copy(const C_<std::string, A_> &source, const std::string &target) {
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
239 for(const auto &s : source) {
832
c13dae194887 * More design documents
cemkalyoncu <cemkalyoncu@gmail.com>
parents: 781
diff changeset
240 if(!Copy(s, target+"/"+GetFilename(s))) return false;
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
241 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
242
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
243 return true;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
244 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
245
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
246 /// Copies list of files and/or directories from the given source to destination.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
247 /// Hard link sources will be copied instead of links themselves.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
248 /// @param begin starting iterator
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
249 /// @param end ending iterator, will not be dereferenced
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
250 /// @param target is directory to copy files or directories into. This directory
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
251 /// should exist before calling this function
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
252 /// @return true on success
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
253 template<class I_>
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
254 bool Copy(const I_ &begin, const I_ &end, const std::string &target) {
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
255 for(I_ it=begin;it!=end;++it) {
832
c13dae194887 * More design documents
cemkalyoncu <cemkalyoncu@gmail.com>
parents: 781
diff changeset
256 if(!Copy(*it, target+"/"+GetFilename(*it))) return false;
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
257 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
258
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
259 return true;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
260 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
261
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
262 /// Copies list of files and/or directories from the given source to destination.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
263 /// Hard link sources will be copied instead of links themselves.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
264 /// @param sourcedir the directory contains source files
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
265 /// @param source list of source files or directories
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
266 /// @param target is directory to copy files or directories into. This directory
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
267 /// should exist before calling this function
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
268 /// @return true on success
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
269 template<template<class> class C_>
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
270 bool Copy(const std::string &sourcedir, const C_<std::string> &source, const std::string &target) {
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
271 for(const auto &s : source) {
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
272 if(!Copy(sourcedir+"/"+s, target+"/"+s)) return false;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
273 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
274
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
275 return true;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
276 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
277
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
278 /// Copies list of files and/or directories from the given source to destination.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
279 /// Hard link sources will be copied instead of links themselves.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
280 /// @param sourcedir the directory contains source files
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
281 /// @param begin starting iterator
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
282 /// @param end ending iterator, will not be dereferenced
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
283 /// @param target is directory to copy files or directories into. This directory
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
284 /// should exist before calling this function
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
285 /// @return true on success
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
286 template<class I_>
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
287 bool Copy(const std::string &sourcedir, const I_ &begin, const I_ &end, const std::string &target) {
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
288 for(I_ it=begin;it!=end;++it) {
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
289 if(!Copy(sourcedir+"/"+*it, target+"/"+*it)) return false;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
290 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
291
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
292 return true;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
293 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
294
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
295 /// Moves a given file or directory. Target is the new path rather than
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
296 /// the target directory. This function can also be used to rename a file or
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
297 /// directory.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
298 /// @param source file or directory to be moved or renamed
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
299 /// @param target path
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
300 /// @return true on success. On Windows this function may not work across
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
301 /// different drives. If this case is possible, use Copy then Delete.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
302 bool Move(const std::string &source, const std::string &target);
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
303
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
304 /// Returns the size of the given file. If the file is not found 0 is returned.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
305 /// @param filename is the name of the file
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
306 /// @return size of the given file
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
307 unsigned long long Size(const std::string &filename);
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
308
1607
31c7f370894e * ChangeTime for files
cemkalyoncu
parents: 1561
diff changeset
309 /// Returns the modification time of the given file. If file is not found 0 is returned.
31c7f370894e * ChangeTime for files
cemkalyoncu
parents: 1561
diff changeset
310 time_t ModificationTime(const std::string &filename);
31c7f370894e * ChangeTime for files
cemkalyoncu
parents: 1561
diff changeset
311
31c7f370894e * ChangeTime for files
cemkalyoncu
parents: 1561
diff changeset
312 /// Returns the change time of the given file. This should be preferred for change detection.
31c7f370894e * ChangeTime for files
cemkalyoncu
parents: 1561
diff changeset
313 /// If file is not found 0 is returned.
31c7f370894e * ChangeTime for files
cemkalyoncu
parents: 1561
diff changeset
314 time_t ChangeTime(const std::string &filename);
31c7f370894e * ChangeTime for files
cemkalyoncu
parents: 1561
diff changeset
315
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
316 /// Saves a given data into the filename. If the file exists, it will be appended
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
317 /// if append parameter is set to true. This function can handle binary data.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
318 bool Save(const std::string &filename, const std::string &data, bool append=false);
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
319
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
320 /// Loads the given file and returns it in a string form. Notice that there is no
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
321 /// size restriction over the file. This function can handle binary data. Throws
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
322 /// PathNotFoundError if the file cannot be found. Before deciding on file is not
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
323 /// found, this function checks if there is a lzma compressed file as filename.lzma
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
324 /// @param filename is the file to be loaded
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
325 /// @return the data loaded from the file
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
326 /// @throw PathNotFoundError if the file cannot be read or does not exits
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
327 std::string Load(const std::string &filename);
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
328
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
329 /// Returns the directory where the program is started from. This will always return the same value
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
330 /// through out the execution.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
331 std::string StartupDirectory();
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
332
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
333 /// Returns the the full path of the application
832
c13dae194887 * More design documents
cemkalyoncu <cemkalyoncu@gmail.com>
parents: 781
diff changeset
334 std::string ExePath();
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
335
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
336 /// Returns the directory where the program resides. Can be used to locate resources. May not be
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
337 /// same as StartupDirectory
832
c13dae194887 * More design documents
cemkalyoncu <cemkalyoncu@gmail.com>
parents: 781
diff changeset
338 std::string ExeDirectory();
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
339
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
340 /// This function returns all entry points in the current system. This function does not
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
341 /// perform caching and should be used sparingly. It may cause Windows systems to read
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
342 /// external devices. On Linux systems, home, root and removable devices are listed.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
343 /// @return The list of entry points
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
344 std::vector<EntryPoint> EntryPoints();
1561
5de6522d46db * Filesystem::Collect to collect list of files from a directory
cemkalyoncu
parents: 1251
diff changeset
345
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
346 /// Locates the given file or directory. If localonly is true, this function only
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
347 /// searches locations that are in the working directory. If it is set to false
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
348 /// standard system locations like user home directory or application data directory
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
349 /// is also searched. While looking for the resource, if the directory parameter is
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
350 /// not empty, the resource is expected to be in the given directory under the local
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
351 /// or system wide directory. Additionally, if the file is found as a lzma compressed
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
352 /// file, it will be extracted. For instance, if directory parameter is "images",
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
353 /// localonly is false, systemname is system and we are looking for icon.png, this
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
354 /// function checks whether file exists in the following forms.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
355 /// The first one found is returned, if none exists, PathNotFoundError exception is thrown.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
356 /// The following list assume user path to be ~ application data path to be ~/apps
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
357 /// images/icon.png, ../images/icon.png, icon.png, ../icon.png,
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
358 /// images/icon.png.lzma, ../images/icon.png.lzma, icon.png.lzma, ../icon.png.lzma,
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
359 /// ~/.system/images/icon.png, ~/.system/images/icon.png.lzma, ~/apps/.system/images/icon.png,
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
360 /// ~/apps/.system/images/icon.png.lzma, ~/system/images/icon.png, ~/system/images/icon.png.lzma,
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
361 /// ~/apps/system/images/icon.png, ~/apps/system/images/icon.png.lzma, ~/images/icon.png,
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
362 /// ~/images/icon.png.lzma, ~/apps/images/icon.png, ~/apps/images/icon.png.lzma,
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
363 /// ~/system/icon.png, ~/system/icon.png.lzma, ~/apps/system/icon.png,
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
364 /// ~/apps/system/icon.png.lzma
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
365 /// If compressed file is found, it will be extracted in place, and the extracted filename
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
366 /// will be returned. Therefore, its not necessary to check if the file is compressed or not.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
367 /// @param path is the filename or directory to be searched. Only compressed files are handled.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
368 /// @param directory is the directory the resource expected to be in. Should be relative.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
369 /// @param localonly if set, no system or user directories will be searched
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
370 /// @return the full path of the resource
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
371 /// @throw PathNotFoundError if the file cannot be found
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
372 /// @throw std::runtime_error if the file cannot be read
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
373 std::string LocateResource(const std::string &path, const std::string &directory="", bool localonly=true);
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
374
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
375 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
376
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
377 }

mercurial