2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2013 Peter Powell <petpow@saberuk.com>
6 * This file is part of InspIRCd. InspIRCd is free software: you can
7 * redistribute it and/or modify it under the terms of the GNU General Public
8 * License as published by the Free Software Foundation, version 2.
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
26 /** Provides an easy method of reading a text file into memory. */
27 class CoreExport FileReader
29 /** The lines of text in the file. */
30 std::vector<std::string> lines;
32 /** File size in bytes. */
33 unsigned long totalSize;
36 /** Initializes a new file reader. */
37 FileReader() : totalSize(0) { }
39 /** Initializes a new file reader and reads the specified file.
40 * @param filename The file to read into memory.
42 FileReader(const std::string& filename);
44 /** Loads a text file from disk.
45 * @param filename The file to read into memory.
46 * @throw CoreException The file can not be loaded.
48 void Load(const std::string& filename);
50 /** Retrieves the entire contents of the file cache as a single string. */
51 std::string GetString() const;
53 /** Retrieves the entire contents of the file cache as a vector of strings. */
54 const std::vector<std::string>& GetVector() const { return lines; }
56 /** Retrieves the total size in bytes of the file. */
57 unsigned long TotalSize() const { return totalSize; }
60 /** Implements methods for file system access */
61 class CoreExport FileSystem
67 /** Expands a path fragment to a full path.
68 * @param base The base path to expand from
69 * @param fragment The path fragment to expand on top of base.
71 static std::string ExpandPath(const std::string& base, const std::string& fragment);
74 * Checks whether a file with the specified name exists on the filesystem.
75 * @param path The path to a file.
76 * @return True if the file exists; otherwise, false.
78 static bool FileExists(const std::string& path);
80 /** Gets the file name segment of a path.
81 * @param path The path to extract the file name from.
82 * @return The file name segment of a path.
84 static std::string GetFileName(const std::string& path);
86 /** Gets a list of files which exist in the specified directory.
87 * @param directory The directory to retrieve files from.
88 * @param entries A vector which entries will be added to.
89 * @param match If defined then a glob match for files to be matched against.
90 * @return True if the directory could be opened; otherwise false.
92 static bool GetFileList(const std::string& directory, std::vector<std::string>& entries, const std::string& match = "*");
94 /** Determines whether the given path starts with a Windows drive letter.
95 * @param path The path to validate.
96 * @returns True if the path begins with a Windows drive letter; otherwise, false.
98 static bool StartsWithWindowsDriveLetter(const std::string& path);