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 
43 class MAIN_EXPORT DataPaths
44 {
45  public:
46  enum MachineType
47  {
48  x86,
49  x64,
50  Preferred
51  };
52 
53  static const QString PROGRAMS_APPDATA_DIR_NAME;
54  static const QString PROGRAMS_APPDATASUPPORT_DIR_NAME;
55  static const QString DEMOS_DIR_NAME;
56  static const QString CHATLOGS_DIR_NAME;
57  static const QString TRANSLATIONS_DIR_NAME;
58  static const QString UPDATE_PACKAGES_DIR_NAME;
59  static const QString UPDATE_PACKAGE_FILENAME_PREFIX;
60 
71  static QString programFilesDirectory(MachineType machineType);
72 
84  static QStringList staticDataSearchDirs(const QString& subdir = QString());
85 
86  static void initDefault(bool bPortableModeOn);
93  static DataPaths *defaultInstance();
94 
95  DataPaths(bool bPortableModeOn = false);
96  virtual ~DataPaths();
97 
103  QStringList canWrite() const;
104 
116  bool createDirectories();
117 
118  QString demosDirectoryPath() const;
119 
125  QStringList directoriesExist() const;
126 
140  QString localDataLocationPath(const QString& subpath = QString()) const;
141 
151  QString programsDataDirectoryPath() const;
152 
156  const QString &programDirName() const;
157 
163  QString programsDataSupportDirectoryPath() const;
164 
165  bool isPortableModeOn() const;
166 
167  void setPortableModeOn(bool b);
168  void setProgramDirName(const QString& name);
169  void setWorkingDirectory(const QString &workingDirectory);
170 
187  QString systemAppDataDirectory(QString append = QString()) const;
188 
193  bool validateAppDataDirectory();
194 
198  const QString &workingDirectory() const;
199 
200  protected:
205  static bool validateDir(const QString& path);
206 
210  bool tryCreateDirectory(const QDir& rootDir, const QString& dirToCreate) const;
211 
212  private:
213  DPtr<DataPaths> d;
214 
215  static DataPaths *staticDefaultInstance;
216 };
217 
218 #endif
Represents directories used by Doomseeker to store data.
Definition: datapaths.h:43