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/>.
22 /** Provides an easy method of reading a text file into memory. */
23 class CoreExport FileReader
25 /** The lines of text in the file. */
26 std::vector<std::string> lines;
28 /** File size in bytes. */
29 unsigned long totalSize;
32 /** Initializes a new file reader. */
33 FileReader() : totalSize(0) { }
35 /** Initializes a new file reader and reads the specified file.
36 * @param filename The file to read into memory.
38 FileReader(const std::string& filename);
40 /** Loads a text file from disk.
41 * @param filename The file to read into memory.
42 * @throw CoreException The file can not be loaded.
44 void Load(const std::string& filename);
46 /** Retrieves the entire contents of the file cache as a single string. */
47 std::string GetString() const;
49 /** Retrieves the entire contents of the file cache as a vector of strings. */
50 const std::vector<std::string>& GetVector() const { return lines; }
52 /** Retrieves the total size in bytes of the file. */
53 unsigned long TotalSize() const { return totalSize; }
56 /** Implements methods for file system access */
57 class CoreExport FileSystem
63 /** Expands a path fragment to a full path.
64 * @param base The base path to expand from
65 * @param fragment The path fragment to expand on top of base.
67 static std::string ExpandPath(const std::string& base, const std::string& fragment);
70 * Checks whether a file with the specified name exists on the filesystem.
71 * @param path The path to a file.
72 * @return True if the file exists; otherwise, false.
74 static bool FileExists(const std::string& path);
76 /** Gets the file name segment of a path.
77 * @param path The path to extract the file name from.
78 * @return The file name segment of a path.
80 static std::string GetFileName(const std::string& path);
82 /** Determines whether the given path starts with a Windows drive letter.
83 * @param path The path to validate.
84 * @returns True if the path begins with a Windows drive letter; otherwise, false.
86 static bool StartsWithWindowsDriveLetter(const std::string& path);