1 /*************************************************************************** 2 * Mechanized Assault and Exploration Reloaded Projectfile * 3 * * 4 * This program is free software; you can redistribute it and/or modify * 5 * it under the terms of the GNU General Public License as published by * 6 * the Free Software Foundation; either version 2 of the License, or * 7 * (at your option) any later version. * 8 * * 9 * This program is distributed in the hope that it will be useful, * 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 12 * GNU General Public License for more details. * 13 * * 14 * You should have received a copy of the GNU General Public License * 15 * along with this program; if not, write to the * 16 * Free Software Foundation, Inc., * 17 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 18 ***************************************************************************/ 19 20 #ifndef utility_filesH 21 #define utility_filesH 22 23 #include <string> 24 //#include "defines.h" 25 #include <vector> 26 27 #include <SDL.h> 28 29 /** 30 * Checks whether a file exists or not 31 * @author beko 32 * @param path Filename to check for 33 * @return true if exists (as in readable) 34 * @return false if does not exist (as in not readable) 35 */ 36 bool FileExists (const char* path); 37 38 /** 39 * Checks whether a directory exists. 40 * @param path Path to check for 41 * @return true if the directory exists. Else false. 42 */ 43 bool DirExists (const std::string& path); 44 45 /** 46 * Creates a new directory. 47 * @param Path to the directory to create. 48 * @return True if the directoy has been created successfully. False on errors. 49 */ 50 bool makeDir (const std::string& path); 51 52 /** 53 * Gets the filenames of all files in the directory 54 * @author alzi 55 * @param sDirectory Directory in which to search 56 * @return A new list with all filenames 57 */ 58 std::vector<std::string> getFilesOfDirectory (const std::string& sDirectory); 59 60 /** 61 * Gets the map folder of the user's custom maps. 62 * @author pagra 63 * @return an absolute path to the user's maps directory or empty string, if no user maps folder is defined on the system 64 */ 65 std::string getUserMapsDir(); 66 67 /** 68 * Gets the folder, where screenshots made by the user should be saved. 69 * @author pagra 70 * @return an absolute path to the user's screenshots directory or empty string, if no user screenshots folder is defined on the system 71 */ 72 std::string getUserScreenshotsDir(); 73 74 std::string getUserLogDir(); 75 void copyFile (const std::string& source, const std::string& dest); 76 77 /** 78 * @author pagra 79 * @return a checksum of all bytes in the given data chunk 80 */ 81 uint32_t calcCheckSum (const char* data, size_t dataSize, uint32_t checksum = 0); 82 uint32_t calcCheckSum (uint32_t data, uint32_t checksum); 83 84 #endif // utility_filesH 85