initial commit, lordsawar source, slightly modified
[lordsawar] / src / File.h
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
6 //
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.
11 //
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.
16 //
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 
20 //  02110-1301, USA.
21
22 #ifndef FILE_H
23 #define FILE_H
24
25 #include <string>
26 #include <list>
27
28 #include "xmlhelper.h"
29
30 /** \brief Miscellaneous functions for file access
31   * 
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.
37   */
38
39 class File
40 {
41     public:
42         //! Get the directory where personal armysets live.
43         static std::string getUserArmysetDir();
44
45         //! Get the directory where system armysets live.
46         static std::string getArmysetDir();
47
48         //! Get the directory where personal tilesets live.
49         static std::string getUserTilesetDir();
50
51         //! Get the directory where system tilesets live.
52         static std::string getTilesetDir();
53
54         //! Get the directory where personal shieldsets live.
55         static std::string getUserShieldsetDir();
56
57         //! Get the directory where system shieldsets live.
58         static std::string getShieldsetDir();
59
60         //! Get the directory where personal citysets live.
61         static std::string getUserCitysetDir();
62
63         //! Get the directory where system citysets live.
64         static std::string getCitysetDir();
65
66         //! load misc file, e.g. hero names 
67         static std::string getMiscFile(std::string filename);
68         
69         //! Load the xml file describing the items
70         static std::string getItemDescription();
71         
72         //! Get the path to an editor image
73         static std::string getEditorFile(std::string filename);
74     
75         // Returns the filename of a music file (description or actual piece)
76         static std::string getMusicFile(std::string filename);
77         
78         // get save game path
79         static std::string getSavePath();
80
81         //! get game data path
82         static std::string getDataPath();
83
84         //! the location of the system directory that holds scenario terrains.
85         static std::string getMapDir();
86
87         //! the location of the system directory that holds personal terrains.
88         static std::string getUserMapDir();
89
90         //! get the path of a system scenario file called file.
91         static std::string getMapFile(std::string file);
92
93         //! get the path of a personal scenario called file.
94         static std::string getUserMapFile(std::string file);
95
96         // get the available scenarios
97         static std::list<std::string> scanMaps();
98
99         // get the available scenarios in the user's personal collection
100         static std::list<std::string> scanUserMaps();
101
102
103         //! Copy a file from one place to another.
104         static int copy (Glib::ustring from, Glib::ustring to);
105
106         //! make a directory if it doesn't already exist.
107         static bool create_dir(std::string dir);
108
109         //! simple basename routine, but also strips the file extension.
110         static std::string get_basename(std::string path, bool keep_ext=false);
111
112         //! is a file writable?
113         static bool is_writable(std::string path);
114
115         //! does a file exist?
116         static bool exists(std::string f);
117
118         //! does filename end with extension?
119         static bool nameEndsWith(std::string filename, std::string extension);
120
121         //! delete a file from the filesystem.
122         static void erase(std::string filename);
123
124         //! delete an empty directory from the filesystem.
125         static void erase_dir(std::string filename);
126
127         static std::string add_slash_if_necessary(std::string dir);
128
129         static std::string getSetConfigurationFilename(std::string dir, std::string subdir, std::string ext);
130
131         static std::string get_dirname(std::string path);
132
133         static std::list<std::string> scanFiles(std::string dir, std::string ext);
134 };
135
136 #endif //FILE_H
137
138 // End of file