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 "dptr.h"
27 #include "global.h"
28 #include <QDir>
29 #include <QString>
30 #include <QStringList>
31 #include <utility>
32 
33 #define gDefaultDataPaths (DataPaths::defaultInstance())
34 
35 struct DirErrno;
36 class EnginePlugin;
37 
88 class MAIN_EXPORT DataPaths
89 {
90 public:
91  enum MachineType
92  {
93  x86,
94  x64,
95  Preferred
96  };
97 
98  static const QString CHATLOGS_DIR_NAME;
99  static const QString TRANSLATIONS_DIR_NAME;
100  static const QString UPDATE_PACKAGES_DIR_NAME;
101  static const QString UPDATE_PACKAGE_FILENAME_PREFIX;
102 
113  static QString programFilesDirectory(MachineType machineType);
114 
126  static QStringList staticDataSearchDirs(const QString &subdir = QString());
127 
128  static void initDefault(bool bPortableModeOn);
135  static DataPaths *defaultInstance();
136 
137  DataPaths(bool bPortableModeOn = false);
138  virtual ~DataPaths();
139 
148  QString cacheLocationPath() const;
149 
157  QStringList canWrite() const;
158 
170  QList<DirErrno> createDirectories();
171 
177  QStringList defaultWadPaths() const;
178 
182  QString demosDirectoryPath() const;
183 
194  QString documentsLocationPath(const QString &subpath = QString()) const;
195 
211  QString localDataLocationPath(const QString &subpath = QString()) const;
212 
226  QString pluginDocumentsLocationPath(const EnginePlugin &plugin) const;
227 
246  QString pluginLocalDataLocationPath(const EnginePlugin &plugin) const;
247 
255  QStringList pluginSearchLocationPaths() const;
256 
264  QString programsDataDirectoryPath() const;
265 
275  QString portablizePath(const QString &path) const;
276 
277  bool isPortableModeOn() const;
278 
288  void setBaseDir(const QDir &baseDir);
289 
300  void setWorkingDirectory(const QString &workingDirectory);
301 
322  QString systemAppDataDirectory(QString append = QString()) const;
323 
332  bool validateAppDataDirectory();
333 
344  const QString &workingDirectory() const;
345 
346 protected:
351  static bool validateDir(const QString &path);
352 
353 private:
354  DPtr<DataPaths> d;
355 
356  static QString env(const QString &key);
357  static DataPaths *staticDefaultInstance;
358 };
359 
360 #endif