Stellarium 0.12.4
StelFileMgr.hpp
1 /*
2  * Stellarium
3  * Copyright (C) 2008 Stellarium Developers
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
18  */
19 
20 #ifndef _STELFILEMGR_HPP_
21 #define _STELFILEMGR_HPP_
22 
23 #define CHECK_FILE "data/ssystem.ini"
24 
25 #include <stdexcept>
26 #include <QSet>
27 #include <QString>
28 #include <QStringList>
29 
41 {
42 public:
44  enum Flags {
45  RemovableMedia = 0x00000001,
46  Writable = 0x00000002,
47 
48  Directory = 0x00000004,
49  File = 0x00000008,
50  New = 0x00000010,
51  Hidden = 0x00000020
52  };
53 
59  static void init();
60 
79  static QString findFile(const QString& path, const Flags& flags=(Flags)0);
80 
86  static QStringList findFileInAllPaths(const QString& path, const Flags& flags=(Flags)0);
87 
95  static QSet<QString> listContents(const QString& path, const Flags& flags=(Flags)0, bool recursive=false);
96 
99  static const QStringList& getSearchPaths(void) {return fileLocations;}
100 
103  static void setSearchPaths(const QStringList& paths);
104 
107  static void makeSureDirExistsAndIsWritable(const QString& dirFullPath);
108 
111  static bool exists(const QString& path);
112 
115  static bool isAbsolute(const QString& path);
116 
120  static bool isReadable(const QString& path);
121 
129  static bool isWritable(const QString& path);
130 
133  static bool isDirectory(const QString& path);
134 
137  static qint64 size(const QString& path);
138 
142  static bool mkDir(const QString& path);
143 
147  static QString dirName(const QString& path);
148 
152  static QString baseName(const QString& path);
153 
163  static QString getDesktopDir();
164 
172  static QString getUserDir();
173 
179  static QString getInstallationDir();
180 
182  static QString getCacheDir();
183 
187  static void setUserDir(const QString& newDir);
188 
194  static QString getScreenshotDir();
195 
201  static void setScreenshotDir(const QString& newDir);
202 
205  static QString getLocaleDir();
206 
207 private:
208 
210  StelFileMgr() {;}
211 
217  static bool fileFlagsCheck(const QString& path, const Flags& flags=(Flags)0);
218 
219  static QStringList fileLocations;
220 
222  static QString userDir;
223 
225  static QString screenshotDir;
226 
227 #ifdef Q_OS_WIN
228 
229 
230  static QString getWin32SpecialDirPath(int csidlId);
231 #endif
232 
233 };
234 
235 #endif // _STELFILEMGR_HPP_