1 // Copyright (C) 2000, 2001, 2002, 2003 Michael Bartl
2 // Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006 Ulf Lorenz
3 // Copyright (C) 2004, 2005, 2006 Andrea Paternesi
4 // Copyright (C) 2006, 2007, 2008, 2009 Ben Asselstine
5 // Copyright (C) 2007 Ole Laursen
7 // This program is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation; either version 3 of the License, or
10 // (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Library General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
28 #include "xmlhelper.h"
30 /** \brief Miscellaneous functions for file access
32 * These functions should be the sole way to access any files. They will
33 * automatically prepend the correct directory, extract the correct file etc.
34 * This enables us to install and package LordsAWar (there is no fixed
35 * directory structure). To use these functions, you issue e.g. an armyset name
36 * and have the full path returned, which is a file you can then load.
42 //! Get the directory where personal armysets live.
43 static std::string getUserArmysetDir();
45 //! Get the directory where system armysets live.
46 static std::string getArmysetDir();
48 //! Get the directory where personal tilesets live.
49 static std::string getUserTilesetDir();
51 //! Get the directory where system tilesets live.
52 static std::string getTilesetDir();
54 //! Get the directory where personal shieldsets live.
55 static std::string getUserShieldsetDir();
57 //! Get the directory where system shieldsets live.
58 static std::string getShieldsetDir();
60 //! Get the directory where personal citysets live.
61 static std::string getUserCitysetDir();
63 //! Get the directory where system citysets live.
64 static std::string getCitysetDir();
66 //! load misc file, e.g. hero names
67 static std::string getMiscFile(std::string filename);
69 //! Load the xml file describing the items
70 static std::string getItemDescription();
72 //! Get the path to an editor image
73 static std::string getEditorFile(std::string filename);
75 // Returns the filename of a music file (description or actual piece)
76 static std::string getMusicFile(std::string filename);
79 static std::string getSavePath();
81 //! get game data path
82 static std::string getDataPath();
84 //! the location of the system directory that holds scenario terrains.
85 static std::string getMapDir();
87 //! the location of the system directory that holds personal terrains.
88 static std::string getUserMapDir();
90 //! get the path of a system scenario file called file.
91 static std::string getMapFile(std::string file);
93 //! get the path of a personal scenario called file.
94 static std::string getUserMapFile(std::string file);
96 // get the available scenarios
97 static std::list<std::string> scanMaps();
99 // get the available scenarios in the user's personal collection
100 static std::list<std::string> scanUserMaps();
103 //! Copy a file from one place to another.
104 static int copy (Glib::ustring from, Glib::ustring to);
106 //! make a directory if it doesn't already exist.
107 static bool create_dir(std::string dir);
109 //! simple basename routine, but also strips the file extension.
110 static std::string get_basename(std::string path, bool keep_ext=false);
112 //! is a file writable?
113 static bool is_writable(std::string path);
115 //! does a file exist?
116 static bool exists(std::string f);
118 //! does filename end with extension?
119 static bool nameEndsWith(std::string filename, std::string extension);
121 //! delete a file from the filesystem.
122 static void erase(std::string filename);
124 //! delete an empty directory from the filesystem.
125 static void erase_dir(std::string filename);
127 static std::string add_slash_if_necessary(std::string dir);
129 static std::string getSetConfigurationFilename(std::string dir, std::string subdir, std::string ext);
131 static std::string get_dirname(std::string path);
133 static std::list<std::string> scanFiles(std::string dir, std::string ext);