datapaths.h
1 //------------------------------------------------------------------------------
2 // datapaths.h
3 //------------------------------------------------------------------------------
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, 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 
81 class MAIN_EXPORT DataPaths
82 {
83  public:
84  enum MachineType
85  {
86  x86,
87  x64,
88  Preferred
89  };
90 
91  static const QString PROGRAMS_APPDATA_DIR_NAME;
92  static const QString PROGRAMS_APPDATASUPPORT_DIR_NAME;
93  static const QString DEMOS_DIR_NAME;
94  static const QString CHATLOGS_DIR_NAME;
95  static const QString TRANSLATIONS_DIR_NAME;
96  static const QString UPDATE_PACKAGES_DIR_NAME;
97  static const QString UPDATE_PACKAGE_FILENAME_PREFIX;
98 
109  static QString programFilesDirectory(MachineType machineType);
110 
122  static QStringList staticDataSearchDirs(const QString& subdir = QString());
123 
124  static void initDefault(bool bPortableModeOn);
131  static DataPaths *defaultInstance();
132 
133  DataPaths(bool bPortableModeOn = false);
134  virtual ~DataPaths();
135 
141  QStringList canWrite() const;
142 
154  bool createDirectories();
155 
156  QString demosDirectoryPath() const;
157 
163  QStringList directoriesExist() const;
164 
175  QString documentsLocationPath(const QString &subpath = QString()) const;
176 
190  QString localDataLocationPath(const QString& subpath = QString()) const;
191 
204  QString pluginDocumentsLocationPath(const EnginePlugin &plugin) const;
205 
221  QString pluginLocalDataLocationPath(const EnginePlugin &plugin) const;
222 
232  QString programsDataDirectoryPath() const;
233 
237  const QString &programDirName() const;
238 
244  QString programsDataSupportDirectoryPath() const;
245 
246  bool isPortableModeOn() const;
247 
248  void setPortableModeOn(bool b);
249  void setProgramDirName(const QString& name);
250  void setWorkingDirectory(const QString &workingDirectory);
251 
268  QString systemAppDataDirectory(QString append = QString()) const;
269 
274  bool validateAppDataDirectory();
275 
279  const QString &workingDirectory() const;
280 
281  protected:
286  static bool validateDir(const QString& path);
287 
291  bool tryCreateDirectory(const QDir& rootDir, const QString& dirToCreate) const;
292 
293  private:
294  DPtr<DataPaths> d;
295 
296  static QString env(const QString &key);
297  static DataPaths *staticDefaultInstance;
298 };
299 
300 #endif
Represents directories used by Doomseeker to store data.
Definition: datapaths.h:81