datapaths.h
1 //------------------------------------------------------------------------------
2 // datapaths.h
3 //------------------------------------------------------------------------------
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library 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 GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 // 02110-1301 USA
19 //
20 //------------------------------------------------------------------------------
21 // Copyright (C) 2010 "Zalewa" <zalewapl@gmail.com>
22 //------------------------------------------------------------------------------
23 #ifndef __DATAPATHS_H__
24 #define __DATAPATHS_H__
25 
26 #include "global.h"
27 #include "dptr.h"
28 #include <QDir>
29 #include <QString>
30 #include <QStringList>
31 
32 #define gDefaultDataPaths (DataPaths::defaultInstance())
33 
34 class EnginePlugin;
35 
82 class MAIN_EXPORT DataPaths
83 {
84  public:
85  enum MachineType
86  {
87  x86,
88  x64,
89  Preferred
90  };
91 
92  static const QString CHATLOGS_DIR_NAME;
93  static const QString TRANSLATIONS_DIR_NAME;
94  static const QString UPDATE_PACKAGES_DIR_NAME;
95  static const QString UPDATE_PACKAGE_FILENAME_PREFIX;
96 
101  struct DirErrno
102  {
103  static const int CUSTOM_ERROR = -1;
104 
105  QDir directory;
106  int errnoNum;
107  QString errnoString;
108 
109  DirErrno() : errnoNum(0) {}
110 
111  DirErrno(QDir directory, int errnoNum, QString errnoString)
112  : directory(directory), errnoNum(errnoNum), errnoString(errnoString)
113  {}
114 
115  bool isError() const
116  {
117  return errnoNum != 0;
118  }
119  };
120 
131  static QString programFilesDirectory(MachineType machineType);
132 
144  static QStringList staticDataSearchDirs(const QString& subdir = QString());
145 
146  static void initDefault(bool bPortableModeOn);
153  static DataPaths *defaultInstance();
154 
155  DataPaths(bool bPortableModeOn = false);
156  virtual ~DataPaths();
157 
165  QString cacheLocationPath() const;
166 
172  QStringList canWrite() const;
173 
184  QList<DirErrno> createDirectories();
185 
191  QStringList defaultWadPaths() const;
192 
193  QString demosDirectoryPath() const;
194 
205  QString documentsLocationPath(const QString &subpath = QString()) const;
206 
220  QString localDataLocationPath(const QString& subpath = QString()) const;
221 
234  QString pluginDocumentsLocationPath(const EnginePlugin &plugin) const;
235 
251  QString pluginLocalDataLocationPath(const EnginePlugin &plugin) const;
252 
259  QStringList pluginSearchLocationPaths() const;
260 
270  QString programsDataDirectoryPath() const;
271 
272  bool isPortableModeOn() const;
273 
281  void setWorkingDirectory(const QString &workingDirectory);
282 
301  QString systemAppDataDirectory(QString append = QString()) const;
302 
307  bool validateAppDataDirectory();
308 
316  const QString &workingDirectory() const;
317 
318  protected:
323  static bool validateDir(const QString& path);
324 
328  DirErrno tryCreateDirectory(const QDir& rootDir, const QString& dirToCreate) const;
329 
330  private:
331  DPtr<DataPaths> d;
332 
333  static QString env(const QString &key);
334  static DataPaths *staticDefaultInstance;
335 };
336 
337 #endif
Represents directories used by Doomseeker to store data.
Definition: datapaths.h:82
Struct which contains the relevant QDir, the errno reported, and the QString generated by the errno...
Definition: datapaths.h:101