author | nemo |
Thu, 24 Nov 2011 16:40:17 -0500 | |
changeset 6419 | 6a464d0a5c13 |
parent 6215 | efe2e2f7cabf |
child 6616 | f77bb02b669f |
permissions | -rw-r--r-- |
6159
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
1 |
/* |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
2 |
* Hedgewars, a free turn based strategy game |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
3 |
* Copyright (c) 2006-2007 Igor Ulyanov <iulyanov@gmail.com> |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
4 |
* Copyright (c) 2007-2011 Andrey Korotaev <unC0Rr@gmail.com> |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
5 |
* |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
6 |
* This program is free software; you can redistribute it and/or modify |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
7 |
* it under the terms of the GNU General Public License as published by |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
8 |
* the Free Software Foundation; version 2 of the License |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
9 |
* |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
10 |
* This program is distributed in the hope that it will be useful, |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
13 |
* GNU General Public License for more details. |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
14 |
* |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
16 |
* along with this program; if not, write to the Free Software |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
18 |
*/ |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
19 |
|
6168 | 20 |
/** |
6170 | 21 |
* @file |
6168 | 22 |
* @brief HWDataManager class definition |
23 |
*/ |
|
24 |
||
6159
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
25 |
#ifndef HEDGEWARS_HWDATAMANAGER_H |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
26 |
#define HEDGEWARS_HWDATAMANAGER_H |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
27 |
|
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
28 |
#include <QDir> |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
29 |
#include <QFile> |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
30 |
|
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
31 |
#include <QStringList> |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
32 |
|
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
33 |
class QDir; |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
34 |
class QFile; |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
35 |
class QStringList; |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
36 |
|
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
37 |
/** |
6160
863d3edf5690
cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents:
6159
diff
changeset
|
38 |
* @brief Offers access to the data files of hedgewars. |
863d3edf5690
cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents:
6159
diff
changeset
|
39 |
* |
863d3edf5690
cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents:
6159
diff
changeset
|
40 |
* @see <a href="http://en.wikipedia.org/wiki/Singleton_pattern">singleton pattern</a> |
863d3edf5690
cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents:
6159
diff
changeset
|
41 |
* |
6159
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
42 |
* @author sheepluva |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
43 |
* @since 0.9.17 |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
44 |
*/ |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
45 |
class HWDataManager |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
46 |
{ |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
47 |
public: |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
48 |
/** |
6165
6fe3e922246e
moving and renaming SDLs.*, making it a singleton; cleaning up class responsibilties wrt SDLInteraction; some comments
sheepluva
parents:
6162
diff
changeset
|
49 |
* @brief Returns reference to the <i>singleton</i> instance of this class. |
6160
863d3edf5690
cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents:
6159
diff
changeset
|
50 |
* |
863d3edf5690
cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents:
6159
diff
changeset
|
51 |
* @see <a href="http://en.wikipedia.org/wiki/Singleton_pattern">singleton pattern</a> |
863d3edf5690
cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents:
6159
diff
changeset
|
52 |
* |
6165
6fe3e922246e
moving and renaming SDLs.*, making it a singleton; cleaning up class responsibilties wrt SDLInteraction; some comments
sheepluva
parents:
6162
diff
changeset
|
53 |
* @return reference to the instance. |
6159
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
54 |
*/ |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
55 |
static HWDataManager & instance(); |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
56 |
|
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
57 |
/** |
6215 | 58 |
* @brief Returns a sorted list of data directory entries. |
6160
863d3edf5690
cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents:
6159
diff
changeset
|
59 |
* |
6159
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
60 |
* @param subDirectory sub-directory to search. |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
61 |
* @param filters filters for entry type. |
6160
863d3edf5690
cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents:
6159
diff
changeset
|
62 |
* @param nameFilters filters by name patterns. |
863d3edf5690
cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents:
6159
diff
changeset
|
63 |
* @return a sorted list of matches in the subDirectory of data directory. |
6159
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
64 |
*/ |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
65 |
QStringList entryList(const QString & subDirectory, |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
66 |
QDir::Filters filters = QDir::NoFilter, |
6160
863d3edf5690
cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents:
6159
diff
changeset
|
67 |
const QStringList & nameFilters = QStringList("*") |
6159
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
68 |
) const; |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
69 |
|
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
70 |
/** |
6196 | 71 |
* @brief Returns the path for the desires data file. |
6160
863d3edf5690
cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents:
6159
diff
changeset
|
72 |
* |
863d3edf5690
cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents:
6159
diff
changeset
|
73 |
* Use this method if you want to read an existing data file. |
863d3edf5690
cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents:
6159
diff
changeset
|
74 |
* |
6167 | 75 |
* @param relativeDataFilePath relative path of the data file. |
76 |
* @return real path to the file. |
|
6159
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
77 |
*/ |
6167 | 78 |
QString findFileForRead(const QString & relativeDataFilePath) const; |
6159
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
79 |
|
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
80 |
|
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
81 |
/** |
6196 | 82 |
* @brief Returns the path for the data file that is to be written. |
6160
863d3edf5690
cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents:
6159
diff
changeset
|
83 |
* |
6159
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
84 |
* Use this method if you want to create or write into a data file. |
6160
863d3edf5690
cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents:
6159
diff
changeset
|
85 |
* |
6196 | 86 |
* @param relativeDataFilePath relative path of data file write path. |
87 |
* @return destination of path data file. |
|
6159
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
88 |
*/ |
6196 | 89 |
QString findFileForWrite(const QString & relativeDataFilePath) const; |
6159
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
90 |
|
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
91 |
|
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
92 |
private: |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
93 |
/** |
6160
863d3edf5690
cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents:
6159
diff
changeset
|
94 |
* @brief Class constructor of the <i>singleton</i>. |
863d3edf5690
cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents:
6159
diff
changeset
|
95 |
* |
863d3edf5690
cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents:
6159
diff
changeset
|
96 |
* Not to be used from outside the class, |
863d3edf5690
cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents:
6159
diff
changeset
|
97 |
* use the static {@link HWDataManager::instance()} instead. |
863d3edf5690
cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents:
6159
diff
changeset
|
98 |
* |
863d3edf5690
cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents:
6159
diff
changeset
|
99 |
* @see <a href="http://en.wikipedia.org/wiki/Singleton_pattern">singleton pattern</a> |
6159
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
100 |
*/ |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
101 |
HWDataManager(); |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
102 |
|
6162 | 103 |
QDir * defaultData; ///< directory of the installed data |
104 |
QDir * userData; ///< directory of custom data in the user's directory |
|
6159
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
105 |
}; |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
106 |
|
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
107 |
#endif // HEDGEWARS_HWDATAMANAGER_H |